added eval of ${var} variables in config templates#43
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. |
| 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.
Style: spaces around '+' and ',' are missing.
| maven.config(TEST_CONFIG_WITH_ENV_VARIABLE); | ||
| maven.install(); | ||
|
|
||
| assert.equal(process.env.NODE_ENV,'test'); |
| 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.
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.
@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.
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