Skip to content

Commit

Permalink
Merge pull request #51 from sj-distributor/50-todo-allow-non-empty-di…
Browse files Browse the repository at this point in the history
…rectories-to-be-initialized

feat(cli): allow non-empty directories to be initialized
  • Loading branch information
goodjun authored Jan 23, 2024
2 parents d24307f + f5e5c89 commit 9928658
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-react-boilerplates",
"version": "2.2.0",
"version": "2.3.0",
"type": "module",
"bin": {
"create-react-boilerplates": "index.js",
Expand Down
25 changes: 20 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,32 @@ async function init() {
},
{
type: () =>
!fs.existsSync(targetDir) || isEmpty(targetDir) ? null : "confirm",
!fs.existsSync(targetDir) || isEmpty(targetDir) ? null : "select",
name: "overwrite",
message: () =>
(targetDir === "."
? "Current directory"
: `Target directory "${targetDir}"`) +
` is not empty. Remove existing files and continue?`,
` is not empty. Please select the steps to perform:`,
initial: 0,
choices: [
{
title: "Cancel operation",
value: 1,
},
{
title: "Ignore files and continue",
value: 2,
},
{
title: "Delete the current file and continue",
value: 3,
},
],
},
{
type: (_, { overwrite }: { overwrite?: boolean }) => {
if (overwrite === false) {
type: (_, { overwrite }: { overwrite?: number }) => {
if (overwrite === 1) {
throw new Error(red("✖") + " Operation cancelled");
}

Expand Down Expand Up @@ -105,7 +120,7 @@ async function init() {

const root = path.join(cwd, targetDir);

if (overwrite) {
if (overwrite === 3) {
emptyDir(root);
} else if (!fs.existsSync(root)) {
fs.mkdirSync(root, { recursive: true });
Expand Down
5 changes: 3 additions & 2 deletions templates/template-react-recoil/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"recoil": "^0.7.7"
},
"devDependencies": {
"@sj-distributor/eslint-plugin-react": "^0.7.1",
"@types/node": "^20.11.5",
"@types/ramda": "^0.29.3",
"@types/react": "^18.0.26",
"@types/react-dom": "^18.0.10",
Expand All @@ -39,7 +41,6 @@
"tailwindcss": "^3.3.5",
"typescript": "^5.1.6",
"typescript-plugin-css-modules": "^5.0.1",
"vite": "^4.4.10",
"@sj-distributor/eslint-plugin-react": "^0.7.1"
"vite": "^4.4.10"
}
}
5 changes: 3 additions & 2 deletions templates/template-react-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"react-router-dom": "^6.19.0"
},
"devDependencies": {
"@sj-distributor/eslint-plugin-react": "^0.7.1",
"@types/node": "^20.11.5",
"@types/ramda": "^0.29.3",
"@types/react": "^18.0.26",
"@types/react-dom": "^18.0.10",
Expand All @@ -38,7 +40,6 @@
"tailwindcss": "^3.3.5",
"typescript": "^5.1.6",
"typescript-plugin-css-modules": "^5.0.1",
"vite": "^4.4.10",
"@sj-distributor/eslint-plugin-react": "^0.7.1"
"vite": "^4.4.10"
}
}

0 comments on commit 9928658

Please sign in to comment.