Skip to content

Commit

Permalink
create-next-app: warn if project dir isn't empty before prompts (#45195)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxLeiter committed Jan 23, 2023
1 parent 189008c commit a3b89a5
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/create-next-app/index.ts
Expand Up @@ -11,6 +11,8 @@ import { getPkgManager } from './helpers/get-pkg-manager'
import { validateNpmName } from './helpers/validate-pkg'
import packageJson from './package.json'
import ciInfo from 'ci-info'
import { isFolderEmpty } from './helpers/is-folder-empty'
import fs from 'fs'

let projectPath: string = ''

Expand Down Expand Up @@ -180,6 +182,17 @@ async function run(): Promise<void> {
process.exit(1)
}

/**
* Verify the project dir is empty or doesn't exist
*/
const root = path.resolve(resolvedProjectPath)
const appName = path.basename(root)
const folderExists = fs.existsSync(root)

if (folderExists && !isFolderEmpty(root, appName)) {
process.exit(1)
}

const example = typeof program.example === 'string' && program.example.trim()
const preferences = (conf.get('preferences') || {}) as Record<
string,
Expand Down

0 comments on commit a3b89a5

Please sign in to comment.