node.js - Get stdout from NPM Script into a variable -


i have node script parse .yaml , output field named version

node node/getassetsversion.js => "2.1.2" 

i'm trying stdout varible , use in npm script

this i'm trying in package.json:

"scripts": {    "build": "cross-env version=\"$(node node/getassetsversion.js)\" \"node-sass --include-path scss src/main.scss dist/$version/main.css\"" } 

thanks!

instead of this:

version=\"$(node node/getassetsversion.js)\"  

you may need use:

version=\"$(node node/getassetsversion.js | cut -d'\"' -f2)\" 

if output of program wrote in question:

=> "2.1.2" 

if it's this:

"2.1.2" 

then above still work can use simpler command:

version=$(node node/getassetsversion.js) 

with no quotes.

but in later part $version not substituted expect.

since tagged question bash recommend writing bash script:

#!/bin/bash version=$(node node/getassetsversion.js | cut -d'\"' -f2) node-sass --include-path scss src/main.scss dist/$version/main.css 

or:

#!/bin/bash version=$(node node/getassetsversion.js) node-sass --include-path scss src/main.scss dist/$version/main.css 

depending on output of getassetsversion.js , put in package.json:

"scripts": {    "build": "bash your-bash-script-name" } 

i avoid quotes escaped more once.


Comments

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -