Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/fifty-books-send.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'sv': patch
---

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
4 changes: 4 additions & 0 deletions documentation/docs/20-commands/10-sv-create.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ Installs dependencies with a specified package manager:

Prevents installing dependencies.

### `--no-dir-check`

Skip checking whether the target directory is empty.

<!-- ## Programmatic interface

```js
Expand Down
12 changes: 7 additions & 5 deletions packages/cli/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ const OptionsSchema = v.strictObject({
addOns: v.boolean(),
install: v.union([v.boolean(), v.picklist(AGENT_NAMES)]),
template: v.optional(v.picklist(templateChoices)),
fromPlayground: v.optional(v.string())
fromPlayground: v.optional(v.string()),
dirCheck: v.boolean()
});
type Options = v.InferOutput<typeof OptionsSchema>;
type ProjectPath = v.InferOutput<typeof ProjectPathSchema>;
Expand All @@ -65,6 +66,7 @@ export const create = new Command('create')
.option('--no-add-ons', 'skips interactive add-on installer')
.option('--no-install', 'skip installing dependencies')
.option('--from-playground <url>', 'create a project from the svelte playground')
.option('--no-dir-check', 'even if the folder is not empty, no prompt will be shown')
.addOption(installOption)
.configureHelp(common.helpConfig)
.action((projectPath, opts) => {
Expand Down Expand Up @@ -140,10 +142,10 @@ async function createProject(cwd: ProjectPath, options: Options) {
});
},
force: async ({ results: { directory } }) => {
if (
fs.existsSync(directory!) &&
fs.readdirSync(directory!).filter((x) => !x.startsWith('.git')).length > 0
) {
const directoryExists = fs.existsSync(directory!);
const hasNonIgnoredFiles =
fs.readdirSync(directory!).filter((x) => !x.startsWith('.git')).length > 0;
if (directoryExists && hasNonIgnoredFiles && options.dirCheck) {
const force = await p.confirm({
message: 'Directory not empty. Continue?',
initialValue: false
Expand Down
Loading