Specifically, I want to download angular.min.js when running 'npm install'.
From what I read here the place to do such things is in a prepublish script. It also mentions I don't need to rely on having wget/curl installed on the system.
However it doesn't go into any detail on how to go about doing it.
Anybody knows how to do it?
Ok, solved it myself.
I added a small javascript file (prepublish.js):
var http = require('http');
var fs = require('fs');
function download(filename, url) {
var file = fs.createWriteStream(filename);
var request = http.get(url, function(response) {
response.pipe(file);
});
}
console.log('Downloading angular');
download('public/scripts/angular.min.js', 'http://code.angularjs.org/1.0.7/angular.min.js');
download('public/scripts/angular.js', 'http://code.angularjs.org/1.0.7/angular.js');
console.log('Downloading angular-ui-router');
download('public/scripts/angular-ui-router.min.js', 'http://angular-ui.github.io/ui-router/release/angular-ui-router.min.js');
download('public/scripts/angular-ui-router.js', 'http://angular-ui.github.io/ui-router/release/angular-ui-router.js');
and I modified my package.json:
...
"scripts": {
"start": "node app.js",
"prepublish": "node prepublish.js"
},
Now when running 'npm install' it downloads my dependencies!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With