I have a simple CLI tool for my project which I run through NPM/Yarn scripts:
"scripts": {
"cli": "dotenv ts-node -r tsconfig-paths/register src/cli/index.ts --",
...
}
I'd like to silence the log info stuff that NPM/Yarn automatically write to stdout when a script is run.
By default, the output is:
$~/foo> yarn cli --help
yarn run v1.22.5
$ dotenv ts-node -r tsconfig-paths/register src/cli/index.ts -- --help
cli <command>
Foo bar baz bat
Options:
--help Show help [boolean]
? Done in 2.42s.
I want to get rid of the part where it writes out the command itself, and the "Done in x
s" part.
I know I can do it manually with yarn --silent cli
or npm run --quiet cli
, or I could set loglevel=quiet
in an npmrc, but neither is preferable.
I don't want to use the npmrc as I want to retail output for other scripts, and I don't want to require users to run it with the --silent
flag themselves.
The CLI tool generates JSON which is fed into other scripts, so it's ideal if it's clean output that can be redirected or piped without the NPM/Yarn guff.
I tried adding --silent
to the start of the command, but that doesn't work. I tried setting npm_config_loglevel=quiet
as an env var, but that doesn't work.
Is there anything else I can try, or is this just not supported?
question from:
https://stackoverflow.com/questions/66062547/set-npm-log-level-to-quiet-in-script-definition 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…