Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: enhance release script #1735

Merged
merged 2 commits into from May 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -26,7 +26,7 @@
"test:ssr": "cross-env VUE_ENV=server jasmine JASMINE_CONFIG_PATH=test/unit/jasmine.json",
"test:types": "tsc -p types/test",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"release": "bash scripts/release.sh",
"release": "node scripts/release.js",
"docs": "vuepress dev docs",
"docs:build": "vuepress build docs"
},
Expand Down Expand Up @@ -61,6 +61,7 @@
"cross-env": "^5.2.0",
"cross-spawn": "^6.0.5",
"css-loader": "^2.1.0",
"enquirer": "^2.3.5",
"eslint": "^6.8.0",
"eslint-plugin-vue-libs": "^4.0.0",
"execa": "^4.0.0",
Expand All @@ -71,6 +72,7 @@
"nightwatch-helpers": "^1.2.0",
"rollup": "^2.7.2",
"rollup-plugin-terser": "^5.3.0",
"semver": "^7.3.2",
"todomvc-app-css": "^2.1.0",
"typescript": "^3.8.3",
"vue": "^2.5.22",
Expand Down
113 changes: 113 additions & 0 deletions scripts/release.js
@@ -0,0 +1,113 @@
const fs = require('fs')
const path = require('path')
const chalk = require('chalk')
const semver = require('semver')
const { prompt } = require('enquirer')
const execa = require('execa')
const currentVersion = require('../package.json').version

const versionIncrements = [
'patch',
'minor',
'major'
]

const tags = [
'latest',
'next'
]

const inc = (i) => semver.inc(currentVersion, i)
const bin = (name) => path.resolve(__dirname, `../node_modules/.bin/${name}`)
const run = (bin, args, opts = {}) => execa(bin, args, { stdio: 'inherit', ...opts })
const step = (msg) => console.log(chalk.cyan(msg))

async function main() {
let targetVersion

const { release } = await prompt({
type: 'select',
name: 'release',
message: 'Select release type',
choices: versionIncrements.map(i => `${i} (${inc(i)})`).concat(['custom'])
})

if (release === 'custom') {
targetVersion = (await prompt({
type: 'input',
name: 'version',
message: 'Input custom version',
initial: currentVersion
})).version
} else {
targetVersion = release.match(/\((.*)\)/)[1]
}

if (!semver.valid(targetVersion)) {
throw new Error(`Invalid target version: ${targetVersion}`)
}

const { tag } = await prompt({
type: 'select',
name: 'tag',
message: 'Select tag type',
choices: tags
})

console.log(tag)

const { yes } = await prompt({
type: 'confirm',
name: 'yes',
message: `Releasing v${targetVersion} with the "${tag}" tag. Confirm?`
})

if (!yes) {
return
}

// Run tests before release.
step('\nRunning tests...')
await run('yarn', ['test'])

// Update the package version.
step('\nUpdating the package version...')
updatePackage(targetVersion)

// Build the package.
step('\nBuilding the package...')
await run('yarn', ['build'])

// Generate the changelog.
step('\nGenerating the changelog...')
await run('yarn', ['changelog'])

// Commit changes to the Git.
step('\nCommitting changes...')
await run('git', ['add', '-A'])
await run('git', ['commit', '-m', `release: v${targetVersion}`])

// Publish the package.
step('\nPublishing the package...')
await run ('yarn', [
'publish', '--tag', tag, '--new-version', targetVersion, '--no-commit-hooks',
'--no-git-tag-version'
])

// Push to GitHub.
step('\nPushing to GitHub...')
await run('git', ['tag', `v${targetVersion}`])
await run('git', ['push', 'origin', `refs/tags/v${targetVersion}`])
await run('git', ['push'])
}

function updatePackage(version) {
const pkgPath = path.resolve(path.resolve(__dirname, '..'), 'package.json')
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))

pkg.version = version

fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + '\n')
}

main().catch((err) => console.error(err))
34 changes: 0 additions & 34 deletions scripts/release.sh

This file was deleted.

17 changes: 17 additions & 0 deletions yarn.lock
Expand Up @@ -1531,6 +1531,11 @@ ansi-colors@3.2.3, ansi-colors@^3.0.0:
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-3.2.3.tgz#57d35b8686e851e2cc04c403f1c00203976a1813"
integrity sha512-LEHHyuhlPY3TmuUYMh2oz89lTShfvgbmzaBcxve9t/9Wuy7Dwf4yoAKcND7KFT1HAQfqZ12qtc+DUrBMeKF9nw==

ansi-colors@^3.2.1:
version "3.2.4"
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-3.2.4.tgz#e3a3da4bfbae6c86a9c285625de124a234026fbf"
integrity sha512-hHUXGagefjN2iRrID63xckIvotOXOojhQKWIPUZ4mNUZ9nLZW+7FMNoE1lOkEhNWYsx/7ysGIuJYCiMAA9FnrA==

ansi-escapes@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.1.0.tgz#f73207bb81207d75fd6c83f125af26eea378ca30"
Expand Down Expand Up @@ -4310,6 +4315,13 @@ enhanced-resolve@^4.1.0:
memory-fs "^0.4.0"
tapable "^1.0.0"

enquirer@^2.3.5:
version "2.3.5"
resolved "https://registry.yarnpkg.com/enquirer/-/enquirer-2.3.5.tgz#3ab2b838df0a9d8ab9e7dff235b0e8712ef92381"
integrity sha512-BNT1C08P9XD0vNg3J475yIUG+mVdp9T6towYFHUv897X0KoHBjB1shyrNmhmtHWKP17iSWgo7Gqh7BBuzLZMSA==
dependencies:
ansi-colors "^3.2.1"

entities@~1.1.1:
version "1.1.2"
resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.2.tgz#bdfa735299664dfafd34529ed4f8522a275fea56"
Expand Down Expand Up @@ -9656,6 +9668,11 @@ semver@^6.0.0, semver@^6.1.2, semver@^6.3.0:
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==

semver@^7.3.2:
version "7.3.2"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.3.2.tgz#604962b052b81ed0786aae84389ffba70ffd3938"
integrity sha512-OrOb32TeeambH6UrhtShmF7CRDqhL6/5XpPNp2DuRH6+9QLw/orhp72j87v8Qa1ScDkvrrBNpZcDejAirJmfXQ==

send@0.17.1:
version "0.17.1"
resolved "https://registry.yarnpkg.com/send/-/send-0.17.1.tgz#c1d8b059f7900f7466dd4938bdc44e11ddb376c8"
Expand Down