Rush is a massive hard Team build and release solution for maintaining multiple projects in a single warehouse. For more information, see the official website. Deepl is a translation tool based on deep learning. Take the first excerpt from rush’s homepage as an example.
The installation
npm install -g @microsoft/rush
Copy the code
Once installed, it is recommended that you take 3 minutes to run through the demo on your own site to get a better understanding of Rush.
The program
Project initialization
We began migrating the MENorepo framework built with PNPM from the previous article rush + PNPM + TS + Menorepo Scaffolding Development Environment 1 to Rush. Create a folder rush in the same directory as demo and run the rush initialization command
rush init
Copy the code
Run copy command to copy utils and Core from menorepo folder into rush folder
cp -R ./.. /menorepo/packagesCopy the code
Modify rush.json file to add core and utils project configuration information in projects
"Projects ": [{"packageName": "core", // Project name "projectFolder": "core", // project address "reviewCategory": "Tools ", // package type "shouldPublic": true // publish}, {"packageName": "utils", "projectFolder": "packages/utils", "reviewCategory": "tools", "shouldPublic": true } ]Copy the code
Add the project repository address to the Repository field
"Url" : "https://github.com/microsoft/rush-example", / / warehouse link with their projectsCopy the code
Fill in the link of the project repository here, rush will do diff with the current version and the remote master branch before each new release, and ask the author to fill in the change log for the convenience of later traceability maintenance.
The default package manager for Rush is PNPM, which needs to be manually changed to NPM or YARN
Link local library files
Go to the core project directory and execute
Rush add -p utils // -p specifies the local library nameCopy the code
Let core re-reference utils.
If we want all subprojects to refer to utils, we can add -all
rush add -p utils -all
Copy the code
Depend on the installation
rush update
Copy the code
This command can be used to update and install dependencies the first time we clone the code locally or manually modify the dependencies in package.json
packaging
rush bulild
Copy the code
In Rush, whenever a project is configured with build in any directory, the rush build command will be executed on all projects
The first time we execute build, we get a warning because we didn’t install @types/node declaration file, so let’s install @types/node
pnpm i @types/node --filter core --filter utils -D
Copy the code
In Rush, all of our installed dependencies are stored by default in the rush/common/ Temp directory, maintained by rush 🙆♂
All subdirectory dependencies are referenced by hard links, so developers don’t have to worry about reinstalling packages.
Once installed, rerun the pack command rush Build
The previous error message disappeared.
More packaging features
Rush Build packages all projects by default, and we can do more with parameters.
- The scene of a
I just want to package core as a project, executable
rush build -o core
Copy the code
- Scenario 2
When we modify the base library utils, we want all projects that rely on that library (including Utils) to be repackaged and ready to execute
rush build -i utils
Copy the code
- Scenario 3
I just want to package core and core dependencies, and I can do that
rush build -t core
Copy the code
Similarly, the rush add -p utils link to the local library file we performed above can be used to add dependencies to specific projects by adding parameters.
release
To simulate the daily development process of iteration -> release, the previous code is first committed to the repository
Git commit -m "init" git remote add origin [email protected]:GongJS/rush-demo git push origin masterCopy the code
Then modify the index.ts files of core and utils respectively
/ / rush/packages/core/index. The ts import {log} from 'utils const core () = = > {the console. The log (' core change') / / new log.info('test', 'Hello world! ') } export default core // rush/packages/utils/src/index.ts import log from 'npmlog' log.level = process.env.LOG_LEVEL ? Process.env. LOG_LEVEL: 'info' log.heading = 'js-cli' // add log.addLevel('success', 2000, {fg: 'green', bold: true}) console.log('utils changed') export { log }Copy the code
Then repackage and submit
rush build
git add .
git commit -m "test rush publish"
Copy the code
Perform Rush Change, which diffs with the remote branch and goes to the developer to fill out the change log
Major, Minor, and Patch correspond to the major, medium, and small version changes respectively. The corresponding version number will be updated during the subsequent upgrade. Select Patch to upgrade the minor version.
Common/Changes records the changes. Execute rush publish –apply to apply the changes you just made
After the command is executed successfully, we can see that the corresponding package version has been upgraded accordingly.
Finally, for official publication, we need to add the source address to publish to by creating a.npmrc-publish file in the project root directory
touch .npmrc-publish
Copy the code
The file content
registry=https://registry.npmjs.org // npm
Copy the code
And then execute
Rush publish -p -- include-all-nCopy the code
NPM tokens need to be generated themselves
It is not recommended to copy the token directly to the console. Every command entered on the console will be recorded and there is a risk of leakage. Instead, save the token in the old.npmrc file
registry=https://registry.npmjs.org
TOKEN = npm_lzRjxxFht6LeFZQHrSxxxxxxxxxx
Copy the code
Finally, execute on the console
rush publish -p --include-all -n TOKEN
Copy the code
Publish the results
conclusion
With the help of Rush, a legacy problem in the environment of Rush + PNPM + TS + Menorepo scaffolding development can be solved well, and rush is far more than this, I recommend you have time to try to use it.
A link to the
Js – CLI scaffolding source code