Skip to content

New release strategy #3020

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

Merged
merged 5 commits into from
Nov 27, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"npmClient": "yarn",
"useWorkspaces": true,
"version": "independent",
"useWorkspaces": false,
"version": "3.1.5",
"packages": [
"packages/@vue/*",
"packages/vue-cli-version-marker"
"packages/@vue/babel-preset-app",
"packages/@vue/cli*"
]
}
8 changes: 7 additions & 1 deletion packages/@vue/cli/lib/Creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const chalk = require('chalk')
const debug = require('debug')
const execa = require('execa')
const inquirer = require('inquirer')
const semver = require('semver')
const EventEmitter = require('events')
const Generator = require('./Generator')
const cloneDeep = require('lodash.clonedeep')
Expand Down Expand Up @@ -105,6 +106,7 @@ module.exports = class Creator extends EventEmitter {

// get latest CLI version
const { latest } = await getVersions()
const latestMinor = `${semver.major(latest)}.${semver.minor(latest)}.0`
// generate package.json with plugin dependencies
const pkg = {
name,
Expand All @@ -117,9 +119,13 @@ module.exports = class Creator extends EventEmitter {
if (preset.plugins[dep]._isPreset) {
return
}

// Note: the default creator includes no more than `@vue/cli-*` & `@vue/babel-preset-env`,
// so it is fine to only test `@vue` prefix.
// Other `@vue/*` packages' version may not be in sync with the cli itself.
pkg.devDependencies[dep] = (
preset.plugins[dep].version ||
((/^@vue/.test(dep) && latest[dep]) ? `^${latest[dep]}` : `latest`)
((/^@vue/.test(dep)) ? `^${latestMinor}` : `latest`)
)
})
// write package.json
Expand Down
2 changes: 2 additions & 0 deletions packages/@vue/cli/lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const presetSchema = createSchema(joi => joi.object().keys({
}))

const schema = createSchema(joi => joi.object().keys({
latestVersion: joi.string().regex(/^\d+\.\d+\.\d+$/),
lastChecked: joi.date().timestamp(),
packageManager: joi.string().only(['yarn', 'npm']),
useTaobaoRegistry: joi.boolean(),
presets: joi.object().pattern(/^/, presetSchema)
Expand Down
10 changes: 5 additions & 5 deletions packages/@vue/cli/lib/util/clearConsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ const { clearConsole } = require('@vue/cli-shared-utils')
exports.generateTitle = async function (checkUpdate) {
const { current, latest } = await getVersions()

let title = chalk.bold.blue(`Vue CLI v${current['@vue/cli']}`)
let title = chalk.bold.blue(`Vue CLI v${current}`)

if (process.env.VUE_CLI_TEST) {
title += ' ' + chalk.blue.bold('TEST')
}
if (process.env.VUE_CLI_DEBUG) {
title += ' ' + chalk.magenta.bold('DEBUG')
}
if (checkUpdate && semver.gt(latest['@vue/cli'], current['@vue/cli'])) {
if (checkUpdate && semver.gt(latest, current)) {
if (process.env.VUE_CLI_API_MODE) {
title += chalk.green(` 🌟️ Update available: ${latest}`)
} else {
title += chalk.green(`
┌────────────────────${`─`.repeat(latest['@vue/cli'].length)}──┐
│ Update available: ${latest['@vue/cli']} │
└────────────────────${`─`.repeat(latest['@vue/cli'].length)}──┘`)
┌────────────────────${`─`.repeat(latest.length)}──┐
│ Update available: ${latest} │
└────────────────────${`─`.repeat(latest.length)}──┘`)
}
}

Expand Down
32 changes: 14 additions & 18 deletions packages/@vue/cli/lib/util/getVersions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const fs = require('fs-extra')
const path = require('path')
const fsCachePath = path.resolve(__dirname, '.versions')
const semver = require('semver')
const { loadOptions, saveOptions } = require('../options')

let sessionCached

Expand All @@ -10,31 +9,26 @@ module.exports = async function getVersions () {
}

let latest
const local = require('vue-cli-version-marker').devDependencies
const local = require(`../../package.json`).version
if (process.env.VUE_CLI_TEST || process.env.VUE_CLI_DEBUG) {
return (sessionCached = {
current: local,
latest: local
})
}

if (!fs.existsSync(fsCachePath)) {
// if the cache file doesn't exist, this is likely a fresh install
// then create a cache file with the bundled version map
await fs.writeFile(fsCachePath, JSON.stringify(local))
}

const cached = JSON.parse(await fs.readFile(fsCachePath, 'utf-8'))
const lastChecked = (await fs.stat(fsCachePath)).mtimeMs
const { latestVersion = local, lastChecked = 0 } = loadOptions()
const cached = latestVersion
const daysPassed = (Date.now() - lastChecked) / (60 * 60 * 1000 * 24)

if (daysPassed > 1) {
// if we haven't check for a new version in a day, wait for the check
// before proceeding
latest = await getAndCacheLatestVersions(cached)
latest = await getAndCacheLatestVersion(cached)
} else {
// Otherwise, do a check in the background. If the result was updated,
// it will be used for the next 24 hours.
getAndCacheLatestVersions(cached)
getAndCacheLatestVersion(cached)
latest = cached
}

Expand All @@ -46,13 +40,15 @@ module.exports = async function getVersions () {

// fetch the latest version and save it on disk
// so that it is available immediately next time
async function getAndCacheLatestVersions (cached) {
async function getAndCacheLatestVersion (cached) {
const getPackageVersion = require('./getPackageVersion')
const res = await getPackageVersion('vue-cli-version-marker', 'latest')
if (res.statusCode === 200) {
const versions = res.body.devDependencies
await fs.writeFile(fsCachePath, JSON.stringify(versions))
return versions
const { version } = res.body
if (semver.valid(version) && version !== cached) {
saveOptions({ lastestVersion: version, lastChecked: Date.now() })
return version
}
}
return cached
}
1 change: 0 additions & 1 deletion packages/@vue/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"shortid": "^2.2.11",
"slash": "^2.0.0",
"validate-npm-package-name": "^3.0.0",
"vue-cli-version-marker": "3.1.2",
"yaml-front-matter": "^3.4.1"
},
"engines": {
Expand Down
39 changes: 31 additions & 8 deletions scripts/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ How to do a release:
6. Go to GitHub releases page and publish the release (this is required for
the release to show up in the issue helper)

Note: eslint-config-* packages should be released separately & manually.

*/

process.env.VUE_CLI_RELEASE = true

const fs = require('fs')
const path = require('path')
const execa = require('execa')
const semver = require('semver')
const inquirer = require('inquirer')
const { syncDeps } = require('./syncDeps')
const { buildEditorConfig } = require('./buildEditorConfig')
// const { buildEditorConfig } = require('./buildEditorConfig')

const curVersion = require('../lerna.json').version

Expand Down Expand Up @@ -81,21 +85,40 @@ const release = async () => {
})
delete process.env.PREFIX

buildEditorConfig()
// buildEditorConfig()

await execa('git', ['add', '-A'], { stdio: 'inherit' })
await execa('git', ['commit', '-m', 'chore: pre release sync'], { stdio: 'inherit' })
}

await execa(require.resolve('lerna/bin/lerna'), [
const lernaArgs = [
'publish',
'--repo-version',
version,
'--force-publish',
'*'
], { stdio: 'inherit' })
version
]
const releaseType = semver.diff(curVersion, version)

// keep packages' minor version in sync
if (releaseType !== 'patch') {
lernaArgs.push('--force-publish')
}
await execa(require.resolve('lerna/cli'), lernaArgs, { stdio: 'inherit' })

require('./genChangelog')(version)

const packages = JSON.parse(
(await execa(require.resolve('lerna/cli'), ['list', '--json'])).stdout
).filter(p => !p.private)
const versionMarkerPath = path.resolve(__dirname, '../packages/vue-cli-version-marker/package.json')
const versionMarkerPkg = JSON.parse(fs.readFileSync(versionMarkerPath))

versionMarkerPkg.version = semver.inc(versionMarkerPkg.version, releaseType)
versionMarkerPkg.devDependencies = packages.reduce((prev, pkg) => {
prev[pkg.name] = pkg.version
return prev
}, {})
fs.writeFileSync(versionMarkerPath, JSON.stringify(versionMarkerPkg, null, 2))

await execa('npm', ['publish'], { stdio: 'inherit', cwd: path.dirname(versionMarkerPath) })
}

release().catch(err => {
Expand Down
Loading