Skip to content

Commit

Permalink
chore: 优化发布脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
renzp94 committed Sep 22, 2023
1 parent c321507 commit 314787f
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions scripts/publish.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,22 @@ import { spinner } from 'zx/experimental'
// 是否重新发布,用于打包及版本更新后发布时出错后使用
const isRepublish = argv.r

let packageName = "packages"
const packageList = await fs.readdir("./packages")
const packageNames = packageList.filter(item => !item.includes('.')).map(item => chalk.blue(item)).toString()

let packageName
do {
packageName = await question(
`可用包名: ${packageNames},请输入包名: `
)
if (!packageList.includes(packageName)) {
echo(chalk.yellow(`当前输入的包名错误:${packageName}`))
}
} while (!packageList.includes(packageName))


// 移动到包目录
cd(`./${packageName}`)
cd(`./packages/${packageName}`)

const pkg = await fs.readJson('./package.json')
let version
Expand All @@ -16,7 +27,7 @@ if(!isRepublish){
const updateTypes = ['patch', 'minor', 'major']
do {
if (version) {
echo(chalk.yellow(`当前输入的update_type错误${version}`))
echo(chalk.yellow(`当前输入的update_type错误: ${version}`))
}
version = await question(
`当前版本:${chalk.blue(pkg.version)},请输入更新版本的<update_type>(${chalk.blue(
Expand All @@ -41,9 +52,9 @@ try {
const publishFlags = ['--access=public', '--no-git-checks']
// 发布
await spinner(chalk.blue('发布中...'), () => $`pnpm publish ${publishFlags}`)
echo(`✨ ${chalk.blue(`${pkg.name} ${chalk.bold(version)}`)}发布成功`)
echo(`✨ ${chalk.blue(`${pkg.name} ${chalk.bold(version)}`)} 发布成功`)
// 提交
cd('../')
await $`git add ./${packageName}`
cd('../../')
await $`git add ./packages/${packageName}`
await $`git commit -m "chore(${packageName}): publish ${version}"`

0 comments on commit 314787f

Please sign in to comment.