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

fix: ignore path prompt if user provided path in create #292

Merged
merged 3 commits into from
Nov 11, 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
5 changes: 5 additions & 0 deletions .changeset/popular-cows-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'sv': patch
---

fix: ignore path prompt if user provided path in `create`
15 changes: 9 additions & 6 deletions packages/cli/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const templateOption = new Option('--template <type>', 'template to scaffold').c
templateChoices
);

const ProjectPathSchema = v.string();
const ProjectPathSchema = v.optional(v.string());
const OptionsSchema = v.strictObject({
types: v.pipe(
v.optional(v.union([v.picklist(langs), v.boolean()])),
Expand All @@ -38,10 +38,11 @@ const OptionsSchema = v.strictObject({
template: v.optional(v.picklist(templateChoices))
});
type Options = v.InferOutput<typeof OptionsSchema>;
type ProjectPath = v.InferOutput<typeof ProjectPathSchema>;

export const create = new Command('create')
.description('scaffolds a new SvelteKit project')
.argument('[path]', 'where the project will be created', process.cwd())
.argument('[path]', 'where the project will be created')
.addOption(templateOption)
.addOption(langOption)
.option('--no-types')
Expand All @@ -58,7 +59,8 @@ export const create = new Command('create')
let i = 1;
const initialSteps: string[] = [];
const relative = path.relative(process.cwd(), directory);
const pm = packageManager ?? detectSync({ cwd })?.name ?? common.getUserAgent() ?? 'npm';
const pm =
packageManager ?? detectSync({ cwd: directory })?.name ?? common.getUserAgent() ?? 'npm';
if (relative !== '') {
const pathHasSpaces = relative.includes(' ');
initialSteps.push(
Expand All @@ -85,12 +87,13 @@ export const create = new Command('create')
});
});

async function createProject(cwd: string, options: Options) {
async function createProject(cwd: ProjectPath, options: Options) {
const { directory, template, language } = await p.group(
{
directory: () => {
const relativePath = path.relative(process.cwd(), cwd);
if (relativePath) return Promise.resolve(relativePath);
if (cwd) {
return Promise.resolve(path.resolve(cwd));
}
const defaultPath = './';
return p.text({
message: 'Where would you like your project to be created?',
Expand Down