Skip to content

Commit

Permalink
Adding a disable git flag in Create Next App (vercel#68821)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arinji2 committed Aug 16, 2024
1 parent 1d465c0 commit 12f2fa7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
4 changes: 4 additions & 0 deletions packages/create-next-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ Options:

Explicitly tell the CLI to skip installing packages

--disable-git

Explicitly tell the CLI to skip initializing a git repository.

--yes

Use previous preferences or defaults for all options that were not
Expand Down
15 changes: 10 additions & 5 deletions packages/create-next-app/create-app.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
/* eslint-disable import/no-extraneous-dependencies */
import retry from 'async-retry'
import { copyFileSync, existsSync, mkdirSync } from 'node:fs'
import { basename, dirname, join, resolve } from 'node:path'
import retry from 'async-retry'
import { red, green, cyan } from 'picocolors'
import { cyan, green, red } from 'picocolors'
import type { RepoInfo } from './helpers/examples'
import {
downloadAndExtractExample,
downloadAndExtractRepo,
getRepoInfo,
existsInRepo,
getRepoInfo,
hasRepo,
} from './helpers/examples'
import type { PackageManager } from './helpers/get-pkg-manager'
import { tryGitInit } from './helpers/git'
import { install } from './helpers/install'
import { isFolderEmpty } from './helpers/is-folder-empty'
import { getOnline } from './helpers/is-online'
import { isWriteable } from './helpers/is-writeable'
import type { PackageManager } from './helpers/get-pkg-manager'

import type { TemplateMode, TemplateType } from './templates'
import { getTemplateFile, installTemplate } from './templates'
Expand All @@ -37,6 +37,7 @@ export async function createApp({
skipInstall,
empty,
turbo,
disableGit,
}: {
appPath: string
packageManager: PackageManager
Expand All @@ -51,6 +52,7 @@ export async function createApp({
skipInstall: boolean
empty: boolean
turbo: boolean
disableGit?: boolean
}): Promise<void> {
let repoInfo: RepoInfo | undefined
const mode: TemplateMode = typescript ? 'ts' : 'js'
Expand Down Expand Up @@ -235,7 +237,10 @@ export async function createApp({
})
}

if (tryGitInit(root)) {
if (disableGit) {
console.log('Skipping git initialization.')
console.log()
} else if (tryGitInit(root)) {
console.log('Initialized a git repository.')
console.log()
}
Expand Down
20 changes: 12 additions & 8 deletions packages/create-next-app/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
#!/usr/bin/env node
/* eslint-disable import/no-extraneous-dependencies */
import type { InitialReturnValue } from 'prompts'
import type { PackageManager } from './helpers/get-pkg-manager'
import Conf from 'conf'
import ciInfo from 'ci-info'
import { Command } from 'commander'
import Conf from 'conf'
import { existsSync } from 'node:fs'
import { basename, resolve } from 'node:path'
import { blue, bold, cyan, green, red, yellow } from 'picocolors'
import type { InitialReturnValue } from 'prompts'
import prompts from 'prompts'
import updateCheck from 'update-check'
import packageJson from './package.json'
import { basename, resolve } from 'node:path'
import { existsSync } from 'node:fs'
import { Command } from 'commander'
import { cyan, green, red, yellow, bold, blue } from 'picocolors'
import { createApp, DownloadError } from './create-app'
import type { PackageManager } from './helpers/get-pkg-manager'
import { getPkgManager } from './helpers/get-pkg-manager'
import { isFolderEmpty } from './helpers/is-folder-empty'
import { validateNpmName } from './helpers/validate-pkg'
import packageJson from './package.json'

let projectPath: string = ''

Expand Down Expand Up @@ -102,6 +102,7 @@ const program = new Command(packageJson.name)
--example-path foo/bar
`
)
.option('--disable-git', `Skip initializing a git repository.`)
.action((name) => {
// Commander does not implicitly support negated options. When they are used
// by the user they will be interpreted as the positional argument (name) in
Expand Down Expand Up @@ -233,6 +234,7 @@ async function run(): Promise<void> {
customizeImportAlias: false,
empty: false,
turbo: false,
disableGit: false,
}
const getPrefOrDefault = (field: string) =>
preferences[field] ?? defaults[field]
Expand Down Expand Up @@ -428,6 +430,7 @@ async function run(): Promise<void> {
skipInstall: opts.skipInstall,
empty: opts.empty,
turbo: opts.turbo,
disableGit: opts.disableGit,
})
} catch (reason) {
if (!(reason instanceof DownloadError)) {
Expand Down Expand Up @@ -459,6 +462,7 @@ async function run(): Promise<void> {
skipInstall: opts.skipInstall,
empty: opts.empty,
turbo: opts.turbo,
disableGit: opts.disableGit,
})
}
conf.set('preferences', preferences)
Expand Down

0 comments on commit 12f2fa7

Please sign in to comment.