chore: add release script

This commit is contained in:
Hufe921
2023-03-24 22:49:49 +08:00
parent 622ef7e648
commit caa2c3463d
2 changed files with 25 additions and 1 deletions
+2 -1
View File
@@ -45,7 +45,8 @@
"docs:dev": "vitepress dev docs",
"docs:build": "vitepress build docs",
"docs:preview": "vitepress preview docs",
"postinstall": "simple-git-hooks"
"postinstall": "simple-git-hooks",
"release": "node scripts/release.js"
},
"devDependencies": {
"@rollup/plugin-typescript": "^10.0.1",
+23
View File
@@ -0,0 +1,23 @@
import { execSync } from 'child_process'
import fs from 'fs'
import path from 'path'
const pkgPath = path.resolve('package.json')
// 缓存项目package.json
const sourcePkg = fs.readFileSync(pkgPath, 'utf-8')
// 删除无用属性
const targetPkg = JSON.parse(sourcePkg)
Reflect.deleteProperty(targetPkg.scripts, 'postinstall')
fs.writeFileSync(pkgPath, JSON.stringify(targetPkg, null, 2))
// 发布包
try {
execSync('npm publish')
} catch (error) {
throw new Error(error)
} finally {
// 还原
fs.writeFileSync(pkgPath, sourcePkg)
}