[英]How to pass scope name to lerna command dynamic?
I use lerna to manage projects and dev
command exists in some projects.我使用 lerna 来管理项目,某些项目中存在
dev
命令。 For exmaple, A and B have command dev
to start project.例如,A 和 B 有命令
dev
来启动项目。 I must write two command in root project:我必须在根项目中写两个命令:
{
"dev:A":"lerna exec --scope A -- yarn dev",
"dev:B":"lerna exec --scope B -- yarn dev"
}
It's there anyway to run like this:无论如何,它可以像这样运行:
yarn dev A
I try but it's failure.我尝试,但它是失败的。 The scope name is pass to yarn dev not lerna.
范围名称传递给 yarn dev 而不是 lerna。
{
"dev":"lerna exec --scope $1 -- yarn dev",
}
The executable is not yarn, but lerna.可执行文件不是yarn,而是lerna。 You want the command to be
你希望命令是
lerna run dev --scope xyz
So either install it globally and call it like that, or install it as a project dependency and then因此,要么全局安装它并像这样调用它,要么将其安装为项目依赖项,然后
yarn lerna -- run dev --scope ...
# or
`npm run lerna -- run dev --scope ...`
or use npx lerna run dev --scope ...
to run it globally without explicit install.或使用
npx lerna run dev --scope ...
在没有显式安装的情况下全局运行它。
Why that way?为什么这样?
Because yarn <bin>
/ npm run <bin>
executes the bin as if you'd call it directly, and the --
seperates arguments to yarn/npm from arguments to the bin you called.因为
yarn <bin>
/ npm run <bin>
执行 bin 就像您直接调用它一样,并且--
将 yarn/npm 的参数与您调用的 bin 的参数分开。 More recent yarns will allow you to drop the --
and figure them out automagically.更新的纱线将允许您放弃
--
并自动找出它们。
I'm not sure if you really need to use yarn dev
instead of simply dev
in the lerna part of the script, as lerna does just that -- walk all projects, look up if any project has a dev
script and executes it (if you use --scope
, it will of course only look up the given project(s)...).我不确定您是否真的需要在脚本的 lerna 部分使用
yarn dev
而不是简单的dev
,因为 lerna 就是这样做的——遍历所有项目,查找是否有任何项目有dev
脚本并执行它(如果您使用--scope
,它当然只会查找给定的项目...)。 You might need it with yarn less it calls the commands in the sub-packages using npm
instead, but I didn't check that, as our company uses npm.您可能需要使用 yarn less 它使用
npm
调用子包中的命令,但我没有检查,因为我们公司使用 npm。
A package.json including一个 package.json 包括
{
"scripts": { "dev": "lerna run dev --scope x" }
}
does the same thing if you launch it with yarn dev
.如果你用
yarn dev
启动它,做同样的事情。
If you want to call the lerna-dev script with more arguments, you can always go for yarn dev -- --include-dependencies
in the terminal, which will append all arguments after dev
to lerna
instead of yarn, in this example resulting in yarn lerna -- dev --scope x --include-dependencies
如果你想用更多的参数调用 lerna-dev 脚本,你总是可以在终端中使用
yarn dev -- --include-dependencies
,它会将dev
之后的所有参数附加到lerna
而不是 yarn,在这个例子中导致yarn lerna -- dev --scope x --include-dependencies
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.