├── .gitattributes ├── .github ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── main.yaml │ └── publish.yml ├── .gitignore ├── .prettierignore ├── .prettierrc.js ├── .vscode └── settings.json ├── CONTRIBUTING.md ├── LICENSE ├── Makefile ├── README.md ├── common ├── _templates │ ├── rush-plugin-for-command │ │ ├── .eslintrc.js │ │ ├── .gitignore │ │ ├── .npmignore │ │ ├── README.md │ │ ├── command-line.json │ │ ├── config │ │ │ └── heft.json │ │ ├── init.config.ts │ │ ├── lint-staged.config.cjs │ │ ├── package.json │ │ ├── rush-plugin-manifest.json │ │ ├── src │ │ │ ├── helpers │ │ │ │ └── terminal.ts │ │ │ └── index.ts │ │ └── tsconfig.json │ └── template.json ├── autoinstallers │ ├── command-plugins │ │ ├── package.json │ │ ├── pnpm-lock.yaml │ │ └── rush-plugins │ │ │ ├── rush-archive-project-plugin │ │ │ ├── rush-archive-project-plugin │ │ │ │ └── command-line.json │ │ │ └── rush-plugin-manifest.json │ │ │ ├── rush-audit-cache-plugin │ │ │ ├── rush-audit-cache-plugin │ │ │ │ └── command-line.json │ │ │ └── rush-plugin-manifest.json │ │ │ ├── rush-init-project-plugin │ │ │ ├── rush-init-project-plugin │ │ │ │ └── command-line.json │ │ │ └── rush-plugin-manifest.json │ │ │ ├── rush-lint-staged-plugin │ │ │ ├── rush-lint-staged-plugin │ │ │ │ └── command-line.json │ │ │ └── rush-plugin-manifest.json │ │ │ ├── rush-sort-package-json │ │ │ ├── rush-plugin-manifest.json │ │ │ └── rush-sort-package-json │ │ │ │ └── command-line.json │ │ │ └── rush-upgrade-self-plugin │ │ │ ├── rush-plugin-manifest.json │ │ │ └── rush-upgrade-self-plugin │ │ │ └── command-line.json │ └── rush-prettier │ │ ├── package.json │ │ └── pnpm-lock.yaml ├── config │ └── rush │ │ ├── .npmrc │ │ ├── .npmrc-publish │ │ ├── .pnpmfile.cjs │ │ ├── artifactory.json │ │ ├── build-cache.json │ │ ├── command-line.json │ │ ├── common-versions.json │ │ ├── experiments.json │ │ ├── pnpm-lock.yaml │ │ ├── repo-state.json │ │ ├── rush-plugins.json │ │ └── version-policies.json ├── git-hooks │ ├── commit-msg.sample │ └── pre-commit └── scripts │ ├── install-run-rush.js │ ├── install-run-rushx.js │ └── install-run.js ├── cspell.json ├── lint-staged.config.cjs ├── rush-plugins ├── rush-archive-project-plugin │ ├── .eslintrc.js │ ├── .gitignore │ ├── .npmignore │ ├── CHANGELOG.json │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── command-line.json │ ├── config │ │ ├── heft.json │ │ └── jest.config.json │ ├── fixtures │ │ ├── monorepo-1 │ │ │ ├── demo │ │ │ │ └── package.json │ │ │ └── rush.json │ │ ├── monorepo-2 │ │ │ ├── common │ │ │ │ └── _graveyard │ │ │ │ │ └── demo-project.tar.gz │ │ │ ├── other │ │ │ │ └── package.json │ │ │ └── rush.json │ │ ├── monorepo-3 │ │ │ ├── apps │ │ │ │ └── my-app │ │ │ │ │ └── package.json │ │ │ ├── libraries │ │ │ │ └── my-lib │ │ │ │ │ └── package.json │ │ │ └── rush.json │ │ ├── monorepo-4 │ │ │ ├── common │ │ │ │ └── _graveyard │ │ │ │ │ └── @my-company │ │ │ │ │ └── my-app.tar.gz │ │ │ ├── libraries │ │ │ │ └── my-lib │ │ │ │ │ └── package.json │ │ │ └── rush.json │ │ └── monorepo-5 │ │ │ ├── apps │ │ │ └── my-app │ │ │ │ └── package.json │ │ │ ├── libraries │ │ │ └── my-lib │ │ │ │ └── package.json │ │ │ └── rush.json │ ├── lint-staged.config.cjs │ ├── package.json │ ├── rush-plugin-manifest.json │ ├── src │ │ ├── __mocks__ │ │ │ └── ora.js │ │ ├── cli.ts │ │ ├── commands │ │ │ ├── archive.ts │ │ │ ├── test │ │ │ │ ├── __snapshots__ │ │ │ │ │ └── archive.test.ts.snap │ │ │ │ ├── archive.test.ts │ │ │ │ └── unarchive.test.ts │ │ │ └── unarchive.ts │ │ └── logic │ │ │ ├── generateMD.ts │ │ │ ├── git.ts │ │ │ ├── graveyard.ts │ │ │ ├── projectMetadata.ts │ │ │ ├── promptRushUpdate.ts │ │ │ └── rushConfiguration.ts │ └── tsconfig.json ├── rush-audit-cache-plugin │ ├── .eslintrc.js │ ├── .gitignore │ ├── .npmignore │ ├── CHANGELOG.json │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── command-line.json │ ├── config │ │ ├── heft.json │ │ └── jest.config.json │ ├── docs │ │ ├── media │ │ │ ├── rush-audit-cache-arch.png │ │ │ └── rush-audit-cache-demo-usage.png │ │ ├── proposal-for-rush-build-diagnostic-tool.md │ │ └── rush-audit-cache-tech-note.md │ ├── lint-staged.config.cjs │ ├── package.json │ ├── rush-plugin-manifest.json │ ├── src │ │ ├── auditCache.ts │ │ ├── bin.ts │ │ ├── core │ │ │ ├── Analyzer.ts │ │ │ ├── Linux │ │ │ │ ├── LinuxTraceExecutor.ts │ │ │ │ └── StraceLogParser.ts │ │ │ ├── ReadFileResolver.ts │ │ │ ├── TraceExecutor.ts │ │ │ ├── WriteFileResolver.ts │ │ │ ├── base │ │ │ │ ├── BaseFileResolver.ts │ │ │ │ └── BaseTraceExecutor.ts │ │ │ └── test │ │ │ │ ├── ReadFileResolver.test.ts │ │ │ │ └── WriteFileResolver.test.ts │ │ ├── helpers │ │ │ ├── constants.ts │ │ │ ├── rushProject.ts │ │ │ ├── terminal.ts │ │ │ └── utils.ts │ │ ├── index.ts │ │ └── schemas │ │ │ └── plugin-options.schema.json │ └── tsconfig.json ├── rush-git-lfs-plugin │ ├── .eslintrc.js │ ├── .gitignore │ ├── .npmignore │ ├── CHANGELOG.json │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── command-line.json │ ├── config │ │ ├── heft.json │ │ └── jest.config.json │ ├── lint-staged.config.cjs │ ├── package.json │ ├── rush-plugin-manifest.json │ ├── schema │ │ └── git-lfs-option.schema.json │ ├── src │ │ ├── bin.ts │ │ ├── constant.ts │ │ ├── executor │ │ │ ├── index.ts │ │ │ ├── modules │ │ │ │ ├── base.ts │ │ │ │ ├── check.ts │ │ │ │ └── index.ts │ │ │ ├── pull.ts │ │ │ ├── run-check.ts │ │ │ └── version.ts │ │ ├── helpers │ │ │ ├── file-path-analyser.ts │ │ │ ├── terminal.ts │ │ │ └── type.ts │ │ ├── index.ts │ │ ├── options.ts │ │ ├── pull.ts │ │ └── tests │ │ │ ├── executor │ │ │ ├── core.test.ts │ │ │ └── verison.test.ts │ │ │ ├── helpers │ │ │ └── file-path-analyser.test.ts │ │ │ └── setup │ │ │ └── TestFileFactory.ts │ └── tsconfig.json ├── rush-init-project-plugin │ ├── .eslintrc.js │ ├── .gitignore │ ├── .npmignore │ ├── CHANGELOG.json │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── command-line.json │ ├── config │ │ ├── heft.json │ │ └── jest.config.json │ ├── docs │ │ └── init_project_configuration.md │ ├── lint-staged.config.cjs │ ├── package.json │ ├── rush-plugin-manifest.json │ ├── src │ │ ├── actions │ │ │ ├── addProjectToRushJson.ts │ │ │ ├── rushRushUpdate.ts │ │ │ └── sortPackageJson.ts │ │ ├── cli.ts │ │ ├── hooks.ts │ │ ├── index.ts │ │ ├── init-project.ts │ │ ├── logic │ │ │ ├── GitConfig.ts │ │ │ ├── TemplateConfiguration.ts │ │ │ ├── loadGlobalConfiguration.ts │ │ │ ├── loadRushConfiguration.ts │ │ │ ├── template.schema.json │ │ │ └── templateFolder.ts │ │ ├── plopfile.ts │ │ ├── terminal.ts │ │ ├── test │ │ │ ├── addManyCustomEngine │ │ │ │ ├── __snapshots__ │ │ │ │ │ └── addManyCustomEngine.test.ts.snap │ │ │ │ ├── addManyCustomEngine.test.ts │ │ │ │ ├── plop-templates │ │ │ │ │ ├── index │ │ │ │ │ └── pkg.json │ │ │ │ └── plopfile.js │ │ │ ├── addManyRaw │ │ │ │ ├── addMany.test.ts │ │ │ │ └── plop-templates │ │ │ │ │ └── pkg.json │ │ │ └── utils.ts │ │ └── ui │ │ │ ├── COLORS.ts │ │ │ ├── EMIT_EVENTS.ts │ │ │ ├── EventManager.ts │ │ │ ├── components │ │ │ ├── AutoCompleteComponent.ts │ │ │ ├── BaseFieldComponent.ts │ │ │ ├── BlessedHiddenInputComponent.ts │ │ │ ├── CheckboxComponent.ts │ │ │ ├── ConfirmComponent.ts │ │ │ ├── InputComponent.ts │ │ │ ├── ListComponent.ts │ │ │ ├── Warning.ts │ │ │ ├── form.ts │ │ │ ├── steps.ts │ │ │ └── templateList.ts │ │ │ └── index.ts │ ├── tsconfig.json │ └── typings.d.ts ├── rush-lint-staged-plugin │ ├── .eslintrc.js │ ├── .gitignore │ ├── .npmignore │ ├── CHANGELOG.json │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── command-line.json │ ├── config │ │ └── heft.json │ ├── lint-staged.config.cjs │ ├── package.json │ ├── rush-plugin-manifest.json │ ├── src │ │ ├── helpers │ │ │ └── terminal.ts │ │ ├── index.ts │ │ └── typings.d.ts │ └── tsconfig.json ├── rush-print-log-if-error-plugin │ ├── .eslintrc.js │ ├── .gitignore │ ├── CHANGELOG.json │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── command-line.json │ ├── config │ │ └── heft.json │ ├── lint-staged.config.cjs │ ├── package.json │ ├── rush-plugin-manifest.json │ ├── src │ │ ├── helpers │ │ │ ├── loadRushConfiguration.ts │ │ │ └── terminal.ts │ │ └── index.ts │ └── tsconfig.json ├── rush-sort-package-json │ ├── .eslintrc.js │ ├── .gitignore │ ├── CHANGELOG.json │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── command-line.json │ ├── config │ │ └── heft.json │ ├── lint-staged.config.cjs │ ├── package.json │ ├── rush-plugin-manifest.json │ ├── src │ │ ├── helpers │ │ │ ├── loadRushConfiguration.ts │ │ │ └── terminal.ts │ │ ├── index.ts │ │ └── sortPackageJson.ts │ └── tsconfig.json └── rush-upgrade-self-plugin │ ├── .eslintrc.js │ ├── .gitignore │ ├── .npmignore │ ├── CHANGELOG.json │ ├── CHANGELOG.md │ ├── LICENSE │ ├── README.md │ ├── command-line.json │ ├── config │ └── heft.json │ ├── lint-staged.config.cjs │ ├── package.json │ ├── rush-plugin-manifest.json │ ├── src │ ├── cli.ts │ └── upgrade-self.ts │ └── tsconfig.json └── rush.json /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ### Basic Checks 5 | 6 | Have you run `rush change` for this change? 7 | 8 | - [ ] Yes 9 | - [ ] No 10 | 11 | If **No**, please run `rush change` before, this is necessary. 12 | 13 | If adding a **new feature**, the PR's description includes: 14 | 15 | - [ ] Reason for adding this feature 16 | - [ ] How to use 17 | - [ ] A basic example 18 | 19 | **Does this PR introduce a breaking change?** (check one) 20 | 21 | - [ ] Yes 22 | - [ ] No 23 | 24 | If yes, please describe the impact and migration path for existing applications: 25 | 26 | ### Summary 27 | 28 | ### Detail 29 | 30 | ### How to test it 31 | -------------------------------------------------------------------------------- /.github/workflows/main.yaml: -------------------------------------------------------------------------------- 1 | name: Build and Test 2 | on: 3 | push: 4 | branches: ['main'] 5 | pull_request: 6 | branches: ['main'] 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v3 12 | with: 13 | fetch-depth: 2 14 | - name: Git config user 15 | uses: snow-actions/git-config-user@v1.0.0 16 | with: 17 | name: bytemate-bot 18 | email: bytematebot@users.noreply.github.com 19 | - uses: actions/setup-node@v3 20 | with: 21 | node-version: 16 22 | - name: Verify Change Logs 23 | run: node common/scripts/install-run-rush.js change --verify 24 | - name: Rush Install 25 | run: node common/scripts/install-run-rush.js install 26 | - name: Rush rebuild 27 | run: node common/scripts/install-run-rush.js rebuild --verbose --production 28 | - name: Rush test 29 | run: node common/scripts/install-run-rush.js test --verbose 30 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish NPM Packages 2 | on: 3 | workflow_dispatch 4 | jobs: 5 | publish: 6 | runs-on: ubuntu-latest 7 | steps: 8 | - uses: actions/checkout@v3 9 | with: 10 | fetch-depth: 2 11 | token: ${{ secrets.BOT_ACCESS_TOKEN }} 12 | - name: Git config user 13 | uses: snow-actions/git-config-user@v1.0.0 14 | with: 15 | name: bytemate-bot 16 | email: bytematebot@users.noreply.github.com 17 | - uses: actions/setup-node@v3 18 | with: 19 | node-version: 16 20 | - name: Rush Install 21 | run: node common/scripts/install-run-rush.js install 22 | - name: Rush build 23 | run: node common/scripts/install-run-rush.js build --verbose --production 24 | - name: Rush test 25 | run: node common/scripts/install-run-rush.js test --verbose 26 | - name: Rush publish 27 | run: node common/scripts/install-run-rush.js publish --apply --publish --target-branch ${{ github.ref_name }} 28 | env: 29 | NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | *.log 3 | npm-debug.log* 4 | yarn-debug.log* 5 | yarn-error.log* 6 | 7 | # Runtime data 8 | *.pid 9 | *.seed 10 | *.pid.lock 11 | 12 | # Directory for instrumented libs generated by jscoverage/JSCover 13 | lib-cov 14 | 15 | # Coverage directory used by tools like istanbul 16 | coverage 17 | 18 | # nyc test coverage 19 | .nyc_output 20 | 21 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 22 | .grunt 23 | 24 | # Bower dependency directory (https://bower.io/) 25 | bower_components 26 | 27 | # node-waf configuration 28 | .lock-wscript 29 | 30 | # Compiled binary addons (https://nodejs.org/api/addons.html) 31 | build/Release 32 | 33 | # Dependency directories 34 | node_modules/ 35 | jspm_packages/ 36 | 37 | # Optional npm cache directory 38 | .npm 39 | 40 | # Optional eslint cache 41 | .eslintcache 42 | 43 | # Optional REPL history 44 | .node_repl_history 45 | 46 | # Output of 'npm pack' 47 | *.tgz 48 | 49 | # Yarn Integrity file 50 | .yarn-integrity 51 | 52 | # dotenv environment variables file 53 | .env 54 | 55 | # next.js build output 56 | .next 57 | 58 | # OS X temporary files 59 | .DS_Store 60 | 61 | # Rush temporary files 62 | common/deploy/ 63 | common/temp/ 64 | common/autoinstallers/*/.npmrc 65 | **/.rush/temp/ 66 | 67 | # Heft 68 | .heft 69 | 70 | temp/ -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------------------------------------------------------- 2 | # Keep this section in sync with .gitignore 3 | #------------------------------------------------------------------------------------------------------------------- 4 | 5 | # Logs 6 | *.log 7 | npm-debug.log* 8 | yarn-debug.log* 9 | yarn-error.log* 10 | 11 | # Runtime data 12 | *.pid 13 | *.seed 14 | *.pid.lock 15 | 16 | # Directory for instrumented libs generated by jscoverage/JSCover 17 | lib-cov 18 | 19 | # Coverage directory used by tools like istanbul 20 | coverage 21 | 22 | # nyc test coverage 23 | .nyc_output 24 | 25 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 26 | .grunt 27 | 28 | # Bower dependency directory (https://bower.io/) 29 | bower_components 30 | 31 | # node-waf configuration 32 | .lock-wscript 33 | 34 | # Compiled binary addons (https://nodejs.org/api/addons.html) 35 | build/Release 36 | 37 | # Dependency directories 38 | node_modules/ 39 | jspm_packages/ 40 | 41 | # Optional npm cache directory 42 | .npm 43 | 44 | # Optional eslint cache 45 | .eslintcache 46 | 47 | # Optional REPL history 48 | .node_repl_history 49 | 50 | # Output of 'npm pack' 51 | *.tgz 52 | 53 | # Yarn Integrity file 54 | .yarn-integrity 55 | 56 | # dotenv environment variables file 57 | .env 58 | 59 | # next.js build output 60 | .next 61 | 62 | # OS X temporary files 63 | .DS_Store 64 | 65 | # Rush temporary files 66 | common/deploy/ 67 | common/temp/ 68 | **/.rush/temp/ 69 | 70 | # Common toolchain intermediate files 71 | temp 72 | lib 73 | lib-amd 74 | lib-es6 75 | dist 76 | *.scss.ts 77 | *.sass.ts 78 | 79 | # Visual Studio Code 80 | .vscode 81 | 82 | # Remove eventually 83 | package-deps.json 84 | 85 | #------------------------------------------------------------------------------------------------------------------- 86 | # Prettier-specific overrides 87 | #------------------------------------------------------------------------------------------------------------------- 88 | 89 | # Machine-egnerated files 90 | common/reviews 91 | common/changes 92 | common/scripts 93 | common/config/rush/browser-approved-packages.json 94 | common/config/rush/nonbrowser-approved-packages.json 95 | CHANGELOG.* 96 | pnpm-lock.yaml 97 | build-tests/*/etc 98 | dist-dev 99 | dist-prod 100 | 101 | # Prettier doesn't understand the /*[LINE "HYPOTHETICAL"]*/ macros in these files: 102 | libraries/rush-lib/assets/rush-init/ 103 | 104 | # These are intentionally invalid files 105 | libraries/heft-config-file/src/test/errorCases/invalidJson/config.json 106 | 107 | # We'll consider enabling this later; Prettier reformats code blocks, which affects end-user content 108 | *.md 109 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | // Documentation for this file: https://prettier.io/docs/en/configuration.html 2 | module.exports = { 3 | // We use a larger print width because Prettier's word-wrapping seems to be tuned 4 | // for plain JavaScript without type annotations 5 | printWidth: 110, 6 | // Microsoft style quotes 7 | singleQuote: true, 8 | // Preserve existing newlines 9 | endOfLine: 'auto', 10 | // For ES5, trailing commas cannot be used in function parameters; it is counterintuitive 11 | // to use them for arrays only 12 | trailingComma: 'none' 13 | }; 14 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | // Controls the rendering size of tabs in characters. Accepted values: "auto", 2, 4, 6, etc. If set to "auto", the value will be guessed when a file is opened. 4 | "editor.tabSize": 2, 5 | // Controls after how many characters the editor will wrap to the next line. Setting this to 0 turns on viewport width wrapping 6 | // When enabled, will trim trailing whitespace when you save a file. 7 | "files.trimTrailingWhitespace": true, 8 | // Controls if the editor should automatically close brackets after opening them 9 | "editor.autoClosingBrackets": "never", 10 | // Configure glob patterns for excluding files and folders in searches. Inherits all glob patterns from the file.exclude setting. 11 | "search.exclude": { 12 | "**/node_modules": true, 13 | "**/bower_components": true, 14 | "**/dist": true, 15 | "**/lib": true, 16 | "**/lib-amd": true, 17 | "**/test/**/temp": false, 18 | "**/temp": true, 19 | "**/coverage": true 20 | }, 21 | "files.associations": { 22 | "**/package.json": "json", 23 | "**/*.json": "jsonc" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Setting your machine 2 | 3 | 1. Install a LTS Node.js version, such as v14.19.1 4 | 2. Install rush globally: `npm install -g @microsoft/rush` 5 | 3. Clone the repository: `git clone git@github.com:bytemate/rush-plugins.git` 6 | 7 | # Building the project 8 | 9 | We use Rush tool for building projects in this monorepo. 10 | 11 | 1. Use rush to install the package dependencies: 12 | 13 | ``` 14 | cd rush-plugins 15 | rush install 16 | ``` 17 | 18 | Note: you need to configure a Github email like **mrexample@users.noreply.github.com** 19 | 20 | 2. Build the project in the repo: 21 | 22 | ``` 23 | # rush build -t 24 | rush build -t rush-archive-project-plugin 25 | ``` 26 | 27 | # Testing the project 28 | 29 | This section shows the way to test the plugin in this repo. 30 | 31 | Use `rush-archive-project-plugin` for example: 32 | 33 | 1. Modify **common/autoinstallers/command-plugins/package.json** 34 | 35 | ``` 36 | { 37 | "name": "command-plugins", 38 | "version": "1.0.0", 39 | "private": true, 40 | "dependencies": { 41 | "rush-archive-project-plugin": "1.1.3", 42 | - "rush-audit-cache-plugin": "0.0.2", 43 | + "rush-audit-cache-plugin": "link:../../../rush-plugins/rush-archive-project-plugin", 44 | "rush-init-project-plugin": "0.6.0", 45 | "rush-lint-staged-plugin": "0.1.6", 46 | "rush-sort-package-json": "0.0.3", 47 | "rush-upgrade-self-plugin": "1.0.6", 48 | "typescript": "4.4.2" 49 | } 50 | } 51 | ``` 52 | 53 | 2. Update the plugins 54 | 55 | ``` 56 | rush update-autoinstaller --name command-plugins 57 | 58 | rush update 59 | ``` 60 | 61 | 3. Test your plugin 62 | 63 | Since `rush-archive-project-plugin` provides `rush archive-project`, you can test it now! 64 | 65 | Note: You can see this approach uses a `link:` protocol to install a rush plugin package by relative path. That means you can also configure another local monorepo to use this plugin as well. 66 | 67 | # Submitting a Pull Request 68 | 69 | We welcome contributions! To submit a feature: 70 | 71 | 1. Fork the repo. 72 | 2. Create a branch and commit your changes. 73 | 3. If you modify any package.json files, run `rush update` to make sure the `pnpm-lock.yaml` file is up to date. Commit any changes made to that file. 74 | 4. Before creating your PR, run `rush change`; If prompted, enter a change log message, commit the files that get created. 75 | 5. Create a [pull request](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request) 76 | 6. Add the project name as a prefix to your PR title. For example: "[rush-archive-project-plugin] Added a new API feature" or "[rush-init-project-plugin] Fixed a bug in the plugin". -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) TikTok Pte. Ltd. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SHELL=/bin/bash 2 | 3 | CURRENT_BRANCH_NAME := $(shell git branch --show-current) 4 | 5 | publish: 6 | @export NPM_AUTH_TOKEN=`cat ~/.npmrc | grep registry.npmjs.org | grep _authToken | awk -F= '{print $$2}'`; \ 7 | rush publish --apply --publish --target-branch $(CURRENT_BRANCH_NAME) 8 | 9 | publish-all: 10 | @export NPM_AUTH_TOKEN=`cat ~/.npmrc | grep registry.npmjs.org | grep _authToken | awk -F= '{print $$2}'`; \ 11 | rush publish --apply --publish --target-branch $(CURRENT_BRANCH_NAME) --include-all 12 | 13 | publish-dev: 14 | @export NPM_AUTH_TOKEN=`cat ~/.npmrc | grep registry.npmjs.org | grep _authToken | awk -F= '{print $$2}'`; \ 15 | rush publish --publish --include-all --tag dev 16 | -------------------------------------------------------------------------------- /common/_templates/rush-plugin-for-command/.eslintrc.js: -------------------------------------------------------------------------------- 1 | // This is a workaround for https://github.com/eslint/eslint/issues/3458 2 | require("@rushstack/eslint-config/patch/modern-module-resolution"); 3 | 4 | module.exports = { 5 | extends: [ 6 | "@rushstack/eslint-config/profile/node-trusted-tool", 7 | "@rushstack/eslint-config/mixins/friendly-locals", 8 | ], 9 | parserOptions: { tsconfigRootDir: __dirname }, 10 | ignorePatterns: ["node_modules/", "lib/"], 11 | rules: { 12 | "@typescript-eslint/no-explicit-any": "off", 13 | }, 14 | }; 15 | -------------------------------------------------------------------------------- /common/_templates/rush-plugin-for-command/.gitignore: -------------------------------------------------------------------------------- 1 | lib/ -------------------------------------------------------------------------------- /common/_templates/rush-plugin-for-command/.npmignore: -------------------------------------------------------------------------------- 1 | # THIS IS A STANDARD TEMPLATE FOR .npmignore FILES IN THIS REPO. 2 | 3 | # Ignore all files by default, to avoid accidentally publishing unintended files. 4 | * 5 | 6 | # Use negative patterns to bring back the specific things we want to publish. 7 | !/bin/** 8 | !/lib/** 9 | !/lib-*/** 10 | !/dist/** 11 | !ThirdPartyNotice.txt 12 | !/src/** 13 | 14 | # Ignore certain patterns that should not get published. 15 | /dist/*.stats.* 16 | /lib/**/test/ 17 | /lib-*/**/test/ 18 | *.test.js 19 | 20 | # NOTE: These don't need to be specified, because NPM includes them automatically. 21 | # 22 | # package.json 23 | # README (and its variants) 24 | # CHANGELOG (and its variants) 25 | # LICENSE / LICENCE 26 | 27 | #-------------------------------------------- 28 | # DO NOT MODIFY THE TEMPLATE ABOVE THIS LINE 29 | #-------------------------------------------- 30 | 31 | # (Add your project-specific overrides here) 32 | !/includes/** 33 | !rush-plugin-manifest.json 34 | !command-line.json 35 | -------------------------------------------------------------------------------- /common/_templates/rush-plugin-for-command/README.md: -------------------------------------------------------------------------------- 1 | # {{ packageName }} 2 | 3 | {{ description }} 4 | 5 | # Prerequisite 6 | 7 | Rush.js >= 5.57.0 8 | -------------------------------------------------------------------------------- /common/_templates/rush-plugin-for-command/command-line.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/command-line.schema.json", 3 | "commands": [ 4 | { 5 | "name": "{{ commandName }}", 6 | "commandKind": "global", 7 | "summary": "{{ description }}", 8 | "shellCommand": "node /lib/index.js", 9 | "safeForSimultaneousRushProcesses": true 10 | } 11 | ] 12 | // "parameters": [], 13 | } 14 | -------------------------------------------------------------------------------- /common/_templates/rush-plugin-for-command/config/heft.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/heft/heft.schema.json", 3 | 4 | "eventActions": [ 5 | { 6 | "actionKind": "deleteGlobs", 7 | "heftEvent": "clean", 8 | "actionId": "defaultClean", 9 | "globsToDelete": ["lib"] 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /common/_templates/rush-plugin-for-command/init.config.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | IConfig, 3 | IHooks, 4 | IAnswers, 5 | PromptQuestion 6 | } from '../../autoinstallers/command-plugins/node_modules/rush-init-project-plugin'; 7 | 8 | const config: IConfig = { 9 | prompts: [], 10 | plugins: [ 11 | { 12 | apply: (hooks: IHooks) => { 13 | hooks.promptQuestion 14 | .for('projectFolder') 15 | .tap('command-plugin', (promptQuestion: PromptQuestion, answersSoFar: IAnswers) => { 16 | const { unscopedPackageName } = answersSoFar; 17 | promptQuestion.default = `rush-plugins/${unscopedPackageName}`; 18 | return undefined; 19 | }); 20 | // hooks.done.tapPromise("command-plugin", async (result, answers) => { 21 | // await new Promise((resolve) => { 22 | // setTimeout(() => { 23 | // console.log(result, answers); 24 | // }, 1000); 25 | // resolve(); 26 | // }); 27 | // }); 28 | } 29 | } 30 | ], 31 | defaultProjectConfiguration: {} 32 | }; 33 | 34 | export default config; 35 | -------------------------------------------------------------------------------- /common/_templates/rush-plugin-for-command/lint-staged.config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-env es6 */ 2 | const config = { 3 | "*.{js,jsx,ts,tsx}": "eslint --fix", 4 | }; 5 | module.exports = config; 6 | -------------------------------------------------------------------------------- /common/_templates/rush-plugin-for-command/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "{{ packageName }}", 3 | "version": "0.0.0", 4 | "description": "{{ description }}", 5 | "keywords": [ 6 | "rush", 7 | "plugin", 8 | "command" 9 | ], 10 | "homepage": "https://github.com/bytemate/rush-plugins#readme", 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/bytemate/rush-plugins", 14 | "directory": "{{ projectFolder }}" 15 | }, 16 | "license": "MIT", 17 | "author": "{{ authorName }}", 18 | "main": "lib/index.js", 19 | "scripts": { 20 | "build": "heft build --clean", 21 | "build:watch": "heft build --watch", 22 | "prepublishOnly": "npm run build", 23 | "test": "heft test" 24 | }, 25 | "dependencies": { 26 | "@rushstack/node-core-library": "3.44.1", 27 | "@rushstack/rush-sdk": "5.62.4" 28 | }, 29 | "devDependencies": { 30 | "@rushstack/eslint-config": "2.4.5", 31 | "@rushstack/heft": "0.43.2", 32 | "@rushstack/heft-node-rig": "1.2.31", 33 | "@types/heft-jest": "1.0.1", 34 | "@types/node": "12.20.24", 35 | "eslint": "7.32.0", 36 | "typescript": "4.4.2" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /common/_templates/rush-plugin-for-command/rush-plugin-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush-plugin-manifest.schema.json", 3 | "plugins": [ 4 | { 5 | "pluginName": "{{ unscopedPackageName }}", 6 | "description": "{{ description }}", 7 | "commandLineJsonFilePath": "command-line.json" 8 | } 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /common/_templates/rush-plugin-for-command/src/helpers/terminal.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Terminal, 3 | ConsoleTerminalProvider, 4 | } from "@rushstack/node-core-library"; 5 | 6 | export const terminal: Terminal = new Terminal(new ConsoleTerminalProvider()); 7 | -------------------------------------------------------------------------------- /common/_templates/rush-plugin-for-command/src/index.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import { terminal } from "./helpers/terminal"; 4 | 5 | // eslint-disable-next-line @typescript-eslint/no-floating-promises 6 | main(); 7 | 8 | async function main(): Promise { 9 | try { 10 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 11 | } catch (error: any) { 12 | if (error.message) { 13 | terminal.writeErrorLine(error.message); 14 | } else { 15 | throw error; 16 | } 17 | process.exit(1); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /common/_templates/template.json: -------------------------------------------------------------------------------- 1 | { 2 | "templates": [ 3 | { 4 | "displayName": "command", 5 | "templateFolder": "rush-plugin-for-command" 6 | } 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /common/autoinstallers/command-plugins/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "command-plugins", 3 | "version": "1.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "rush-archive-project-plugin": "1.1.3", 7 | "rush-audit-cache-plugin": "0.0.2", 8 | "rush-init-project-plugin": "0.6.0", 9 | "rush-lint-staged-plugin": "0.1.6", 10 | "rush-sort-package-json": "0.0.3", 11 | "rush-upgrade-self-plugin": "1.0.6", 12 | "typescript": "4.4.2" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /common/autoinstallers/command-plugins/rush-plugins/rush-archive-project-plugin/rush-archive-project-plugin/command-line.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/command-line.schema.json", 3 | "commands": [ 4 | { 5 | "name": "archive-project", 6 | "commandKind": "global", 7 | "summary": "Archives the project to a tar file", 8 | "shellCommand": "rush-project-archiver archive", 9 | "safeForSimultaneousRushProcesses": true 10 | }, 11 | { 12 | "name": "unarchive-project", 13 | "commandKind": "global", 14 | "summary": "Unarchive the project from a tar file", 15 | "shellCommand": "rush-project-archiver unarchive", 16 | "safeForSimultaneousRushProcesses": true 17 | } 18 | ], 19 | "parameters": [ 20 | { 21 | "parameterKind": "string", 22 | "description": "The name of the package", 23 | "longName": "--package-name", 24 | "argumentName": "PACKAGE_NAME", 25 | "associatedCommands": ["archive-project", "unarchive-project"], 26 | "required": true 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /common/autoinstallers/command-plugins/rush-plugins/rush-archive-project-plugin/rush-plugin-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush-plugin-manifest.schema.json", 3 | "plugins": [ 4 | { 5 | "pluginName": "rush-archive-project-plugin", 6 | "description": "Rush plugin to archive project", 7 | "commandLineJsonFilePath": "command-line.json" 8 | } 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /common/autoinstallers/command-plugins/rush-plugins/rush-audit-cache-plugin/rush-audit-cache-plugin/command-line.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/command-line.schema.json", 3 | "commands": [ 4 | { 5 | "name": "audit-cache", 6 | "commandKind": "global", 7 | "summary": "Audit cache configuration by diagnosing the build processes of the target project and its dependencies", 8 | "shellCommand": "node /lib/bin.js", 9 | "safeForSimultaneousRushProcesses": true 10 | } 11 | ], 12 | "parameters": [ 13 | { 14 | "parameterKind": "string", 15 | "description": "The package name of the project", 16 | "longName": "--project", 17 | "shortName": "-p", 18 | "argumentName": "PACKAGE_NAME", 19 | "associatedCommands": [ "audit-cache" ], 20 | "required": false 21 | }, 22 | { 23 | "parameterKind": "string", 24 | "description": "verbosity that can be increased", 25 | "longName": "--verbose", 26 | "shortName": "-v", 27 | "argumentName": "VERBOSE", 28 | "associatedCommands": [ "audit-cache" ], 29 | "required": false 30 | }, 31 | { 32 | "parameterKind": "flag", 33 | "description": "show current version", 34 | "longName": "--version", 35 | "shortName": "-V", 36 | "associatedCommands": [ "audit-cache" ], 37 | "required": false 38 | } 39 | ] 40 | } 41 | -------------------------------------------------------------------------------- /common/autoinstallers/command-plugins/rush-plugins/rush-audit-cache-plugin/rush-plugin-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush-plugin-manifest.schema.json", 3 | "plugins": [ 4 | { 5 | "pluginName": "rush-audit-cache-plugin", 6 | "description": "A diagnostic tool for rush build cache", 7 | "commandLineJsonFilePath": "command-line.json" 8 | } 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /common/autoinstallers/command-plugins/rush-plugins/rush-init-project-plugin/rush-init-project-plugin/command-line.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/command-line.schema.json", 3 | "commands": [ 4 | { 5 | "name": "init-project", 6 | "commandKind": "global", 7 | "summary": "Initialize project in this monorepo", 8 | "shellCommand": "rush-init-project", 9 | "safeForSimultaneousRushProcesses": true 10 | } 11 | ], 12 | "parameters": [ 13 | { 14 | "parameterKind": "string", 15 | "description": "Provide predefined answers with JSON string", 16 | "shortName": "-a", 17 | "longName": "--answer", 18 | "argumentName": "ANSWER", 19 | "associatedCommands": ["init-project"], 20 | "required": false 21 | }, 22 | { 23 | "parameterKind": "flag", 24 | "description": "Provide the option isDryRun in plugin context", 25 | "shortName": "-d", 26 | "longName": "--dry-run", 27 | "associatedCommands": ["init-project"], 28 | "required": false 29 | }, 30 | { 31 | "parameterKind": "flag", 32 | "description": "Provide verbose log output", 33 | "shortName": "-v", 34 | "longName": "--verbose", 35 | "associatedCommands": ["init-project"], 36 | "required": false 37 | } 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /common/autoinstallers/command-plugins/rush-plugins/rush-init-project-plugin/rush-plugin-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush-plugin-manifest.schema.json", 3 | "plugins": [ 4 | { 5 | "pluginName": "rush-init-project-plugin", 6 | "description": "Rush plugin for initialize project in monorepo", 7 | "commandLineJsonFilePath": "command-line.json" 8 | } 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /common/autoinstallers/command-plugins/rush-plugins/rush-lint-staged-plugin/rush-lint-staged-plugin/command-line.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/command-line.schema.json", 3 | "commands": [ 4 | { 5 | "name": "lint-staged", 6 | "commandKind": "global", 7 | "summary": "Rush plugin for lint-staged", 8 | "shellCommand": "node /lib/index.js", 9 | "safeForSimultaneousRushProcesses": true 10 | } 11 | ] 12 | // "parameters": [], 13 | } 14 | -------------------------------------------------------------------------------- /common/autoinstallers/command-plugins/rush-plugins/rush-lint-staged-plugin/rush-plugin-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush-plugin-manifest.schema.json", 3 | "plugins": [ 4 | { 5 | "pluginName": "rush-lint-staged-plugin", 6 | "description": "Rush plugin for lint-staged", 7 | "commandLineJsonFilePath": "command-line.json" 8 | } 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /common/autoinstallers/command-plugins/rush-plugins/rush-sort-package-json/rush-plugin-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush-plugin-manifest.schema.json", 3 | "plugins": [ 4 | { 5 | "pluginName": "rush-sort-package-json", 6 | "description": "Rush plugin for sort package.json file in the project", 7 | "commandLineJsonFilePath": "command-line.json" 8 | } 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /common/autoinstallers/command-plugins/rush-plugins/rush-sort-package-json/rush-sort-package-json/command-line.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/command-line.schema.json", 3 | "commands": [ 4 | { 5 | "name": "sort-package-json", 6 | "commandKind": "global", 7 | "summary": "Rush plugin for sort package.json file in the project", 8 | "shellCommand": "node /lib/index.js", 9 | "safeForSimultaneousRushProcesses": true 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /common/autoinstallers/command-plugins/rush-plugins/rush-upgrade-self-plugin/rush-plugin-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush-plugin-manifest.schema.json", 3 | "plugins": [ 4 | { 5 | "pluginName": "rush-upgrade-self-plugin", 6 | "description": "Rush plugin for upgrade Rush itself", 7 | "commandLineJsonFilePath": "command-line.json" 8 | } 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /common/autoinstallers/command-plugins/rush-plugins/rush-upgrade-self-plugin/rush-upgrade-self-plugin/command-line.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/command-line.schema.json", 3 | "commands": [ 4 | { 5 | "name": "upgrade-self", 6 | "commandKind": "global", 7 | "summary": "Upgrade Rush.js itself", 8 | "shellCommand": "rush-upgrade-self", 9 | "safeForSimultaneousRushProcesses": true 10 | } 11 | ] 12 | // "parameters": [], 13 | } 14 | -------------------------------------------------------------------------------- /common/autoinstallers/rush-prettier/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rush-prettier", 3 | "version": "1.0.0", 4 | "private": true, 5 | "dependencies": { 6 | "pretty-quick": "3.1.3", 7 | "prettier": "2.7.1" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /common/config/rush/.npmrc: -------------------------------------------------------------------------------- 1 | # Rush uses this file to configure the NPM package registry during installation. It is applicable 2 | # to PNPM, NPM, and Yarn package managers. It is used by operations such as "rush install", 3 | # "rush update", and the "install-run.js" scripts. 4 | # 5 | # NOTE: The "rush publish" command uses .npmrc-publish instead. 6 | # 7 | # Before invoking the package manager, Rush will copy this file to the folder where installation 8 | # is performed. The copied file will omit any config lines that reference environment variables 9 | # that are undefined in that session; this avoids problems that would otherwise result due to 10 | # a missing variable being replaced by an empty string. 11 | # 12 | # * * * SECURITY WARNING * * * 13 | # 14 | # It is NOT recommended to store authentication tokens in a text file on a lab machine, because 15 | # other unrelated processes may be able to read the file. Also, the file may persist indefinitely, 16 | # for example if the machine loses power. A safer practice is to pass the token via an 17 | # environment variable, which can be referenced from .npmrc using ${} expansion. For example: 18 | # 19 | # //registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN} 20 | # 21 | registry=https://registry.npmjs.org/ 22 | always-auth=false 23 | -------------------------------------------------------------------------------- /common/config/rush/.npmrc-publish: -------------------------------------------------------------------------------- 1 | # This config file is very similar to common/config/rush/.npmrc, except that .npmrc-publish 2 | # is used by the "rush publish" command, as publishing often involves different credentials 3 | # and registries than other operations. 4 | # 5 | # Before invoking the package manager, Rush will copy this file to "common/temp/publish-home/.npmrc" 6 | # and then temporarily map that folder as the "home directory" for the current user account. 7 | # This enables the same settings to apply for each project folder that gets published. The copied file 8 | # will omit any config lines that reference environment variables that are undefined in that session; 9 | # this avoids problems that would otherwise result due to a missing variable being replaced by 10 | # an empty string. 11 | # 12 | # * * * SECURITY WARNING * * * 13 | # 14 | # It is NOT recommended to store authentication tokens in a text file on a lab machine, because 15 | # other unrelated processes may be able to read the file. Also, the file may persist indefinitely, 16 | # for example if the machine loses power. A safer practice is to pass the token via an 17 | # environment variable, which can be referenced from .npmrc using ${} expansion. For example: 18 | # 19 | # //registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN} 20 | # 21 | registry=https://registry.npmjs.org/ 22 | always-auth=true 23 | //registry.npmjs.org/:_authToken=${NPM_AUTH_TOKEN} -------------------------------------------------------------------------------- /common/config/rush/.pnpmfile.cjs: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * When using the PNPM package manager, you can use pnpmfile.js to workaround 5 | * dependencies that have mistakes in their package.json file. (This feature is 6 | * functionally similar to Yarn's "resolutions".) 7 | * 8 | * For details, see the PNPM documentation: 9 | * https://pnpm.js.org/docs/en/hooks.html 10 | * 11 | * IMPORTANT: SINCE THIS FILE CONTAINS EXECUTABLE CODE, MODIFYING IT IS LIKELY TO INVALIDATE 12 | * ANY CACHED DEPENDENCY ANALYSIS. After any modification to pnpmfile.js, it's recommended to run 13 | * "rush update --full" so that PNPM will recalculate all version selections. 14 | */ 15 | module.exports = { 16 | hooks: { 17 | readPackage 18 | } 19 | }; 20 | 21 | /** 22 | * This hook is invoked during installation before a package's dependencies 23 | * are selected. 24 | * The `packageJson` parameter is the deserialized package.json 25 | * contents for the package that is about to be installed. 26 | * The `context` parameter provides a log() function. 27 | * The return value is the updated object. 28 | */ 29 | function readPackage(packageJson, context) { 30 | 31 | // // The karma types have a missing dependency on typings from the log4js package. 32 | // if (packageJson.name === '@types/karma') { 33 | // context.log('Fixed up dependencies for @types/karma'); 34 | // packageJson.dependencies['log4js'] = '0.6.38'; 35 | // } 36 | 37 | return packageJson; 38 | } 39 | -------------------------------------------------------------------------------- /common/config/rush/experiments.json: -------------------------------------------------------------------------------- 1 | /** 2 | * This configuration file allows repo maintainers to enable and disable experimental 3 | * Rush features. More documentation is available on the Rush website: https://rushjs.io 4 | */ 5 | { 6 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/experiments.schema.json", 7 | 8 | /** 9 | * By default, 'rush install' passes --no-prefer-frozen-lockfile to 'pnpm install'. 10 | * Set this option to true to pass '--frozen-lockfile' instead for faster installs. 11 | */ 12 | // "usePnpmFrozenLockfileForRushInstall": true, 13 | 14 | /** 15 | * By default, 'rush update' passes --no-prefer-frozen-lockfile to 'pnpm install'. 16 | * Set this option to true to pass '--prefer-frozen-lockfile' instead to minimize shrinkwrap changes. 17 | */ 18 | // "usePnpmPreferFrozenLockfileForRushUpdate": true, 19 | 20 | /** 21 | * If using the 'preventManualShrinkwrapChanges' option, restricts the hash to only include the layout of external dependencies. 22 | * Used to allow links between workspace projects or the addition/removal of references to existing dependency versions to not 23 | * cause hash changes. 24 | */ 25 | // "omitImportersFromPreventManualShrinkwrapChanges": true, 26 | 27 | /** 28 | * If true, the chmod field in temporary project tar headers will not be normalized. 29 | * This normalization can help ensure consistent tarball integrity across platforms. 30 | */ 31 | // "noChmodFieldInTarHeaderNormalization": true, 32 | 33 | /** 34 | * If true, build caching will respect the allowWarningsInSuccessfulBuild flag and cache builds with warnings. 35 | * This will not replay warnings from the cached build. 36 | */ 37 | // "buildCacheWithAllowWarningsInSuccessfulBuild": true 38 | } 39 | -------------------------------------------------------------------------------- /common/config/rush/repo-state.json: -------------------------------------------------------------------------------- 1 | // DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush. 2 | { 3 | "preferredVersionsHash": "bf21a9e8fbc5a3846fb05b4fa0859e0917b2202f" 4 | } 5 | -------------------------------------------------------------------------------- /common/config/rush/rush-plugins.json: -------------------------------------------------------------------------------- 1 | /** 2 | * This configuration file manages Rush's plugin feature. 3 | */ 4 | { 5 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush-plugins.schema.json", 6 | "plugins": [ 7 | /** 8 | * Each item defines a plugin configuration used by Rush. 9 | */ 10 | // { 11 | // /** 12 | // * The name of the rush plugin package. 13 | // */ 14 | // "packageName": "@scope/my-rush-plugin", 15 | // /** 16 | // * The name of the plugin provided by rush plugin package 17 | // */ 18 | // "pluginName": "my-plugin-name", 19 | // /** 20 | // * Autoinstaller name used to install the plugin. 21 | // */ 22 | // "autoinstallerName": "plugins" 23 | // } 24 | { 25 | "packageName": "rush-init-project-plugin", 26 | "pluginName": "rush-init-project-plugin", 27 | "autoinstallerName": "command-plugins" // the name of autoinstaller you created before 28 | }, 29 | { 30 | "packageName": "rush-archive-project-plugin", 31 | "pluginName": "rush-archive-project-plugin", 32 | "autoinstallerName": "command-plugins" // the name of autoinstaller you created before 33 | }, 34 | { 35 | "packageName": "rush-audit-cache-plugin", 36 | "pluginName": "rush-audit-cache-plugin", 37 | "autoinstallerName": "command-plugins" // the name of autoinstaller you created before 38 | }, 39 | { 40 | "packageName": "rush-lint-staged-plugin", 41 | "pluginName": "rush-lint-staged-plugin", 42 | "autoinstallerName": "command-plugins" // the name of autoinstaller you created before 43 | }, 44 | { 45 | "packageName": "rush-sort-package-json", 46 | "pluginName": "rush-sort-package-json", 47 | "autoinstallerName": "command-plugins" // the name of autoinstaller you created before 48 | }, 49 | { 50 | "packageName": "rush-upgrade-self-plugin", 51 | "pluginName": "rush-upgrade-self-plugin", 52 | "autoinstallerName": "command-plugins" // the name of autoinstaller you created before 53 | } 54 | ] 55 | } 56 | -------------------------------------------------------------------------------- /common/git-hooks/commit-msg.sample: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # This is an example Git hook for use with Rush. To enable this hook, rename this file 4 | # to "commit-msg" and then run "rush install", which will copy it from common/git-hooks 5 | # to the .git/hooks folder. 6 | # 7 | # TO LEARN MORE ABOUT GIT HOOKS 8 | # 9 | # The Git documentation is here: https://git-scm.com/docs/githooks 10 | # Some helpful resources: https://githooks.com 11 | # 12 | # ABOUT THIS EXAMPLE 13 | # 14 | # The commit-msg hook is called by "git commit" with one argument, the name of the file 15 | # that has the commit message. The hook should exit with non-zero status after issuing 16 | # an appropriate message if it wants to stop the commit. The hook is allowed to edit 17 | # the commit message file. 18 | 19 | # This example enforces that commit message should contain a minimum amount of 20 | # description text. 21 | if [ `cat $1 | wc -w` -lt 3 ]; then 22 | echo "" 23 | echo "Invalid commit message: The message must contain at least 3 words." 24 | exit 1 25 | fi 26 | -------------------------------------------------------------------------------- /common/git-hooks/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Called by "git commit" with no arguments. The hook should 4 | # exit with non-zero status after issuing an appropriate message if 5 | # it wants to stop the commit. 6 | 7 | # Invoke the "rush prettier" custom command to reformat files whenever they 8 | # are committed. The command is defined in common/config/rush/command-line.json 9 | # and uses the "rush-prettier" autoinstaller. 10 | node common/scripts/install-run-rush.js --quiet prettier || exit $? 11 | 12 | node common/scripts/install-run-rush.js --quiet lint-staged || exit $? -------------------------------------------------------------------------------- /common/scripts/install-run-rushx.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. 3 | // See the @microsoft/rush package's LICENSE file for license information. 4 | Object.defineProperty(exports, "__esModule", { value: true }); 5 | // THIS FILE WAS GENERATED BY A TOOL. ANY MANUAL MODIFICATIONS WILL GET OVERWRITTEN WHENEVER RUSH IS UPGRADED. 6 | // 7 | // This script is intended for usage in an automated build environment where the Rush command may not have 8 | // been preinstalled, or may have an unpredictable version. This script will automatically install the version of Rush 9 | // specified in the rush.json configuration file (if not already installed), and then pass a command-line to the 10 | // rushx command. 11 | // 12 | // An example usage would be: 13 | // 14 | // node common/scripts/install-run-rushx.js custom-command 15 | // 16 | // For more information, see: https://rushjs.io/pages/maintainer/setup_new_repo/ 17 | require("./install-run-rush"); 18 | //# sourceMappingURL=install-run-rushx.js.map -------------------------------------------------------------------------------- /cspell.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2", 3 | "ignorePaths": [], 4 | "dictionaryDefinitions": [], 5 | "dictionaries": [], 6 | "words": [ 7 | "buildable", 8 | "bytemate", 9 | "bytemate", 10 | "lilconfig", 11 | "nonbrowser", 12 | "noreply", 13 | "npmjs", 14 | "npmrc", 15 | "packument", 16 | "pacote", 17 | "plopfile", 18 | "subfolders", 19 | "unshift" 20 | ], 21 | "ignoreWords": [], 22 | "import": [] 23 | } 24 | -------------------------------------------------------------------------------- /lint-staged.config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-env es6 */ 2 | const config = { 3 | "*": "echo 'good job'", 4 | }; 5 | module.exports = config; 6 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/.eslintrc.js: -------------------------------------------------------------------------------- 1 | // This is a workaround for https://github.com/eslint/eslint/issues/3458 2 | require("@rushstack/eslint-config/patch/modern-module-resolution"); 3 | 4 | module.exports = { 5 | extends: [ 6 | "@rushstack/eslint-config/profile/node-trusted-tool", 7 | "@rushstack/eslint-config/mixins/friendly-locals", 8 | ], 9 | parserOptions: { tsconfigRootDir: __dirname }, 10 | ignorePatterns: ["node_modules/", "lib/", "**/test/**"], 11 | rules: { 12 | "@typescript-eslint/no-explicit-any": "off", 13 | }, 14 | }; 15 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | lib/ -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/.npmignore: -------------------------------------------------------------------------------- 1 | # THIS IS A STANDARD TEMPLATE FOR .npmignore FILES IN THIS REPO. 2 | 3 | # Ignore all files by default, to avoid accidentally publishing unintended files. 4 | * 5 | 6 | # Use negative patterns to bring back the specific things we want to publish. 7 | !/bin/** 8 | !/lib/** 9 | !/lib-*/** 10 | !/dist/** 11 | !ThirdPartyNotice.txt 12 | !/src/** 13 | 14 | # Ignore certain patterns that should not get published. 15 | /dist/*.stats.* 16 | /lib/**/test/ 17 | /lib-*/**/test/ 18 | *.test.js 19 | /lib/__mocks__/ 20 | /src/__mocks__/ 21 | 22 | # NOTE: These don't need to be specified, because NPM includes them automatically. 23 | # 24 | # package.json 25 | # README (and its variants) 26 | # CHANGELOG (and its variants) 27 | # LICENSE / LICENCE 28 | 29 | #-------------------------------------------- 30 | # DO NOT MODIFY THE TEMPLATE ABOVE THIS LINE 31 | #-------------------------------------------- 32 | 33 | # (Add your project-specific overrides here) 34 | !/includes/** 35 | !rush-plugin-manifest.json 36 | !command-line.json 37 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log - rush-archive-project-plugin 2 | 3 | This log was last generated on Wed, 18 Jan 2023 06:59:28 GMT and should not be manually modified. 4 | 5 | ## 1.1.7 6 | Wed, 18 Jan 2023 06:59:28 GMT 7 | 8 | ### Patches 9 | 10 | - Add support for graveyard folder in archive plugin config file 11 | 12 | ## 1.1.6 13 | Mon, 16 Jan 2023 05:03:53 GMT 14 | 15 | ### Patches 16 | 17 | - Add ability to push git branch and generate md file for archived projects" 18 | 19 | ## 1.1.5 20 | Sat, 07 Jan 2023 01:07:03 GMT 21 | 22 | ### Patches 23 | 24 | - Updated to include a git checkpoint branch when archiving a project 25 | - Update README for archive plugin and add unarchiving support 26 | 27 | ## 1.1.4 28 | Wed, 31 Aug 2022 04:09:13 GMT 29 | 30 | ### Patches 31 | 32 | - Update readme 33 | - Update readme 34 | 35 | ## 1.1.3 36 | Thu, 24 Feb 2022 11:57:31 GMT 37 | 38 | ### Patches 39 | 40 | - Upgrade rush-sdk to latest 41 | 42 | ## 1.1.2 43 | Thu, 24 Feb 2022 10:57:56 GMT 44 | 45 | ### Patches 46 | 47 | - Upgrade rush-sdk to latest 48 | 49 | ## 1.1.1 50 | Tue, 14 Dec 2021 15:40:43 GMT 51 | 52 | ### Patches 53 | 54 | - Fix rush configuration cache 55 | 56 | ## 1.1.0 57 | Tue, 14 Dec 2021 15:22:03 GMT 58 | 59 | ### Minor changes 60 | 61 | - Prompt user to run rush update after archive 62 | - Assert no consuming projects when archive 63 | 64 | ## 1.0.1 65 | Mon, 13 Dec 2021 00:58:24 GMT 66 | 67 | ### Patches 68 | 69 | - update readme 70 | 71 | ## 1.0.0 72 | Sun, 12 Dec 2021 14:59:51 GMT 73 | 74 | ### Breaking changes 75 | 76 | - improve cli logging 77 | 78 | ### Patches 79 | 80 | - update readme 81 | 82 | ## 0.1.0 83 | Sun, 12 Dec 2021 14:29:03 GMT 84 | 85 | ### Minor changes 86 | 87 | - unarchive first implementation 88 | 89 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) TikTok Pte. Ltd. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/README.md: -------------------------------------------------------------------------------- 1 | # rush-archive-project-plugin 2 | 3 | A rush plugin for archive/unarchive project source code in monorepo. 4 | 5 | # Prerequisite 6 | 7 | Rush.js >= 5.57.0 8 | 9 | # Quick Start 10 | 11 | 1. Enabling this rush plugin 12 | 13 | Please follow the [official doc](https://rushjs.io/pages/maintainer/using_rush_plugins/) to enable this plugin in your repo. 14 | 15 | 16 | 2. Running archive project command 17 | 18 | ``` 19 | rush archive-project --package-name 20 | ``` 21 | 22 | > restoring your code by `rush unarchive-project --package-name ` 23 | 24 | # Archive working process 25 | 26 | 1. Find project configuration by Rush.js SDK 27 | 2. Check whether there are projects depends on target project 28 | 3. Run `git clean -xdf` under project folder 29 | 4. Create a checkpoint branch with the name `${projectName}-checkpoint-${date}` 30 | 5. Update checkpoint branch information in `common/_graveyard/projectCheckpoints.json` file 31 | 6. Record project configuration into `rush-metadata.json` file 32 | 7. Create a tarball by running `tar -czf .tar.gz -C .` 33 | 8. Move the tarball to `common/_graveyard` folder 34 | 9. Remove project config to `rush.json` 35 | 10. Delete project folder 36 | 37 | # Unarchive working process 38 | 39 | 1. Find the tarball by `packageName` 40 | 2. Extract the tarball by running `tar xf .tar.gz` 41 | 3. Get project configuration by reading `rush-metadata.json` 42 | 4. Remove checkpoint branch information from checkpoint metadata file if it exists 43 | 5. Move the code to project folder 44 | 6. Restore project configuration into `rush.json` 45 | 7. Delete metadata file and tarball 46 | 47 | # LICENSE 48 | 49 | MIT [@chengcyber](https://github.com/chengcyber) 50 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/command-line.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/command-line.schema.json", 3 | "commands": [ 4 | { 5 | "name": "archive-project", 6 | "commandKind": "global", 7 | "summary": "Archives the project to a tar file", 8 | "shellCommand": "rush-project-archiver archive", 9 | "safeForSimultaneousRushProcesses": true 10 | }, 11 | { 12 | "name": "unarchive-project", 13 | "commandKind": "global", 14 | "summary": "Unarchive the project from a tar file", 15 | "shellCommand": "rush-project-archiver unarchive", 16 | "safeForSimultaneousRushProcesses": true 17 | } 18 | ], 19 | "parameters": [ 20 | { 21 | "parameterKind": "string", 22 | "description": "The name of the package", 23 | "longName": "--package-name", 24 | "argumentName": "PACKAGE_NAME", 25 | "associatedCommands": ["archive-project", "unarchive-project"], 26 | "required": true 27 | } 28 | ] 29 | } 30 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/config/heft.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/heft/heft.schema.json", 3 | 4 | "eventActions": [ 5 | { 6 | "actionKind": "deleteGlobs", 7 | "heftEvent": "clean", 8 | "actionId": "defaultClean", 9 | "globsToDelete": ["lib"] 10 | } 11 | ], 12 | 13 | "heftPlugins": [{ "plugin": "@rushstack/heft-jest-plugin" }] 14 | } 15 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/config/jest.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@rushstack/heft-jest-plugin/includes/jest-shared.config.json" 3 | } 4 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/fixtures/monorepo-1/demo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "demo-project", 3 | "version": "0.0.1" 4 | } 5 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/fixtures/monorepo-1/rush.json: -------------------------------------------------------------------------------- 1 | { 2 | "rushVersion": "5.57.1", 3 | "pnpmVersion": "6.23.1", 4 | "pnpmOptions": { 5 | "useWorkspaces": true 6 | }, 7 | "projects": [ 8 | { 9 | "packageName": "demo-project", 10 | "projectFolder": "demo", 11 | "reviewCategory": "lib", 12 | "cyclicDependencyProjects": [], 13 | "shouldPublish": false 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/fixtures/monorepo-2/common/_graveyard/demo-project.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bytemate/rush-plugins/4404c9ad0b2b375997370233b2cc11b77b5d570c/rush-plugins/rush-archive-project-plugin/fixtures/monorepo-2/common/_graveyard/demo-project.tar.gz -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/fixtures/monorepo-2/other/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "other", 3 | "version": "0.0.1" 4 | } 5 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/fixtures/monorepo-2/rush.json: -------------------------------------------------------------------------------- 1 | /** 2 | * This is the main configuration file for Rush. 3 | * For full documentation, please see https://rushjs.io 4 | */ 5 | { 6 | /** 7 | * (Required) This specifies the version of the Rush engine to be used in this repo. 8 | * Rush's "version selector" feature ensures that the globally installed tool will 9 | * behave like this release, regardless of which version is installed globally. 10 | * 11 | * The common/scripts/install-run-rush.js automation script also uses this version. 12 | * 13 | * NOTE: If you upgrade to a new major version of Rush, you should replace the "v5" 14 | * path segment in the "$schema" field for all your Rush config files. This will ensure 15 | * correct error-underlining and tab-completion for editors such as VS Code. 16 | */ 17 | "rushVersion": "5.57.1", 18 | "pnpmVersion": "6.23.1", 19 | "pnpmOptions": { 20 | "useWorkspaces": true 21 | }, 22 | "projects": [ 23 | { 24 | "packageName": "other", 25 | "projectFolder": "other" 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/fixtures/monorepo-3/apps/my-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@my-company/my-app", 3 | "version": "0.0.1" 4 | } 5 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/fixtures/monorepo-3/libraries/my-lib/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@my-company/my-lib", 3 | "version": "0.0.1" 4 | } 5 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/fixtures/monorepo-3/rush.json: -------------------------------------------------------------------------------- 1 | /** 2 | * This is the main configuration file for Rush. 3 | * For full documentation, please see https://rushjs.io 4 | */ 5 | { 6 | /** 7 | * (Required) This specifies the version of the Rush engine to be used in this repo. 8 | * Rush's "version selector" feature ensures that the globally installed tool will 9 | * behave like this release, regardless of which version is installed globally. 10 | * 11 | * The common/scripts/install-run-rush.js automation script also uses this version. 12 | * 13 | * NOTE: If you upgrade to a new major version of Rush, you should replace the "v5" 14 | * path segment in the "$schema" field for all your Rush config files. This will ensure 15 | * correct error-underlining and tab-completion for editors such as VS Code. 16 | */ 17 | "rushVersion": "5.57.1", 18 | "pnpmVersion": "6.23.1", 19 | "pnpmOptions": { 20 | "useWorkspaces": true 21 | }, 22 | "projects": [ 23 | { 24 | "packageName": "@my-company/my-lib", 25 | "projectFolder": "libraries/my-lib" 26 | }, 27 | { 28 | "packageName": "@my-company/my-app", 29 | "projectFolder": "apps/my-app" 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/fixtures/monorepo-4/common/_graveyard/@my-company/my-app.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bytemate/rush-plugins/4404c9ad0b2b375997370233b2cc11b77b5d570c/rush-plugins/rush-archive-project-plugin/fixtures/monorepo-4/common/_graveyard/@my-company/my-app.tar.gz -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/fixtures/monorepo-4/libraries/my-lib/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@my-company/my-lib", 3 | "version": "0.0.1" 4 | } 5 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/fixtures/monorepo-4/rush.json: -------------------------------------------------------------------------------- 1 | /** 2 | * This is the main configuration file for Rush. 3 | * For full documentation, please see https://rushjs.io 4 | */ 5 | { 6 | /** 7 | * (Required) This specifies the version of the Rush engine to be used in this repo. 8 | * Rush's "version selector" feature ensures that the globally installed tool will 9 | * behave like this release, regardless of which version is installed globally. 10 | * 11 | * The common/scripts/install-run-rush.js automation script also uses this version. 12 | * 13 | * NOTE: If you upgrade to a new major version of Rush, you should replace the "v5" 14 | * path segment in the "$schema" field for all your Rush config files. This will ensure 15 | * correct error-underlining and tab-completion for editors such as VS Code. 16 | */ 17 | "rushVersion": "5.57.1", 18 | "pnpmVersion": "6.23.1", 19 | "pnpmOptions": { 20 | "useWorkspaces": true 21 | }, 22 | "projects": [ 23 | { 24 | "packageName": "@my-company/my-lib", 25 | "projectFolder": "libraries/my-lib" 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/fixtures/monorepo-5/apps/my-app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@my-company/my-app", 3 | "version": "0.0.1", 4 | "dependencies": { 5 | "@my-company/my-lib": "workspace:*" 6 | } 7 | } -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/fixtures/monorepo-5/libraries/my-lib/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@my-company/my-lib", 3 | "version": "0.0.1" 4 | } 5 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/fixtures/monorepo-5/rush.json: -------------------------------------------------------------------------------- 1 | /** 2 | * This is the main configuration file for Rush. 3 | * For full documentation, please see https://rushjs.io 4 | */ 5 | { 6 | /** 7 | * (Required) This specifies the version of the Rush engine to be used in this repo. 8 | * Rush's "version selector" feature ensures that the globally installed tool will 9 | * behave like this release, regardless of which version is installed globally. 10 | * 11 | * The common/scripts/install-run-rush.js automation script also uses this version. 12 | * 13 | * NOTE: If you upgrade to a new major version of Rush, you should replace the "v5" 14 | * path segment in the "$schema" field for all your Rush config files. This will ensure 15 | * correct error-underlining and tab-completion for editors such as VS Code. 16 | */ 17 | "rushVersion": "5.57.1", 18 | "pnpmVersion": "6.23.1", 19 | "pnpmOptions": { 20 | "useWorkspaces": true 21 | }, 22 | "projects": [ 23 | { 24 | "packageName": "@my-company/my-lib", 25 | "projectFolder": "libraries/my-lib" 26 | }, 27 | { 28 | "packageName": "@my-company/my-app", 29 | "projectFolder": "apps/my-app" 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/lint-staged.config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-env es6 */ 2 | const config = { 3 | "*.{js,jsx,ts,tsx}": "eslint --fix", 4 | }; 5 | module.exports = config; 6 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rush-archive-project-plugin", 3 | "version": "1.1.7", 4 | "description": "Rush plugin to archive project", 5 | "keywords": [ 6 | "rush", 7 | "plugin", 8 | "archive", 9 | "project" 10 | ], 11 | "homepage": "https://github.com/bytemate/rush-plugins#readme", 12 | "bugs": { 13 | "url": "https://github.com/bytemate/rush-plugins/issues" 14 | }, 15 | "repository": { 16 | "type": "git", 17 | "url": "git+https://github.com/bytemate/rush-plugins.git", 18 | "directory": "rush-plugins/rush-archive-project-plugin" 19 | }, 20 | "license": "MIT", 21 | "contributors": [ 22 | "Cheng Liu " 23 | ], 24 | "main": "lib/index.js", 25 | "bin": { 26 | "rush-project-archiver": "lib/cli.js" 27 | }, 28 | "scripts": { 29 | "build": "heft build --clean", 30 | "build:watch": "heft build --watch", 31 | "prepublishOnly": "npm run build", 32 | "test": "heft test" 33 | }, 34 | "dependencies": { 35 | "@rushstack/node-core-library": "3.44.1", 36 | "@rushstack/rush-sdk": "5.62.4", 37 | "inquirer": "~8.2.0", 38 | "json2md": "~2.0.0", 39 | "ora": "5.4.1", 40 | "tar": "~6.1.11", 41 | "yargs": "~17.3.0" 42 | }, 43 | "devDependencies": { 44 | "@rushstack/eslint-config": "2.4.5", 45 | "@rushstack/heft": "0.43.2", 46 | "@rushstack/heft-jest-plugin": "~0.1.53", 47 | "@rushstack/heft-node-rig": "1.2.31", 48 | "@types/heft-jest": "1.0.1", 49 | "@types/inquirer": "~8.1.3", 50 | "@types/json2md": "~1.5.1", 51 | "@types/node": "12.20.24", 52 | "@types/pacote": "~11.1.1", 53 | "@types/tar": "~6.1.1", 54 | "@types/yargs": "~17.0.7", 55 | "eslint": "7.32.0", 56 | "typescript": "4.4.2" 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/rush-plugin-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush-plugin-manifest.schema.json", 3 | "plugins": [ 4 | { 5 | "pluginName": "rush-archive-project-plugin", 6 | "description": "Rush plugin to archive project", 7 | "commandLineJsonFilePath": "command-line.json" 8 | } 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/src/__mocks__/ora.js: -------------------------------------------------------------------------------- 1 | /* eslint-env es6 */ 2 | const ora = require("ora"); 3 | 4 | module.exports = function (text) { 5 | const spinner = ora(text); 6 | spinner.stream = process.stdout; 7 | return spinner; 8 | }; 9 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/src/cli.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import yargs from "yargs"; 4 | import { hideBin } from "yargs/helpers"; 5 | import { 6 | Colors, 7 | Terminal, 8 | ConsoleTerminalProvider, 9 | } from "@rushstack/node-core-library"; 10 | import { promptRushUpdate } from "./logic/promptRushUpdate"; 11 | 12 | const terminal: Terminal = new Terminal(new ConsoleTerminalProvider()); 13 | 14 | // eslint-disable-next-line @typescript-eslint/no-floating-promises 15 | main(); 16 | 17 | async function main(): Promise { 18 | await yargs(hideBin(process.argv)) 19 | .command( 20 | "archive", 21 | "Archive a project", 22 | (yargs) => { 23 | return yargs 24 | .option("packageName", { 25 | type: "string", 26 | describe: "The name of the package to archive", 27 | }) 28 | .option("gitCheckpoint", { 29 | type: "boolean", 30 | describe: "Create a git checkpoint before archival" 31 | }) 32 | .default('gitCheckpoint', true) 33 | .demandOption(["packageName", "gitCheckpoint"]); 34 | }, 35 | async (argv) => { 36 | const { archive } = await import("./commands/archive"); 37 | try { 38 | await archive(argv); 39 | await promptRushUpdate({ 40 | terminal, 41 | }); 42 | terminal.writeLine(Colors.green("Archive ALL DONE!")); 43 | } catch (e: any) { 44 | terminal.writeErrorLine(`Archive FAILED: ${e.message}`); 45 | process.exit(1); 46 | } 47 | } 48 | ) 49 | .command( 50 | "unarchive", 51 | "Unarchive a project", 52 | (yargs) => { 53 | return yargs 54 | .option("packageName", { 55 | type: "string", 56 | describe: "The name of the package to unarchive", 57 | }) 58 | .demandOption(["packageName"]); 59 | }, 60 | async (argv) => { 61 | const { unarchive } = await import("./commands/unarchive"); 62 | try { 63 | await unarchive(argv); 64 | await promptRushUpdate({ 65 | terminal 66 | }); 67 | terminal.writeLine(Colors.green("Unarchive ALL DONE!")); 68 | } catch (e: any) { 69 | terminal.writeErrorLine(`Unarchive FAILED: ${e.message}`); 70 | process.exit(1); 71 | } 72 | } 73 | ) 74 | .demandCommand(1, "You need at least one command before moving on") 75 | .parse(); 76 | } 77 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/src/commands/test/__snapshots__/archive.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`archive archive package with dependent should not work with package has dependent 1`] = ` 4 | "Target project @my-company/my-lib is depended by other 1 project(s): 5 | @my-company/my-app" 6 | `; 7 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/src/logic/generateMD.ts: -------------------------------------------------------------------------------- 1 | import json2md from 'json2md'; 2 | import { IProjectCheckpointMetadata } from './projectMetadata'; 3 | 4 | // Generate a md file with the corresponding json content for archived projects 5 | export const convertProjectMetadataToMD = (archivedProjectMetadataObject: { [key in string]: IProjectCheckpointMetadata }): string => { 6 | // Try saving a md file of this json file 7 | const mdFileContents: any = [ 8 | { h2: "Archived Projects" } 9 | ]; 10 | const tableRows: any = [] 11 | for (const [projectName, projectMetadata] of Object.entries(archivedProjectMetadataObject)) { 12 | tableRows.push([ 13 | projectName, 14 | projectMetadata.checkpointBranch, 15 | projectMetadata.description, 16 | projectMetadata.archivedOn 17 | ]) 18 | } 19 | mdFileContents.push({ 20 | table: { 21 | headers: ["Project Name", "Checkpoint Branch", "Description", "Archive Date"], 22 | rows: tableRows 23 | } 24 | }) 25 | return json2md(mdFileContents); 26 | } -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/src/logic/git.ts: -------------------------------------------------------------------------------- 1 | import { Executable } from "@rushstack/node-core-library"; 2 | 3 | import type { SpawnSyncReturns } from "child_process"; 4 | 5 | let checkedGitPath: boolean = false; 6 | let gitPath: string | undefined; 7 | 8 | export const getGitPath = (): string | undefined => { 9 | if (!checkedGitPath) { 10 | checkedGitPath = true; 11 | gitPath = Executable.tryResolve("git"); 12 | } 13 | return gitPath; 14 | }; 15 | 16 | export const getGitPathOrThrow = (): string => { 17 | const gitPath: string | undefined = getGitPath(); 18 | if (!gitPath) { 19 | throw new Error("Unable to find git."); 20 | } 21 | return gitPath; 22 | }; 23 | 24 | export const gitFullClean = (cwd: string): void => { 25 | const gitPath: string = getGitPathOrThrow(); 26 | Executable.spawnSync(gitPath, ["clean", "-fdx"], { 27 | currentWorkingDirectory: cwd, 28 | }); 29 | }; 30 | 31 | export const gitCheckIgnored = (cwd: string, filePath: string): string => { 32 | const gitPath: string = getGitPathOrThrow(); 33 | let result: string = ""; 34 | try { 35 | const process: SpawnSyncReturns = Executable.spawnSync( 36 | gitPath, 37 | ["check-ignore", "-v", filePath], 38 | { 39 | currentWorkingDirectory: cwd, 40 | } 41 | ); 42 | if (process.status === 0) { 43 | result = process.stdout.toString(); 44 | } 45 | } catch (e: any) { 46 | if (e.message.includes("The command failed with exit code 1")) { 47 | // ignore 48 | } else { 49 | // rethrow 50 | throw e; 51 | } 52 | } 53 | return result; 54 | }; 55 | 56 | export const getCheckpointBranch = (cwd: string, branchName: string): string => { 57 | const gitPath: string = getGitPathOrThrow(); 58 | const currDate: string = new Date().toISOString().substring(0, 10); 59 | const branchNameToCreate: string = `${branchName}-checkpoint-${currDate}`; 60 | const process: SpawnSyncReturns = Executable.spawnSync(gitPath, ["branch", branchNameToCreate], { 61 | currentWorkingDirectory: cwd, 62 | }); 63 | if (process.status === 128) { 64 | throw new Error(`The passed branch name is invalid: ${branchNameToCreate}`) 65 | } 66 | 67 | return branchNameToCreate; 68 | } 69 | 70 | export const pushGitBranch = (cwd: string, branchName: string): void => { 71 | const gitPath: string = getGitPathOrThrow(); 72 | const process: SpawnSyncReturns = Executable.spawnSync(gitPath, ["push", "origin", `${branchName}:${branchName}`], { 73 | currentWorkingDirectory: cwd, 74 | }); 75 | if (process.status !== 0) { 76 | console.error('Could not push branch to origin'); 77 | } 78 | } -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/src/logic/graveyard.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | import { PackageName, IParsedPackageName, JsonFile, FileSystem } from '@rushstack/node-core-library'; 3 | import { RushConfiguration } from '@rushstack/rush-sdk'; 4 | import { loadRushConfiguration } from './rushConfiguration'; 5 | 6 | export const defaultGraveyardRelativeFolder: string = 'common/_graveyard'; 7 | 8 | export interface IGraveyardInfo { 9 | graveyardRelativeFolder: string; 10 | tarballFolder: string; 11 | tarballRelativeFolder: string; 12 | tarballName: string; 13 | } 14 | 15 | export interface IGetGraveyardInfoParams { 16 | monoRoot: string; 17 | packageName: string; 18 | } 19 | 20 | export interface IArchiveConfig { 21 | graveyardFolder?: string; 22 | } 23 | 24 | export const getGraveyardInfo = ({ monoRoot, packageName }: IGetGraveyardInfoParams): IGraveyardInfo => { 25 | const rushConfiguration: RushConfiguration = loadRushConfiguration(); 26 | // Check for config file 27 | const pluginOptionsJsonFilePath: string = path.join( 28 | rushConfiguration.rushPluginOptionsFolder, 29 | `rush-archive-project-plugin.json` 30 | ); 31 | 32 | let graveyardRelativeFolder: string = defaultGraveyardRelativeFolder; 33 | let archiveConfigs: IArchiveConfig | undefined; 34 | try { 35 | archiveConfigs = JsonFile.load(pluginOptionsJsonFilePath); 36 | } catch (e) { 37 | if (!FileSystem.isNotExistError(e as Error)) { 38 | throw e; 39 | } 40 | } 41 | 42 | if (archiveConfigs?.graveyardFolder) { 43 | graveyardRelativeFolder = archiveConfigs.graveyardFolder; 44 | } 45 | 46 | const parsedPackageName: IParsedPackageName = PackageName.parse(packageName); 47 | const tarballRelativeFolder: string = path.join(graveyardRelativeFolder, parsedPackageName.scope); 48 | const tarballFolder: string = path.join(monoRoot, tarballRelativeFolder); 49 | return { 50 | graveyardRelativeFolder, 51 | tarballFolder, 52 | tarballRelativeFolder, 53 | tarballName: `${parsedPackageName.unscopedName}.tar.gz` 54 | }; 55 | }; 56 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/src/logic/projectMetadata.ts: -------------------------------------------------------------------------------- 1 | import { JsonObject, JsonFile } from "@rushstack/node-core-library"; 2 | export class ProjectMetadata { 3 | private _projectConfig: JsonObject; 4 | public static FILENAME: string = "rush-project-metadata.json"; 5 | 6 | public constructor(projectConfig: JsonObject) { 7 | this._projectConfig = projectConfig; 8 | } 9 | 10 | public static load(filePath: string): ProjectMetadata { 11 | const { projectConfig } = JsonFile.load(filePath); 12 | return new ProjectMetadata(projectConfig); 13 | } 14 | 15 | public save(filePath: string): void { 16 | JsonFile.save( 17 | { 18 | projectConfig: this._projectConfig, 19 | }, 20 | filePath, 21 | { 22 | ensureFolderExists: true, 23 | } 24 | ); 25 | } 26 | 27 | public get projectConfig(): JsonObject { 28 | return this._projectConfig; 29 | } 30 | } 31 | 32 | export interface IProjectCheckpointMetadata { 33 | checkpointBranch: string; 34 | archivedOn: string; 35 | description: string; 36 | } -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/src/logic/promptRushUpdate.ts: -------------------------------------------------------------------------------- 1 | import type { RushConfiguration } from "@rushstack/rush-sdk"; 2 | import type { ITerminal } from "@rushstack/node-core-library"; 3 | import { Executable } from "@rushstack/node-core-library"; 4 | import * as path from "path"; 5 | import { loadRushConfiguration } from "./rushConfiguration"; 6 | 7 | export interface IPromptRushUpdateParams { 8 | terminal: ITerminal; 9 | } 10 | 11 | export async function promptRushUpdate({ 12 | terminal, 13 | }: IPromptRushUpdateParams): Promise { 14 | const { prompt } = await import("inquirer"); 15 | interface IShouldRunRushUpdateAnswer { 16 | shouldRunRushUpdate: boolean; 17 | } 18 | const rushConfiguration: RushConfiguration = loadRushConfiguration(); 19 | const runRushJSPath: string = path.join( 20 | rushConfiguration.commonScriptsFolder, 21 | "install-run-rush.js" 22 | ); 23 | 24 | const { shouldRunRushUpdate } = await prompt([ 25 | { 26 | type: "confirm", 27 | name: "shouldRunRushUpdate", 28 | message: "Run rush update right now?", 29 | default: true, 30 | }, 31 | ]); 32 | 33 | if (shouldRunRushUpdate) { 34 | terminal.writeLine("Run rush update..."); 35 | try { 36 | Executable.spawnSync("node", [runRushJSPath, "update"], { 37 | stdio: "inherit", 38 | }); 39 | } catch (e) { 40 | terminal.writeErrorLine("Rush update failed, please run it manually."); 41 | } 42 | terminal.writeLine("Rush update successfully."); 43 | } else { 44 | terminal.writeWarningLine("Rush update skipped, please run it manually."); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /rush-plugins/rush-archive-project-plugin/src/logic/rushConfiguration.ts: -------------------------------------------------------------------------------- 1 | import { RushConfiguration } from "@rushstack/rush-sdk"; 2 | 3 | const cwd2rushConfiguration: Record = {}; 4 | 5 | export const loadRushConfiguration = ( 6 | cwd: string = process.cwd() 7 | ): RushConfiguration => { 8 | let rushConfiguration: RushConfiguration | undefined = 9 | cwd2rushConfiguration[cwd]; 10 | if (!rushConfiguration) { 11 | try { 12 | rushConfiguration = RushConfiguration.loadFromDefaultLocation({ 13 | startingFolder: cwd, 14 | }); 15 | } catch { 16 | // no-catch 17 | } 18 | if (!rushConfiguration) { 19 | throw new Error("Could not load rush configuration"); 20 | } 21 | cwd2rushConfiguration[cwd] = rushConfiguration; 22 | } 23 | return rushConfiguration; 24 | }; 25 | -------------------------------------------------------------------------------- /rush-plugins/rush-audit-cache-plugin/.eslintrc.js: -------------------------------------------------------------------------------- 1 | // This is a workaround for https://github.com/eslint/eslint/issues/3458 2 | require("@rushstack/eslint-config/patch/modern-module-resolution"); 3 | 4 | module.exports = { 5 | extends: [ 6 | "@rushstack/eslint-config/profile/node-trusted-tool", 7 | "@rushstack/eslint-config/mixins/friendly-locals", 8 | ], 9 | parserOptions: { tsconfigRootDir: __dirname }, 10 | ignorePatterns: ["node_modules/", "lib/"], 11 | rules: { 12 | "@typescript-eslint/no-explicit-any": "off", 13 | }, 14 | }; 15 | -------------------------------------------------------------------------------- /rush-plugins/rush-audit-cache-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | lib/ -------------------------------------------------------------------------------- /rush-plugins/rush-audit-cache-plugin/.npmignore: -------------------------------------------------------------------------------- 1 | # THIS IS A STANDARD TEMPLATE FOR .npmignore FILES IN THIS REPO. 2 | 3 | # Ignore all files by default, to avoid accidentally publishing unintended files. 4 | * 5 | 6 | # Use negative patterns to bring back the specific things we want to publish. 7 | !/bin/** 8 | !/lib/** 9 | !/lib-*/** 10 | !/dist/** 11 | !ThirdPartyNotice.txt 12 | !/src/** 13 | 14 | # Ignore certain patterns that should not get published. 15 | /dist/*.stats.* 16 | /lib/**/test/ 17 | /lib-*/**/test/ 18 | *.test.js 19 | 20 | # NOTE: These don't need to be specified, because NPM includes them automatically. 21 | # 22 | # package.json 23 | # README (and its variants) 24 | # CHANGELOG (and its variants) 25 | # LICENSE / LICENCE 26 | 27 | #-------------------------------------------- 28 | # DO NOT MODIFY THE TEMPLATE ABOVE THIS LINE 29 | #-------------------------------------------- 30 | 31 | # (Add your project-specific overrides here) 32 | !/includes/** 33 | !rush-plugin-manifest.json 34 | !command-line.json 35 | -------------------------------------------------------------------------------- /rush-plugins/rush-audit-cache-plugin/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log - rush-audit-cache-plugin 2 | 3 | This log was last generated on Wed, 23 Aug 2023 05:01:48 GMT and should not be manually modified. 4 | 5 | ## 0.2.3 6 | Wed, 23 Aug 2023 05:01:48 GMT 7 | 8 | ### Patches 9 | 10 | - rush-audit-cache-plugin support dependsOnAdditionalFiles 11 | 12 | ## 0.2.2 13 | Mon, 05 Jun 2023 04:43:06 GMT 14 | 15 | ### Patches 16 | 17 | - build cache audit tool support phased command 18 | 19 | ## 0.2.1 20 | Wed, 01 Mar 2023 04:51:48 GMT 21 | 22 | ### Patches 23 | 24 | - audit cache if select project, will not audit dependencies projects 25 | 26 | ## 0.2.0 27 | Tue, 28 Feb 2023 08:06:50 GMT 28 | 29 | ### Minor changes 30 | 31 | - rush audit cache plugin support multiple projects 32 | 33 | ## 0.1.10 34 | Mon, 12 Dec 2022 02:58:12 GMT 35 | 36 | ### Patches 37 | 38 | - fix outputFolderNames bug and support schema 39 | 40 | ## 0.1.9 41 | Mon, 28 Nov 2022 08:16:15 GMT 42 | 43 | ### Patches 44 | 45 | - add repo audit cache config 46 | 47 | ## 0.1.8 48 | Fri, 25 Nov 2022 06:42:23 GMT 49 | 50 | ### Patches 51 | 52 | - fix rush-audit-cache-plugin parser file director error 53 | 54 | ## 0.1.7 55 | Tue, 22 Nov 2022 05:56:31 GMT 56 | 57 | ### Patches 58 | 59 | - change output of audit specific project and support rush-audit-cache.json 60 | 61 | ## 0.1.6 62 | Mon, 07 Nov 2022 13:26:33 GMT 63 | 64 | ### Patches 65 | 66 | - rush audit cache add some low risk path 67 | 68 | ## 0.1.5 69 | Mon, 07 Nov 2022 12:07:21 GMT 70 | 71 | ### Patches 72 | 73 | - fix linux parse log bug 74 | 75 | ## 0.1.4 76 | Mon, 07 Nov 2022 08:20:01 GMT 77 | 78 | ### Patches 79 | 80 | - use -ff to separate strace log and disable rush build cache when rebuild 81 | 82 | ## 0.1.3 83 | Thu, 03 Nov 2022 02:10:44 GMT 84 | 85 | ### Patches 86 | 87 | - rush audit cache add --exclude parameter and filter directory 88 | 89 | ## 0.1.2 90 | Thu, 27 Oct 2022 13:12:33 GMT 91 | 92 | ### Patches 93 | 94 | - rush install before run rebuild 95 | 96 | ## 0.1.1 97 | Wed, 26 Oct 2022 13:03:49 GMT 98 | 99 | ### Patches 100 | 101 | - fix rush-audit-cache-plugin rebuild bug 102 | 103 | ## 0.1.0 104 | Wed, 26 Oct 2022 07:19:37 GMT 105 | 106 | ### Minor changes 107 | 108 | - Add --all parameter to select all cache configured projects 109 | 110 | ## 0.0.3 111 | Fri, 21 Oct 2022 01:41:04 GMT 112 | 113 | ### Patches 114 | 115 | - Fix rush project json path 116 | 117 | ## 0.0.2 118 | Wed, 19 Oct 2022 14:08:21 GMT 119 | 120 | ### Patches 121 | 122 | - Fix shellCommand 123 | 124 | ## 0.0.1 125 | Wed, 19 Oct 2022 14:02:29 GMT 126 | 127 | ### Patches 128 | 129 | - Initial Release 130 | 131 | -------------------------------------------------------------------------------- /rush-plugins/rush-audit-cache-plugin/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) TikTok Pte. Ltd. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /rush-plugins/rush-audit-cache-plugin/README.md: -------------------------------------------------------------------------------- 1 | # rush-audit-cache-plugin 2 | 3 | A diagnostic tool for rush build cache 4 | 5 | # Prerequisite 6 | 7 | - Rush.js >= 5.57.0 8 | - strace >= 4.26 in Linux 9 | 10 | # Quick Start 11 | 12 | 1. Enabling this rush plugin 13 | 14 | Please follow the [official doc](https://rushjs.io/pages/maintainer/using_rush_plugins/) to enable this plugin in your repo. 15 | 16 | 2. Running `audit-cache` command 17 | 18 | ``` 19 | rush audit-cache --project 20 | ``` 21 | 22 | # Demo 23 | 24 | Please check [this demo repo](https://github.com/chengcyber/rush-build-diagnostic-demo) 25 | 26 | ![rush-audit-cache-demo-usage](./docs/media/rush-audit-cache-demo-usage.png) 27 | 28 | # Tech Note 29 | 30 | [rush audit-cache tech note](./docs/rush-audit-cache-tech-note.md) 31 | 32 | # LICENSE 33 | 34 | MIT -------------------------------------------------------------------------------- /rush-plugins/rush-audit-cache-plugin/command-line.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/command-line.schema.json", 3 | "commands": [ 4 | { 5 | "name": "audit-cache", 6 | "commandKind": "global", 7 | "summary": "Audit cache configuration by diagnosing the build processes of the target project and its dependencies", 8 | "shellCommand": "node /lib/bin.js", 9 | "safeForSimultaneousRushProcesses": true 10 | } 11 | ], 12 | "parameters": [ 13 | { 14 | "parameterKind": "stringList", 15 | "description": "The package name of the project", 16 | "longName": "--project", 17 | "shortName": "-p", 18 | "argumentName": "PACKAGE_NAME", 19 | "associatedCommands": ["audit-cache"], 20 | "required": false 21 | }, 22 | { 23 | "parameterKind": "flag", 24 | "description": "Audit all cache configured project", 25 | "longName": "--all", 26 | "shortName": "-a", 27 | "associatedCommands": ["audit-cache"], 28 | "required": false 29 | }, 30 | { 31 | "parameterKind": "stringList", 32 | "description": "Exclude package from audit cache", 33 | "longName": "--exclude", 34 | "shortName": "-e", 35 | "argumentName": "EXCLUDE_PACKAGE_NAME", 36 | "associatedCommands": ["audit-cache"], 37 | "required": false 38 | }, 39 | { 40 | "parameterKind": "stringList", 41 | "description": "Phased commands need to be audit", 42 | "longName": "--phased-commands", 43 | "shortName": "-P", 44 | "argumentName": "PHASED_COMMANDS_NAMES", 45 | "associatedCommands": ["audit-cache"], 46 | "required": false 47 | }, 48 | { 49 | "parameterKind": "string", 50 | "description": "verbosity that can be increased", 51 | "longName": "--verbose", 52 | "shortName": "-v", 53 | "argumentName": "VERBOSE", 54 | "associatedCommands": ["audit-cache"], 55 | "required": false 56 | }, 57 | { 58 | "parameterKind": "flag", 59 | "description": "show current version", 60 | "longName": "--version", 61 | "shortName": "-V", 62 | "associatedCommands": ["audit-cache"], 63 | "required": false 64 | }, 65 | { 66 | "parameterKind": "string", 67 | "description": "Specifies the maximum number of concurrent processes to launch during a build. (eg. '50% | '5')", 68 | "longName": "--parallelism", 69 | "shortName": "-c", 70 | "argumentName": "COUNT", 71 | "associatedCommands": ["audit-cache"], 72 | "required": false 73 | } 74 | ] 75 | } 76 | -------------------------------------------------------------------------------- /rush-plugins/rush-audit-cache-plugin/config/heft.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/heft/heft.schema.json", 3 | 4 | "eventActions": [ 5 | { 6 | "actionKind": "deleteGlobs", 7 | "heftEvent": "clean", 8 | "actionId": "defaultClean", 9 | "globsToDelete": ["lib"] 10 | }, 11 | { 12 | "actionKind": "copyFiles", 13 | "heftEvent": "pre-compile", 14 | "actionId": "copySchemas", 15 | "copyOperations": [ 16 | { 17 | "sourceFolder": "src", 18 | "destinationFolders": ["lib"], 19 | "includeGlobs": ["schemas/*.json"] 20 | } 21 | ] 22 | } 23 | ], 24 | "heftPlugins": [{ "plugin": "@rushstack/heft-jest-plugin" }] 25 | } 26 | -------------------------------------------------------------------------------- /rush-plugins/rush-audit-cache-plugin/config/jest.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@rushstack/heft-jest-plugin/includes/jest-shared.config.json" 3 | } 4 | -------------------------------------------------------------------------------- /rush-plugins/rush-audit-cache-plugin/docs/media/rush-audit-cache-arch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bytemate/rush-plugins/4404c9ad0b2b375997370233b2cc11b77b5d570c/rush-plugins/rush-audit-cache-plugin/docs/media/rush-audit-cache-arch.png -------------------------------------------------------------------------------- /rush-plugins/rush-audit-cache-plugin/docs/media/rush-audit-cache-demo-usage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bytemate/rush-plugins/4404c9ad0b2b375997370233b2cc11b77b5d570c/rush-plugins/rush-audit-cache-plugin/docs/media/rush-audit-cache-demo-usage.png -------------------------------------------------------------------------------- /rush-plugins/rush-audit-cache-plugin/docs/rush-audit-cache-tech-note.md: -------------------------------------------------------------------------------- 1 | # Rush audit-cache tech note 2 | 3 | The **"rush audit-cache"** feature is a diagnostic tool for Rush.js that allows an engineer to monitor the building process of one project. 4 | 5 | Goals: 6 | 7 | - When setting up a new project, provide an easy way to validate that the build cache configuration correctly reflects the toolchain's filesystem inputs and outputs 8 | - If an engineer encounters a failure that is suspected to be a cache malfunction, provide an easy way to investigate 9 | 10 | Non-goals: 11 | 12 | - Continuous monitoring/validation of every build: In our initial implementation, the analysis may significantly impact build times. The feature will only be available if the OS supports the strace native tool and it has been installed. 13 | 14 | During build projects, Rush audit-cache leverages external tools to trace system calls and signals, such as [strace](https://man7.org/linux/man-pages/man1/strace.1.html). This includes file system access for the complete life of building. And then detecting potential issues by analyzing the tracing log. 15 | 16 | In our initial proof of concept implementation, use of **rush audit-cache** will require the Linux operating system, because of the dependency on the **strace** tool. This can be changed later by supporting tracing tools for other platforms, such as [dtrace](https://www.brendangregg.com/dtrace.html) in MacOS. 17 | 18 | # Design Overview 19 | 20 | Rush audit-cache logically consists of the following parts: 21 | - A mechanism for tracing system calls of file access for a process, including forked processes. 22 | - A mechanism for analyzing the trace log to get all inputs and outputs via file system 23 | - A mechanism for reporting issues by comparing project build cache configuration with trace log. 24 | 25 | # Design Details 26 | 27 | ![rush-audit-cache-arch](./media/rush-audit-cache-arch.png) 28 | 29 | 1. Get `TraceExecutor` according to the OS platform. e.g. `LinuxTraceExecutor` for Linux platform. 30 | 2. `TraceExecutor` spawns a child process with `strace` command. `strace` will trace all system calls of the child process and its forked processes. 31 | 3. `TraceExecutor` reads the trace log from `strace` and parses it to get all file system access events. 32 | 4. `Analyzer` analyzes the trace log with rush project configurations and detects potential issues. 33 | 34 | # Reference 35 | 36 | - [Proposal for rush build diagnostic tool](./proposal-for-rush-build-diagnostic-tool.md) -------------------------------------------------------------------------------- /rush-plugins/rush-audit-cache-plugin/lint-staged.config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-env es6 */ 2 | const config = { 3 | "*.{js,jsx,ts,tsx}": "eslint --fix", 4 | }; 5 | module.exports = config; 6 | -------------------------------------------------------------------------------- /rush-plugins/rush-audit-cache-plugin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rush-audit-cache-plugin", 3 | "version": "0.2.3", 4 | "description": "A diagnostic tool for rush build cache", 5 | "keywords": [ 6 | "rush", 7 | "plugin", 8 | "command", 9 | "build", 10 | "cache" 11 | ], 12 | "homepage": "https://github.com/bytemate/rush-plugins#readme", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/bytemate/rush-plugins", 16 | "directory": "rush-plugins/rush-audit-cache-plugin" 17 | }, 18 | "license": "MIT", 19 | "contributors": [ 20 | "heyunfeng" 21 | ], 22 | "main": "lib/index.js", 23 | "typings": "lib/index.d.ts", 24 | "scripts": { 25 | "build": "heft build --clean", 26 | "build:watch": "heft build --watch", 27 | "prepublishOnly": "npm run build", 28 | "test": "heft test" 29 | }, 30 | "dependencies": { 31 | "@rushstack/node-core-library": "3.44.1", 32 | "@rushstack/rush-sdk": "5.62.4", 33 | "commander": "~9.4.0", 34 | "ignore": "5.1.9" 35 | }, 36 | "devDependencies": { 37 | "@rushstack/eslint-config": "2.4.5", 38 | "@rushstack/heft": "0.43.2", 39 | "@rushstack/heft-jest-plugin": "~0.1.53", 40 | "@rushstack/heft-node-rig": "1.2.31", 41 | "@types/heft-jest": "1.0.1", 42 | "@types/node": "12.20.24", 43 | "eslint": "7.32.0", 44 | "typescript": "4.4.2" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /rush-plugins/rush-audit-cache-plugin/rush-plugin-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush-plugin-manifest.schema.json", 3 | "plugins": [ 4 | { 5 | "pluginName": "rush-audit-cache-plugin", 6 | "description": "A diagnostic tool for rush build cache", 7 | "commandLineJsonFilePath": "command-line.json", 8 | "optionsSchema": "lib/schemas/plugin-options.schema.json" 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /rush-plugins/rush-audit-cache-plugin/src/core/TraceExecutor.ts: -------------------------------------------------------------------------------- 1 | import { BaseTraceExecutor, IBaseTraceExecutorOptions } from "./base/BaseTraceExecutor"; 2 | import * as os from 'os'; 3 | import { Import } from "@rushstack/node-core-library"; 4 | 5 | const LinuxTraceExecutorModule: typeof import('./Linux/LinuxTraceExecutor') = Import.lazy("./Linux/LinuxTraceExecutor", require); 6 | 7 | export class TraceExecutorFactory { 8 | 9 | private constructor() { } 10 | 11 | public static create(options: IBaseTraceExecutorOptions): BaseTraceExecutor { 12 | const platform: NodeJS.Platform = os.platform(); 13 | switch (platform) { 14 | case 'linux': { 15 | return new LinuxTraceExecutorModule.LinuxTraceExecutor(options); 16 | } 17 | default: { 18 | throw new Error(`Unsupported OS platform: ${platform}, only linux is supported now.`); 19 | } 20 | } 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /rush-plugins/rush-audit-cache-plugin/src/core/WriteFileResolver.ts: -------------------------------------------------------------------------------- 1 | import ignore, { Ignore } from "ignore"; 2 | import { BaseFileResolver } from "./base/BaseFileResolver"; 3 | import type { 4 | IUserProjectAfterFileFilter, 5 | IUserProjectFileFilter, 6 | } from "./base/BaseFileResolver"; 7 | 8 | export class WriteFileResolver extends BaseFileResolver { 9 | private _lowRiskNodeWrite: string[] = [ 10 | "**/update-notifier-npm.json*", 11 | "**/node_modules/.cache/", 12 | "**/node_modules/.pnpm/", 13 | ]; 14 | private _lowRiskNodeWriteMatcher: Ignore = ignore(); 15 | 16 | private _lowRiskSystemWrite: string[] = ["/dev/null", "/dev/null/"]; 17 | private _lowRiskSystemWriteMatcher: Ignore = ignore(); 18 | 19 | public constructor() { 20 | super(); 21 | this.initDefaultMatchers([ 22 | { 23 | matcher: this._lowRiskNodeWriteMatcher, 24 | paths: this._lowRiskNodeWrite, 25 | option: { 26 | kind: "node", 27 | }, 28 | }, 29 | { 30 | matcher: this._lowRiskSystemWriteMatcher, 31 | paths: this._lowRiskSystemWrite, 32 | option: { 33 | kind: "system", 34 | }, 35 | }, 36 | ]); 37 | } 38 | 39 | public loadProjectFilterConfig(fileFilters: IUserProjectFileFilter[]): void { 40 | fileFilters.forEach((fileFilter) => { 41 | if (fileFilter.operate === "write") { 42 | if ("kind" in fileFilter) { 43 | this._userProjectAfterFileFilters.unshift( 44 | fileFilter as IUserProjectAfterFileFilter 45 | ); 46 | } else { 47 | this._userProjectBeforeFileFilters.unshift(fileFilter); 48 | } 49 | } 50 | }); 51 | } 52 | 53 | public loadGlobalFilterConfig(fileFilters: IUserProjectFileFilter[]): void { 54 | fileFilters.forEach((fileFilter) => { 55 | if (fileFilter.operate === "write") { 56 | if ("kind" in fileFilter) { 57 | this._userProjectAfterFileFilters.push( 58 | fileFilter as IUserProjectAfterFileFilter 59 | ); 60 | } else { 61 | this._userProjectBeforeFileFilters.push(fileFilter); 62 | } 63 | } 64 | }); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /rush-plugins/rush-audit-cache-plugin/src/core/base/BaseTraceExecutor.ts: -------------------------------------------------------------------------------- 1 | import type { ITerminal } from "@rushstack/node-core-library"; 2 | import type { RushConfigurationProject } from "@rushstack/rush-sdk"; 3 | 4 | export interface IBaseTraceExecutorOptions { 5 | projects: RushConfigurationProject[]; 6 | logFolder: string; 7 | terminal: ITerminal; 8 | parallelism?: string; 9 | } 10 | 11 | export interface ITraceResult { 12 | [packageName: string]: { 13 | readFiles: ReadonlySet; 14 | writeFiles: ReadonlySet; 15 | }; 16 | } 17 | 18 | export abstract class BaseTraceExecutor { 19 | protected _projects: RushConfigurationProject[]; 20 | protected _logFolder: string; 21 | protected _terminal: ITerminal; 22 | public constructor(options: IBaseTraceExecutorOptions) { 23 | this._projects = options.projects; 24 | this._logFolder = options.logFolder; 25 | this._terminal = options.terminal; 26 | } 27 | 28 | abstract execAsync(): Promise; 29 | } 30 | -------------------------------------------------------------------------------- /rush-plugins/rush-audit-cache-plugin/src/helpers/constants.ts: -------------------------------------------------------------------------------- 1 | export const AUDIT_CACHE_FOLDER: string = "rush-audit-cache"; 2 | export const TRACE_LOG_FILENAME: string = "trace.log"; 3 | export const RUSH_PROJECT_JSON_RELATIVE_PATH: string = 4 | "./config/rush-project.json"; 5 | export const RUSH_AUDIT_CACHE_JSON_RELATIVE_PATH: string = 6 | "./config/rush-audit-cache.json"; 7 | 8 | export const PLUGIN_NAME: string = "rush-audit-cache-plugin"; 9 | -------------------------------------------------------------------------------- /rush-plugins/rush-audit-cache-plugin/src/helpers/terminal.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Terminal, 3 | ConsoleTerminalProvider, 4 | } from "@rushstack/node-core-library"; 5 | 6 | export const terminalProvider: ConsoleTerminalProvider = new ConsoleTerminalProvider(); 7 | export const terminal: Terminal = new Terminal(terminalProvider); 8 | -------------------------------------------------------------------------------- /rush-plugins/rush-audit-cache-plugin/src/helpers/utils.ts: -------------------------------------------------------------------------------- 1 | export const durationToString = (duration: number): string => { 2 | if (duration > 60) { 3 | const minutes: number = Math.floor(duration / 60); 4 | const seconds: number = duration % 60.0; 5 | 6 | return `${minutes.toFixed(0)} minute${ 7 | minutes === 1 ? "" : "s" 8 | } ${seconds.toFixed(1)} seconds`; 9 | } else { 10 | return `${duration.toFixed(2)} seconds`; 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /rush-plugins/rush-audit-cache-plugin/src/index.ts: -------------------------------------------------------------------------------- 1 | export { auditCache } from './auditCache'; 2 | 3 | export type { IAuditCacheOptions, IAuditCacheResult } from './auditCache'; -------------------------------------------------------------------------------- /rush-plugins/rush-audit-cache-plugin/src/schemas/plugin-options.schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-04/schema#", 3 | "title": "Configuration for Rush's build cache.", 4 | "description": "For use with the Rush tool, this file provides per-project configuration options. See http://rushjs.io for details.", 5 | "type": "object", 6 | "additionalProperties": false, 7 | "properties": { 8 | "$schema": { 9 | "description": "Part of the JSON Schema standard, this optional keyword declares the URL of the schema that the file conforms to. Editors may download the schema and use it to perform syntax highlighting.", 10 | "type": "string" 11 | }, 12 | "extends": { 13 | "description": "Optionally specifies another JSON config file that this file extends from. This provides a way for standard settings to be shared across multiple projects.", 14 | "type": "string" 15 | }, 16 | "globalFileFilters": { 17 | "type": "array", 18 | "description": "Defines overrides for file operate level for kind or path. Through this setting you can hide specific file or give them a more important visibility.", 19 | "items": { 20 | "type": "object", 21 | "additionalProperties": false, 22 | "properties": { 23 | "level": { 24 | "type": "string", 25 | "enum": ["low", "high", "safe"], 26 | "description": "The risk level of file operate" 27 | }, 28 | "operate": { 29 | "type": "string", 30 | "enum": ["read", "write"], 31 | "description": "The operate of file access" 32 | }, 33 | "kind": { 34 | "type": "string", 35 | "enums": ["system", "node", "tool", "project"], 36 | "description": "The kind of file" 37 | }, 38 | "pattern": { 39 | "type": "string", 40 | "description": "Use RegExp to match file path" 41 | } 42 | }, 43 | "oneOf": [ 44 | { 45 | "type": "object", 46 | "properties": { 47 | "kind": { 48 | "type": "string", 49 | "enums": ["system", "node", "tool", "project"], 50 | "description": "The kind of file" 51 | } 52 | }, 53 | "required": ["kind"] 54 | }, 55 | { 56 | "type": "object", 57 | "properties": { 58 | "pattern": { 59 | "type": "string", 60 | "description": "Use RegExp to match file path" 61 | } 62 | }, 63 | "required": ["pattern"] 64 | } 65 | ] 66 | } 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/.eslintrc.js: -------------------------------------------------------------------------------- 1 | // This is a workaround for https://github.com/eslint/eslint/issues/3458 2 | require('@rushstack/eslint-config/patch/modern-module-resolution'); 3 | 4 | module.exports = { 5 | extends: [ 6 | '@rushstack/eslint-config/profile/node-trusted-tool', 7 | '@rushstack/eslint-config/mixins/friendly-locals', 8 | ], 9 | parserOptions: { tsconfigRootDir: __dirname }, 10 | ignorePatterns: ['node_modules/', 'lib/', 'jest.config.js'], 11 | rules: { 12 | '@typescript-eslint/no-explicit-any': 'off', 13 | }, 14 | }; 15 | -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | lib/ -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/.npmignore: -------------------------------------------------------------------------------- 1 | # THIS IS A STANDARD TEMPLATE FOR .npmignore FILES IN THIS REPO. 2 | 3 | # Ignore all files by default, to avoid accidentally publishing unintended files. 4 | * 5 | 6 | # Use negative patterns to bring back the specific things we want to publish. 7 | !/bin/** 8 | !/lib/** 9 | !/lib-*/** 10 | !/dist/** 11 | !ThirdPartyNotice.txt 12 | !/src/** 13 | 14 | # Ignore certain patterns that should not get published. 15 | /dist/*.stats.* 16 | /lib/**/test/ 17 | /lib-*/**/test/ 18 | *.test.js 19 | 20 | # NOTE: These don't need to be specified, because NPM includes them automatically. 21 | # 22 | # package.json 23 | # README (and its variants) 24 | # CHANGELOG (and its variants) 25 | # LICENSE / LICENCE 26 | 27 | #-------------------------------------------- 28 | # DO NOT MODIFY THE TEMPLATE ABOVE THIS LINE 29 | #-------------------------------------------- 30 | 31 | # (Add your project-specific overrides here) 32 | !/includes/** 33 | !rush-plugin-manifest.json 34 | !command-line.json 35 | -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/CHANGELOG.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rush-git-lfs-plugin", 3 | "entries": [ 4 | { 5 | "version": "0.2.0", 6 | "tag": "rush-git-lfs-plugin_v0.2.0", 7 | "date": "Tue, 14 Feb 2023 03:16:01 GMT", 8 | "comments": { 9 | "minor": [ 10 | { 11 | "comment": "add git lfs pull plugin" 12 | } 13 | ] 14 | } 15 | }, 16 | { 17 | "version": "0.1.2", 18 | "tag": "rush-git-lfs-plugin_v0.1.2", 19 | "date": "Wed, 08 Feb 2023 07:35:21 GMT", 20 | "comments": { 21 | "patch": [ 22 | { 23 | "comment": "Reduce log and use ora as alternative" 24 | } 25 | ] 26 | } 27 | }, 28 | { 29 | "version": "0.1.1", 30 | "tag": "rush-git-lfs-plugin_v0.1.1", 31 | "date": "Mon, 19 Dec 2022 11:19:35 GMT", 32 | "comments": { 33 | "patch": [ 34 | { 35 | "comment": "fix rush-git-lfs-plugin configuration and wrong constant" 36 | } 37 | ] 38 | } 39 | }, 40 | { 41 | "version": "0.1.0", 42 | "tag": "rush-git-lfs-plugin_v0.1.0", 43 | "date": "Fri, 16 Dec 2022 12:24:06 GMT", 44 | "comments": { 45 | "minor": [ 46 | { 47 | "comment": "Add new plugin rush-git-lfs-plugin to support git-lfs check." 48 | } 49 | ] 50 | } 51 | } 52 | ] 53 | } 54 | -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log - rush-git-lfs-plugin 2 | 3 | This log was last generated on Tue, 14 Feb 2023 03:16:01 GMT and should not be manually modified. 4 | 5 | ## 0.2.0 6 | Tue, 14 Feb 2023 03:16:01 GMT 7 | 8 | ### Minor changes 9 | 10 | - add git lfs pull plugin 11 | 12 | ## 0.1.2 13 | Wed, 08 Feb 2023 07:35:21 GMT 14 | 15 | ### Patches 16 | 17 | - Reduce log and use ora as alternative 18 | 19 | ## 0.1.1 20 | Mon, 19 Dec 2022 11:19:35 GMT 21 | 22 | ### Patches 23 | 24 | - fix rush-git-lfs-plugin configuration and wrong constant 25 | 26 | ## 0.1.0 27 | Fri, 16 Dec 2022 12:24:06 GMT 28 | 29 | ### Minor changes 30 | 31 | - Add new plugin rush-git-lfs-plugin to support git-lfs check. 32 | 33 | -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) TikTok Pte. Ltd. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/README.md: -------------------------------------------------------------------------------- 1 | # rush-git-lfs-plugin 2 | 3 | A rush plugin that can check if files are correctly managed by Git LFS. 4 | 5 | # Prerequisite 6 | 7 | Rush.js >= 5.83.2 8 | 9 | 10 | # Quick Start 11 | 12 | 1. Enabling this rush plugin 13 | 14 | Please follow the [official doc](https://rushjs.io/pages/maintainer/using_rush_plugins/) to enable this plugin in your repo. 15 | 16 | 1. Running `git-lfs-check` command 17 | 18 | ```bash 19 | # auto detect changed files by "git diff" 20 | rush git-lfs-check 21 | 22 | # or you can specify the files that need to be check\ 23 | rush git-lfs-check --file 24 | 25 | # you can add --fix option to auto fix incorrect lfs status 26 | ``` 27 | # Configuration 28 | 29 | You can specify which paths should be checked by provided a set of glob patterns and the size threshold can be customized. 30 | 31 | **JSON Schema For configuration** 32 | ```json5 33 | { 34 | "$schema": "http://json-schema.org/draft-04/schema#", 35 | "title": "Configuration for Rush Git LFS plugin", 36 | "type": "object", 37 | "additionalProperties": false, 38 | "properties": { 39 | "$schema": { 40 | "type": "string", 41 | "default": "http://json-schema.org/draft-04/schema#" 42 | }, 43 | "checkPattern": { 44 | "description": "Glob patterns that need to check", 45 | "patternProperties": { 46 | "^.+$": { 47 | "type": "string", 48 | "description": "Customized size threshold for this pattern." 49 | } 50 | } 51 | }, 52 | "errorTips": { 53 | "type": "string", 54 | "description": "Tips that shown while there are check errors" 55 | } 56 | } 57 | } 58 | ``` 59 | 60 | ## Example Configurations 61 | * Ban all png and dll files 62 | ```json5 63 | { 64 | "checkPattern": { 65 | "**/*.png": -1, 66 | "**/*.dll": -1 67 | }, 68 | } 69 | ``` 70 | * Ban all files that larger than 5MB 71 | ```json5 72 | { 73 | "checkPattern": { 74 | "**/*": 5 * 1024 * 124, 75 | }, 76 | } 77 | ``` 78 | * Ban files in particular folder 79 | ```json5 80 | { 81 | "checkPattern": { 82 | "**/some_folder_path": -1, 83 | }, 84 | } 85 | ``` 86 | # LICENSE 87 | 88 | MIT [@EscapeB](https://github.com/EscapeB) 89 | -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/command-line.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/command-line.schema.json", 3 | "commands": [ 4 | { 5 | "name": "git-lfs-check", 6 | "commandKind": "global", 7 | "summary": "Check Git LFS file in rush project", 8 | "shellCommand": "node /lib/bin.js", 9 | "safeForSimultaneousRushProcesses": true 10 | }, 11 | { 12 | "name": "git-lfs-pull", 13 | "commandKind": "global", 14 | "summary": "pull git lfs", 15 | "shellCommand": "node /lib/pull.js", 16 | "safeForSimultaneousRushProcesses": true 17 | } 18 | ], 19 | "parameters": [ 20 | { 21 | "description": "Fix Git LFS status", 22 | "parameterKind": "flag", 23 | "longName": "--fix", 24 | "associatedCommands": ["git-lfs-check"], 25 | "required": false 26 | }, 27 | { 28 | "description": "The path array of the files", 29 | "parameterKind": "stringList", 30 | "longName": "--file", 31 | "argumentName": "FILE_PATH", 32 | "required": false, 33 | "associatedCommands": ["git-lfs-check"] 34 | }, 35 | { 36 | "description": "The version of the plugin", 37 | "parameterKind": "flag", 38 | "longName": "--version", 39 | "required": false, 40 | "associatedCommands": ["git-lfs-check"] 41 | }, 42 | { 43 | "parameterKind": "string", 44 | "description": "verbosity that can be increased", 45 | "longName": "--verbose", 46 | "argumentName": "VERBOSE", 47 | "associatedCommands": ["git-lfs-check"], 48 | "required": false 49 | }, 50 | { 51 | "parameterKind": "stringList", 52 | "argumentName": "PROJECT", 53 | "longName": "--to", 54 | "shortName": "-t", 55 | "description": "choose project", 56 | "associatedCommands": ["git-lfs-pull"] 57 | } 58 | ] 59 | } 60 | -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/config/heft.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/heft/heft.schema.json", 3 | "eventActions": [ 4 | { 5 | "actionKind": "deleteGlobs", 6 | "heftEvent": "clean", 7 | "actionId": "defaultClean", 8 | "globsToDelete": [ 9 | "lib" 10 | ] 11 | } 12 | ], 13 | "heftPlugins": [ 14 | { 15 | "plugin": "@rushstack/heft-jest-plugin" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/config/jest.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@rushstack/heft-jest-plugin/includes/jest-shared.config.json", 3 | } -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/lint-staged.config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-env es6 */ 2 | const config = { 3 | "*.{js,jsx,ts,tsx}": "eslint --fix", 4 | }; 5 | module.exports = config; 6 | -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rush-git-lfs-plugin", 3 | "version": "0.2.0", 4 | "description": "Rush plugin for git-lfs", 5 | "keywords": [ 6 | "rush", 7 | "plugin", 8 | "git-lfs", 9 | "command" 10 | ], 11 | "homepage": "https://github.com/bytemate/rush-plugins#readme", 12 | "repository": { 13 | "type": "git", 14 | "url": "https://github.com/bytemate/rush-plugins", 15 | "directory": "rush-plugins/rush-git-lfs-plugin" 16 | }, 17 | "license": "MIT", 18 | "contributors": [ 19 | "EscapeB" 20 | ], 21 | "main": "lib/index.js", 22 | "scripts": { 23 | "build": "heft build --clean", 24 | "build:watch": "heft build --watch", 25 | "prepublishOnly": "npm run build", 26 | "test": "heft test" 27 | }, 28 | "dependencies": { 29 | "@rushstack/node-core-library": "3.44.1", 30 | "@rushstack/rush-sdk": "5.62.4", 31 | "chalk": "4.1.2", 32 | "commander": "~9.4.0", 33 | "execa": "~5.1.1", 34 | "fs-extra": "~10.1.0", 35 | "minimatch": "~5.1.1", 36 | "ora": "5.4.1" 37 | }, 38 | "devDependencies": { 39 | "@rushstack/eslint-config": "2.4.5", 40 | "@rushstack/heft": "0.43.2", 41 | "@rushstack/heft-jest-plugin": "~0.1.53", 42 | "@rushstack/heft-node-rig": "1.2.31", 43 | "@types/fs-extra": "~9.0.13", 44 | "@types/heft-jest": "1.0.1", 45 | "@types/minimatch": "~5.1.2", 46 | "@types/node": "12.20.24", 47 | "eslint": "7.32.0", 48 | "typescript": "4.4.2" 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/rush-plugin-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush-plugin-manifest.schema.json", 3 | "plugins": [ 4 | { 5 | "pluginName": "git-lfs-check", 6 | "description": "Check if new files are correct managed by git-lfs", 7 | "commandLineJsonFilePath": "command-line.json" 8 | }, 9 | { 10 | "pluginName": "git-lfs-pull", 11 | "description": "build-aware git lfs pull tooling", 12 | "commandLineJsonFilePath": "command-line.json" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/schema/git-lfs-option.schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-04/schema#", 3 | "title": "Configuration for Rush Git LFS plugin", 4 | "type": "object", 5 | "additionalProperties": false, 6 | "properties": { 7 | "$schema": { 8 | "type": "string", 9 | "default": "http://json-schema.org/draft-04/schema#" 10 | }, 11 | "checkPattern": { 12 | "description": "Glob patterns that need to check", 13 | "patternProperties": { 14 | "^.+$": { 15 | "type": "string", 16 | "description": "Customized size threshold for this pattern." 17 | } 18 | } 19 | }, 20 | "errorTips": { 21 | "type": "string", 22 | "description": "Tips that shown while there are check errors" 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/src/bin.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | import { program } from 'commander'; 3 | 4 | import { terminal, terminalProvider, withPrefix } from './helpers/terminal'; 5 | import { version, runCheck } from './executor'; 6 | 7 | export interface ICommandLineOptions { 8 | verbose?: boolean; 9 | fix?: boolean; 10 | file?: string[]; 11 | to?: string[]; 12 | } 13 | 14 | const increaseVerbosity = (u: unknown, previous: number): number => { 15 | return previous + 1; 16 | }; 17 | const setLogLevel = (verbose: number): void => { 18 | if (verbose > 0) { 19 | switch (verbose) { 20 | case 1: 21 | terminalProvider.verboseEnabled = true; 22 | break; 23 | default: 24 | terminalProvider.verboseEnabled = true; 25 | terminalProvider.debugEnabled = true; 26 | break; 27 | } 28 | } 29 | }; 30 | 31 | async function main(): Promise { 32 | try { 33 | await program 34 | .version(version()) 35 | .option('--verbose', 'Verbosity that can be increased', increaseVerbosity, 0) 36 | .option('--fix', 'Auto fix Git LFS status') 37 | .option('--file [file_path...]', 'The path of files') 38 | .action(async options => { 39 | setLogLevel(options.verbose); 40 | await runCheck(options); 41 | }) 42 | .parseAsync(process.argv); 43 | } catch (error: any) { 44 | if (error.message) { 45 | terminal.writeErrorLine(withPrefix(error.message)); 46 | } else { 47 | throw error; 48 | } 49 | process.exit(1); 50 | } 51 | } 52 | 53 | // eslint-disable-next-line @typescript-eslint/no-floating-promises 54 | main(); 55 | -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/src/constant.ts: -------------------------------------------------------------------------------- 1 | import type { IRushGitLFSPluginOption } from './options'; 2 | import type { NestedRequired } from './helpers/type'; 3 | 4 | export const DefaultOption: NestedRequired = { 5 | checkPattern: {}, 6 | errorTips: '', 7 | }; 8 | 9 | export const PluginName: string = 'rush-git-lfs-plugin'; 10 | -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/src/executor/index.ts: -------------------------------------------------------------------------------- 1 | export * from './version'; 2 | export * from './run-check'; 3 | export * from './modules'; 4 | export * from './pull'; 5 | -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/src/executor/modules/base.ts: -------------------------------------------------------------------------------- 1 | import type { NestedRequired } from '../../helpers/type'; 2 | import type { IRushGitLFSPluginOption } from '../../options'; 3 | 4 | export interface IGitLFSModuleContext { 5 | option: NestedRequired; 6 | } 7 | export abstract class GitLFSBaseModule { 8 | abstract run(ctx: IGitLFSModuleContext): Promise; 9 | } 10 | -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/src/executor/modules/index.ts: -------------------------------------------------------------------------------- 1 | export * from './check'; 2 | -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/src/executor/pull.ts: -------------------------------------------------------------------------------- 1 | import { Executable } from '@rushstack/node-core-library'; 2 | import { SpawnSyncReturns } from 'child_process'; 3 | 4 | interface IProject { 5 | path: string; 6 | } 7 | 8 | // get all related packages include project in workspace by projectName 9 | const getPackagesByProjectName = ( 10 | projectNames: Array 11 | ): { 12 | projects: Array; 13 | } => { 14 | const projectParams: Array> = projectNames.map((projectName) => ['-t', projectName]); 15 | const result: SpawnSyncReturns = Executable.spawnSync( 16 | 'rush', 17 | ['list'].concat(...projectParams, '--json') 18 | ); 19 | if (result.status === 0) { 20 | return JSON.parse(result.stdout); 21 | } 22 | throw new Error(`rush list error code ${result.status}`); 23 | }; 24 | 25 | const getAllIncludedPaths = ( 26 | projects: Array<{ 27 | path: string; 28 | }> 29 | ): string => projects.map((p) => p.path).join(','); 30 | 31 | // default action 32 | const gitLfsPull = (): void => { 33 | Executable.spawnSync('git', ['lfs', 'pull']); 34 | }; 35 | const gitLfsInstall = (): void => { 36 | Executable.spawnSync('git', ['lfs', 'install']); 37 | }; 38 | /** 39 | * 40 | * @param {*} to stringList, projectName(s) 41 | */ 42 | const gitLfsPullByProject = (projectNames: Array): void => { 43 | const { 44 | projects 45 | }: { 46 | projects: Array; 47 | } = getPackagesByProjectName(projectNames); 48 | // git lfs pull --include paths 49 | const includePaths: string = getAllIncludedPaths(projects); 50 | if (projects.length > 0) { 51 | const result: SpawnSyncReturns = Executable.spawnSync('git', [ 52 | 'lfs', 53 | 'pull', 54 | '--include', 55 | includePaths 56 | ]); 57 | if (result.status !== 0) { 58 | throw new Error(`git lfs pull --include failed ${result.status}`); 59 | } 60 | } else { 61 | throw new Error('no projects'); 62 | } 63 | }; 64 | 65 | export { gitLfsPull, gitLfsInstall, gitLfsPullByProject }; 66 | -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/src/executor/run-check.ts: -------------------------------------------------------------------------------- 1 | import { GitLFSCheckModule, IGitLFSCheckModuleContext } from './modules'; 2 | 3 | import { IRushGitLFSPluginOption, loadPluginOptions } from '../options'; 4 | 5 | import { getFilePathsFromChangedFiles, validateFilePaths } from '../helpers/file-path-analyser'; 6 | import { terminal, withPrefix } from '../helpers/terminal'; 7 | 8 | import type { NestedRequired } from '../helpers/type'; 9 | import type { ICommandLineOptions } from '../bin'; 10 | import ora from 'ora'; 11 | 12 | const normalizeCheckContext = ( 13 | commandLineOption: ICommandLineOptions 14 | ): IGitLFSCheckModuleContext => { 15 | // eslint-disable-next-line prefer-const 16 | let { file: files, fix } = commandLineOption; 17 | if (typeof files === 'undefined') { 18 | files = getFilePathsFromChangedFiles(); 19 | } else { 20 | try { 21 | validateFilePaths(files); 22 | } catch (e: any) { 23 | if (e.message) { 24 | terminal.writeErrorLine(withPrefix(e.message)); 25 | } else { 26 | throw e; 27 | } 28 | process.exit(1); 29 | } 30 | } 31 | 32 | const option: NestedRequired = loadPluginOptions(); 33 | const spinner: ora.Ora = ora(); 34 | return { 35 | result: [], 36 | fix, 37 | files, 38 | option, 39 | spinner, 40 | }; 41 | }; 42 | 43 | export const runCheck = async (commandLineOption: ICommandLineOptions): Promise => { 44 | const checker: GitLFSCheckModule = new GitLFSCheckModule(); 45 | const ctx: IGitLFSCheckModuleContext = normalizeCheckContext(commandLineOption); 46 | await checker.run(ctx); 47 | if (ctx.result.filter(e => typeof e.errorType !== 'undefined' && !e.fixed).length > 0) { 48 | if (ctx.option.errorTips) { 49 | terminal.writeLine(ctx.option.errorTips); 50 | } 51 | process.exit(1); 52 | } 53 | }; 54 | -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/src/executor/version.ts: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import fse from 'fs-extra'; 3 | 4 | export const version = (): string => { 5 | // eslint-disable-next-line @typescript-eslint/typedef 6 | const pkg = fse.readJSONSync(path.resolve(__dirname, '../../package.json')); 7 | return pkg.version; 8 | }; 9 | -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/src/helpers/terminal.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Terminal, 3 | ConsoleTerminalProvider, 4 | } from '@rushstack/node-core-library'; 5 | 6 | import { PluginName } from '../constant'; 7 | 8 | export const terminalProvider: ConsoleTerminalProvider = new ConsoleTerminalProvider(); 9 | export const terminal: Terminal = new Terminal(terminalProvider); 10 | 11 | export const withPrefix = (msg: string): string => { 12 | return `[${PluginName}]` + msg; 13 | }; 14 | -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/src/helpers/type.ts: -------------------------------------------------------------------------------- 1 | export type NestedRequired = { 2 | [P in keyof T]-?: NestedRequired; 3 | }; 4 | export type NestedPartial = { 5 | [P in keyof T]?: NestedPartial; 6 | }; 7 | -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/src/index.ts: -------------------------------------------------------------------------------- 1 | export * from './constant'; 2 | export * from './options'; -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/src/options.ts: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import { RushConfiguration } from '@rushstack/rush-sdk'; 3 | 4 | import fse from 'fs-extra'; 5 | 6 | import { PluginName, DefaultOption } from './constant'; 7 | import { NestedRequired } from './helpers/type'; 8 | 9 | export interface IRushGitLFSPluginOption { 10 | checkPattern: Record; 11 | errorTips?: string; 12 | } 13 | 14 | export const loadPluginOptions = (): NestedRequired => { 15 | const rushConfig: RushConfiguration = RushConfiguration.loadFromDefaultLocation(); 16 | const pluginConfigFolder: string = rushConfig.rushPluginOptionsFolder; 17 | const optionFilePath: string = path.resolve(pluginConfigFolder, `${PluginName}.json`); 18 | 19 | const option: NestedRequired = DefaultOption; 20 | 21 | if (fse.existsSync(optionFilePath)) { 22 | const customOption: Partial = fse.readJSONSync(optionFilePath); 23 | 24 | if (typeof customOption.checkPattern === 'object') { 25 | option.checkPattern = { 26 | ...option.checkPattern, 27 | ...customOption.checkPattern, 28 | }; 29 | } 30 | if (customOption.errorTips) { 31 | option.errorTips = customOption.errorTips; 32 | } 33 | } 34 | return option; 35 | }; 36 | -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/src/pull.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * git lfs pull related project files 3 | * rush git-lsf-pull -t/--to projectName 4 | */ 5 | import { program } from 'commander'; 6 | import { gitLfsInstall, gitLfsPullByProject } from './executor'; 7 | import { terminal } from './helpers/terminal'; 8 | 9 | (async () => { 10 | program.option('--to ', '-t ', 'select project').action(async (params) => { 11 | const { to } = params; 12 | gitLfsInstall(); 13 | try { 14 | gitLfsPullByProject([].concat(to)); 15 | terminal.writeLine(`git-lfs-pull pull ${to} success`); 16 | } catch (error: any) { 17 | if (error && error.toString) { 18 | terminal.writeErrorLine(error.toString()); 19 | } else { 20 | throw error; 21 | } 22 | process.exit(1); 23 | } 24 | }); 25 | 26 | program.on('command:*', () => { 27 | console.error('undefined command', program.args.join(' ')); 28 | process.exit(1); 29 | }); 30 | 31 | await program.parseAsync(process.argv); 32 | })().catch((e: any) => console.error(e && e.message ? e.message : e)); 33 | -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/src/tests/executor/verison.test.ts: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import fs from 'fs'; 3 | 4 | import { version } from '../../executor/version'; 5 | 6 | describe('version parameter', () => { 7 | it('version should match current version in package.json', () => { 8 | const pkg = JSON.parse( 9 | fs 10 | .readFileSync(path.resolve(__dirname, '../../../package.json'), { encoding: 'utf-8' }) 11 | .toString() 12 | ); 13 | expect(version()).toStrictEqual(pkg.version); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/src/tests/helpers/file-path-analyser.test.ts: -------------------------------------------------------------------------------- 1 | jest.mock('execa'); 2 | import execa from 'execa'; 3 | import path from 'path'; 4 | 5 | import { 6 | getFilePathsFromChangedFiles, 7 | findFileBelongProject, 8 | validateFilePaths, 9 | } from '../../helpers/file-path-analyser'; 10 | import { terminal, terminalProvider } from '../../helpers/terminal'; 11 | 12 | const mockCommandSyncReturn = (result: Partial): void => { 13 | ( 14 | execa.commandSync as unknown as jest.MockedFunction 15 | ).mockImplementation((() => { 16 | return result; 17 | }) as any); 18 | }; 19 | 20 | describe('test file path analyser', () => { 21 | it('should get changed files by git diff', () => { 22 | const testPath = path.resolve(__dirname); 23 | mockCommandSyncReturn({ 24 | exitCode: 0, 25 | stdout: testPath, 26 | }); 27 | expect(getFilePathsFromChangedFiles()?.[0]).toStrictEqual(testPath); 28 | }); 29 | 30 | it('should throw error if git diff run failed', () => { 31 | mockCommandSyncReturn({ exitCode: 1, stderr: 'This should be an error' }); 32 | terminal.unregisterProvider(terminalProvider); 33 | expect(getFilePathsFromChangedFiles).toThrowError(); 34 | terminal.registerProvider(terminalProvider); 35 | }); 36 | 37 | it('should find file path belong package correctly', () => { 38 | const p1 = path.resolve(__dirname); 39 | 40 | const p2 = path.resolve(__dirname, '../../../../../rush.json'); 41 | const p3 = path.resolve('/some/path/that/incorrect'); 42 | expect(findFileBelongProject(p1)?.packageName).toStrictEqual('rush-git-lfs-plugin'); 43 | expect(findFileBelongProject(p2)).toBeUndefined(); 44 | expect(findFileBelongProject(p3)).toBeUndefined(); 45 | }); 46 | 47 | it('should valid path correctly', () => { 48 | const pathsCorrect = [ 49 | path.resolve(__dirname), 50 | path.resolve(__dirname, '../../../package.json'), 51 | ]; 52 | 53 | const pathsPatternIncorrect = [path.resolve(__dirname), 20, Boolean]; 54 | 55 | const pathsFileNotExist = [ 56 | path.resolve(__dirname), 57 | path.resolve(__dirname, './not-exist-file.ts'), 58 | ]; 59 | 60 | expect(() => validateFilePaths(pathsCorrect)).not.toThrow(); 61 | expect(() => validateFilePaths(pathsPatternIncorrect as string[])).toThrowError(); 62 | expect(() => validateFilePaths(pathsFileNotExist)).toThrowError(); 63 | }); 64 | }); 65 | -------------------------------------------------------------------------------- /rush-plugins/rush-git-lfs-plugin/src/tests/setup/TestFileFactory.ts: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import fse from 'fs-extra'; 3 | import execa from 'execa'; 4 | 5 | export default class TestFileFactory { 6 | private static _instance?: TestFileFactory; 7 | public tempFolder: string = path.resolve(__dirname, '../temp'); 8 | public static getInstance(): TestFileFactory { 9 | if (!this._instance) { 10 | this._instance = new TestFileFactory(); 11 | } 12 | return this._instance; 13 | } 14 | 15 | private _writeFile(fileName: string, data: any): string { 16 | const filePath: string = path.resolve(this.tempFolder, `${fileName}`); 17 | fse.ensureDirSync(path.dirname(filePath)); 18 | fse.writeFileSync(filePath, data); 19 | return filePath; 20 | } 21 | 22 | public createTextFile(fileName: string): string { 23 | const str: string = (Math.random() + 1).toString(36).substring(7); 24 | 25 | return this._writeFile(fileName, str); 26 | } 27 | public createBinaryFile(fileName: string): string { 28 | const simplePngBase64Str: string = 29 | 'iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAKElEQVQ4jWNgYGD4Twzu6FhFFGYYNXDUwGFpIAk2E4dHDRw1cDgaCAASFOffhEIO3gAAAABJRU5ErkJggg=='; 30 | 31 | return this._writeFile(fileName + '.png', Buffer.from(simplePngBase64Str, 'base64')); 32 | } 33 | public createSizedFile(fileName: string, size: number): string { 34 | const filePath: string = path.resolve(this.tempFolder, fileName); 35 | fse.ensureFileSync(filePath); 36 | const f: number = fse.openSync(filePath, 'w'); 37 | fse.writeSync(f, 'ok', Math.max(0, size - 2)); 38 | fse.closeSync(f); 39 | return filePath; 40 | } 41 | public addFileToLFS(filePath: string): void { 42 | const relativePath: string = path.relative(this.tempFolder, filePath); 43 | const { exitCode } = execa.commandSync(`git lfs track ${relativePath}`, { 44 | cwd: this.tempFolder, 45 | }); 46 | if (exitCode !== 0) { 47 | throw new Error('Add file to lfs failed'); 48 | } 49 | } 50 | public removeFileFromLFS(filePath: string): void { 51 | const relativePath: string = path.relative(this.tempFolder, filePath); 52 | const { exitCode } = execa.commandSync(`git lfs untrack ${relativePath}`, { 53 | cwd: this.tempFolder, 54 | }); 55 | if (exitCode !== 0) { 56 | throw new Error('Remove file from lfs failed'); 57 | } 58 | } 59 | 60 | public cleanTempFolder(): void { 61 | fse.removeSync(this.tempFolder); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/.eslintrc.js: -------------------------------------------------------------------------------- 1 | // This is a workaround for https://github.com/eslint/eslint/issues/3458 2 | require("@rushstack/eslint-config/patch/modern-module-resolution"); 3 | 4 | module.exports = { 5 | extends: [ 6 | "@rushstack/eslint-config/profile/node-trusted-tool", 7 | "@rushstack/eslint-config/mixins/friendly-locals", 8 | ], 9 | parserOptions: { tsconfigRootDir: __dirname }, 10 | ignorePatterns: ["node_modules/", "lib/"], 11 | rules: { 12 | "@rushstack/no-new-null": "off", 13 | "@typescript-eslint/no-explicit-any": "off", 14 | }, 15 | }; 16 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | lib/ 2 | temp/ 3 | output/ -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/.npmignore: -------------------------------------------------------------------------------- 1 | # THIS IS A STANDARD TEMPLATE FOR .npmignore FILES IN THIS REPO. 2 | 3 | # Ignore all files by default, to avoid accidentally publishing unintended files. 4 | * 5 | 6 | # Use negative patterns to bring back the specific things we want to publish. 7 | !/bin/** 8 | !/lib/** 9 | !/lib-*/** 10 | !/dist/** 11 | !ThirdPartyNotice.txt 12 | !/src/** 13 | 14 | # Ignore certain patterns that should not get published. 15 | /dist/*.stats.* 16 | /lib/**/test/ 17 | /lib-*/**/test/ 18 | *.test.js 19 | 20 | # NOTE: These don't need to be specified, because NPM includes them automatically. 21 | # 22 | # package.json 23 | # README (and its variants) 24 | # CHANGELOG (and its variants) 25 | # LICENSE / LICENCE 26 | 27 | #-------------------------------------------- 28 | # DO NOT MODIFY THE TEMPLATE ABOVE THIS LINE 29 | #-------------------------------------------- 30 | 31 | # (Add your project-specific overrides here) 32 | !/includes/** 33 | !rush-plugin-manifest.json 34 | !command-line.json 35 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) TikTok Pte. Ltd. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/README.md: -------------------------------------------------------------------------------- 1 | # rush-init-project-plugin 2 | 3 | Initialize project in Rush.js monorepo like a pro! 4 | 5 | # Prerequisite 6 | 7 | Rush.js >= 5.57.0 8 | 9 | # Quick Start 10 | 11 | 1. Enabling this rush plugin 12 | 13 | Please follow the [official doc](https://rushjs.io/pages/maintainer/using_rush_plugins/) to enable this plugin in your repo. 14 | 15 | 2. Adding your first template 16 | 17 | Let's say you want to add a new template named `my-template`, put the template files under `common/_templates/my-template` folder. 18 | 19 | ``` 20 | common/_templates 21 | └── my-template 22 | ├── README.md 23 | └── package.json 24 | ``` 25 | 26 | Now, run `rush init-project` prompts you select a template list, which contains `my-template`. 27 | 28 | After you answer some simple questions, files under `common/_templates/my-template` will be added into your project folder, and project configuration will be added to `rush.json` as well. 29 | 30 | # Advance Usage 31 | 32 | Kind of boring in a template way? 33 | 34 | You can create a configuration file to extend initialization process. 35 | 36 | See [HERE](./docs/init_project_configuration.md) for detail. 37 | 38 | # Tech Notes 39 | 40 | The whole CLI is based on [node-plop](https://www.npmjs.com/package/plop) 41 | 42 | All directories under `common/_templates/` are template source code, except those who prefixes with `_`. For instance, folder named `_plugins` is treated as internal folder not template folder where you can store shared code across templates. 43 | 44 | All source code will be rendered by [handlebars](https://handlebarsjs.com/guide/), while using custom render engine is supported. 45 | 46 | Plenty of handlebar helpers are provided as default by [handlebars-helpers](https://www.npmjs.com/package/handlebars-helpers) 47 | 48 | Third party node modules can be used in `init.config` configuration file by installing them into the corresponding autoinstaller folder, such as `common/autoinstallers/rush-plugins/`. 49 | 50 | Default prompts includes: 51 | - `packageName`: `"name"` field in `package.json` 52 | - `unscopedPackageName`: `packageName` without npm scope 53 | - `projectFolder`: the dest file path where the template will be rendered 54 | - `description`: project description 55 | - `authorName`: author name 56 | 57 | # LICENSE 58 | 59 | MIT [@chengcyber](https://github.com/chengcyber) 60 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/command-line.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/command-line.schema.json", 3 | "commands": [ 4 | { 5 | "name": "init-project", 6 | "commandKind": "global", 7 | "summary": "Initialize project in this monorepo", 8 | "shellCommand": "rush-init-project", 9 | "safeForSimultaneousRushProcesses": true 10 | } 11 | ], 12 | "parameters": [ 13 | { 14 | "parameterKind": "string", 15 | "description": "Provide predefined answers with JSON string", 16 | "shortName": "-a", 17 | "longName": "--answer", 18 | "argumentName": "ANSWER", 19 | "associatedCommands": ["init-project"], 20 | "required": false 21 | }, 22 | { 23 | "parameterKind": "flag", 24 | "description": "Provide the option isDryRun in plugin context", 25 | "shortName": "-d", 26 | "longName": "--dry-run", 27 | "associatedCommands": ["init-project"], 28 | "required": false 29 | }, 30 | { 31 | "parameterKind": "flag", 32 | "description": "Provide verbose log output", 33 | "shortName": "-v", 34 | "longName": "--verbose", 35 | "associatedCommands": ["init-project"], 36 | "required": false 37 | }, 38 | { 39 | "parameterKind": "flag", 40 | "description": "Provide terminal ui operation", 41 | "longName": "--ui", 42 | "associatedCommands": ["init-project"], 43 | "required": false 44 | } 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/config/heft.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/heft/heft.schema.json", 3 | 4 | "eventActions": [ 5 | { 6 | "actionKind": "deleteGlobs", 7 | "heftEvent": "clean", 8 | "actionId": "defaultClean", 9 | "globsToDelete": ["lib"] 10 | } 11 | ], 12 | 13 | "heftPlugins": [ 14 | { "plugin": "@rushstack/heft-jest-plugin" } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/config/jest.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@rushstack/heft-jest-plugin/includes/jest-shared.config.json" 3 | } 4 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/lint-staged.config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-env es6 */ 2 | const config = { 3 | "*.{js,jsx,ts,tsx}": "eslint --fix", 4 | }; 5 | module.exports = config; 6 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rush-init-project-plugin", 3 | "version": "0.9.0", 4 | "description": "Rush plugin for initialize project in monorepo", 5 | "keywords": [ 6 | "rush", 7 | "plugin", 8 | "command", 9 | "init", 10 | "project" 11 | ], 12 | "homepage": "https://github.com/bytemate/rush-plugins#readme", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/bytemate/rush-plugins", 16 | "directory": "rush-plugins/rush-init-project-plugin" 17 | }, 18 | "license": "MIT", 19 | "contributors": [ 20 | "Cheng Liu " 21 | ], 22 | "main": "lib/index.js", 23 | "typings": "lib/index.d.ts", 24 | "bin": { 25 | "rush-init-project": "lib/cli.js" 26 | }, 27 | "scripts": { 28 | "build": "heft build --clean", 29 | "build:watch": "heft build --watch", 30 | "prepublishOnly": "npm run build", 31 | "test": "heft test" 32 | }, 33 | "dependencies": { 34 | "@rushstack/node-core-library": "3.44.1", 35 | "@rushstack/rush-sdk": "5.62.4", 36 | "@types/inquirer-autocomplete-prompt": "~3.0.0", 37 | "blessed": "~0.1.81", 38 | "blessed-contrib": "~4.11.0", 39 | "chalk": "4.1.2", 40 | "commander": "~9.4.0", 41 | "handlebars-helpers": "~0.10.0", 42 | "inquirer": "~8.2.0", 43 | "inquirer-autocomplete-prompt": "~1.4.0", 44 | "lilconfig": "~2.0.4", 45 | "lodash": "4.17.21", 46 | "node-plop": "0.26.3", 47 | "ora": "5.4.1", 48 | "sort-package-json": "1.54.0", 49 | "tapable": "~2.2.1", 50 | "ts-node": "~10.4.0", 51 | "validate-npm-package-name": "~3.0.0" 52 | }, 53 | "devDependencies": { 54 | "@rushstack/eslint-config": "2.4.5", 55 | "@rushstack/heft": "0.43.2", 56 | "@rushstack/heft-jest-plugin": "~0.1.53", 57 | "@rushstack/heft-node-rig": "1.2.31", 58 | "@types/blessed": "~0.1.19", 59 | "@types/ejs": "~3.1.1", 60 | "@types/heft-jest": "1.0.1", 61 | "@types/inquirer": "~8.1.3", 62 | "@types/lodash": "4.14.184", 63 | "@types/node": "12.20.24", 64 | "del": "6.1.1", 65 | "ejs": "~3.1.8", 66 | "eslint": "7.32.0", 67 | "typescript": "4.4.2" 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/rush-plugin-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush-plugin-manifest.schema.json", 3 | "plugins": [ 4 | { 5 | "pluginName": "rush-init-project-plugin", 6 | "description": "Rush plugin for initialize project in monorepo", 7 | "commandLineJsonFilePath": "command-line.json" 8 | } 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/src/actions/addProjectToRushJson.ts: -------------------------------------------------------------------------------- 1 | import { JsonFile, JsonObject } from "@rushstack/node-core-library"; 2 | import { loadRushConfiguration } from "../logic/loadRushConfiguration"; 3 | 4 | import type { RushConfiguration } from "@rushstack/rush-sdk"; 5 | import type { IDefaultProjectConfiguration } from "../logic/TemplateConfiguration"; 6 | 7 | export interface IAddProjectToRushJsonParams { 8 | packageName: string; 9 | projectFolder: string; 10 | defaultProjectConfiguration?: IDefaultProjectConfiguration; 11 | } 12 | 13 | export const addProjectToRushJson = ({ 14 | packageName, 15 | projectFolder, 16 | defaultProjectConfiguration = {}, 17 | }: IAddProjectToRushJsonParams): void => { 18 | const rushConfiguration: RushConfiguration = 19 | loadRushConfiguration() as unknown as RushConfiguration; 20 | const { rushJsonFile } = rushConfiguration; 21 | const rawRushConfigJson: JsonObject = JsonFile.load(rushJsonFile); 22 | const projectConfiguration: JsonObject = { 23 | packageName, 24 | projectFolder, 25 | ...defaultProjectConfiguration, 26 | }; 27 | rawRushConfigJson.projects.push({ 28 | ...projectConfiguration, 29 | }); 30 | JsonFile.save(rawRushConfigJson, rushJsonFile, { 31 | updateExistingFile: true, 32 | }); 33 | }; 34 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/src/actions/rushRushUpdate.ts: -------------------------------------------------------------------------------- 1 | import { Executable } from "@rushstack/node-core-library"; 2 | import type { SpawnSyncReturns } from "child_process"; 3 | 4 | export const runRushUpdate = (): void => { 5 | const result: SpawnSyncReturns = Executable.spawnSync( 6 | "rush", 7 | ["update"], 8 | { 9 | stdio: "inherit", 10 | } 11 | ); 12 | if (result.status !== 0) { 13 | throw new Error('Run "rush update" failed'); 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/src/actions/sortPackageJson.ts: -------------------------------------------------------------------------------- 1 | import * as path from "path"; 2 | import { FileSystem } from "@rushstack/node-core-library"; 3 | import sort from "sort-package-json"; 4 | import { loadRushConfiguration } from "../logic/loadRushConfiguration"; 5 | 6 | export const sortPackageJson = (projectFolder: string): void => { 7 | const { rushJsonFolder } = loadRushConfiguration(); 8 | const packageJsonPath: string = path.join( 9 | rushJsonFolder, 10 | projectFolder, 11 | "package.json" 12 | ); 13 | if (!FileSystem.exists(packageJsonPath)) { 14 | throw new Error(`package.json for ${projectFolder} does not exist`); 15 | } 16 | 17 | const input: string = FileSystem.readFile(packageJsonPath); 18 | FileSystem.writeFile(packageJsonPath, sort(input)); 19 | }; 20 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/src/cli.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import { Terminal } from '@rushstack/node-core-library'; 4 | import { program } from 'commander'; 5 | import { initProject } from './init-project'; 6 | import { getTemplatesFolderAndValidate } from './logic/templateFolder'; 7 | import { TerminalSingleton } from './terminal'; 8 | 9 | (async () => { 10 | program 11 | .option('-a, --answer ', 'Provide predefined answers with JSON string') 12 | .option('-d, --dry-run', 'Provide the option isDryRun in plugin context', false) 13 | .option('-v, --verbose', 'Enable output verbose debug purposing messages', false) 14 | .option('--ui', 'Provide terminal ui operation', false) 15 | .description('Initialize new Rush projects') 16 | .action(async (params) => { 17 | TerminalSingleton.setVerboseEnabled(params?.verbose ?? false); 18 | const terminal: Terminal = TerminalSingleton.getInstance(); 19 | try { 20 | await getTemplatesFolderAndValidate(); 21 | await initProject(params); 22 | } catch (error: any) { 23 | if (error.message) { 24 | terminal.writeErrorLine(error.message); 25 | } else { 26 | throw error; 27 | } 28 | process.exit(1); 29 | } 30 | }); 31 | 32 | program.on('command:*', () => { 33 | console.error('undefined command', program.args.join(' ')); 34 | process.exit(1); 35 | }); 36 | 37 | await program.parseAsync(process.argv); 38 | })().catch((e) => (e?.message ? console.error(e.message) : console.error(e))); 39 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/src/hooks.ts: -------------------------------------------------------------------------------- 1 | import { AsyncSeriesHook, HookMap, SyncHook } from 'tapable'; 2 | 3 | import type { ActionType, NodePlopAPI, PromptQuestion } from 'node-plop'; 4 | import type { IDefaultProjectConfiguration } from './logic/TemplateConfiguration'; 5 | import type { IExtendedAnswers } from './plopfile'; 6 | import type { ITemplatePathNameType } from './logic/templateFolder'; 7 | 8 | export interface ITemplatesHook { 9 | templates: ITemplatePathNameType[]; 10 | } 11 | 12 | export interface IPromptsHookParams { 13 | /** 14 | * The queue of prompt question. and question will be prompt to use in sequence order 15 | */ 16 | promptQueue: PromptQuestion[]; 17 | } 18 | 19 | export interface IActionsHookParams { 20 | /** 21 | * A list of plop action. These actions will be registered into plop 22 | */ 23 | actions: ActionType[]; 24 | } 25 | 26 | type IAnswers = IExtendedAnswers; 27 | 28 | export type IResult = 'Succeeded' | 'Failed'; 29 | 30 | export interface IHooks { 31 | templates: AsyncSeriesHook; 32 | prompts: AsyncSeriesHook; 33 | actions: SyncHook; 34 | answers: AsyncSeriesHook; 35 | plop: SyncHook; 36 | promptQuestion: HookMap>; 37 | defaultProjectConfiguration: SyncHook<[IDefaultProjectConfiguration, IAnswers]>; 38 | done: AsyncSeriesHook<[IResult, IAnswers]>; 39 | } 40 | 41 | const initHooks = (): IHooks => { 42 | return { 43 | templates: new AsyncSeriesHook(['templates']), 44 | prompts: new AsyncSeriesHook(['promptsHookParams']), 45 | answers: new AsyncSeriesHook(['answers']), 46 | actions: new SyncHook(['actionsHookParams']), 47 | plop: new SyncHook(['plop']), 48 | promptQuestion: new HookMap( 49 | (key: string) => 50 | new SyncHook<[PromptQuestion, IAnswers], null | undefined>(['promptQuestion', 'answersSoFar']) 51 | ), 52 | defaultProjectConfiguration: new SyncHook<[IDefaultProjectConfiguration, IAnswers]>([ 53 | 'defaultProjectConfiguration', 54 | 'answers' 55 | ]), 56 | done: new AsyncSeriesHook<[IResult, IAnswers]>(['result', 'answers']) 57 | }; 58 | }; 59 | 60 | const hooks: IHooks = initHooks(); 61 | 62 | export const getHooks: () => IHooks = (): IHooks => { 63 | return hooks; 64 | }; 65 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/src/index.ts: -------------------------------------------------------------------------------- 1 | export type { 2 | IPlugin, 3 | IConfig, 4 | IPluginContext, 5 | IDefaultProjectConfiguration, 6 | } from "./logic/TemplateConfiguration"; 7 | export type { IHooks, IActionsHookParams, IPromptsHookParams, IResult } from "./hooks"; 8 | export type { NodePlopAPI, PromptQuestion } from "node-plop"; 9 | export type { IExtendedAnswers as IAnswers } from "./plopfile"; 10 | export * from "./terminal"; 11 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/src/logic/GitConfig.ts: -------------------------------------------------------------------------------- 1 | import { Executable } from "@rushstack/node-core-library"; 2 | import type { SpawnSyncReturns } from "child_process"; 3 | 4 | export const getGitUserName = (cwd: string): string => { 5 | try { 6 | const result: SpawnSyncReturns = Executable.spawnSync( 7 | 'git', 8 | ['config', 'user.name'], 9 | { 10 | currentWorkingDirectory: cwd, 11 | stdio: "pipe", 12 | } 13 | ); 14 | if (result.status !== 0) { 15 | return ''; 16 | } 17 | return result.stdout?.trim() ?? ''; 18 | } catch (e) { 19 | // no-catch 20 | return ''; 21 | } 22 | } -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/src/logic/loadGlobalConfiguration.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | import { LilconfigResult, lilconfigSync } from 'lilconfig'; 3 | import { FileSystem, Terminal, JsonFile, JsonSchema, JsonObject } from '@rushstack/node-core-library'; 4 | import templeteSchema from './template.schema.json'; 5 | import { TerminalSingleton } from '../terminal'; 6 | import { getTemplatesFolder, getTemplateNameList, ITemplatePathNameType } from './templateFolder'; 7 | import { IHooks } from '../hooks'; 8 | import { IPluginContext } from './TemplateConfiguration'; 9 | 10 | export interface IGlobalConfig { 11 | templateNameList: ITemplatePathNameType[]; 12 | } 13 | 14 | const globalPluginLoaders: Record void> = { 15 | '.js': (path) => require(path), 16 | '.ts': (path) => { 17 | require('ts-node').register({ 18 | transpileOnly: true, 19 | compilerOptions: { 20 | esModuleInterop: true 21 | } 22 | }); 23 | const module: any = require(path); 24 | try { 25 | if ('default' in module) { 26 | return module.default; 27 | } 28 | } catch { 29 | // no-catch 30 | } 31 | return module; 32 | } 33 | }; 34 | 35 | // global configuration will load config from `template.json` 36 | export async function loadGlobalConfiguration( 37 | hooks: IHooks, 38 | pluginContext: IPluginContext 39 | ): Promise { 40 | const terminal: Terminal = TerminalSingleton.getInstance(); 41 | const templateFolder: string = getTemplatesFolder(); 42 | const templateConfigPath: string = path.join(templateFolder, 'template.json'); 43 | // if template.json doesn't exists, get the template list from folder 44 | if (!FileSystem.exists(templateConfigPath)) { 45 | return { 46 | templateNameList: getTemplateNameList(templateFolder) 47 | }; 48 | } 49 | const jsonSchema: JsonSchema = JsonSchema.fromLoadedObject(templeteSchema); 50 | const res: JsonObject = await JsonFile.loadAndValidateWithCallbackAsync( 51 | templateConfigPath, 52 | jsonSchema, 53 | ({ details = '' }): void => { 54 | terminal.writeErrorLine(details); 55 | process.exit(1); 56 | } 57 | ); 58 | const { templates, globalPluginEntryPoint } = res; 59 | if (globalPluginEntryPoint) { 60 | const result: LilconfigResult = lilconfigSync('init', { 61 | searchPlaces: [globalPluginEntryPoint], 62 | loaders: globalPluginLoaders 63 | }).search(templateFolder); 64 | if (result) { 65 | for (const plugin of result.config?.plugins) { 66 | plugin.apply(hooks, pluginContext); 67 | } 68 | } 69 | } 70 | 71 | return { 72 | templateNameList: templates as ITemplatePathNameType[] 73 | }; 74 | } 75 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/src/logic/loadRushConfiguration.ts: -------------------------------------------------------------------------------- 1 | import { RushConfiguration } from "@rushstack/rush-sdk"; 2 | 3 | const cwd2RushConfiguration: Record = {}; 4 | 5 | export const loadRushConfiguration = ( 6 | cwd: string = process.cwd() 7 | ): RushConfiguration => { 8 | let rushConfiguration: RushConfiguration = cwd2RushConfiguration[cwd]; 9 | if (!rushConfiguration) { 10 | try { 11 | rushConfiguration = RushConfiguration.loadFromDefaultLocation({ 12 | startingFolder: cwd, 13 | }); 14 | if (!rushConfiguration) { 15 | throw new Error("Rush configuration not found"); 16 | } 17 | cwd2RushConfiguration[cwd] = rushConfiguration; 18 | } catch (e) { 19 | throw new Error("Load rush configuration failed"); 20 | } 21 | } 22 | return rushConfiguration; 23 | }; 24 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/src/logic/template.schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-04/schema#", 3 | "title": "Template config File", 4 | "description": "The main configuration file Template management.", 5 | "type": "object", 6 | "properties": { 7 | "$schema": { 8 | "description": "Part of the JSON Schema standard, this optional keyword declares the URL of the schema that the file conforms to. Editors may download the schema and use it to perform syntax highlighting.", 9 | "type": "string" 10 | }, 11 | "templates": { 12 | "description": "A list of templates managed by this tool.", 13 | "type": "array", 14 | "items": { 15 | "type": "object", 16 | "properties": { 17 | "displayName": { 18 | "description": "The display name of the template.", 19 | "type": "string" 20 | }, 21 | "templateFolder": { 22 | "description": "The path to the template folder relative to the template config file.", 23 | "type": "string" 24 | } 25 | }, 26 | "additionalProperties": false, 27 | "required": ["templateFolder"] 28 | } 29 | }, 30 | "globalPluginEntryPoint": { 31 | "description": "entry point for global plugins", 32 | "type": "string" 33 | } 34 | }, 35 | "additionalProperties": false, 36 | "required": ["templates"] 37 | } 38 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/src/logic/templateFolder.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | import { FileSystem } from '@rushstack/node-core-library'; 3 | import { loadRushConfiguration } from './loadRushConfiguration'; 4 | 5 | export interface ITemplatePathNameType { 6 | templateFolder: string; 7 | displayName?: string; 8 | } 9 | 10 | const templatesFolder2templateNameList: Record> = {}; 11 | 12 | export const getTemplatesFolder = (): string => { 13 | const { commonFolder } = loadRushConfiguration(); 14 | const templatesFolder: string = path.join(commonFolder, '_templates'); 15 | return templatesFolder; 16 | }; 17 | 18 | export const getTemplatesFolderAndValidate = (): string => { 19 | const templatesFolder: string = getTemplatesFolder(); 20 | if (!FileSystem.exists(templatesFolder)) { 21 | FileSystem.ensureFolder(templatesFolder); 22 | throw new Error(`Templates folder created, please setup template under "${templatesFolder}"`); 23 | } 24 | 25 | const templateNameList: ITemplatePathNameType[] = getTemplateNameList(templatesFolder); 26 | if (templateNameList.length === 0) { 27 | throw new Error(`Please setup template under ${templatesFolder}`); 28 | } 29 | 30 | return templatesFolder; 31 | }; 32 | 33 | // get template list from folder 34 | export function getTemplateNameList(templatesFolder: string): ITemplatePathNameType[] { 35 | let templateNameList: ITemplatePathNameType[] = templatesFolder2templateNameList[templatesFolder]; 36 | if (!templateNameList) { 37 | const templateFolderList: string[] = FileSystem.readFolder(templatesFolder) 38 | .filter((filename: string) => { 39 | return FileSystem.getStatistics(path.resolve(templatesFolder, filename)).isDirectory(); 40 | }) 41 | .filter((filename: string) => { 42 | return !filename.startsWith('_'); 43 | }); 44 | templateNameList = templateFolderList.map((templateFolder: string) => ({ templateFolder })); 45 | } 46 | // eslint-disable-next-line require-atomic-updates 47 | templatesFolder2templateNameList[templatesFolder] = templateNameList; 48 | return templateNameList; 49 | } 50 | 51 | export function getTemplateFolder(template: string): string { 52 | const templatesFolder: string = getTemplatesFolder(); 53 | const templateFolder: string = path.join(templatesFolder, template); 54 | return templateFolder; 55 | } 56 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/src/test/addManyCustomEngine/__snapshots__/addManyCustomEngine.test.ts.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`addManyCustomEngine should add many files 1`] = ` 4 | "/* eslint-disable */ 5 | // prettier-ignore 6 | import React from \\"react\\"; 7 | 8 | interface ImageProps { 9 | src: string; 10 | } 11 | 12 | const Image = (props: ImageProps): JSX.Element => { 13 | const { src } = props; 14 | return ( 15 | 20 | ); 21 | }; 22 | 23 | export default Image; 24 | " 25 | `; 26 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/src/test/addManyCustomEngine/addManyCustomEngine.test.ts: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import fs from 'fs'; 3 | import del from 'del'; 4 | import { preparePlop } from "../utils"; 5 | 6 | import type { NodePlopAPI } from "node-plop"; 7 | 8 | describe('addManyCustomEngine', () => { 9 | let plop: NodePlopAPI; 10 | const baseFolder: string = path.resolve(__dirname, 'plop-templates'); 11 | const destination: string = path.resolve(__dirname, 'output'); 12 | const plopfilePath: string = path.resolve(__dirname, 'plopfile.js'); 13 | beforeEach(async () => { 14 | await del(destination); 15 | plop = preparePlop(plopfilePath); 16 | }); 17 | it('should add many files', async () => { 18 | const answer = { 19 | packageName: 'foo' 20 | } 21 | plop.setGenerator("testAddManyCustomEngine", { 22 | description: '', 23 | prompts: [], 24 | actions: [ 25 | { 26 | type: "addMany", 27 | force: true, 28 | destination, 29 | base: baseFolder, 30 | templateFiles: [`**/*`, "!init.config.ts", "!init.config.js"], 31 | globOptions: { 32 | cwd: baseFolder, 33 | dot: true, 34 | absolute: true, 35 | }, 36 | data: {}, 37 | }, 38 | ], 39 | }); 40 | 41 | await plop.getGenerator("testAddManyCustomEngine").runActions(answer); 42 | 43 | const packageJsonFile: string = path.resolve(destination, 'pkg.json'); 44 | expect(fs.existsSync(packageJsonFile)).toBe(true); 45 | let packageJson = {} as any; 46 | expect(() => { 47 | packageJson = JSON.parse(fs.readFileSync(packageJsonFile, 'utf-8')) 48 | }).not.toThrow(); 49 | expect(packageJson.name).toBe('foo'); 50 | 51 | const indexFile: string = path.resolve(destination, 'index'); 52 | expect(fs.existsSync(indexFile)).toBe(true); 53 | expect(fs.readFileSync(indexFile, 'utf-8')).toMatchSnapshot(); 54 | }); 55 | }); -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/src/test/addManyCustomEngine/plop-templates/index: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | // prettier-ignore 3 | import React from "react"; 4 | 5 | interface ImageProps { 6 | src: string; 7 | } 8 | 9 | const Image = (props: ImageProps): JSX.Element => { 10 | const { src } = props; 11 | return ( 12 | 17 | ); 18 | }; 19 | 20 | export default Image; 21 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/src/test/addManyCustomEngine/plop-templates/pkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "<%= packageName %>", 3 | "version": "1.0.0" 4 | } 5 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/src/test/addManyCustomEngine/plopfile.js: -------------------------------------------------------------------------------- 1 | /* eslint-env es6 */ 2 | const ejs = require("ejs"); 3 | 4 | module.exports = function (plop) { 5 | // A easy way to use custom render engine. 6 | plop.renderString = function (template, data) { 7 | return ejs.render(template, data); 8 | }; 9 | }; 10 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/src/test/addManyRaw/addMany.test.ts: -------------------------------------------------------------------------------- 1 | import path from 'path'; 2 | import fs from 'fs'; 3 | import del from 'del'; 4 | import { preparePlop } from "../utils"; 5 | 6 | import type { NodePlopAPI } from "node-plop"; 7 | 8 | describe('addMany', () => { 9 | let plop: NodePlopAPI; 10 | const destination: string = path.resolve(__dirname, 'output'); 11 | const baseFolder: string = path.resolve(__dirname, 'plop-templates'); 12 | beforeEach(async () => { 13 | await del(destination); 14 | plop = preparePlop(); 15 | }); 16 | it('should add many files', async () => { 17 | const answer = { 18 | packageName: 'foo' 19 | } 20 | plop.setGenerator("testAddMany", { 21 | description: '', 22 | prompts: [], 23 | actions: [ 24 | { 25 | type: "addMany", 26 | force: true, 27 | destination, 28 | base: baseFolder, 29 | templateFiles: [`**/*`, "!init.config.ts", "!init.config.js"], 30 | globOptions: { 31 | cwd: baseFolder, 32 | dot: true, 33 | absolute: true, 34 | }, 35 | data: {}, 36 | }, 37 | ], 38 | }); 39 | 40 | await plop.getGenerator("testAddMany").runActions(answer); 41 | 42 | const destFile: string = path.resolve(destination, 'pkg.json'); 43 | expect(fs.existsSync(destFile)).toBe(true); 44 | let packageJson = {} as any; 45 | expect(() => { 46 | packageJson = JSON.parse(fs.readFileSync(destFile, 'utf-8')) 47 | }).not.toThrow(); 48 | expect(packageJson.name).toBe('foo'); 49 | }); 50 | }); -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/src/test/addManyRaw/plop-templates/pkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "{{ packageName }}", 3 | "version": "1.0.0" 4 | } 5 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/src/test/utils.ts: -------------------------------------------------------------------------------- 1 | import nodePlop, { NodePlopAPI } from "node-plop"; 2 | export const preparePlop = (plopfilePath: string = ''): NodePlopAPI => { 3 | const plop: NodePlopAPI = nodePlop(plopfilePath, {} as any); 4 | return plop 5 | } -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/src/ui/EMIT_EVENTS.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is used to record custom events. 3 | * Do not name events direct in the system. 4 | * Because you might register others's action. 5 | */ 6 | export const CUSTOM_EMIT_EVENTS: Record = { 7 | SUBMIT_ANSWERS: 'submit answers', 8 | UPDATE_LAYOUT: 'update layout' 9 | }; 10 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/src/ui/EventManager.ts: -------------------------------------------------------------------------------- 1 | export const PROCESS_STATUS: Record = { 2 | NULL: -1, 3 | START: 0, 4 | TEMPLATE_SELECTING: 1, 5 | FORM_FILLING: 2, 6 | ACTIONS_INVOKING: 3, 7 | FINISHED: 4 8 | }; 9 | 10 | let currentState: number = PROCESS_STATUS.NULL; 11 | 12 | export const getCurrentState = (): number => { 13 | return currentState; 14 | }; 15 | export const start = (): void => { 16 | currentState = PROCESS_STATUS.TEMPLATE_SELECTING; 17 | }; 18 | export const goNext = (): void => { 19 | switch (currentState) { 20 | case PROCESS_STATUS.NULL: 21 | currentState = PROCESS_STATUS.START; 22 | break; 23 | case PROCESS_STATUS.START: 24 | currentState = PROCESS_STATUS.TEMPLATE_SELECTING; 25 | break; 26 | case PROCESS_STATUS.TEMPLATE_SELECTING: 27 | currentState = PROCESS_STATUS.FORM_FILLING; 28 | break; 29 | case PROCESS_STATUS.FORM_FILLING: 30 | currentState = PROCESS_STATUS.ACTIONS_INVOKING; 31 | break; 32 | case PROCESS_STATUS.ACTIONS_INVOKING: 33 | currentState = PROCESS_STATUS.FINISHED; 34 | break; 35 | default: 36 | currentState = PROCESS_STATUS.NULL; 37 | break; 38 | } 39 | }; 40 | 41 | // const goPrev = () => { 42 | // switch(currentState){ 43 | // case PROCESS_STATUS.FORM_FILLING: 44 | // currentState = PROCESS_STATUS.TEMPLATE_SELECTING; 45 | // break; 46 | // default 47 | // break; 48 | // } 49 | // } 50 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/src/ui/components/BlessedHiddenInputComponent.ts: -------------------------------------------------------------------------------- 1 | import { Widgets } from 'blessed'; 2 | import { BaseValueType } from './BaseFieldComponent'; 3 | import Box from 'blessed/lib/widgets/box'; 4 | 5 | export class BlessedHiddenInputComponent extends Box { 6 | public value: BaseValueType; 7 | public type: string = 'hiddeninput'; 8 | public constructor(opts: Widgets.InputOptions) { 9 | super(opts); 10 | this.value = ''; 11 | } 12 | public setValue(value: BaseValueType): void { 13 | if (!value) { 14 | return; 15 | } 16 | this.value = value; 17 | } 18 | public getValue(): BaseValueType { 19 | return this.value; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/src/ui/components/Warning.ts: -------------------------------------------------------------------------------- 1 | import { box, Widgets } from 'blessed'; 2 | import { COLORS } from '../COLORS'; 3 | 4 | export const Warning = (): { 5 | WarningBox: Widgets.BoxElement; 6 | setWarningContent: (content: string) => void; 7 | } => { 8 | const WarningBox: Widgets.BoxElement = box({ 9 | bottom: 0, 10 | height: 1, 11 | transparent: true, 12 | index: 10, 13 | style: { 14 | fg: COLORS.amber6 15 | } 16 | }); 17 | const setWarningContent = (content: string): void => { 18 | WarningBox.setContent(content); 19 | }; 20 | // list.focus(); 21 | return { WarningBox, setWarningContent }; 22 | }; 23 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/src/ui/components/steps.ts: -------------------------------------------------------------------------------- 1 | import { box, layout, Widgets } from 'blessed'; 2 | import { COLORS } from '../COLORS'; 3 | import { PROCESS_STATUS } from '../EventManager'; 4 | export const Steps = (): { 5 | stepBox: Widgets.LayoutElement; 6 | setStep: (step: number) => void; 7 | } => { 8 | const stepBox: Widgets.LayoutElement = layout({ 9 | layout: 'grid', 10 | top: 0, 11 | shrink: true, 12 | left: 0, 13 | height: 3, 14 | width: '100%' 15 | }); 16 | const stepsKey: number[] = [PROCESS_STATUS.TEMPLATE_SELECTING, PROCESS_STATUS.FORM_FILLING]; 17 | const steps: string[] = ['Template Selection', 'Form Filling']; 18 | const setStep: (step: number) => void = (step: number) => { 19 | while (stepBox.children.length > 0) { 20 | stepBox.children.pop(); 21 | } 22 | stepsKey.forEach((stepKey: number, index) => { 23 | const stepEle: Widgets.BoxElement = box({ 24 | tags: true, 25 | padding: { 26 | top: 1, 27 | right: 2, 28 | left: 2, 29 | bottom: 1 30 | }, 31 | content: `{center}step ${index + 1}: ${steps[index]}{/center}`, 32 | width: '50%', 33 | style: { 34 | bold: stepKey === step, 35 | bg: stepKey === step ? COLORS.blue4 : COLORS.grey0 36 | } 37 | }); 38 | stepBox.append(stepEle); 39 | }); 40 | stepBox.screen.render(); 41 | }; 42 | 43 | return { stepBox, setStep }; 44 | }; 45 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/src/ui/components/templateList.ts: -------------------------------------------------------------------------------- 1 | import { list, Widgets } from 'blessed'; 2 | import { COLORS } from '../COLORS'; 3 | 4 | export const TemplateList = ( 5 | choices: { name: string; value: string }[] 6 | ): { 7 | templateList: Widgets.ListElement; 8 | } => { 9 | const templateList: Widgets.ListElement = list({ 10 | keys: true, 11 | width: '100%', 12 | mouse: true, 13 | style: { 14 | item: { 15 | hover: { 16 | bg: COLORS.grey0 17 | } 18 | }, 19 | selected: { 20 | bg: COLORS.blue4, 21 | bold: true 22 | } 23 | }, 24 | items: choices.map((choice) => choice.name) 25 | }); 26 | 27 | // list.focus(); 28 | return { templateList }; 29 | }; 30 | -------------------------------------------------------------------------------- /rush-plugins/rush-init-project-plugin/typings.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'validate-npm-package-name'; 2 | 3 | declare module 'handlebars-helpers*'; 4 | 5 | declare module 'blessed/lib/widgets/*'; 6 | -------------------------------------------------------------------------------- /rush-plugins/rush-lint-staged-plugin/.eslintrc.js: -------------------------------------------------------------------------------- 1 | // // This is a workaround for https://github.com/eslint/eslint/issues/3458 2 | // require("@rushstack/eslint-config/patch/modern-module-resolution"); 3 | 4 | // module.exports = { 5 | // extends: [ 6 | // "@rushstack/eslint-config/profile/node-trusted-tool", 7 | // "@rushstack/eslint-config/mixins/friendly-locals", 8 | // ], 9 | // parserOptions: { tsconfigRootDir: __dirname }, 10 | // ignorePatterns: ["node_modules/", "lib/"], 11 | // rules: { 12 | // "@typescript-eslint/no-explicit-any": "off", 13 | // }, 14 | // }; 15 | -------------------------------------------------------------------------------- /rush-plugins/rush-lint-staged-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | lib/ -------------------------------------------------------------------------------- /rush-plugins/rush-lint-staged-plugin/.npmignore: -------------------------------------------------------------------------------- 1 | # THIS IS A STANDARD TEMPLATE FOR .npmignore FILES IN THIS REPO. 2 | 3 | # Ignore all files by default, to avoid accidentally publishing unintended files. 4 | * 5 | 6 | # Use negative patterns to bring back the specific things we want to publish. 7 | !/bin/** 8 | !/lib/** 9 | !/lib-*/** 10 | !/dist/** 11 | !ThirdPartyNotice.txt 12 | !/src/** 13 | 14 | # Ignore certain patterns that should not get published. 15 | /dist/*.stats.* 16 | /lib/**/test/ 17 | /lib-*/**/test/ 18 | *.test.js 19 | 20 | # NOTE: These don't need to be specified, because NPM includes them automatically. 21 | # 22 | # package.json 23 | # README (and its variants) 24 | # CHANGELOG (and its variants) 25 | # LICENSE / LICENCE 26 | 27 | #-------------------------------------------- 28 | # DO NOT MODIFY THE TEMPLATE ABOVE THIS LINE 29 | #-------------------------------------------- 30 | 31 | # (Add your project-specific overrides here) 32 | !/includes/** 33 | !rush-plugin-manifest.json 34 | !command-line.json 35 | -------------------------------------------------------------------------------- /rush-plugins/rush-lint-staged-plugin/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log - rush-lint-staged-plugin 2 | 3 | This log was last generated on Wed, 31 Aug 2022 04:09:13 GMT and should not be manually modified. 4 | 5 | ## 0.1.6 6 | Wed, 31 Aug 2022 04:09:13 GMT 7 | 8 | ### Patches 9 | 10 | - Update readme 11 | 12 | ## 0.1.5 13 | Mon, 13 Jun 2022 02:59:04 GMT 14 | 15 | ### Patches 16 | 17 | - Update only 18 | 19 | ## 0.1.4 20 | Mon, 13 Jun 2022 02:56:11 GMT 21 | 22 | ### Patches 23 | 24 | - Exit with code 1 if linting failed 25 | 26 | ## 0.1.3 27 | Tue, 22 Mar 2022 03:26:29 GMT 28 | 29 | ### Patches 30 | 31 | - something change 32 | 33 | ## 0.1.2 34 | Thu, 24 Feb 2022 11:57:31 GMT 35 | 36 | ### Patches 37 | 38 | - Upgrade lint-staged 39 | 40 | ## 0.1.1 41 | Thu, 03 Feb 2022 11:45:46 GMT 42 | 43 | ### Patches 44 | 45 | - Upgrade lint-staged to 12.3.3 46 | 47 | ## 0.1.0 48 | Thu, 03 Feb 2022 11:43:28 GMT 49 | 50 | ### Minor changes 51 | 52 | - Upgrade lint-staged to 12.3.3 with fixing cwd for subtasks 53 | 54 | ## 0.0.1 55 | Wed, 19 Jan 2022 15:06:25 GMT 56 | 57 | ### Patches 58 | 59 | - First implementation 60 | 61 | -------------------------------------------------------------------------------- /rush-plugins/rush-lint-staged-plugin/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) TikTok Pte. Ltd. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /rush-plugins/rush-lint-staged-plugin/README.md: -------------------------------------------------------------------------------- 1 | # rush-lint-staged-plugin 2 | 3 | Rush plugin for lint-staged 4 | 5 | # Prerequisite 6 | 7 | - Rush.js >= 5.57.0 8 | - Node >= 12 9 | 10 | # Quick Start 11 | 12 | 1. Enabling this rush plugin 13 | 14 | Please follow the [official doc](https://rushjs.io/pages/maintainer/using_rush_plugins/) to enable this plugin in your repo. 15 | 16 | 2. Running `lint-staged` 17 | 18 | ``` 19 | rush lint-staged 20 | ``` 21 | 22 | 3. Set up Git `pre-commit` hook 23 | 24 | **common/git-hooks/pre-commit** 25 | 26 | ``` 27 | #!/bin/sh 28 | 29 | node common/scripts/install-run-rush.js lint-staged || exit $? 30 | ``` 31 | 32 | 4. Add a placeholder `lint-staged` config in root path. 33 | 34 | The reason of adding this file is the fact that `lint-staged` behaves differently with the number of config files. With this placeholder config, `lint-staged` will always find multiple config files in your monorepo, which corrects the working directory of each task. 35 | 36 | **/.lintstagedrc.json** 37 | 38 | ``` 39 | { 40 | "*": "echo ok" 41 | } 42 | ``` 43 | 44 | # Rational 45 | 46 | `lint-staged@>=12.2.1` supports a new feature called multiple config files. With this feature, each staged files can load different lint-staged configuration. This plugin invokes `lintStaged` for you. No more no less. 47 | 48 | For example, 49 | 50 | ``` 51 | monorepo-root 52 | ├── scripts 53 | | └── index.js 54 | ├── apps/my-app 55 | | ├── index.js 56 | | └── .lintstagedrc.js 57 | └── libraries/my-lib 58 | ├── index.js 59 | └── .lintstagedrc.js 60 | ``` 61 | 62 | Assuming git staged `apps/my-app/index.js`, `libraries/my-lib/index.js` and `scripts/index.js` 63 | 64 | when `rush lint-staged` runs, 65 | 66 | 1. `apps/my-app/index.js` uses config from `apps/my-app/.lintstagedrc.js` 67 | 2. `libraries/my-lib/index.js` uses config from `libraries/my-lib/.lintstagedrc.js` 68 | 3. `scripts/index.js` has no related config, nothing runs for this file 69 | 70 | # LICENSE 71 | 72 | MIT [@chengcyber](https://github.com/chengcyber) 73 | -------------------------------------------------------------------------------- /rush-plugins/rush-lint-staged-plugin/command-line.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/command-line.schema.json", 3 | "commands": [ 4 | { 5 | "name": "lint-staged", 6 | "commandKind": "global", 7 | "summary": "Rush plugin for lint-staged", 8 | "shellCommand": "node /lib/index.js", 9 | "safeForSimultaneousRushProcesses": true 10 | } 11 | ] 12 | // "parameters": [], 13 | } 14 | -------------------------------------------------------------------------------- /rush-plugins/rush-lint-staged-plugin/config/heft.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/heft/heft.schema.json", 3 | 4 | "eventActions": [ 5 | { 6 | "actionKind": "deleteGlobs", 7 | "heftEvent": "clean", 8 | "actionId": "defaultClean", 9 | "globsToDelete": ["lib"] 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /rush-plugins/rush-lint-staged-plugin/lint-staged.config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-env es6 */ 2 | const config = { 3 | "*.{js,jsx,ts,tsx}": "eslint --fix", 4 | }; 5 | module.exports = config; 6 | -------------------------------------------------------------------------------- /rush-plugins/rush-lint-staged-plugin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rush-lint-staged-plugin", 3 | "version": "0.1.6", 4 | "description": "Rush plugin for lint-staged", 5 | "keywords": [ 6 | "rush", 7 | "plugin", 8 | "command" 9 | ], 10 | "homepage": "https://github.com/bytemate/rush-plugins#readme", 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/bytemate/rush-plugins", 14 | "directory": "rush-plugins/rush-lint-staged-plugin" 15 | }, 16 | "license": "MIT", 17 | "contributors": [ 18 | "Cheng Liu " 19 | ], 20 | "type": "module", 21 | "exports": { 22 | ".": "./lib/index.mjs" 23 | }, 24 | "scripts": { 25 | "build": "heft build --clean --lite", 26 | "build:watch": "heft build --lite --watch", 27 | "prepublishOnly": "npm run build", 28 | "test": "" 29 | }, 30 | "dependencies": { 31 | "@rushstack/node-core-library": "3.44.1", 32 | "lint-staged": "12.3.4" 33 | }, 34 | "devDependencies": { 35 | "@rushstack/eslint-config": "2.4.5", 36 | "@rushstack/heft": "0.43.2", 37 | "@rushstack/heft-node-rig": "1.2.31", 38 | "@types/heft-jest": "1.0.1", 39 | "@types/node": "12.20.24", 40 | "eslint": "7.32.0", 41 | "typescript": "4.4.2" 42 | }, 43 | "engines": { 44 | "node": "^12.20.0 || ^14.13.1 || >=16.0.0" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /rush-plugins/rush-lint-staged-plugin/rush-plugin-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush-plugin-manifest.schema.json", 3 | "plugins": [ 4 | { 5 | "pluginName": "rush-lint-staged-plugin", 6 | "description": "Rush plugin for lint-staged", 7 | "commandLineJsonFilePath": "command-line.json" 8 | } 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /rush-plugins/rush-lint-staged-plugin/src/helpers/terminal.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Terminal, 3 | ConsoleTerminalProvider, 4 | } from "@rushstack/node-core-library"; 5 | 6 | export const terminal: Terminal = new Terminal(new ConsoleTerminalProvider()); 7 | -------------------------------------------------------------------------------- /rush-plugins/rush-lint-staged-plugin/src/index.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import lintStaged from 'lint-staged'; 4 | 5 | // import { terminal } from "./helpers/terminal.mjs"; 6 | 7 | // eslint-disable-next-line @typescript-eslint/no-floating-promises 8 | main(); 9 | 10 | async function main(): Promise { 11 | try { 12 | // https://github.com/okonet/lint-staged/pull/1080 13 | const success = await lintStaged(); 14 | if (!success) process.exit(1); 15 | } catch (error: any) { 16 | if (error.message) { 17 | // terminal.writeErrorLine(error.message); 18 | } else { 19 | throw error; 20 | } 21 | process.exit(1); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /rush-plugins/rush-lint-staged-plugin/src/typings.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'lint-staged'; -------------------------------------------------------------------------------- /rush-plugins/rush-print-log-if-error-plugin/.eslintrc.js: -------------------------------------------------------------------------------- 1 | // This is a workaround for https://github.com/eslint/eslint/issues/3458 2 | require("@rushstack/eslint-config/patch/modern-module-resolution"); 3 | 4 | module.exports = { 5 | extends: [ 6 | "@rushstack/eslint-config/profile/node-trusted-tool", 7 | "@rushstack/eslint-config/mixins/friendly-locals", 8 | ], 9 | parserOptions: { tsconfigRootDir: __dirname }, 10 | ignorePatterns: ["node_modules/", "lib/"], 11 | rules: { 12 | "@typescript-eslint/no-explicit-any": "off", 13 | }, 14 | }; 15 | -------------------------------------------------------------------------------- /rush-plugins/rush-print-log-if-error-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | lib/ -------------------------------------------------------------------------------- /rush-plugins/rush-print-log-if-error-plugin/CHANGELOG.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rush-print-log-if-error-plugin", 3 | "entries": [ 4 | { 5 | "version": "0.0.5", 6 | "tag": "rush-print-log-if-error-plugin_v0.0.5", 7 | "date": "Wed, 31 Aug 2022 04:09:13 GMT", 8 | "comments": { 9 | "patch": [ 10 | { 11 | "comment": "Update readme" 12 | } 13 | ] 14 | } 15 | }, 16 | { 17 | "version": "0.0.4", 18 | "tag": "rush-print-log-if-error-plugin_v0.0.4", 19 | "date": "Thu, 24 Feb 2022 11:57:31 GMT", 20 | "comments": { 21 | "patch": [ 22 | { 23 | "comment": "Upgrade rush-sdk to load rushConfiguration" 24 | } 25 | ] 26 | } 27 | }, 28 | { 29 | "version": "0.0.3", 30 | "tag": "rush-print-log-if-error-plugin_v0.0.3", 31 | "date": "Mon, 10 Jan 2022 06:10:29 GMT", 32 | "comments": { 33 | "patch": [ 34 | { 35 | "comment": "Refactor cat with readline" 36 | } 37 | ] 38 | } 39 | }, 40 | { 41 | "version": "0.0.2", 42 | "tag": "rush-print-log-if-error-plugin_v0.0.2", 43 | "date": "Mon, 10 Jan 2022 04:06:08 GMT", 44 | "comments": { 45 | "patch": [ 46 | { 47 | "comment": "Update readme only" 48 | } 49 | ] 50 | } 51 | }, 52 | { 53 | "version": "0.0.1", 54 | "tag": "rush-print-log-if-error-plugin_v0.0.1", 55 | "date": "Mon, 10 Jan 2022 03:46:23 GMT", 56 | "comments": { 57 | "patch": [ 58 | { 59 | "comment": "Initial implementation" 60 | } 61 | ] 62 | } 63 | } 64 | ] 65 | } 66 | -------------------------------------------------------------------------------- /rush-plugins/rush-print-log-if-error-plugin/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log - rush-print-log-if-error-plugin 2 | 3 | This log was last generated on Wed, 31 Aug 2022 04:09:13 GMT and should not be manually modified. 4 | 5 | ## 0.0.5 6 | Wed, 31 Aug 2022 04:09:13 GMT 7 | 8 | ### Patches 9 | 10 | - Update readme 11 | 12 | ## 0.0.4 13 | Thu, 24 Feb 2022 11:57:31 GMT 14 | 15 | ### Patches 16 | 17 | - Upgrade rush-sdk to load rushConfiguration 18 | 19 | ## 0.0.3 20 | Mon, 10 Jan 2022 06:10:29 GMT 21 | 22 | ### Patches 23 | 24 | - Refactor cat with readline 25 | 26 | ## 0.0.2 27 | Mon, 10 Jan 2022 04:06:08 GMT 28 | 29 | ### Patches 30 | 31 | - Update readme only 32 | 33 | ## 0.0.1 34 | Mon, 10 Jan 2022 03:46:23 GMT 35 | 36 | ### Patches 37 | 38 | - Initial implementation 39 | 40 | -------------------------------------------------------------------------------- /rush-plugins/rush-print-log-if-error-plugin/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) TikTok Pte. Ltd. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /rush-plugins/rush-print-log-if-error-plugin/README.md: -------------------------------------------------------------------------------- 1 | # rush-print-log-if-error-plugin 2 | 3 | Rush plugin for print entire log if error log exists 4 | 5 | # Prerequisite 6 | 7 | Rush.js >= 5.57.0 8 | 9 | # Quick Start 10 | 11 | 1. Enabling this rush plugin 12 | 13 | Please follow the [official doc](https://rushjs.io/pages/maintainer/using_rush_plugins/) to enable this plugin in your repo. 14 | 15 | 2. Print log if error log exists 16 | 17 | ``` 18 | rush print-log-if-error 19 | ``` 20 | 21 | If `.build.error.log` exists, print the content of `.build.log` 22 | 23 | ## Advance Usage 24 | 25 | ```bash 26 | #!/bin/bash 27 | 28 | # logout if error 29 | trap "node common/scripts/install-run-rush.js print-log-if-error" ERR 30 | 31 | node common/scripts/install-run-rush.js build 32 | ``` 33 | 34 | # LICENSE 35 | 36 | MIT [@chengcyber](https://github.com/chengcyber) 37 | -------------------------------------------------------------------------------- /rush-plugins/rush-print-log-if-error-plugin/command-line.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/command-line.schema.json", 3 | "commands": [ 4 | { 5 | "name": "print-log-if-error", 6 | "commandKind": "global", 7 | "summary": "Rush plugin for print entire log if error log exists", 8 | "shellCommand": "node /lib/index.js", 9 | "safeForSimultaneousRushProcesses": true 10 | } 11 | ] 12 | // "parameters": [], 13 | } 14 | -------------------------------------------------------------------------------- /rush-plugins/rush-print-log-if-error-plugin/config/heft.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/heft/heft.schema.json", 3 | 4 | "eventActions": [ 5 | { 6 | "actionKind": "deleteGlobs", 7 | "heftEvent": "clean", 8 | "actionId": "defaultClean", 9 | "globsToDelete": ["lib"] 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /rush-plugins/rush-print-log-if-error-plugin/lint-staged.config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-env es6 */ 2 | const config = { 3 | "*.{js,jsx,ts,tsx}": "eslint --fix", 4 | }; 5 | module.exports = config; 6 | -------------------------------------------------------------------------------- /rush-plugins/rush-print-log-if-error-plugin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rush-print-log-if-error-plugin", 3 | "version": "0.0.5", 4 | "description": "Rush plugin for print entire log if error log exists", 5 | "keywords": [ 6 | "rush", 7 | "plugin", 8 | "command", 9 | "print", 10 | "log" 11 | ], 12 | "homepage": "https://github.com/bytemate/rush-plugins#readme", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/bytemate/rush-plugins", 16 | "directory": "rush-plugins/rush-print-log-if-error-plugin" 17 | }, 18 | "license": "MIT", 19 | "contributors": [ 20 | "Cheng Liu " 21 | ], 22 | "main": "lib/index.js", 23 | "scripts": { 24 | "build": "heft build --clean", 25 | "build:watch": "heft build --watch", 26 | "prepublishOnly": "npm run build", 27 | "test": "heft test" 28 | }, 29 | "dependencies": { 30 | "@rushstack/node-core-library": "3.44.1", 31 | "@rushstack/rush-sdk": "5.62.4" 32 | }, 33 | "devDependencies": { 34 | "@rushstack/eslint-config": "2.4.5", 35 | "@rushstack/heft": "0.43.2", 36 | "@rushstack/heft-node-rig": "1.2.31", 37 | "@types/heft-jest": "1.0.1", 38 | "@types/node": "12.20.24", 39 | "eslint": "7.32.0", 40 | "typescript": "4.4.2" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /rush-plugins/rush-print-log-if-error-plugin/rush-plugin-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush-plugin-manifest.schema.json", 3 | "plugins": [ 4 | { 5 | "pluginName": "rush-print-log-if-error-plugin", 6 | "description": "Rush plugin for print entire log if error log exists", 7 | "commandLineJsonFilePath": "command-line.json" 8 | } 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /rush-plugins/rush-print-log-if-error-plugin/src/helpers/loadRushConfiguration.ts: -------------------------------------------------------------------------------- 1 | import { RushConfiguration } from "@rushstack/rush-sdk"; 2 | 3 | const cwd2RushConfiguration: Record = {}; 4 | 5 | export const loadRushConfiguration = ( 6 | cwd: string = process.cwd() 7 | ): RushConfiguration => { 8 | let rushConfiguration: RushConfiguration = cwd2RushConfiguration[cwd]; 9 | if (!rushConfiguration) { 10 | try { 11 | rushConfiguration = RushConfiguration.loadFromDefaultLocation({ 12 | startingFolder: cwd, 13 | }); 14 | if (!rushConfiguration) { 15 | throw new Error("Rush configuration not found"); 16 | } 17 | cwd2RushConfiguration[cwd] = rushConfiguration; 18 | } catch (e) { 19 | throw new Error("Load rush configuration failed"); 20 | } 21 | } 22 | return rushConfiguration; 23 | }; 24 | -------------------------------------------------------------------------------- /rush-plugins/rush-print-log-if-error-plugin/src/helpers/terminal.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Terminal, 3 | ConsoleTerminalProvider, 4 | } from "@rushstack/node-core-library"; 5 | 6 | export const terminal: Terminal = new Terminal(new ConsoleTerminalProvider()); 7 | -------------------------------------------------------------------------------- /rush-plugins/rush-sort-package-json/.eslintrc.js: -------------------------------------------------------------------------------- 1 | // This is a workaround for https://github.com/eslint/eslint/issues/3458 2 | require("@rushstack/eslint-config/patch/modern-module-resolution"); 3 | 4 | module.exports = { 5 | extends: [ 6 | "@rushstack/eslint-config/profile/node-trusted-tool", 7 | "@rushstack/eslint-config/mixins/friendly-locals", 8 | ], 9 | parserOptions: { tsconfigRootDir: __dirname }, 10 | ignorePatterns: ["node_modules/", "lib/"], 11 | rules: { 12 | "@typescript-eslint/no-explicit-any": "off", 13 | }, 14 | }; 15 | -------------------------------------------------------------------------------- /rush-plugins/rush-sort-package-json/.gitignore: -------------------------------------------------------------------------------- 1 | lib/ -------------------------------------------------------------------------------- /rush-plugins/rush-sort-package-json/CHANGELOG.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rush-sort-package-json", 3 | "entries": [ 4 | { 5 | "version": "0.0.4", 6 | "tag": "rush-sort-package-json_v0.0.4", 7 | "date": "Wed, 31 Aug 2022 04:09:13 GMT", 8 | "comments": { 9 | "patch": [ 10 | { 11 | "comment": "Update readme" 12 | } 13 | ] 14 | } 15 | }, 16 | { 17 | "version": "0.0.3", 18 | "tag": "rush-sort-package-json_v0.0.3", 19 | "date": "Sat, 11 Jun 2022 08:01:34 GMT", 20 | "comments": { 21 | "patch": [ 22 | { 23 | "comment": "Mark as safe for simultaneous processes" 24 | } 25 | ] 26 | } 27 | }, 28 | { 29 | "version": "0.0.2", 30 | "tag": "rush-sort-package-json_v0.0.2", 31 | "date": "Tue, 22 Mar 2022 03:26:29 GMT", 32 | "comments": { 33 | "patch": [ 34 | { 35 | "comment": "init" 36 | } 37 | ] 38 | } 39 | } 40 | ] 41 | } 42 | -------------------------------------------------------------------------------- /rush-plugins/rush-sort-package-json/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log - rush-sort-package-json 2 | 3 | This log was last generated on Wed, 31 Aug 2022 04:09:13 GMT and should not be manually modified. 4 | 5 | ## 0.0.4 6 | Wed, 31 Aug 2022 04:09:13 GMT 7 | 8 | ### Patches 9 | 10 | - Update readme 11 | 12 | ## 0.0.3 13 | Sat, 11 Jun 2022 08:01:34 GMT 14 | 15 | ### Patches 16 | 17 | - Mark as safe for simultaneous processes 18 | 19 | ## 0.0.2 20 | Tue, 22 Mar 2022 03:26:29 GMT 21 | 22 | ### Patches 23 | 24 | - init 25 | 26 | -------------------------------------------------------------------------------- /rush-plugins/rush-sort-package-json/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) TikTok Pte. Ltd. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /rush-plugins/rush-sort-package-json/README.md: -------------------------------------------------------------------------------- 1 | # rush-sort-package-json 2 | 3 | Rush plugin for sort package.json file in the project. 4 | 5 | # Quick Start 6 | 7 | 1. Enabling this rush plugin 8 | 9 | Please follow the [official doc](https://rushjs.io/pages/maintainer/using_rush_plugins/) to enable this plugin in your repo. 10 | 11 | 2. Running `sort-package-json` 12 | 13 | ``` 14 | rush sort-package-json 15 | ``` 16 | 17 | # What is the plugin for? 18 | 19 | We have noticed that: 20 | 21 | 1. There is some feedback about the package.json file under the rush repository being out of order. 22 | 2. `rush add` only puts the added dependencies at the end of the deps field. 23 | 24 | Therefore, this command will sort all package.json files in the rush repository. 25 | 26 | # Q: Why not modify the `rush add` command to keep it in order? 27 | 28 | A: Because many other commands may also change package.json, such as `rush version --bump` or manually modify dependencies. 29 | 30 | # Related issues 31 | 32 | 33 | [rushstack #2496](https://github.com/microsoft/rushstack/issues/2496) 34 | 35 | 36 | # LICENSE 37 | 38 | MIT -------------------------------------------------------------------------------- /rush-plugins/rush-sort-package-json/command-line.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/command-line.schema.json", 3 | "commands": [ 4 | { 5 | "name": "sort-package-json", 6 | "commandKind": "global", 7 | "summary": "Rush plugin for sort package.json file in the project", 8 | "shellCommand": "node /lib/index.js", 9 | "safeForSimultaneousRushProcesses": true 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /rush-plugins/rush-sort-package-json/config/heft.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/heft/heft.schema.json", 3 | 4 | "eventActions": [ 5 | { 6 | "actionKind": "deleteGlobs", 7 | "heftEvent": "clean", 8 | "actionId": "defaultClean", 9 | "globsToDelete": ["lib"] 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /rush-plugins/rush-sort-package-json/lint-staged.config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-env es6 */ 2 | const config = { 3 | "*.{js,jsx,ts,tsx}": "eslint --fix", 4 | }; 5 | module.exports = config; 6 | -------------------------------------------------------------------------------- /rush-plugins/rush-sort-package-json/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rush-sort-package-json", 3 | "version": "0.0.4", 4 | "description": "Rush plugin for sort package.json file in the project", 5 | "keywords": [ 6 | "rush", 7 | "plugin", 8 | "command", 9 | "sort", 10 | "package.json" 11 | ], 12 | "homepage": "https://github.com/bytemate/rush-plugins#readme", 13 | "repository": { 14 | "type": "git", 15 | "url": "https://github.com/bytemate/rush-plugins", 16 | "directory": "rush-plugins/rush-sort-package-json" 17 | }, 18 | "license": "MIT", 19 | "contributors": [ 20 | "bohanzh" 21 | ], 22 | "main": "lib/index.js", 23 | "scripts": { 24 | "build": "heft build --clean", 25 | "build:watch": "heft build --watch", 26 | "prepublishOnly": "npm run build", 27 | "test": "heft test" 28 | }, 29 | "dependencies": { 30 | "@rushstack/node-core-library": "3.44.1", 31 | "@rushstack/rush-sdk": "5.62.4", 32 | "sort-package-json": "1.54.0" 33 | }, 34 | "devDependencies": { 35 | "@rushstack/eslint-config": "2.4.5", 36 | "@rushstack/heft": "0.43.2", 37 | "@rushstack/heft-node-rig": "1.2.31", 38 | "@types/heft-jest": "1.0.1", 39 | "@types/node": "12.20.24", 40 | "eslint": "7.32.0", 41 | "typescript": "4.4.2" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /rush-plugins/rush-sort-package-json/rush-plugin-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush-plugin-manifest.schema.json", 3 | "plugins": [ 4 | { 5 | "pluginName": "rush-sort-package-json", 6 | "description": "Rush plugin for sort package.json file in the project", 7 | "commandLineJsonFilePath": "command-line.json" 8 | } 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /rush-plugins/rush-sort-package-json/src/helpers/loadRushConfiguration.ts: -------------------------------------------------------------------------------- 1 | import { RushConfiguration } from "@rushstack/rush-sdk"; 2 | 3 | const cwd2RushConfiguration: Record = {}; 4 | 5 | export const loadRushConfiguration = ( 6 | cwd: string = process.cwd() 7 | ): RushConfiguration => { 8 | let rushConfiguration: RushConfiguration = cwd2RushConfiguration[cwd]; 9 | if (!rushConfiguration) { 10 | try { 11 | rushConfiguration = RushConfiguration.loadFromDefaultLocation({ 12 | startingFolder: cwd, 13 | }); 14 | if (!rushConfiguration) { 15 | throw new Error("Rush configuration not found"); 16 | } 17 | cwd2RushConfiguration[cwd] = rushConfiguration; 18 | } catch (e) { 19 | throw new Error("Load rush configuration failed"); 20 | } 21 | } 22 | return rushConfiguration; 23 | }; 24 | -------------------------------------------------------------------------------- /rush-plugins/rush-sort-package-json/src/helpers/terminal.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Terminal, 3 | ConsoleTerminalProvider, 4 | } from "@rushstack/node-core-library"; 5 | 6 | export const terminal: Terminal = new Terminal(new ConsoleTerminalProvider()); 7 | -------------------------------------------------------------------------------- /rush-plugins/rush-sort-package-json/src/index.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import path from "path"; 4 | 5 | import { loadRushConfiguration } from "./helpers/loadRushConfiguration"; 6 | import { terminal } from "./helpers/terminal"; 7 | 8 | import type { RushConfiguration } from "@rushstack/rush-sdk"; 9 | import { sortPackageJson } from "./sortPackageJson"; 10 | 11 | // eslint-disable-next-line @typescript-eslint/no-floating-promises 12 | main(); 13 | 14 | async function main(): Promise { 15 | try { 16 | const rushConfig: RushConfiguration = loadRushConfiguration(); 17 | for (const project of rushConfig.projects) { 18 | const packageJsonFilePath: string = path.resolve( 19 | rushConfig.rushJsonFolder, 20 | project.projectFolder 21 | ); 22 | sortPackageJson(packageJsonFilePath); 23 | } 24 | terminal.writeLine('sort package.json successfully'); 25 | } catch (error: any) { 26 | if (error.message) { 27 | terminal.writeErrorLine(error.message); 28 | } else { 29 | throw error; 30 | } 31 | process.exit(1); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /rush-plugins/rush-sort-package-json/src/sortPackageJson.ts: -------------------------------------------------------------------------------- 1 | import path from "path"; 2 | import { FileSystem } from "@rushstack/node-core-library"; 3 | import sort from "sort-package-json"; 4 | 5 | export const sortPackageJson = (projectPath: string): void => { 6 | const packageJsonFilePath: string = path.resolve(projectPath, "package.json"); 7 | if (!FileSystem.exists(packageJsonFilePath)) { 8 | throw new Error(`package.json for ${packageJsonFilePath} does not exist`); 9 | } 10 | const input: string = FileSystem.readFile(packageJsonFilePath); 11 | FileSystem.writeFile(packageJsonFilePath, sort(input)); 12 | }; 13 | -------------------------------------------------------------------------------- /rush-plugins/rush-upgrade-self-plugin/.eslintrc.js: -------------------------------------------------------------------------------- 1 | // This is a workaround for https://github.com/eslint/eslint/issues/3458 2 | require("@rushstack/eslint-config/patch/modern-module-resolution"); 3 | 4 | module.exports = { 5 | extends: [ 6 | "@rushstack/eslint-config/profile/node-trusted-tool", 7 | "@rushstack/eslint-config/mixins/friendly-locals", 8 | ], 9 | parserOptions: { tsconfigRootDir: __dirname }, 10 | ignorePatterns: ["node_modules/", "lib/"], 11 | rules: { 12 | "@typescript-eslint/no-explicit-any": "off", 13 | }, 14 | }; 15 | -------------------------------------------------------------------------------- /rush-plugins/rush-upgrade-self-plugin/.gitignore: -------------------------------------------------------------------------------- 1 | lib/ -------------------------------------------------------------------------------- /rush-plugins/rush-upgrade-self-plugin/.npmignore: -------------------------------------------------------------------------------- 1 | # THIS IS A STANDARD TEMPLATE FOR .npmignore FILES IN THIS REPO. 2 | 3 | # Ignore all files by default, to avoid accidentally publishing unintended files. 4 | * 5 | 6 | # Use negative patterns to bring back the specific things we want to publish. 7 | !/bin/** 8 | !/lib/** 9 | !/lib-*/** 10 | !/dist/** 11 | !ThirdPartyNotice.txt 12 | !/src/** 13 | 14 | # Ignore certain patterns that should not get published. 15 | /dist/*.stats.* 16 | /lib/**/test/ 17 | /lib-*/**/test/ 18 | *.test.js 19 | 20 | # NOTE: These don't need to be specified, because NPM includes them automatically. 21 | # 22 | # package.json 23 | # README (and its variants) 24 | # CHANGELOG (and its variants) 25 | # LICENSE / LICENCE 26 | 27 | #-------------------------------------------- 28 | # DO NOT MODIFY THE TEMPLATE ABOVE THIS LINE 29 | #-------------------------------------------- 30 | 31 | # (Add your project-specific overrides here) 32 | !/includes/** 33 | !rush-plugin-manifest.json 34 | !command-line.json 35 | -------------------------------------------------------------------------------- /rush-plugins/rush-upgrade-self-plugin/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log - rush-upgrade-self-plugin 2 | 3 | This log was last generated on Wed, 31 Aug 2022 04:09:13 GMT and should not be manually modified. 4 | 5 | ## 1.0.7 6 | Wed, 31 Aug 2022 04:09:13 GMT 7 | 8 | ### Patches 9 | 10 | - Update readme 11 | 12 | ## 1.0.6 13 | Thu, 24 Feb 2022 11:57:31 GMT 14 | 15 | ### Patches 16 | 17 | - Upgrade rush-sdk to load rushConfiguration 18 | 19 | ## 1.0.5 20 | Thu, 16 Dec 2021 16:10:36 GMT 21 | 22 | ### Patches 23 | 24 | - Update @rushstack/rush-sdk version as well 25 | 26 | ## 1.0.4 27 | Mon, 13 Dec 2021 00:58:24 GMT 28 | 29 | ### Patches 30 | 31 | - update readme 32 | 33 | ## 1.0.3 34 | Fri, 10 Dec 2021 08:54:01 GMT 35 | 36 | ### Patches 37 | 38 | - update readme only 39 | 40 | ## 1.0.2 41 | Fri, 10 Dec 2021 03:27:48 GMT 42 | 43 | ### Patches 44 | 45 | - pretty log 46 | 47 | ## 1.0.1 48 | Fri, 10 Dec 2021 02:55:26 GMT 49 | 50 | ### Patches 51 | 52 | - fix run rush update 53 | 54 | ## 1.0.0 55 | Thu, 09 Dec 2021 19:50:06 GMT 56 | 57 | ### Breaking changes 58 | 59 | - first formal release 60 | 61 | ### Patches 62 | 63 | - fix update autoinstaller 64 | 65 | ## 0.4.0 66 | Thu, 09 Dec 2021 19:33:35 GMT 67 | 68 | ### Minor changes 69 | 70 | - ignore invalid package.json' 71 | 72 | ## 0.3.0 73 | Thu, 09 Dec 2021 19:08:21 GMT 74 | 75 | ### Minor changes 76 | 77 | - add workaround for rush-sdk 78 | 79 | ## 0.2.0 80 | Thu, 09 Dec 2021 18:03:31 GMT 81 | 82 | ### Minor changes 83 | 84 | - should not ignore command-line.json 85 | 86 | ## 0.1.0 87 | Thu, 09 Dec 2021 17:50:47 GMT 88 | 89 | ### Minor changes 90 | 91 | - initial implementation 92 | 93 | -------------------------------------------------------------------------------- /rush-plugins/rush-upgrade-self-plugin/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) TikTok Pte. Ltd. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /rush-plugins/rush-upgrade-self-plugin/README.md: -------------------------------------------------------------------------------- 1 | # rush-upgrade-self-plugin 2 | 3 | Rush plugin for upgrade Rush.js itself in monorepo. 4 | 5 | # Prerequisite 6 | 7 | Rush.js >= 5.57.0 8 | 9 | # Quick Start 10 | 11 | 1. Enabling this rush plugin 12 | 13 | Please follow the [official doc](https://rushjs.io/pages/maintainer/using_rush_plugins/) to enable this plugin in your repo. 14 | 15 | 2. Upgrade Rush.js 16 | 17 | ``` 18 | rush upgrade-self 19 | ``` 20 | 21 | ## Working process 22 | 23 | 1. Fetch `microsoft/rush` versions by `pacote` 24 | 2. Prompt user to choose a version, which decides the target versions of dependencies should be updated.(Those who prefixes with `@microsoft/` or `@rushstack/`) 25 | 3. Update dependencies(including devDependencies) in all `package.json` files 26 | 4. Update autoinstallers accordingly. 27 | 5. Prompt user whether to run `rush update` 28 | 29 | # Something went wrong? 30 | 31 | - Run `git checkout .` to revert all changes by this plugin. 32 | - This plugin is designed to be idempotent. just run it again! 33 | 34 | # LICENSE 35 | 36 | MIT [@chengcyber](https://github.com/chengcyber) 37 | -------------------------------------------------------------------------------- /rush-plugins/rush-upgrade-self-plugin/command-line.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/command-line.schema.json", 3 | "commands": [ 4 | { 5 | "name": "upgrade-self", 6 | "commandKind": "global", 7 | "summary": "Upgrade Rush.js itself", 8 | "shellCommand": "rush-upgrade-self", 9 | "safeForSimultaneousRushProcesses": true 10 | } 11 | ] 12 | // "parameters": [], 13 | } 14 | -------------------------------------------------------------------------------- /rush-plugins/rush-upgrade-self-plugin/config/heft.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/heft/heft.schema.json", 3 | 4 | "eventActions": [ 5 | { 6 | "actionKind": "deleteGlobs", 7 | "heftEvent": "clean", 8 | "actionId": "defaultClean", 9 | "globsToDelete": ["lib"] 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /rush-plugins/rush-upgrade-self-plugin/lint-staged.config.cjs: -------------------------------------------------------------------------------- 1 | /* eslint-env es6 */ 2 | const config = { 3 | "*.{js,jsx,ts,tsx}": "eslint --fix", 4 | }; 5 | module.exports = config; 6 | -------------------------------------------------------------------------------- /rush-plugins/rush-upgrade-self-plugin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rush-upgrade-self-plugin", 3 | "version": "1.0.7", 4 | "description": "Rush plugin for upgrade rush.js in monorepo", 5 | "keywords": [ 6 | "rush", 7 | "plugin", 8 | "upgrade" 9 | ], 10 | "homepage": "https://github.com/bytemate/rush-plugins#readme", 11 | "bugs": { 12 | "url": "https://github.com/bytemate/rush-plugins/issues" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git+https://github.com/bytemate/rush-plugins.git", 17 | "directory": "rush-plugins/rush-upgrade-self-plugin" 18 | }, 19 | "license": "MIT", 20 | "contributors": [ 21 | "Cheng Liu " 22 | ], 23 | "main": "lib/index.js", 24 | "bin": { 25 | "rush-upgrade-self": "lib/cli.js" 26 | }, 27 | "scripts": { 28 | "build": "heft build --clean", 29 | "build:watch": "heft build --watch", 30 | "prepublishOnly": "npm run build", 31 | "test": "heft test" 32 | }, 33 | "dependencies": { 34 | "@rushstack/node-core-library": "3.44.1", 35 | "@rushstack/rush-sdk": "5.62.4", 36 | "fast-glob": "~3.2.7", 37 | "find-up": "5.0.0", 38 | "inquirer": "~8.2.0", 39 | "ora": "5.4.1", 40 | "pacote": "~12.0.2" 41 | }, 42 | "devDependencies": { 43 | "@rushstack/eslint-config": "2.4.5", 44 | "@rushstack/heft": "0.43.2", 45 | "@rushstack/heft-node-rig": "1.2.31", 46 | "@types/heft-jest": "1.0.1", 47 | "@types/inquirer": "~8.1.3", 48 | "@types/node": "12.20.24", 49 | "@types/pacote": "~11.1.1", 50 | "eslint": "7.32.0", 51 | "typescript": "4.4.2" 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /rush-plugins/rush-upgrade-self-plugin/rush-plugin-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://developer.microsoft.com/json-schemas/rush/v5/rush-plugin-manifest.schema.json", 3 | "plugins": [ 4 | { 5 | "pluginName": "rush-upgrade-self-plugin", 6 | "description": "Rush plugin for upgrade Rush itself", 7 | "commandLineJsonFilePath": "command-line.json" 8 | } 9 | ] 10 | } 11 | -------------------------------------------------------------------------------- /rush-plugins/rush-upgrade-self-plugin/src/cli.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import { upgradeSelf } from "./upgrade-self"; 4 | 5 | // eslint-disable-next-line @typescript-eslint/no-floating-promises 6 | main(); 7 | 8 | async function main(): Promise { 9 | try { 10 | await upgradeSelf(); 11 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 12 | } catch (error: any) { 13 | if (error.message) { 14 | console.log(error.message); 15 | } else { 16 | throw error; 17 | } 18 | process.exit(1); 19 | } 20 | } 21 | --------------------------------------------------------------------------------