Skip to content

Commit

Permalink
dir not empty warning
Browse files Browse the repository at this point in the history
  • Loading branch information
rossrobino committed Oct 9, 2024
1 parent 106e06d commit 185c105
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-walls-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-domco": patch
---

show warning if the target directory exists and is not empty
18 changes: 18 additions & 0 deletions packages/create-domco/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ export const createDomco = async () => {
process.exit(0);
}

try {
const existingFiles = await fs.readdir(dir);

if (existingFiles.length) {
const proceed = await p.confirm({
message: `The \`${dir}\` directory is not empty, continue?`,
initialValue: false,
});

if (!proceed || p.isCancel(proceed)) {
p.cancel("Operation cancelled.");
process.exit(0);
}
}
} catch {
// will throw if dir doesn't exist - OK, should proceed
}

const lang = await p.select({
message: "Select language",
options: [
Expand Down

0 comments on commit 185c105

Please sign in to comment.