Skip to content

Commit 71372c3

Browse files
authored
chore: enhance release script (#1735)
* chore: enhance release script * chore: update release script
1 parent eb33ed6 commit 71372c3

File tree

4 files changed

+133
-35
lines changed

4 files changed

+133
-35
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"test:ssr": "cross-env VUE_ENV=server jasmine JASMINE_CONFIG_PATH=test/unit/jasmine.json",
2727
"test:types": "tsc -p types/test",
2828
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
29-
"release": "bash scripts/release.sh",
29+
"release": "node scripts/release.js",
3030
"docs": "vuepress dev docs",
3131
"docs:build": "vuepress build docs"
3232
},
@@ -61,6 +61,7 @@
6161
"cross-env": "^5.2.0",
6262
"cross-spawn": "^6.0.5",
6363
"css-loader": "^2.1.0",
64+
"enquirer": "^2.3.5",
6465
"eslint": "^6.8.0",
6566
"eslint-plugin-vue-libs": "^4.0.0",
6667
"execa": "^4.0.0",
@@ -71,6 +72,7 @@
7172
"nightwatch-helpers": "^1.2.0",
7273
"rollup": "^2.7.2",
7374
"rollup-plugin-terser": "^5.3.0",
75+
"semver": "^7.3.2",
7476
"todomvc-app-css": "^2.1.0",
7577
"typescript": "^3.8.3",
7678
"vue": "^2.5.22",

scripts/release.js

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
const fs = require('fs')
2+
const path = require('path')
3+
const chalk = require('chalk')
4+
const semver = require('semver')
5+
const { prompt } = require('enquirer')
6+
const execa = require('execa')
7+
const currentVersion = require('../package.json').version
8+
9+
const versionIncrements = [
10+
'patch',
11+
'minor',
12+
'major'
13+
]
14+
15+
const tags = [
16+
'latest',
17+
'next'
18+
]
19+
20+
const inc = (i) => semver.inc(currentVersion, i)
21+
const bin = (name) => path.resolve(__dirname, `../node_modules/.bin/${name}`)
22+
const run = (bin, args, opts = {}) => execa(bin, args, { stdio: 'inherit', ...opts })
23+
const step = (msg) => console.log(chalk.cyan(msg))
24+
25+
async function main() {
26+
let targetVersion
27+
28+
const { release } = await prompt({
29+
type: 'select',
30+
name: 'release',
31+
message: 'Select release type',
32+
choices: versionIncrements.map(i => `${i} (${inc(i)})`).concat(['custom'])
33+
})
34+
35+
if (release === 'custom') {
36+
targetVersion = (await prompt({
37+
type: 'input',
38+
name: 'version',
39+
message: 'Input custom version',
40+
initial: currentVersion
41+
})).version
42+
} else {
43+
targetVersion = release.match(/\((.*)\)/)[1]
44+
}
45+
46+
if (!semver.valid(targetVersion)) {
47+
throw new Error(`Invalid target version: ${targetVersion}`)
48+
}
49+
50+
const { tag } = await prompt({
51+
type: 'select',
52+
name: 'tag',
53+
message: 'Select tag type',
54+
choices: tags
55+
})
56+
57+
console.log(tag)
58+
59+
const { yes } = await prompt({
60+
type: 'confirm',
61+
name: 'yes',
62+
message: `Releasing v${targetVersion} with the "${tag}" tag. Confirm?`
63+
})
64+
65+
if (!yes) {
66+
return
67+
}
68+
69+
// Run tests before release.
70+
step('\nRunning tests...')
71+
await run('yarn', ['test'])
72+
73+
// Update the package version.
74+
step('\nUpdating the package version...')
75+
updatePackage(targetVersion)
76+
77+
// Build the package.
78+
step('\nBuilding the package...')
79+
await run('yarn', ['build'])
80+
81+
// Generate the changelog.
82+
step('\nGenerating the changelog...')
83+
await run('yarn', ['changelog'])
84+
85+
// Commit changes to the Git.
86+
step('\nCommitting changes...')
87+
await run('git', ['add', '-A'])
88+
await run('git', ['commit', '-m', `release: v${targetVersion}`])
89+
90+
// Publish the package.
91+
step('\nPublishing the package...')
92+
await run ('yarn', [
93+
'publish', '--tag', tag, '--new-version', targetVersion, '--no-commit-hooks',
94+
'--no-git-tag-version'
95+
])
96+
97+
// Push to GitHub.
98+
step('\nPushing to GitHub...')
99+
await run('git', ['tag', `v${targetVersion}`])
100+
await run('git', ['push', 'origin', `refs/tags/v${targetVersion}`])
101+
await run('git', ['push'])
102+
}
103+
104+
function updatePackage(version) {
105+
const pkgPath = path.resolve(path.resolve(__dirname, '..'), 'package.json')
106+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
107+
108+
pkg.version = version
109+
110+
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
111+
}
112+
113+
main().catch((err) => console.error(err))

scripts/release.sh

Lines changed: 0 additions & 34 deletions
This file was deleted.

yarn.lock

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,6 +1531,11 @@ [email protected], ansi-colors@^3.0.0:
15311531
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-3.2.3.tgz#57d35b8686e851e2cc04c403f1c00203976a1813"
15321532
integrity sha512-LEHHyuhlPY3TmuUYMh2oz89lTShfvgbmzaBcxve9t/9Wuy7Dwf4yoAKcND7KFT1HAQfqZ12qtc+DUrBMeKF9nw==
15331533

1534+
ansi-colors@^3.2.1:
1535+
version "3.2.4"
1536+
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-3.2.4.tgz#e3a3da4bfbae6c86a9c285625de124a234026fbf"
1537+
integrity sha512-hHUXGagefjN2iRrID63xckIvotOXOojhQKWIPUZ4mNUZ9nLZW+7FMNoE1lOkEhNWYsx/7ysGIuJYCiMAA9FnrA==
1538+
15341539
ansi-escapes@^3.0.0:
15351540
version "3.1.0"
15361541
resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.1.0.tgz#f73207bb81207d75fd6c83f125af26eea378ca30"
@@ -4310,6 +4315,13 @@ enhanced-resolve@^4.1.0:
43104315
memory-fs "^0.4.0"
43114316
tapable "^1.0.0"
43124317

4318+
enquirer@^2.3.5:
4319+
version "2.3.5"
4320+
resolved "https://registry.yarnpkg.com/enquirer/-/enquirer-2.3.5.tgz#3ab2b838df0a9d8ab9e7dff235b0e8712ef92381"
4321+
integrity sha512-BNT1C08P9XD0vNg3J475yIUG+mVdp9T6towYFHUv897X0KoHBjB1shyrNmhmtHWKP17iSWgo7Gqh7BBuzLZMSA==
4322+
dependencies:
4323+
ansi-colors "^3.2.1"
4324+
43134325
entities@~1.1.1:
43144326
version "1.1.2"
43154327
resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.2.tgz#bdfa735299664dfafd34529ed4f8522a275fea56"
@@ -9656,6 +9668,11 @@ semver@^6.0.0, semver@^6.1.2, semver@^6.3.0:
96569668
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
96579669
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==
96589670

9671+
semver@^7.3.2:
9672+
version "7.3.2"
9673+
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.2.tgz#604962b052b81ed0786aae84389ffba70ffd3938"
9674+
integrity sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==
9675+
96599676
96609677
version "0.17.1"
96619678
resolved "https://registry.yarnpkg.com/send/-/send-0.17.1.tgz#c1d8b059f7900f7466dd4938bdc44e11ddb376c8"

0 commit comments

Comments
 (0)