i have those 2 npm(s) for each operating system:
"pack": "cd dist/fold1 && type script11.js script22.js script33.js > all.js",
"pack-unix": "cd dist/fold1 && cat script11.js script22.js script33.js > all.js"
how can i make them a single command?
like:
"pack": "cd dist/fold1 && <if win than type else cat> script11.js script22.js script33.js > all.js",
CodePudding user response:
There is a great package for this case called run-script-os
link here
Note! You can combine OS tags that have similar scripts.
{
...
"scripts": {
...
"pack": "run-script-os",
"pack:win32": "...",
"pack:macos": "...",
"pack:default": "..."
...
},
...
}
CodePudding user response:
You can use shelljs/shx
as a development only dependency.
npm install shx --save-dev
Then in package.json
:
pack: "cd dist/fold1 && shx cat script11.js script22.js script33.js > all.js"
Using shx
over run-script-os
has an advantage that you don't need to write different scripts for different environments. Prefer using shelljs
instead if you are having some complex stuff going on. If your use case(s) are not met by both of them (like a dependency on some *sh only feature that is not supported by ShellJS), then you can use run-script-os
as the other answer suggests, or you can do this: https://stackoverflow.com/a/41551958, if you don't want another dependency.