Skip to content

Commit

Permalink
feat: 新增命令行更新 package.json 版本号
Browse files Browse the repository at this point in the history
  • Loading branch information
李金文 committed Jul 14, 2023
1 parent f522448 commit a63adf0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
5 changes: 4 additions & 1 deletion README1.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,7 @@ Instead change the require of index.js in E:\toolkit-use\node_modules\cliui\buil
at buildArgv (E:\toolkit-use\node_modules\jest-cli\build\cli\index.js:177:20)
at Object.run (E:\toolkit-use\node_modules\jest-cli\build\cli\index.js:147:18)
at Object.<anonymous> (E:\toolkit-use\node_modules\jest-cli\bin\jest.js:16:17)
at Object.<anonymous> (E:\toolkit-use\node_modules\jest\bin\jest.js:12:3)
at Object.<anonymous> (E:\toolkit-use\node_modules\jest\bin\jest.js:12:3)


https://juejin.cn/post/7220164534316433467
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "toolkit-use",
"version": "0.0.15",
"version": "0.0.16",
"description": "a npm toolkit use for vue.js and react",
"main": "dist/index.umd.js",
"types": "types/index.d.ts",
Expand Down Expand Up @@ -34,7 +34,8 @@
"fix:src": "npx eslint src --fix --ext .ts",
"fix:test": "npx eslint test --fix --ext .js",
"lint": "npm run fix:src && npm run fix:test",
"commit": "git-cz"
"commit": "git-cz",
"update:version": "node ./scripts/update-version.js"
},
"author": "kennana",
"license": "MIT",
Expand Down Expand Up @@ -75,4 +76,4 @@
"crypto-js": "^4.1.1",
"rimraf": "^4"
}
}
}
19 changes: 19 additions & 0 deletions scripts/update-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const path = require('path')
const fs = require('fs')
const newVersion = process.argv[2].replace('/^v/', '')
if(!newVersion) {
console.log('请传入新版本号,版本号遵循semver规范 .eg: 1.0.0, 1.0.1, 1.1.0')
process.exit(1)
}

// 获取当前命令行上下文路径
const currentDirectory = process.cwd()
const packageJsonPath = path.join(currentDirectory, 'package.json')
const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf8')
const packageJson = JSON.parse(packageJsonContent)
const currentVersion = packageJson.version

// 更新 package.json 文件中的版本号
packageJson.version = newVersion
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2))
console.log(`版本号已从 ${currentVersion} 更新为 ${newVersion}`)

0 comments on commit a63adf0

Please sign in to comment.