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.










share|improve this question


















  • 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















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.










share|improve this question


















  • 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













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.










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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














  • 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








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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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







Popular posts from this blog

If I really need a card on my start hand, how many mulligans make sense? [duplicate]

Alcedinidae

Can an atomic nucleus contain both particles and antiparticles? [duplicate]