|
@@ -8,10 +8,28 @@ import { readFileSync, writeFileSync } from 'fs'
|
|
const packageFile = './package.json'
|
|
const packageFile = './package.json'
|
|
const versionFile = './public/version.json'
|
|
const versionFile = './public/version.json'
|
|
|
|
|
|
|
|
+// 获取执行的参数
|
|
|
|
+const args = process.argv.slice(2)
|
|
|
|
+// console.log(args)
|
|
|
|
+switch (args[0]) {
|
|
|
|
+ case '--patch':
|
|
|
|
+ autoTagVersion('patch')
|
|
|
|
+ break
|
|
|
|
+ case '--minor':
|
|
|
|
+ autoTagVersion('minor')
|
|
|
|
+ break
|
|
|
|
+ case '--major':
|
|
|
|
+ autoTagVersion('major')
|
|
|
|
+ break
|
|
|
|
+ default:
|
|
|
|
+ autoTagVersion('patch')
|
|
|
|
+ break
|
|
|
|
+}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 自动打标签
|
|
* 自动打标签
|
|
*/
|
|
*/
|
|
-autoTagVersion()
|
|
|
|
|
|
+// autoTagVersion()
|
|
/**
|
|
/**
|
|
* 撤销标签
|
|
* 撤销标签
|
|
*/
|
|
*/
|
|
@@ -59,10 +77,10 @@ function getLatestVersion() {
|
|
* @param {*} latestVersion
|
|
* @param {*} latestVersion
|
|
* @returns
|
|
* @returns
|
|
*/
|
|
*/
|
|
-function suggestNextVersion(latestVersion) {
|
|
|
|
|
|
+function suggestNextVersion(latestVersion, type = 'patch') {
|
|
const cleanVersion = semver.clean(latestVersion)
|
|
const cleanVersion = semver.clean(latestVersion)
|
|
if (cleanVersion) {
|
|
if (cleanVersion) {
|
|
- return semver.inc(cleanVersion, 'patch') // 或者 'minor' 或者 'major' 根据需要
|
|
|
|
|
|
+ return semver.inc(cleanVersion, type) // 或者 'minor' 或者 'major' 根据需要
|
|
}
|
|
}
|
|
return '1.0.0'
|
|
return '1.0.0'
|
|
}
|
|
}
|
|
@@ -96,9 +114,9 @@ function revertTag(version) {
|
|
}
|
|
}
|
|
|
|
|
|
// 主函数
|
|
// 主函数
|
|
-function autoTagVersion() {
|
|
|
|
|
|
+function autoTagVersion(type = 'patch') {
|
|
getLatestVersion().then((latestVersion) => {
|
|
getLatestVersion().then((latestVersion) => {
|
|
- const nextVersion = 'v' + suggestNextVersion(latestVersion)
|
|
|
|
|
|
+ const nextVersion = 'v' + suggestNextVersion(latestVersion, type)
|
|
const content = readFileSync(packageFile, 'utf-8')
|
|
const content = readFileSync(packageFile, 'utf-8')
|
|
const packageInfo = JSON.parse(content)
|
|
const packageInfo = JSON.parse(content)
|
|
packageInfo['version'] = nextVersion
|
|
packageInfo['version'] = nextVersion
|