Using environment variables in npm scripts across platforms
To make it cross-platform, use cross-var
:
"scripts": {
"build": "cross-var md %npm_package_version%\helloworld"
}
npm
doesn't appear to have a cross platform way to expand environment variables, but you do have node at your disposal, so I'd recommend implementing all your scripts as node scripts, then you can access process.env
and cross-platform filesystem functions, like mkdirSync
.
package.json
"scripts": {
"build": "node utils/mdkir.js"
}
utils/mkdir.js
'use strict';
var fs = require('fs');
fs.mkdirSync(process.env.npm_package_version + '/helloworld');