-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5aae782
commit 8c13df2
Showing
6 changed files
with
76 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,33 @@ | ||
const shell = require('shelljs') | ||
const pkg = require('../package.json') | ||
const generateVersion = require("./utils").generateVersion | ||
const updatedVersion = require("./updatedVersion").updatedVersion | ||
|
||
// 先获取下个 版本号 | ||
const nextVersion = generateVersion(pkg.version) | ||
|
||
let gitAddMsg = shell.exec('git add .') | ||
if (gitAddMsg.code !== 0) { | ||
console.error(gitAddMsg.stderr) | ||
} | ||
|
||
let gitCommitMsg = shell.exec(`git commit -m "chore(release): ${pkg.version}"`) | ||
// 更新项目的版本号 | ||
updatedVersion(pkg.version) | ||
|
||
// 提交代码 | ||
let gitCommitMsg = shell.exec(`git commit -m "chore(release): ${nextVersion}"`) | ||
if (gitCommitMsg.code !== 0) { | ||
console.error(gitCommitMsg.stderr) | ||
} | ||
|
||
// 添加git tag | ||
let gitTagMsg = shell.exec(`git tag ${'v' + nextVersion}`) | ||
if (gitTagMsg.code !== 0) { | ||
console.error(gitTagMsg.stderr) | ||
} | ||
|
||
// 推送到远程仓库 | ||
let gitPushMsg = shell.exec('git push --follow-tags origin master') | ||
if (gitPushMsg.code !== 0) { | ||
console.error(gitPushMsg.stderr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const generateVersion = require("./utils").generateVersion | ||
const fs = require("fs"); | ||
|
||
function updatedVersion(version) { | ||
let newVersion = generateVersion(version); | ||
const packageJson = JSON.parse(fs.readFileSync("package.json", "utf8")); | ||
const packageLockJson = JSON.parse(fs.readFileSync("package-lock.json", "utf8")); | ||
|
||
packageJson.version = newVersion; | ||
packageLockJson.version = newVersion; | ||
packageLockJson.packages[""].version = newVersion; | ||
|
||
fs.writeFileSync("package.json", JSON.stringify(packageJson, null, 2) + '\n'); | ||
fs.writeFileSync("package-lock.json", JSON.stringify(packageLockJson, null, 2) + '\n'); | ||
|
||
} | ||
|
||
module.exports = { | ||
updatedVersion, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const pkg = require("../package.json"); | ||
|
||
function generateVersion(version = pkg.version) { | ||
let maxTag = 9 | ||
let versionA = version.split("."); | ||
let [major, minor, patch] = versionA; | ||
if (Number(patch) !== maxTag) { | ||
patch = parseInt(patch) + 1; | ||
return `${major}.${minor}.${patch}`; | ||
} | ||
if (Number(patch) === maxTag) { | ||
patch = "0"; | ||
minor = parseInt(minor) + 1; | ||
} | ||
if ((Number(patch) === 0 && Number(minor) === (maxTag + 1)) || Number(minor) === maxTag) { | ||
minor = "0"; | ||
major = parseInt(major) + 1; | ||
} | ||
return `${major}.${minor}.${patch}`; | ||
} | ||
|
||
module.exports = { | ||
generateVersion, | ||
}; |