asp.net core - Accessing project.json webroot value from a npm script command? -


i trying use npm asp.net 5 (vnext) build tool use build js/cs files not want duplicate configuration values in npm , asp.net 5 config files.

in project have following files

package.json

"scripts": {   "build:js": "browserify assets/scripts/main.js > $npm_package_config_aspnet5_webroot/main.js" } 

project.json

{     "version": "1.0.0-*",     "webroot": "wwwroot", } 

and want able extract webroot value asp.net 5 json file , use in npm scripts commands following

the json npm package cool cli tool i've been using things this. can use extract individual values of json file. combining bash scripts means trivially extract asp.net webroot project.json.

assuming project.json looks this:

{     "webroot": "www/" } 

you can use json tool, so:

$ json -f project.json webroot www/ 

now, case of combining build:js command:

"scripts": {     "build:js": "browserify assets/scripts/main.js > $(json -f project.json webroot)/main.js" } 

you make npm task out of extracting value, useful if need use multiple times:

"scripts": {     "getwebroot": "json -f project.json webroot",     "build:js": "browserify assets/scripts/main.js > $(npm run getwebroot -s)/main.js",     "build:css": "cat assets/styles/* > $(npm run getwebroot -s)/style.css" } 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -