Skip to content

Commit

Permalink
fix(helper): keep current working directory intact to avoid errors
Browse files Browse the repository at this point in the history
release-npm
  • Loading branch information
tobua committed May 8, 2024
1 parent 79a148f commit c8f0a50
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 9 additions & 5 deletions helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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')
}
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down

0 comments on commit c8f0a50

Please sign in to comment.