-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: check and show newer version on create
- Loading branch information
Showing
6 changed files
with
69 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
const chalk = require('chalk') | ||
const version = require('../../package.json').version | ||
const semver = require('semver') | ||
const getVersions = require('./getVersions') | ||
const { clearConsole } = require('@vue/cli-shared-utils') | ||
|
||
let title = chalk.bold.green(`Vue CLI v${version}`) | ||
if (process.env.VUE_CLI_TEST) { | ||
title += ' ' + chalk.blue.bold('TEST') | ||
} | ||
if (process.env.VUE_CLI_DEBUG) { | ||
title += ' ' + chalk.magenta.bold('DEBUG') | ||
} | ||
module.exports = async function clearConsoleWithTitle () { | ||
const { current, latest } = await getVersions() | ||
|
||
let title = chalk.bold.blue(`Vue CLI v${current}`) | ||
|
||
module.exports = () => clearConsole(title) | ||
if (process.env.VUE_CLI_TEST) { | ||
title += ' ' + chalk.blue.bold('TEST') | ||
} | ||
if (process.env.VUE_CLI_DEBUG) { | ||
title += ' ' + chalk.magenta.bold('DEBUG') | ||
} | ||
if (semver.gt(latest, current)) { | ||
title += chalk.green(` | ||
┌─────────────────────────${`─`.repeat(latest.length)}─┐ | ||
│ ✨ Update available: ${latest} ✨ │ | ||
└─────────────────────────${`─`.repeat(latest.length)}─┘`) | ||
} | ||
|
||
clearConsole(title) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module.exports = async function getVersions () { | ||
const current = require(`../../package.json`).version | ||
let latest | ||
if (process.env.VUE_CLI_LATEST_VERSION) { | ||
// cached value | ||
latest = process.env.VUE_CLI_LATEST_VERSION | ||
} else if (process.env.VUE_CLI_TEST || process.env.VUE_CLI_DEBUG) { | ||
// test/debug, use local version | ||
latest = process.env.VUE_CLI_LATEST_VERSION = current | ||
} else { | ||
const axios = require('axios') | ||
const options = require('../options').loadOptions() | ||
const registry = options.useTaobaoRegistry | ||
? `https://registry.npm.taobao.org` | ||
: `https://registry.npmjs.org` | ||
|
||
const res = await axios.get(`${registry}/vue-cli-version-marker/latest`) | ||
if (res.status === 200) { | ||
latest = process.env.VUE_CLI_LATEST_VERSION = res.data.version | ||
} else { | ||
// fallback to local version | ||
latest = process.env.VUE_CLI_LATEST_VERSION = current | ||
} | ||
} | ||
return { | ||
current, | ||
latest | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# What is This? | ||
|
||
The npm registry does not expose `/latest` endpoints for scoped packages. Getting the full metadata for a scoped package is typically `~300ms` slower than simply getting the latest version from an unscoped package. | ||
|
||
This package serves as an unscoped marker to expose the latest version currently published for `@vue/cli`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "vue-cli-version-marker", | ||
"version": "3.0.0-alpha.6", | ||
"description": "version marker for @vue/cli", | ||
"author": "Evan You", | ||
"license": "MIT" | ||
} |