An overview of the

Running with arguments (such as NPM run view test) is actually concatenating strings to the end, which is not flexible enough.

Use the npM_config environment variable to pass parameters. Multiple parameters and commands can be executed in sequence.

scripts

Method 1: Use the nPM_config environment variable (recommended)

"scripts": {
 "view": "echo %npm_config_host% & echo %npm_config_port%",}Copy the code

NPM run view –host=localhost –port=2333

Cross-platform environment variables

If the script needs to run cross-platform, use cross-env to get the environment variable (no need to distinguish between %npm_config% and $npm_config)

NPM install cross-env –save-dev

Use:

"scripts": {
 "view": "cross-env-shell echo %npm_config_host% & echo $npm_config_port",}Copy the code

Method 2 Adjust the command format

This parameter is applicable only when there are few variables and the command format can be adjusted. For example, if you want to run frida -u appname -l _agent.js, where appname is variable, the command format is: frida -u appname -l _agent.js

"scripts": {
    "attach": "frida -l _agent.js -U"
}
Copy the code

Run NPM run attach Appname

Js or ts

"scripts": {
    "test": "node test.js"
}
Copy the code

NPM run test appName, obtained directly from process.argv:

const args = process.argv.slice(2);
console.log('process. Argv: \ n', process.argv)
console.log('Parameter: \n', args)
Copy the code

reference

NPM script pass parameter

NPM Scripts Usage Guide