Skip to content

Commit

Permalink
chore: add release script
Browse files Browse the repository at this point in the history
  • Loading branch information
Hufe921 committed Mar 24, 2023
1 parent 622ef7e commit caa2c34
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 23 additions & 0 deletions scripts/release.js
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit caa2c34

Please sign in to comment.