命令列出所有 npm_package_vars [英] Command to list all npm_package_vars
问题描述
是否有一个命令可以列出所有 npm_package_var
变量?
Is there a command to list all the npm_package_var
variables?
我知道我们可以单独使用 npm_package_var 语法获取变量.
I know individually we can get the vars using npm_package_var syntax.
是否有一个命令可以用来列出所有这些变量?
Is there a command that I can use to list all these vars?
推荐答案
简短回答: npm 没有提供完全满足您需求的内置命令.但是,它可以列出所有变量.例如:
Short Answer: npm does not provide a built-in command that does exactly what you need. However, it can list all variables. For instance:
首先,
cd
到您的项目目录.
然后运行以下命令列出所有变量:
Then run the following command to list all variables:
npm run env
文档 陈述了关于 env 的以下内容代码>脚本:
The documentation states the following about the env
script:
env
脚本是一个特殊的内置命令,可用于列出脚本在运行时可用的环境变量.如果包中定义了env"命令,它将优先于内置命令.
The
env
script is a special built-in command that can be used to list environment variables that will be available to the script at runtime. If an "env" command is defined in your package, it will take precedence over the built-in.
解决方案:
要仅列出 npm_package_vars
,考虑将上述 npm run env
命令的结果通过管道传递给其中之一;grep
如果使用 *nix,或 findstr
如果使用 Windows.
Solution:
To list the npm_package_vars
only, consider piping the result of the aforementioned npm run env
command to either; grep
if using *nix, or to findstr
if using Windows.
例如,首先 cd
到您的项目目录,然后运行以下任一复合命令 - 取决于您使用的操作系统:
For instance, firstly cd
to your project directory then run either of the following compound commands - depending on which OS you're using:
在 *nix 平台上运行以下内容:
On *nix platforms run the following:
npm run env | grep ^npm_package_
或者,在 Windows 上运行以下代码:
Or, on Windows run the following instead:
npm run env | findstr /B npm_package_
注意(Windows 版 Git):
如果您使用的是 Git for Windows(即如果您使用的是 git-bash 作为您的首选命令行)然后我建议使用前面提到的 grep
命令:
If you're using Git for Windows (i.e. if you're using git-bash as your preferred command line) then I recommend utilizing the aforementioned grep
command:
npm run env | grep ^npm_package_
但是,如果由于某种原因您想使用 findstr
而不是 grep
,(使用 git-bash 时),您需要替换 /B
选项用 -B
代替.例如:
However if for some reason you wanted to use findstr
instead of grep
, (when using git-bash), you'll need to replace the /B
option with -B
instead. For instance:
npm run env | findstr -B npm_package_
或者,如果失败,则尝试使用两个正斜杠代替.例如:
Or, if that fails, then try using two forward slashes instead. For instance:
npm run env | findstr //B npm_package_
顺便说一句. /B
选项匹配位于行首的模式.这类似于 GREP 中的插入符号 ^
.`
Btw. The /B
option matches a pattern if it's at the beginning of a line. This is analogous to the caret ^
in GREP.`
这篇关于命令列出所有 npm_package_vars的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!