Skip to content

Commit 165f56c

Browse files
sacrosancticmanuel3108jycouet
authored
feat(cli): sv create --no-dir-check (#785)
* add feat * Update .changeset/fifty-books-send.md Co-authored-by: jyc.dev <[email protected]> * better dx * docs --------- Co-authored-by: Manuel <[email protected]> Co-authored-by: jyc.dev <[email protected]> Co-authored-by: Manuel Serret <[email protected]>
1 parent a819446 commit 165f56c

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

.changeset/fifty-books-send.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'sv': patch
3+
---
4+
5+
feat(cli): add `--no-dir-check` option to `sv create`. With this flag, even if the folder is not empty, no prompt will be shown

documentation/docs/20-commands/10-sv-create.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ Installs dependencies with a specified package manager:
5959

6060
Prevents installing dependencies.
6161

62+
### `--no-dir-check`
63+
64+
Skip checking whether the target directory is empty.
65+
6266
<!-- ## Programmatic interface
6367
6468
```js

packages/cli/commands/create.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ const OptionsSchema = v.strictObject({
5151
addOns: v.boolean(),
5252
install: v.union([v.boolean(), v.picklist(AGENT_NAMES)]),
5353
template: v.optional(v.picklist(templateChoices)),
54-
fromPlayground: v.optional(v.string())
54+
fromPlayground: v.optional(v.string()),
55+
dirCheck: v.boolean()
5556
});
5657
type Options = v.InferOutput<typeof OptionsSchema>;
5758
type ProjectPath = v.InferOutput<typeof ProjectPathSchema>;
@@ -65,6 +66,7 @@ export const create = new Command('create')
6566
.option('--no-add-ons', 'skips interactive add-on installer')
6667
.option('--no-install', 'skip installing dependencies')
6768
.option('--from-playground <url>', 'create a project from the svelte playground')
69+
.option('--no-dir-check', 'even if the folder is not empty, no prompt will be shown')
6870
.addOption(installOption)
6971
.configureHelp(common.helpConfig)
7072
.action((projectPath, opts) => {
@@ -140,10 +142,10 @@ async function createProject(cwd: ProjectPath, options: Options) {
140142
});
141143
},
142144
force: async ({ results: { directory } }) => {
143-
if (
144-
fs.existsSync(directory!) &&
145-
fs.readdirSync(directory!).filter((x) => !x.startsWith('.git')).length > 0
146-
) {
145+
const directoryExists = fs.existsSync(directory!);
146+
const hasNonIgnoredFiles =
147+
fs.readdirSync(directory!).filter((x) => !x.startsWith('.git')).length > 0;
148+
if (directoryExists && hasNonIgnoredFiles && options.dirCheck) {
147149
const force = await p.confirm({
148150
message: 'Directory not empty. Continue?',
149151
initialValue: false

0 commit comments

Comments
 (0)