script-file
script-file maps a npm-script
to the exports of a .js
file.
Installation
npm install script-file
Usage
Create a file scripts/foo.js
in your project root
const main = console; // Read command line argumentsconst foo = 'ls -al'; // A string runs a simple commandconst bar = 'webpack' 'python -m SimpleHTTPServer'; // An array of string runs on command after another moduleexports = main foo bar ;
Add the following to your package.json
:
"scripts": {
"foo": "script-file --name=script-file",
"foo:foo": "script-file",
"foo:bar": "script-file",
"bar:foo": "script-file-alias foo:bar"
}
run your scripts, npm run foo
, npm run foo:foo
, npm run foo:bar
, npm run bar:foo
Parameter Usage
Arguments passed to script file are processed by the yargs package. Check the documentation for details on how you can specify the arguments.
API
script-file comes with some build-in utils, which make working with external commands easy.
parallel(...cmds)
Run all passed scripts in parallel.
const parallel = ; const main = ; moduleexports = main ;
env(string|object) : function
Returns a function which sets environment variables. If you pass in a string
it will be set as process.env.NODE_ENV
.
If you pass an object
it takes the key as environment variable and assigns the corresponding value to it.
const main = 'webpack';const production = main;const staging = main; moduleexports = main production staging ;
spawn(cmd, [options]) : Promise
A slightly more advanced version of child_process.spawn
which returns a promise when the process exits.
You can optionally pass an options object to wait until the command line prints out a specified string.
E.g. {resolve: 'Server is running'}
const spawn = ;const webdriverio = ; const options = desiredCapabilities: browserName: 'safari' marionette: 'true' ;const browser = webdriverio; const SELENIUM_STARTED_SIGNIFIER = '35bf4d76-394c-4a0d-b31f-9a2ee2d51bf6'; const captureScreenshot = browser ; const main = ; moduleexports = main ;
killAll() : Promise
Kills all subprocess which have been spawned. This is useful when you want to quit all running processes on a remote after you executed some commands.
const spawn killAll = ; const main => ; moduleexports = main ;