From d049eafcbaa2d7daf2e79891d894e024b605b09b Mon Sep 17 00:00:00 2001 From: Austen Collins Date: Wed, 10 Feb 2016 17:54:21 -0800 Subject: [PATCH] Templates: use convention s-templates.ext.json for extending templates --- lib/ServerlessComponent.js | 6 ++++++ lib/ServerlessFunction.js | 18 ++++++++++++++++++ .../{s-templates.json => s-templates.ext.json} | 0 .../{s-templates.json => s-templates.ext.json} | 0 .../{s-templates.json => s-templates.ext.json} | 0 .../{s-templates.json => s-templates.ext.json} | 0 tests/tests/classes/ServerlessProjectTest.js | 2 +- 7 files changed, 25 insertions(+), 1 deletion(-) rename tests/test-prj/nodejscomponent/function0/{s-templates.json => s-templates.ext.json} (100%) rename tests/test-prj/nodejscomponent/group1/function1/{s-templates.json => s-templates.ext.json} (100%) rename tests/test-prj/nodejscomponent/group1/function2/{s-templates.json => s-templates.ext.json} (100%) rename tests/test-prj/nodejscomponent/{s-templates.json => s-templates.ext.json} (100%) diff --git a/lib/ServerlessComponent.js b/lib/ServerlessComponent.js index bc743bf09..3b637db76 100644 --- a/lib/ServerlessComponent.js +++ b/lib/ServerlessComponent.js @@ -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() { diff --git a/lib/ServerlessFunction.js b/lib/ServerlessFunction.js index 0b2a10402..dfeb5ac5e 100644 --- a/lib/ServerlessFunction.js +++ b/lib/ServerlessFunction.js @@ -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')); + } } } diff --git a/tests/test-prj/nodejscomponent/function0/s-templates.json b/tests/test-prj/nodejscomponent/function0/s-templates.ext.json similarity index 100% rename from tests/test-prj/nodejscomponent/function0/s-templates.json rename to tests/test-prj/nodejscomponent/function0/s-templates.ext.json diff --git a/tests/test-prj/nodejscomponent/group1/function1/s-templates.json b/tests/test-prj/nodejscomponent/group1/function1/s-templates.ext.json similarity index 100% rename from tests/test-prj/nodejscomponent/group1/function1/s-templates.json rename to tests/test-prj/nodejscomponent/group1/function1/s-templates.ext.json diff --git a/tests/test-prj/nodejscomponent/group1/function2/s-templates.json b/tests/test-prj/nodejscomponent/group1/function2/s-templates.ext.json similarity index 100% rename from tests/test-prj/nodejscomponent/group1/function2/s-templates.json rename to tests/test-prj/nodejscomponent/group1/function2/s-templates.ext.json diff --git a/tests/test-prj/nodejscomponent/s-templates.json b/tests/test-prj/nodejscomponent/s-templates.ext.json similarity index 100% rename from tests/test-prj/nodejscomponent/s-templates.json rename to tests/test-prj/nodejscomponent/s-templates.ext.json diff --git a/tests/tests/classes/ServerlessProjectTest.js b/tests/tests/classes/ServerlessProjectTest.js index bb09d6e76..10f87a5e4 100644 --- a/tests/tests/classes/ServerlessProjectTest.js +++ b/tests/tests/classes/ServerlessProjectTest.js @@ -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