Skip to content

Commit

Permalink
workflow: optimize scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
cloydlau committed Dec 17, 2023
1 parent f8f5368 commit 946d2d2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"build": "vite build",
"serve": "vite preview",
"release": "esno ./scripts/release.mts",
"pnpm:devPreinstall": "node ./scripts/devPreinstall.js",
"pnpm:devPreinstall": "node -e \"if (process.env.INIT_CWD === process.cwd()) { process.exit(1) }\" || node ./scripts/devPreinstall.mjs",
"preinstall": "node -e \"if (process.env.INIT_CWD === process.cwd()) { process.exit(1) }\" || npx only-allow pnpm",
"postinstall": "node -e \"if (process.env.INIT_CWD === process.cwd()) { process.exit(1) }\" || npx simple-git-hooks"
},
Expand Down Expand Up @@ -134,4 +134,4 @@
],
"{scripts,src}": "eslint --cache --fix"
}
}
}
6 changes: 3 additions & 3 deletions scripts/dev.mts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ async function dev() {
await installDependencies()
}

spawn.sync('npx', ['vite', '--open'], { stdio: 'inherit' })
spawn.sync('npx', ['vite', '--open', '--force'], { stdio: 'inherit' })

async function installDependencies() {
if (['darwin', 'linux'].includes(process.platform)) {
Expand Down Expand Up @@ -202,8 +202,8 @@ async function dev() {
} */
console.log(cyan('Setting registry...'))
spawn.sync('pnpm', ['config', 'set', 'registry', 'https://registry.npmmirror.com'], { stdio: 'inherit' })
console.log(cyan('Installing node lts...'))
spawn.sync('pnpm', ['env', 'use', '-g', 'lts'], { stdio: 'inherit' })
// console.log(cyan('Installing node lts...'))
// spawn.sync('pnpm', ['env', 'use', '-g', 'lts'], { stdio: 'inherit' })
console.log(cyan('Installing global packages...'))
spawn('pnpm', ['add', 'cnpm', '@antfu/ni', '-g'], { stdio: 'inherit' })
console.log(cyan('Deleting ./node_modules...'))
Expand Down
2 changes: 1 addition & 1 deletion scripts/devPreinstall.js → scripts/devPreinstall.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require('node:fs')
import fs from 'node:fs'

function devPreinstall() {
// 安装依赖前,将 devDependencies 的版本号替换为 latest
Expand Down
23 changes: 8 additions & 15 deletions scripts/release.mts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ async function release() {
return
}

console.log(cyan('Upgrading dependencies...'))
if (spawn.sync('pnpm', ['up'], { stdio: 'inherit' }).status === 1) {
return
}

console.log(cyan('Linting staged...'))
if (spawn.sync('npx', ['lint-staged'], { stdio: 'inherit' }).status === 1) {
return
Expand All @@ -37,8 +32,6 @@ async function release() {
return
}

open('./stats.html')

console.log(cyan('Packing...'))
if (spawn.sync('npm', ['pack'], { stdio: 'inherit' }).status === 1) {
return
Expand Down Expand Up @@ -121,14 +114,6 @@ async function release() {
pkg.version = targetVersion
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2))

console.log(cyan('Publishing...'))
if (spawn.sync('npm', ['publish', '--registry=https://registry.npmjs.org'], { stdio: 'inherit' }).status === 1) {
// 恢复版本号
pkg.version = currentVersion
fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2))
return
}

console.log(cyan('Committing...'))
if (spawn.sync('git', ['add', '-A'], { stdio: 'inherit' }).status === 1) {
return
Expand All @@ -148,6 +133,14 @@ async function release() {
return
}

console.log(cyan('Publishing...'))
if (spawn.sync('npm', ['publish', '--registry=https://registry.npmjs.org'], { stdio: 'inherit' }).status === 1) {
// 恢复版本号
// pkg.version = currentVersion
// fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2))
return
}

console.log(cyan('Updating npmmirror...'))
spawn.sync('cnpm', ['sync'], { stdio: 'inherit' })
open(`https://npmmirror.com/sync/${name}`)
Expand Down

0 comments on commit 946d2d2

Please sign in to comment.