Skip to content

Commit

Permalink
fix: ignore path prompt if user provided path in create (#292)
Browse files Browse the repository at this point in the history
Co-authored-by: AdrianGonz97 <31664583+AdrianGonz97@users.noreply.github.com>
  • Loading branch information
manuel3108 and AdrianGonz97 authored Nov 11, 2024
1 parent 9857030 commit 4e6552b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
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

0 comments on commit 4e6552b

Please sign in to comment.