一次更新所有过时的 Angular 包
Update all outdated Angular packages at once
我以前使用过 ng update --all
,因为我想将每个包更新到最新版本,包括那些没有附加原理图的依赖项。
--all
选项现已弃用,将不再起作用。唯一的选择是指定要更新的每个包,我觉得这很乏味。有没有办法将 ng update
的过时包输出 grep 到单行 space 分隔变量,然后可以将其输入到新的 ng update ${packageList}
?
ng update
的输出如下:
The installed local Angular CLI version is older than the latest stable version.
Installing a temporary version to perform the update.
Installing packages for tooling via npm.
Installed packages for tooling via npm.
Using package manager: 'npm'
Collecting installed dependencies...
Found 67 dependencies.
We analyzed your package.json, there are some packages to update:
Name Version Command to update
--------------------------------------------------------------------------------------
@angular/cdk 10.2.5 -> 11.0.0 ng update @angular/cdk
@angular/cli 10.1.7 -> 11.0.0 ng update @angular/cli
@angular/core 10.2.0 -> 11.0.0 ng update @angular/core
@angular/material 10.2.5 -> 11.0.0 ng update @angular/material
@nrwl/angular 10.3.1 -> 10.3.3 ng update @nrwl/angular
@nrwl/cypress 10.3.1 -> 10.3.3 ng update @nrwl/cypress
@nrwl/jest 10.3.1 -> 10.3.3 ng update @nrwl/jest
@nrwl/storybook 10.3.1 -> 10.3.3 ng update @nrwl/storybook
@nrwl/workspace 10.3.1 -> 10.3.3 ng update @nrwl/workspace
There might be additional packages which don't provide 'ng update' capabilities that are outdated.
You can update the addition packages by running the update command of your package manager.
我想要 运行 一个 bash 脚本,该脚本仅从该输出的第一列收集包名称,并将其反馈到一个变量中。最终结果是:
> ng update ${packageList}
ng update @angular/cdk @angular/cli @angular/core @angular/material @nrwl/angular @nrwl/cypress @nrwl/jest @nrwl/storybook @nrwl/workspace --force=true
帮忙?这可能吗?
我想我用这个单线就搞定了:
ng update | awk -v re='@[[:alnum:]]' '[=10=] ~ re {printf " "}' | xargs ng update --force=true && npm update
通过将第一个 ng update
运行 的输出通过管道传输到 awk,我可以搜索类似于包名称的文本并输出一个 space 分隔的参数列表,然后我作为 xargs 通过管道传输到第二个 ng update
命令中。
通过先 运行 和 npm update
之后,我首先更新了迁移原理图的每个依赖项,然后是所有其他依赖项。快乐的!
免责声明:在运行此命令之前先备份您的整个项目。
ng update @angular/cli @angular/core --force --allow-dirty
我以前使用过 ng update --all
,因为我想将每个包更新到最新版本,包括那些没有附加原理图的依赖项。
--all
选项现已弃用,将不再起作用。唯一的选择是指定要更新的每个包,我觉得这很乏味。有没有办法将 ng update
的过时包输出 grep 到单行 space 分隔变量,然后可以将其输入到新的 ng update ${packageList}
?
ng update
的输出如下:
The installed local Angular CLI version is older than the latest stable version.
Installing a temporary version to perform the update.
Installing packages for tooling via npm.
Installed packages for tooling via npm.
Using package manager: 'npm'
Collecting installed dependencies...
Found 67 dependencies.
We analyzed your package.json, there are some packages to update:
Name Version Command to update
--------------------------------------------------------------------------------------
@angular/cdk 10.2.5 -> 11.0.0 ng update @angular/cdk
@angular/cli 10.1.7 -> 11.0.0 ng update @angular/cli
@angular/core 10.2.0 -> 11.0.0 ng update @angular/core
@angular/material 10.2.5 -> 11.0.0 ng update @angular/material
@nrwl/angular 10.3.1 -> 10.3.3 ng update @nrwl/angular
@nrwl/cypress 10.3.1 -> 10.3.3 ng update @nrwl/cypress
@nrwl/jest 10.3.1 -> 10.3.3 ng update @nrwl/jest
@nrwl/storybook 10.3.1 -> 10.3.3 ng update @nrwl/storybook
@nrwl/workspace 10.3.1 -> 10.3.3 ng update @nrwl/workspace
There might be additional packages which don't provide 'ng update' capabilities that are outdated.
You can update the addition packages by running the update command of your package manager.
我想要 运行 一个 bash 脚本,该脚本仅从该输出的第一列收集包名称,并将其反馈到一个变量中。最终结果是:
> ng update ${packageList}
ng update @angular/cdk @angular/cli @angular/core @angular/material @nrwl/angular @nrwl/cypress @nrwl/jest @nrwl/storybook @nrwl/workspace --force=true
帮忙?这可能吗?
我想我用这个单线就搞定了:
ng update | awk -v re='@[[:alnum:]]' '[=10=] ~ re {printf " "}' | xargs ng update --force=true && npm update
通过将第一个 ng update
运行 的输出通过管道传输到 awk,我可以搜索类似于包名称的文本并输出一个 space 分隔的参数列表,然后我作为 xargs 通过管道传输到第二个 ng update
命令中。
通过先 运行 和 npm update
之后,我首先更新了迁移原理图的每个依赖项,然后是所有其他依赖项。快乐的!
免责声明:在运行此命令之前先备份您的整个项目。
ng update @angular/cli @angular/core --force --allow-dirty