mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
Merge pull request #1764 from johncmckim/issue-1728
Move variableSyntax into defaults and update docs
This commit is contained in:
commit
6da0e11bd3
@ -19,6 +19,7 @@ plugins:
|
||||
defaults: # overwrite defaults
|
||||
stage: dev
|
||||
region: us-east-1
|
||||
variableSyntax: '\${{([\s\S]+?)}}' # change variable syntax to ${{foo}}
|
||||
|
||||
package:
|
||||
# only the following paths will be included in the resulting artifact which will be uploaded. Without specific include everything in the current folder will be included
|
||||
|
||||
@ -18,8 +18,8 @@ class Service {
|
||||
this.defaults = {
|
||||
stage: 'dev',
|
||||
region: 'us-east-1',
|
||||
variableSyntax: null,
|
||||
};
|
||||
this.variableSyntax = null;
|
||||
this.custom = {};
|
||||
this.plugins = [];
|
||||
this.functions = {};
|
||||
@ -88,7 +88,6 @@ class Service {
|
||||
|
||||
that.service = serverlessYml.service;
|
||||
that.provider = serverlessYml.provider;
|
||||
that.variableSyntax = serverlessYml.variableSyntax;
|
||||
that.custom = serverlessYml.custom;
|
||||
that.plugins = serverlessYml.plugins;
|
||||
that.resources = serverlessYml.resources;
|
||||
@ -116,6 +115,9 @@ class Service {
|
||||
if (serverlessYml.defaults && serverlessYml.defaults.region) {
|
||||
this.defaults.region = serverlessYml.defaults.region;
|
||||
}
|
||||
if (serverlessYml.defaults && serverlessYml.defaults.variableSyntax) {
|
||||
this.defaults.variableSyntax = serverlessYml.defaults.variableSyntax;
|
||||
}
|
||||
})
|
||||
.then(() => that.serverless.yamlParser
|
||||
.parse(serverlessEnvYmlPath))
|
||||
@ -166,11 +168,11 @@ class Service {
|
||||
|
||||
let varTemplateSyntax = /\${([\s\S]+?)}/g;
|
||||
|
||||
if (this.variableSyntax) {
|
||||
varTemplateSyntax = RegExp(this.variableSyntax, 'g');
|
||||
if (this.defaults && this.defaults.variableSyntax) {
|
||||
varTemplateSyntax = RegExp(this.defaults.variableSyntax, 'g');
|
||||
|
||||
// temporally remove variable syntax from service otherwise it'll match
|
||||
this.variableSyntax = true;
|
||||
this.defaults.variableSyntax = true;
|
||||
}
|
||||
|
||||
const commonVars = this.getVariables();
|
||||
@ -310,7 +312,9 @@ class Service {
|
||||
this.environment = environment;
|
||||
|
||||
// put back variable syntax if we removed it for processing
|
||||
if (this.variableSyntax) this.variableSyntax = varTemplateSyntax;
|
||||
if (this.defaults && this.defaults.variableSyntax) {
|
||||
this.defaults.variableSyntax = varTemplateSyntax;
|
||||
}
|
||||
|
||||
return this;
|
||||
});
|
||||
|
||||
@ -22,7 +22,11 @@ describe('Service', () => {
|
||||
|
||||
expect(serviceInstance.service).to.be.equal(null);
|
||||
expect(serviceInstance.provider).to.deep.equal({});
|
||||
expect(serviceInstance.variableSyntax).to.be.equal(null);
|
||||
expect(serviceInstance.defaults).to.deep.equal({
|
||||
stage: 'dev',
|
||||
region: 'us-east-1',
|
||||
variableSyntax: null,
|
||||
});
|
||||
expect(serviceInstance.custom).to.deep.equal({});
|
||||
expect(serviceInstance.plugins).to.deep.equal([]);
|
||||
expect(serviceInstance.functions).to.deep.equal({});
|
||||
@ -539,7 +543,9 @@ describe('Service', () => {
|
||||
const tmpDirPath = path.join(os.tmpdir(), (new Date).getTime().toString());
|
||||
const serverlessYml = {
|
||||
service: '${{testVar}}',
|
||||
variableSyntax: '\\${{([\\s\\S]+?)}}',
|
||||
defaults: {
|
||||
variableSyntax: '\\${{([\\s\\S]+?)}}',
|
||||
},
|
||||
provider: 'aws',
|
||||
functions: {},
|
||||
};
|
||||
@ -569,7 +575,7 @@ describe('Service', () => {
|
||||
|
||||
return serviceInstance.load().then((loadedService) => {
|
||||
expect(loadedService.service).to.be.equal('commonVar');
|
||||
delete serviceInstance.variableSyntax;
|
||||
delete serviceInstance.defaults.variableSyntax;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user