diff --git a/helper.ts b/helper.ts index 58791ed..f0aead6 100644 --- a/helper.ts +++ b/helper.ts @@ -4,13 +4,19 @@ import validate from 'validate-npm-package-name' import { log } from './log' import { promptClear } from './prompt' +const hiddenFiles = ['.DS_Store'] +const protectedFiles = ['.git'] // User checking out a template into a repository. +const invisibleFiles = [...hiddenFiles, ...protectedFiles] + function deleteFolderContents(directory: string) { for (const file of readdirSync(directory)) { - rmSync(join(directory, file), { recursive: true }) + if (!protectedFiles.includes(file)) { + rmSync(join(directory, file), { recursive: true }) + } } } -const isDirectoryEmpty = (directory: string) => readdirSync(directory).filter((file: string) => file !== '.DS_Store').length === 0 +const isDirectoryEmpty = (directory: string) => readdirSync(directory).filter((file: string) => !invisibleFiles.includes(file)).length === 0 export const getDestinationPath = async (input = process.cwd(), skipClear = false) => { let destinationPath = process.cwd() diff --git a/package.json b/package.json index 594e825..5cfe3e1 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "mock-stdin": "^1.0.0", "read-chunk": "^4.0.3", "typescript": "^5.4.5", - "zero-configuration": "^0.7.2" + "zero-configuration": "^0.8.0" }, "trustedDependencies": [ "zero-configuration"