From c8f0a5035c6db89dc141437c24509c245dfdd6c9 Mon Sep 17 00:00:00 2001 From: Matthias Giger Date: Wed, 8 May 2024 19:54:24 +0200 Subject: [PATCH] fix(helper): keep current working directory intact to avoid errors release-npm --- README.md | 12 ++++++------ helper.ts | 14 +++++++++----- package.json | 6 +++--- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index c9b50ce..44aa44f 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,15 @@ # now -Create projects from templates. +Create projects from templates. This CLI will bootstrap templates from the `/template` directory in a GitHub repository linked to form an npm-package. ## Usage Install template for compatible packages like this: ```sh -bun create now papua -bunx create-now papua +bun create now zero-configuration +bunx create-now zero-configuration . web ``` ## Options @@ -25,13 +25,13 @@ The second argument can be used to describe the location where to place the proj ### Example -Use the papua build tool with the `website` template and place result in `/my-site` folder. +Use the `zero-configuration` configuration tool with the `web` template and place result in `/my-site` folder. ```sh -bun create now papua my-site website +bun create now zero-configuration my-site web ``` -Create a React Native app managed with numic inside the `/my-app` folder avoiding the prompt for a bundle name by presetting the variable. +Create a React Native app managed with `numic` inside the `/my-app` folder avoiding the prompt for a bundle name by presetting the variable. ```sh bun create now numic my-app default name=tesla diff --git a/helper.ts b/helper.ts index 34dd3c2..58791ed 100644 --- a/helper.ts +++ b/helper.ts @@ -4,7 +4,13 @@ import validate from 'validate-npm-package-name' import { log } from './log' import { promptClear } from './prompt' -const isDirectoryEmpty = (directory: string) => readdirSync(directory).length === 0 +function deleteFolderContents(directory: string) { + for (const file of readdirSync(directory)) { + rmSync(join(directory, file), { recursive: true }) + } +} + +const isDirectoryEmpty = (directory: string) => readdirSync(directory).filter((file: string) => file !== '.DS_Store').length === 0 export const getDestinationPath = async (input = process.cwd(), skipClear = false) => { let destinationPath = process.cwd() @@ -23,10 +29,8 @@ export const getDestinationPath = async (input = process.cwd(), skipClear = fals const clear = await promptClear(destinationPath) if (clear) { - // Clear directory to ensure proper npm install. - rmSync(destinationPath, { recursive: true }) - // Directory itself is needed. - mkdirSync(destinationPath, { recursive: true }) + // Clear directory contents to ensure proper template installation. + deleteFolderContents(destinationPath) } else { log('Keeping existing contents, might be overriden when copying the template') } diff --git a/package.json b/package.json index bc53b26..594e825 100644 --- a/package.json +++ b/package.json @@ -22,10 +22,10 @@ "prompts": "^2.4.2", "strip-dirs": "^3.0.0", "temp-dir": "^3.0.0", - "validate-npm-package-name": "^5.0.0" + "validate-npm-package-name": "^5.0.1" }, "devDependencies": { - "@biomejs/biome": "^1.7.2", + "@biomejs/biome": "^1.7.3", "@types/bun": "^1.1.1", "@types/decompress": "^4.2.7", "@types/ejs": "^3.1.5", @@ -36,7 +36,7 @@ "mock-stdin": "^1.0.0", "read-chunk": "^4.0.3", "typescript": "^5.4.5", - "zero-configuration": "^0.7.1" + "zero-configuration": "^0.7.2" }, "trustedDependencies": [ "zero-configuration"