8000 fix: do not always output git init information by btea · Pull Request #776 · vuejs/create-vue · GitHub
[go: up one dir, main page]

Skip to content

fix: do not always output git init information #776

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 10 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import ejs from 'ejs'
import * as banners from './utils/banners'

import renderTemplate from './utils/renderTemplate'
import { postOrderDirectoryTraverse, preOrderDirectoryTraverse } from './utils/directoryTraverse'
import {
postOrderDirectoryTraverse,
preOrderDirectoryTraverse,
dotGitDirectoryState,
} from './utils/directoryTraverse'
import generateReadme from './utils/generateReadme'
import getCommand from './utils/getCommand'
import getLanguage from './utils/getLanguage'
Expand Down Expand Up @@ -121,6 +125,7 @@ function canSkipEmptying(dir: string) {
return true
}
if (files.length === 1 && files[0] === '.git') {
dotGitDirectoryState.hasDotGitDirectory = true
return true
}

Expand Down Expand Up @@ -670,10 +675,12 @@ async function init() {
}
outroMessage += ` ${bold(green(getCommand(packageManager, 'dev')))}\n`

outroMessage += `
if (!dotGitDirectoryState.hasDotGitDirectory) {
outroMessage += `
${dim('|')} ${language.infos.optionalGitCommand}

${bold(green('git init && git add -A && git commit -m "initial commit"'))}`
}

outro(outroMessage)
}
Expand Down
5 changes: 5 additions & 0 deletions utils/directoryTraverse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ export function preOrderDirectoryTraverse(dir, dirCallback, fileCallback) {
}
}

export const dotGitDirectoryState = {
hasDotGitDirectory: false,
}

export function postOrderDirectoryTraverse(dir, dirCallback, fileCallback) {
for (const filename of fs.readdirSync(dir)) {
if (filename === '.git') {
dotGitDirectoryState.hasDotGitDirectory = true
continue
}
const fullpath = path.resolve(dir, filename)
Expand Down
0