-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added eval of ${var} variables in config templates #43
base: master
Are you sure you want to change the base?
Conversation
Why not simply using native template-strings? For example: const config = {
// ...
version: `{version}.${process.env.BUILD_NUMBER}-${process.env.NODE_ENV}`,
// ...
}; |
Because you cannot use this syntax in .json configs and cli-tools like https://github.com/wallaroo/maven-deploy-cli/blob/master/cli.js |
I understand. But I have a bad feeling about using What about something like: const config = {
// ...
version: `{version}.{env(BUILD_NUMBER)}-{env(NODE_ENV)}`,
// ...
}; So, we can parse the content in curly braces. if its something like |
Looks good. I will change my PR that way. |
Alternatively we may use something like mustache or lodash.template for supporting variables in config strings. So, we could have full control over the context and adding more data would be easy. A proper context could look like: const context = {
... pkg, // merge values from package.json for backwards compatibility
package,
env: process.env
};
// ...
const config = {
// ...
version: '{{package.version}}.{{env.BUILD_NUMBER}}-{{env.NODE_ENV}}'
// ...
} With this solution we dont't need to implement an own templating system… |
Added mustache in my last commit. |
test.js
Outdated
const EXPECTED_ARGS = [ | ||
'-Dfile=dist' + path.sep + TEST_PKG_JSON.name + '-' + | ||
process.env.NODE_ENV + | ||
'.'+semver.inc(TEST_PKG_JSON.version,'patch')+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: spaces around '+' and ',' are missing.
test.js
Outdated
maven.config(TEST_CONFIG_WITH_ENV_VARIABLE); | ||
maven.install(); | ||
|
||
assert.equal(process.env.NODE_ENV,'test'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto here.
test.js
Outdated
repositories: [DUMMY_REPO_SNAPSHOT, DUMMY_REPO_RELEASE], | ||
classifier: TEST_CLASSIFIER, | ||
generatePom: false, | ||
'finalName': '{name}-{{env.NODE_ENV}}.{{package.version}}', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: Quoting of finalName
is unneeded, and doesn't match the rest of the area.
return pkg[key]; | ||
}); | ||
obj[key] = Mustache.render(value, replacibleKeys) | ||
.replace(/{([^}]+)}/g, function (org, key) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@skyway777 have you tested if single curly braces could work with mustache? Maybe we could remove the old replacing mechanism entirely?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it doesn't support single curly braces...
Now you can add ENV variables or another variables to config.
For example, you want to add build number to version.
You set BUILD_NUMBER to ENV variable, and then write into your config ${process.env.BUILD_NUMBER}
Now, version of config
will produce version: 1.0.1.234-production