Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): allow non-empty directories to be initialized #51

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
}
}