├── .fatherrc.js ├── .github └── workflows │ └── publish.yml ├── .gitignore ├── .prettierrc ├── LICENSE ├── README.md ├── example ├── .umirc.js ├── package.json ├── pages │ └── index.js └── tsconfig.json ├── package.json └── src └── index.js /.fatherrc.js: -------------------------------------------------------------------------------- 1 | 2 | export default { 3 | target: 'node', 4 | cjs: 'babel', 5 | }; 6 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: npm-publish 2 | 3 | on: 4 | push: 5 | branches: [main] 6 | 7 | jobs: 8 | publish: 9 | runs-on: ubuntu-latest 10 | 11 | name: 'publish npm' 12 | 13 | environment: npm 14 | 15 | steps: 16 | - uses: actions/checkout@main 17 | 18 | - name: Install and Build 19 | run: | 20 | npm install 21 | npm run build 22 | 23 | - name: 'Publish to the npm registry' 24 | uses: primer/publish@3.0.0 25 | env: 26 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 27 | NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }} # 跟前面步骤中的 NPM_AUTH_TOKEN 保持一致 28 | with: 29 | default_branch: 'main' -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /yarn.lock 3 | /package-lock.json 4 | /example/dist 5 | /example/node_modules 6 | /example/pages/.umi 7 | /example/pages/.umi-production 8 | /lib 9 | example/yarn.lock 10 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all", 4 | "semi": false, 5 | "printWidth": 100, 6 | "overrides": [ 7 | { 8 | "files": ".prettierrc", 9 | "options": { "parser": "json" } 10 | } 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 shawerestart 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # umi-plugin-git-version 2 | 3 | [](https://npmjs.org/package/umi-plugin-git-version) 4 | [](https://npmjs.org/package/umi-plugin-git-version) 5 | 6 | 此功能基于 [git-revision-webpack-plugin](https://github.com/pirelenito/git-revision-webpack-plugin)封装 7 | 8 | ## 使用方法 9 | 10 | 1. 安装 11 | 12 | ```bash 13 | npm install umi-plugin-git-version --save 14 | # or 15 | yarn add umi-plugin-git-version 16 | ``` 17 | 18 | 2. 使用 19 | 20 | 在umi@4中使用 21 | 22 | ```javascript 23 | // .umirc.js 或者 .umirc.ts 24 | // 添加 25 | export default { 26 | plugins: ['umi-plugin-git-version'], 27 | } 28 | ``` 29 | 在umi@3中使用 30 | 31 | ```javascript 32 | // do nothing, umi@3 will scan your node_modules and add to plugins 33 | ``` 34 | 35 | 3. 在页面中使用变量 36 | 37 | ```javascript 38 | __VERSION__: 当前版本号 39 | __COMMIT_HASH__: 当前提交hash值 40 | __BRANCH__: 当前提交分支 41 | __LAST_COMMIT_DATETIME__: 最后提交时间 42 | ``` 43 | 44 | ## LICENSE 45 | 46 | MIT 47 | -------------------------------------------------------------------------------- /example/.umirc.js: -------------------------------------------------------------------------------- 1 | export default { 2 | plugins: [ 3 | 'umi-plugin-git-version' 4 | ], 5 | } 6 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": ".umirc.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "MIT", 12 | "dependencies": { 13 | "umi-plugin-git-version": "^0.0.1" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /example/pages/index.js: -------------------------------------------------------------------------------- 1 | import { useState } from 'react' 2 | 3 | const index = () => { 4 | return ( 5 |