Templates: use convention s-templates.ext.json for extending templates

This commit is contained in:
Austen Collins 2016-02-10 17:54:21 -08:00
parent 9193c21497
commit d049eafcba
7 changed files with 25 additions and 1 deletions

View File

@ -148,9 +148,15 @@ class ServerlessComponent {
.then(function() {
// Get templates
// TODO: Backwards Compatibility Support -- Remove in V1
if (_this._config.fullPath && SUtils.fileExistsSync(path.join(_this._config.fullPath, 's-templates.json'))) {
componentJson.templates = require(path.join(_this._config.fullPath, 's-templates.json'));
}
// Get templates.ext
if (_this._config.fullPath && SUtils.fileExistsSync(path.join(_this._config.fullPath, 's-templates.ext.json'))) {
componentJson.templates = require(path.join(_this._config.fullPath, 's-templates.ext.json'));
}
})
.then(function() {

View File

@ -172,10 +172,16 @@ class ServerlessFunction {
.then(function() {
// Get templates
// TODO: Backwards Compatibility Support -- Remove in V1
if (_this._config.fullPath && SUtils.fileExistsSync(path.join(_this._config.fullPath, 's-templates.json'))) {
functionJson.templates = require(path.join(_this._config.fullPath, 's-templates.json'));
}
// Get templates.ext
if (_this._config.fullPath && SUtils.fileExistsSync(path.join(_this._config.fullPath, 's-templates.ext.json'))) {
functionJson.templates = require(path.join(_this._config.fullPath, 's-templates.ext.json'));
}
// Get templates in parent folders and merge into this.templates
let parentOne = path.join(_this._config.fullPath, '..'),
parentTwo = path.join(_this._config.fullPath, '..', '..'),
@ -183,14 +189,26 @@ class ServerlessFunction {
parentTemplateTwo = {};
if (!SUtils.fileExistsSync(path.join(parentOne, 's-component.json'))) {
// TODO: Backwards Compatibility Support -- Remove in V1
if (SUtils.fileExistsSync(path.join(parentOne, 's-templates.json'))) {
parentTemplateOne = SUtils.readAndParseJsonSync(path.join(parentOne, 's-templates.json'));
}
if (SUtils.fileExistsSync(path.join(parentOne, 's-templates.ext.json'))) {
parentTemplateOne = SUtils.readAndParseJsonSync(path.join(parentOne, 's-templates.ext.json'));
}
if (!SUtils.fileExistsSync(path.join(parentTwo, 's-component.json'))) {
// TODO: Backwards Compatibility Support -- Remove in V1
if (SUtils.fileExistsSync(path.join(parentTwo, 's-templates.json'))) {
parentTemplateTwo = SUtils.readAndParseJsonSync(path.join(parentTwo, 's-templates.json'));
}
if (SUtils.fileExistsSync(path.join(parentTwo, 's-templates.ext.json'))) {
parentTemplateTwo = SUtils.readAndParseJsonSync(path.join(parentTwo, 's-templates.ext.json'));
}
}
}

View File

@ -65,8 +65,8 @@ describe('Test Serverless Project Class', function() {
it('Get populated instance data', function(done) {
let data = instance.getPopulated({ stage: config.stage, region: config.region });
console.log("here", JSON.stringify(data))
assert.equal(true, JSON.stringify(data).indexOf('$${') == -1);
console.log(JSON.stringify(data))
assert.equal(true, JSON.stringify(data).indexOf('${') == -1);
// We've set a template in the project that gets extended at the module level and function level, check it:
// Project template