From 185c10553167afca0e2a638ff33b432eb78b46cd Mon Sep 17 00:00:00 2001 From: rossrobino Date: Wed, 9 Oct 2024 15:30:00 -0400 Subject: [PATCH] dir not empty warning --- .changeset/ten-walls-check.md | 5 +++++ packages/create-domco/src/index.ts | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 .changeset/ten-walls-check.md diff --git a/.changeset/ten-walls-check.md b/.changeset/ten-walls-check.md new file mode 100644 index 0000000..e7129c1 --- /dev/null +++ b/.changeset/ten-walls-check.md @@ -0,0 +1,5 @@ +--- +"create-domco": patch +--- + +show warning if the target directory exists and is not empty diff --git a/packages/create-domco/src/index.ts b/packages/create-domco/src/index.ts index 82301cd..42e5ffd 100644 --- a/packages/create-domco/src/index.ts +++ b/packages/create-domco/src/index.ts @@ -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: [