Npm run script with dynamically computed parameters
up vote
0
down vote
favorite
I currently have this script in my package.json, for building the app to work on the cdn:
"build:cdn": "ng build --prod --extract-css --output-hashing=none --deploy-url https://my-cdn.com/static/20181118000000/frontend/dist/"
Where 20181118000000
is simply the convention for cache busting.
But that means that every time I want to build, I have to manually edit that value in the build:cdn
script in package.json. Not to mention that I can't have the app running in watch mode...
How can I tell npm to dynamically compute that when running the command? Like --deploy-url https://my-cdn.com/static/{getCurrentTimeStampHereAndFormatItTo('YYYYMMDDHHMMSS')}/frontend/dist/
whatever.
Especially since I would also like to use npm run build:cdn -- --watch
to have it watching and build automatically when saving a file, while developing. Because local development also uses CDN - don't ask why :( - but it's a VM in the cloud, and with EACH change the code is automatically uploaded (thanks to WebStorm) through ftp to that development VM in the cloud, then I can refresh the browser to see the changes. Apparently, people preferred this over the Docker filesystem issues with mounted folders being slow.
Ideally, the solution should work on both Windows and Mac OS.
npm
add a comment |
up vote
0
down vote
favorite
I currently have this script in my package.json, for building the app to work on the cdn:
"build:cdn": "ng build --prod --extract-css --output-hashing=none --deploy-url https://my-cdn.com/static/20181118000000/frontend/dist/"
Where 20181118000000
is simply the convention for cache busting.
But that means that every time I want to build, I have to manually edit that value in the build:cdn
script in package.json. Not to mention that I can't have the app running in watch mode...
How can I tell npm to dynamically compute that when running the command? Like --deploy-url https://my-cdn.com/static/{getCurrentTimeStampHereAndFormatItTo('YYYYMMDDHHMMSS')}/frontend/dist/
whatever.
Especially since I would also like to use npm run build:cdn -- --watch
to have it watching and build automatically when saving a file, while developing. Because local development also uses CDN - don't ask why :( - but it's a VM in the cloud, and with EACH change the code is automatically uploaded (thanks to WebStorm) through ftp to that development VM in the cloud, then I can refresh the browser to see the changes. Apparently, people preferred this over the Docker filesystem issues with mounted folders being slow.
Ideally, the solution should work on both Windows and Mac OS.
npm
2
Just write a script in the language of your choice (shell or JS probably simplest) and invoke that instead.
– jonrsharpe
Nov 18 at 19:48
well, unless there is a straight-forward and simple solution, I guess I'll have to see how can I do that (I have zero shell/bash scripting experience... and anyway, either bash or JS script will just add complexity to the simple use ofng build
command) maybe there is a simpler solution, I hope... I'll wait for a while before doing anything else. thanks for the suggestion @jonrsharpe !
– MrCroft
Nov 18 at 19:53
You can call that from the script, I just mean to build the parameters. You still runnpm run build:cdn
and it'd still end up calling the Angular CLI.
– jonrsharpe
Nov 18 at 20:12
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I currently have this script in my package.json, for building the app to work on the cdn:
"build:cdn": "ng build --prod --extract-css --output-hashing=none --deploy-url https://my-cdn.com/static/20181118000000/frontend/dist/"
Where 20181118000000
is simply the convention for cache busting.
But that means that every time I want to build, I have to manually edit that value in the build:cdn
script in package.json. Not to mention that I can't have the app running in watch mode...
How can I tell npm to dynamically compute that when running the command? Like --deploy-url https://my-cdn.com/static/{getCurrentTimeStampHereAndFormatItTo('YYYYMMDDHHMMSS')}/frontend/dist/
whatever.
Especially since I would also like to use npm run build:cdn -- --watch
to have it watching and build automatically when saving a file, while developing. Because local development also uses CDN - don't ask why :( - but it's a VM in the cloud, and with EACH change the code is automatically uploaded (thanks to WebStorm) through ftp to that development VM in the cloud, then I can refresh the browser to see the changes. Apparently, people preferred this over the Docker filesystem issues with mounted folders being slow.
Ideally, the solution should work on both Windows and Mac OS.
npm
I currently have this script in my package.json, for building the app to work on the cdn:
"build:cdn": "ng build --prod --extract-css --output-hashing=none --deploy-url https://my-cdn.com/static/20181118000000/frontend/dist/"
Where 20181118000000
is simply the convention for cache busting.
But that means that every time I want to build, I have to manually edit that value in the build:cdn
script in package.json. Not to mention that I can't have the app running in watch mode...
How can I tell npm to dynamically compute that when running the command? Like --deploy-url https://my-cdn.com/static/{getCurrentTimeStampHereAndFormatItTo('YYYYMMDDHHMMSS')}/frontend/dist/
whatever.
Especially since I would also like to use npm run build:cdn -- --watch
to have it watching and build automatically when saving a file, while developing. Because local development also uses CDN - don't ask why :( - but it's a VM in the cloud, and with EACH change the code is automatically uploaded (thanks to WebStorm) through ftp to that development VM in the cloud, then I can refresh the browser to see the changes. Apparently, people preferred this over the Docker filesystem issues with mounted folders being slow.
Ideally, the solution should work on both Windows and Mac OS.
npm
npm
asked Nov 18 at 19:42
MrCroft
1,60411938
1,60411938
2
Just write a script in the language of your choice (shell or JS probably simplest) and invoke that instead.
– jonrsharpe
Nov 18 at 19:48
well, unless there is a straight-forward and simple solution, I guess I'll have to see how can I do that (I have zero shell/bash scripting experience... and anyway, either bash or JS script will just add complexity to the simple use ofng build
command) maybe there is a simpler solution, I hope... I'll wait for a while before doing anything else. thanks for the suggestion @jonrsharpe !
– MrCroft
Nov 18 at 19:53
You can call that from the script, I just mean to build the parameters. You still runnpm run build:cdn
and it'd still end up calling the Angular CLI.
– jonrsharpe
Nov 18 at 20:12
add a comment |
2
Just write a script in the language of your choice (shell or JS probably simplest) and invoke that instead.
– jonrsharpe
Nov 18 at 19:48
well, unless there is a straight-forward and simple solution, I guess I'll have to see how can I do that (I have zero shell/bash scripting experience... and anyway, either bash or JS script will just add complexity to the simple use ofng build
command) maybe there is a simpler solution, I hope... I'll wait for a while before doing anything else. thanks for the suggestion @jonrsharpe !
– MrCroft
Nov 18 at 19:53
You can call that from the script, I just mean to build the parameters. You still runnpm run build:cdn
and it'd still end up calling the Angular CLI.
– jonrsharpe
Nov 18 at 20:12
2
2
Just write a script in the language of your choice (shell or JS probably simplest) and invoke that instead.
– jonrsharpe
Nov 18 at 19:48
Just write a script in the language of your choice (shell or JS probably simplest) and invoke that instead.
– jonrsharpe
Nov 18 at 19:48
well, unless there is a straight-forward and simple solution, I guess I'll have to see how can I do that (I have zero shell/bash scripting experience... and anyway, either bash or JS script will just add complexity to the simple use of
ng build
command) maybe there is a simpler solution, I hope... I'll wait for a while before doing anything else. thanks for the suggestion @jonrsharpe !– MrCroft
Nov 18 at 19:53
well, unless there is a straight-forward and simple solution, I guess I'll have to see how can I do that (I have zero shell/bash scripting experience... and anyway, either bash or JS script will just add complexity to the simple use of
ng build
command) maybe there is a simpler solution, I hope... I'll wait for a while before doing anything else. thanks for the suggestion @jonrsharpe !– MrCroft
Nov 18 at 19:53
You can call that from the script, I just mean to build the parameters. You still run
npm run build:cdn
and it'd still end up calling the Angular CLI.– jonrsharpe
Nov 18 at 20:12
You can call that from the script, I just mean to build the parameters. You still run
npm run build:cdn
and it'd still end up calling the Angular CLI.– jonrsharpe
Nov 18 at 20:12
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53364767%2fnpm-run-script-with-dynamically-computed-parameters%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Just write a script in the language of your choice (shell or JS probably simplest) and invoke that instead.
– jonrsharpe
Nov 18 at 19:48
well, unless there is a straight-forward and simple solution, I guess I'll have to see how can I do that (I have zero shell/bash scripting experience... and anyway, either bash or JS script will just add complexity to the simple use of
ng build
command) maybe there is a simpler solution, I hope... I'll wait for a while before doing anything else. thanks for the suggestion @jonrsharpe !– MrCroft
Nov 18 at 19:53
You can call that from the script, I just mean to build the parameters. You still run
npm run build:cdn
and it'd still end up calling the Angular CLI.– jonrsharpe
Nov 18 at 20:12