Skip to content

Commit 2de3222

Browse files
committed
workflow: adjust release setup
1 parent 960e3e5 commit 2de3222

File tree

4 files changed

+216
-2
lines changed

4 files changed

+216
-2
lines changed

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"@types/jest": "^26.0.19",
2525
"@types/node": "^14.14.10",
2626
"@typescript-eslint/parser": "^4.9.1",
27+
"chalk": "^4.1.0",
2728
"conventional-changelog-cli": "^2.1.1",
2829
"cross-env": "^7.0.3",
2930
"enquirer": "^2.3.6",

Diff for: packages/plugin-vue/CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## [1.0.2](https://github.com/vitejs/vite/compare/[email protected]@1.0.2) (2021-01-02)
2+
3+
4+
### Bug Fixes
5+
6+
* **plugin-vue:** avoid throwing on never requested file ([48a24c1](https://github.com/vitejs/vite/commit/48a24c1fa1f64e89ca853635580911859ef5881b))
7+
* **plugin-vue:** custom block prev handling ([8dbc2b4](https://github.com/vitejs/vite/commit/8dbc2b47dd8fea4a953fb05057edb47122e2dcb7))
8+
* avoid self referencing type in plugin-vue ([9cccdaa](https://github.com/vitejs/vite/commit/9cccdaa0935ca664c8a709a89ebd1f2216565546))
9+
* **plugin-vue:** ensure id on descriptor ([91217f6](https://github.com/vitejs/vite/commit/91217f6d968485303e71128bb79ad4400b9b4412))

Diff for: packages/plugin-vue/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
"build": "rimraf dist && run-s build-bundle build-types",
1313
"build-bundle": "esbuild src/index.ts --bundle --platform=node --target=node12 --external:@vue/compiler-sfc --outfile=dist/index.js",
1414
"build-types": "tsc -p . --emitDeclarationOnly --outDir temp && api-extractor run && rimraf temp",
15-
"prepublishOnly": "yarn build"
15+
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path . --lerna-package plugin-vue",
16+
"release": "node ../../scripts/release.js"
1617
},
1718
"engines": {
1819
"node": ">=12.0.0"
@@ -24,7 +25,7 @@
2425
"bugs": {
2526
"url": "https://github.com/vitejs/vite/issues"
2627
},
27-
"homepage": "https://github.com/vitejs/vite/tree/master/#readme",
28+
"homepage": "https://github.com/vitejs/vite/tree/master/packages/plugin-vue#readme",
2829
"peerDependencies": {
2930
"@vue/compiler-sfc": "^3.0.4"
3031
},

Diff for: scripts/release.js

+203
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
// @ts-check
2+
3+
/**
4+
* modified from https://github.com/vuejs/vue-next/blob/master/scripts/release.js
5+
*/
6+
const execa = require('execa')
7+
const path = require('path')
8+
const fs = require('fs')
9+
const args = require('minimist')(process.argv.slice(2))
10+
const semver = require('semver')
11+
const chalk = require('chalk')
12+
const { prompt } = require('enquirer')
13+
14+
const pkgDir = process.cwd()
15+
const pkgPath = path.resolve(pkgDir, 'package.json')
16+
/**
17+
* @type {{ name: string, version: string }}
18+
*/
19+
const pkg = require(pkgPath)
20+
const pkgName = pkg.name.replace(/^@vitejs\//, '')
21+
const currentVersion = pkg.version
22+
/**
23+
* @type {boolean}
24+
*/
25+
const isDryRun = args.dry
26+
/**
27+
* @type {boolean}
28+
*/
29+
const skipBuild = args.skipBuild
30+
31+
/**
32+
* @type {import('semver').ReleaseType[]}
33+
*/
34+
const versionIncrements = [
35+
'patch',
36+
'minor',
37+
'major',
38+
'prepatch',
39+
'preminor',
40+
'premajor',
41+
'prerelease'
42+
]
43+
44+
/**
45+
* @param {import('semver').ReleaseType} i
46+
*/
47+
const inc = (i) => semver.inc(currentVersion, i)
48+
49+
/**
50+
* @param {string} bin
51+
* @param {string[]} args
52+
* @param {object} opts
53+
*/
54+
const run = (bin, args, opts = {}) =>
55+
execa(bin, args, { stdio: 'inherit', ...opts })
56+
57+
/**
58+
* @param {string} bin
59+
* @param {string[]} args
60+
* @param {object} opts
61+
*/
62+
const dryRun = (bin, args, opts = {}) =>
63+
console.log(chalk.blue(`[dryrun] ${bin} ${args.join(' ')}`), opts)
64+
65+
const runIfNotDry = isDryRun ? dryRun : run
66+
67+
/**
68+
* @param {string} msg
69+
*/
70+
const step = (msg) => console.log(chalk.cyan(msg))
71+
72+
async function main() {
73+
let targetVersion = args._[0]
74+
75+
if (!targetVersion) {
76+
// no explicit version, offer suggestions
77+
/**
78+
* @type {{ release: string }}
79+
*/
80+
const { release } = await prompt({
81+
type: 'select',
82+
name: 'release',
83+
message: 'Select release type',
84+
choices: versionIncrements
85+
.map((i) => `${i} (${inc(i)})`)
86+
.concat(['custom'])
87+
})
88+
89+
if (release === 'custom') {
90+
/**
91+
* @type {{ version: string }}
92+
*/
93+
const res = await prompt({
94+
type: 'input',
95+
name: 'version',
96+
message: 'Input custom version',
97+
initial: currentVersion
98+
})
99+
targetVersion = res.version
100+
} else {
101+
targetVersion = release.match(/\((.*)\)/)[1]
102+
}
103+
}
104+
105+
if (!semver.valid(targetVersion)) {
106+
throw new Error(`invalid target version: ${targetVersion}`)
107+
}
108+
109+
const tag =
110+
pkgName === 'vite' ? `v${targetVersion}` : `${pkgName}@${targetVersion}`
111+
112+
/**
113+
* @type {{ yes: boolean }}
114+
*/
115+
const { yes } = await prompt({
116+
type: 'confirm',
117+
name: 'yes',
118+
message: `Releasing ${tag}. Confirm?`
119+
})
120+
121+
if (!yes) {
122+
return
123+
}
124+
125+
step('\nUpdating package version...')
126+
updateVersion(targetVersion)
127+
128+
step('\nBuilding package...')
129+
if (!skipBuild && !isDryRun) {
130+
await run('yarn', ['build'])
131+
} else {
132+
console.log(`(skipped)`)
133+
}
134+
135+
step('\nGenerating changelog...')
136+
await run('yarn', ['changelog'])
137+
138+
const { stdout } = await run('git', ['diff'], { stdio: 'pipe' })
139+
if (stdout) {
140+
step('\nCommitting changes...')
141+
await runIfNotDry('git', ['add', '-A'])
142+
await runIfNotDry('git', ['commit', '-m', `release: ${tag}`])
143+
} else {
144+
console.log('No changes to commit.')
145+
}
146+
147+
step('\nPublishing package...')
148+
await publishPackage(targetVersion, runIfNotDry)
149+
150+
step('\nPushing to GitHub...')
151+
await runIfNotDry('git', ['tag', tag])
152+
await runIfNotDry('git', ['push', 'origin', `refs/tags/${tag}`])
153+
await runIfNotDry('git', ['push'])
154+
155+
if (isDryRun) {
156+
console.log(`\nDry run finished - run git diff to see package changes.`)
157+
}
158+
159+
console.log()
160+
}
161+
162+
/**
163+
* @param {string} version
164+
*/
165+
function updateVersion(version) {
166+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
167+
pkg.version = version
168+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
169+
}
170+
171+
/**
172+
* @param {string} version
173+
* @param {Function} runIfNotDry
174+
*/
175+
async function publishPackage(version, runIfNotDry) {
176+
const publicArgs = [
177+
'publish',
178+
'--no-git-tag-version',
179+
'--new-version',
180+
version,
181+
'--access',
182+
'public'
183+
]
184+
if (args.tag) {
185+
publicArgs.push(`--tag`, args.tag)
186+
}
187+
try {
188+
await runIfNotDry('yarn', publicArgs, {
189+
stdio: 'pipe'
190+
})
191+
console.log(chalk.green(`Successfully published ${pkgName}@${version}`))
192+
} catch (e) {
193+
if (e.stderr.match(/previously published/)) {
194+
console.log(chalk.red(`Skipping already published: ${pkgName}`))
195+
} else {
196+
throw e
197+
}
198+
}
199+
}
200+
201+
main().catch((err) => {
202+
console.error(err)
203+
})

0 commit comments

Comments
 (0)