mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-03-13 12:40:18 -05:00
feat(cli): skip git if already in a git repo, add --skipGit option
close #967
This commit is contained in:
@@ -39,9 +39,10 @@ program
|
||||
.option('-p, --preset <presetName>', 'Skip prompts and use saved or remote preset')
|
||||
.option('-d, --default', 'Skip prompts and use default preset')
|
||||
.option('-i, --inlinePreset <json>', 'Skip prompts and use inline JSON string as preset')
|
||||
.option('-g, --initialCommit <message>', 'Specify initial commit message (when git is available)')
|
||||
.option('-m, --packageManager <command>', 'Use specified npm client when installing dependencies')
|
||||
.option('-r, --registry <url>', 'Use specified npm registry when installing dependencies (only for npm)')
|
||||
.option('-s, --skipGit', 'Do not setup git repository when creating project')
|
||||
.option('-g, --git <message>', 'Specify initial commit message (when git is available)')
|
||||
.option('-f, --force', 'Overwrite target directory if it exists')
|
||||
.option('-c, --clone', 'Use git clone when fetching remote preset')
|
||||
.action((name, cmd) => {
|
||||
|
||||
@@ -46,17 +46,15 @@ module.exports = class Creator {
|
||||
this.promptCompleteCbs = []
|
||||
this.createCompleteCbs = []
|
||||
|
||||
this.run = this.run.bind(this)
|
||||
|
||||
const promptAPI = new PromptModuleAPI(this)
|
||||
promptModules.forEach(m => m(promptAPI))
|
||||
}
|
||||
|
||||
async create (cliOptions = {}) {
|
||||
const isTestOrDebug = process.env.VUE_CLI_TEST || process.env.VUE_CLI_DEBUG
|
||||
const { name, context, createCompleteCbs } = this
|
||||
const run = (command, args) => {
|
||||
if (!args) { [command, ...args] = command.split(/\s+/) }
|
||||
return execa(command, args, { cwd: context })
|
||||
}
|
||||
const { run, name, context, createCompleteCbs } = this
|
||||
|
||||
let preset
|
||||
if (cliOptions.preset) {
|
||||
@@ -114,7 +112,8 @@ module.exports = class Creator {
|
||||
|
||||
// intilaize git repository before installing deps
|
||||
// so that vue-cli-service can setup git hooks.
|
||||
if (hasGit()) {
|
||||
const shouldInitGit = await this.shouldInitGit(cliOptions)
|
||||
if (shouldInitGit) {
|
||||
logWithSpinner(`🗃`, `Initializing git repository...`)
|
||||
await run('git init')
|
||||
}
|
||||
@@ -158,7 +157,7 @@ module.exports = class Creator {
|
||||
}
|
||||
|
||||
// commit initial state
|
||||
if (hasGit()) {
|
||||
if (shouldInitGit) {
|
||||
await run('git add -A')
|
||||
if (isTestOrDebug) {
|
||||
await run('git', ['config', 'user.name', 'test'])
|
||||
@@ -181,6 +180,11 @@ module.exports = class Creator {
|
||||
generator.printExitLogs()
|
||||
}
|
||||
|
||||
run (command, args) {
|
||||
if (!args) { [command, ...args] = command.split(/\s+/) }
|
||||
return execa(command, args, { cwd: this.context })
|
||||
}
|
||||
|
||||
async promptAndResolvePreset () {
|
||||
// prompt
|
||||
await clearConsole(true)
|
||||
@@ -379,4 +383,23 @@ module.exports = class Creator {
|
||||
debug('vue-cli:prompts')(prompts)
|
||||
return prompts
|
||||
}
|
||||
|
||||
async shouldInitGit (cliOptions) {
|
||||
if (!hasGit()) {
|
||||
return false
|
||||
}
|
||||
if (cliOptions.skipGit) {
|
||||
return false
|
||||
}
|
||||
// check if we are in a git repo already
|
||||
try {
|
||||
await this.run('git', ['status'])
|
||||
} catch (e) {
|
||||
// if git status failed, let's create a fresh repo
|
||||
return true
|
||||
}
|
||||
// if git status worked, it means we are already in a git repo
|
||||
// so don't init again.
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user