diff --git a/CHANGELOG.md b/CHANGELOG.md index e9ac656..19bb63d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # CHANGELOG +## v0.0.12 + +* Update the confusing attributes `ifShortSHA` and `ifGitSHA`. If you want to enable `ifShortSHA`, you do not need to configure `ifGitSHA` to be `true`. (by [@littlecxm](https://github.com/ZhongxuYang/vite-plugin-version-mark/issues/8)) +* The default value of `ifShortSHA` is changed to `false`. + ## v0.0.11 * Support export version field in the entry file. diff --git a/README.md b/README.md index 99272bc..cd0b89b 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ export default defineConfig({ // name: 'test-app', // version: '0.0.1', // command: 'git describe --tags', - ifGitSHA: true, + // ifGitSHA: true, ifShortSHA: true, ifMeta: true, ifLog: true, @@ -69,7 +69,7 @@ export default defineNuxtConfig({ // name: 'test-app', // version: '0.0.1', // command: 'git describe --tags', - ifGitSHA: true, + // ifGitSHA: true, ifShortSHA: true, ifMeta: true, ifLog: true, @@ -85,18 +85,19 @@ Then you can use `vite-plugin-version-mark` ! 🎉 > `vite-plugin-version-mark` can be print application version in the `Console`, defined `global` or add `` in HTML element. -| name | description | type | default | supported | +| Name | Description | Type | Default | Supported | | --- | --- | --- | --- | --- | | name | application name | `string` | `name` in package.json | `0.0.1+` | | version | application version | `string` | `version` in package.json | `0.0.1+` | | ifGitSHA | use git commit SHA as the version | `boolean` | false | `0.0.1+` | -| ifShortSHA | use git commit short SHA as the version | `boolean` | true | `0.0.1+` | +| ifShortSHA | use git commit short SHA as the version | `boolean` | false | `0.0.1+` | | command | provide a custom command to retrieve the version
For example: `git describe --tags` | `string` | git rev-parse --short HEAD | `0.0.8+` | | ifLog | print info in the Console | `boolean` | true | `0.0.1+` | | ifGlobal | set a variable named *\`\_\_${APPNAME}\_VERSION\_\_\`* in the window
[For TypeScript users, make sure to add the type declarations in the env.d.ts or vite-env.d.ts file to get type checks and Intellisense.](https://vitejs.dev/config/shared-options.html#define) | `boolean` | true | `0.0.4+` | | ifMeta | add \ in the \ | `boolean` | true | `0.0.1+` | | ifExport | export the version field in the entry file. This may be used when you use vite to build a `library mode`.
Through `import { {APPNAME}_VERSION } from ` | `boolean` | false | `0.0.11+` | +> The **version field** takes precedence: `command` > `ifShortSHA` > `ifGitSHA` > `version` ## Other diff --git a/README_ZH.md b/README_ZH.md index 80d5c68..8d8603b 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -91,7 +91,7 @@ export default defineNuxtConfig({ | name | 应用名 | `string` | 在 `package.json` 中定义的 `name` 属性 | `0.0.1+` | | version | 应用版本 | `string` | 在 `package.json` 中定义的 `version` 属性 | `0.0.1+` | | ifGitSHA | 使用git commitSHA作为版本号 | `boolean` | false | `0.0.1+` | -| ifShortSHA | 使用git的短commitSHA作为版本号 | `boolean` | true | `0.0.1+` | +| ifShortSHA | 使用git的短commitSHA作为版本号 | `boolean` | false | `0.0.1+` | | command | 提供自定义指令,以便自定义版本号的获取方式
例如使用git tag作为版本号: `git describe --tags` | `string` | git rev-parse --short HEAD | `0.0.8+` | | ifLog | 在控制台打印版本信息 | `boolean` | true | `0.0.1+` | | ifGlobal | 在window上定义变量 *\`\_\_${APPNAME}\_VERSION\_\_\`*
[对于TypeScript使用者, 请确保您在 env.d.ts 或者 vite-env.d.ts 文件中定义该变量,以便通过类型检查。](https://vitejs.dev/config/shared-options.html#define) | `boolean` | true | `0.0.4+` | @@ -99,6 +99,8 @@ export default defineNuxtConfig({ | ifExport | 在入口文件导出版本字段。这在您使用vite构建 `library mode`时或许会用到。
通过 `import { {APPNAME}_VERSION} from ` | `boolean` | false | `0.0.11+` | +> **版本字段**的取值优先级为: `command` > `ifShortSHA` > `ifGitSHA` > `version` + ## 其它 ### 如何在您的vite插件中获取版本号? diff --git a/playground/vite-webapp/vite.config.ts b/playground/vite-webapp/vite.config.ts index b23443f..3e26575 100644 --- a/playground/vite-webapp/vite.config.ts +++ b/playground/vite-webapp/vite.config.ts @@ -14,14 +14,14 @@ const testPlugin: () => Plugin = () => ({ export default defineConfig({ plugins: [ vue(), - vitePluginVersionMark({ - ifGitSHA: true, - ifShortSHA: true, + vitePluginVersionMark({ + // ifGitSHA: true, + ifShortSHA: true, + // command: 'git describe --tags', ifMeta: true, ifLog: true, ifGlobal: true, ifExport: true, - // command: 'git describe --tags' }), testPlugin(), ], diff --git a/src/plugins/core/main.ts b/src/plugins/core/main.ts index c7663e4..0730cc9 100644 --- a/src/plugins/core/main.ts +++ b/src/plugins/core/main.ts @@ -28,19 +28,11 @@ export type VitePluginVersionMarkConfig = { printInfo: string } -const getGitSHA = (ifShortSHA: boolean, command: string | undefined) => { +const execCommand = (command: string) => { const {exec} = childProcess - let sh: string - if (command) { - sh = command - } else if (ifShortSHA) { - sh = 'git rev-parse --short HEAD' - } else { - sh = 'git rev-parse HEAD' - } return new Promise((resolve, reject) => { - exec(sh, (error, stdout) => { + exec(command, (error, stdout) => { if (error) { reject(error) } else { @@ -55,16 +47,16 @@ export const analyticOptions: (options: VitePluginVersionMarkInput) => Promise