mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
fix: improve nuxt version number when running from git (#4946)
This commit is contained in:
parent
858c9eeb5d
commit
92803b23d9
@ -10,7 +10,7 @@
|
|||||||
"clean:build": "rimraf distributions/*/dist packages/*/dist",
|
"clean:build": "rimraf distributions/*/dist packages/*/dist",
|
||||||
"clean:examples": "rimraf examples/*/dist examples/*/.nuxt",
|
"clean:examples": "rimraf examples/*/dist examples/*/.nuxt",
|
||||||
"clean:test": "rimraf test/fixtures/*/dist test/fixtures/*/.nuxt*",
|
"clean:test": "rimraf test/fixtures/*/dist test/fixtures/*/.nuxt*",
|
||||||
"dev": "node -r esm ./scripts/dev",
|
"dev": "node -r esm ./scripts/dev.js",
|
||||||
"coverage": "codecov",
|
"coverage": "codecov",
|
||||||
"lint": "eslint --ext .js,.mjs,.vue .",
|
"lint": "eslint --ext .js,.mjs,.vue .",
|
||||||
"lint:app": "eslint-multiplexer eslint --ignore-path packages/vue-app/template/.eslintignore 'test/fixtures/!(missing-plugin)/.nuxt!(-dev)/**' | eslint-multiplexer -b",
|
"lint:app": "eslint-multiplexer eslint --ignore-path packages/vue-app/template/.eslintignore 'test/fixtures/!(missing-plugin)/.nuxt!(-dev)/**' | eslint-multiplexer -b",
|
||||||
|
@ -24,16 +24,17 @@ const _require = esm(module, {
|
|||||||
|
|
||||||
const execa = require('execa')
|
const execa = require('execa')
|
||||||
|
|
||||||
global.__NUXT = new Proxy({}, {
|
global.__NUXT = {}
|
||||||
get(target, propertyKey, receiver) {
|
Object.defineProperty(global.__NUXT, 'version', {
|
||||||
if (propertyKey === 'version') {
|
enumerable: true,
|
||||||
|
get() {
|
||||||
try {
|
try {
|
||||||
const { stdout } = execa.sync('git', ['status', '-s', '-b', '--porcelain=2'])
|
const { stdout } = execa.sync('git', ['status', '-s', '-b', '--porcelain=2'])
|
||||||
|
|
||||||
const status = { dirty: false }
|
const status = { dirty: false }
|
||||||
for (const line of stdout.split('\\n')) {
|
for (const line of stdout.split('\\n')) {
|
||||||
if (line[0] === '#') {
|
if (line[0] === '#') {
|
||||||
const match = line.match(/branch\.([^\\s]+) (.*)\$/)
|
const match = line.match(/branch\\.([^\\s]+) (.*)$/)
|
||||||
if (match && match.length) {
|
if (match && match.length) {
|
||||||
status[match[1]] = match[2]
|
status[match[1]] = match[2]
|
||||||
}
|
}
|
||||||
@ -43,14 +44,12 @@ global.__NUXT = new Proxy({}, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return \`git<\${status.head}\${status.dirty ? '~' : '-'}\${(status.oid && status.oid.substr(0, 7)) || ''}> (\${status.ab})\`
|
return \`git<\${status.head}\${status.dirty ? '~' : '-'}\${(status.oid && status.oid.substr(0, 7)) || ''}>\` +
|
||||||
|
(status.ab ? \` (\${status.ab})\` : '')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return 'source'
|
return 'source'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return target[propertyKey]
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
module.exports = _require('../src/index')
|
module.exports = _require('../src/index')
|
Loading…
Reference in New Issue
Block a user