Skip to content

Commit 97c0e7e

Browse files
feat: combine next steps prompt for create (#637)
* feat: combine next steps prompt for `create` * tweak `create` * nit * italics πŸ™…β€β™‚οΈ emojis πŸ‘Œ --------- Co-authored-by: AdrianGonz97 <[email protected]>
1 parent 8aeb7c3 commit 97c0e7e

File tree

3 files changed

+38
-32
lines changed

3 files changed

+38
-32
lines changed

β€Ž.changeset/blue-islands-eat.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: combine next steps prompt for `create`

β€Žpackages/cli/commands/add/index.ts

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,17 @@ export const add = new Command('add')
202202
common.runCommand(async () => {
203203
const selectedAddonIds = selectedAddons.map(({ id }) => id);
204204
const { nextSteps } = await runAddCommand(options, selectedAddonIds);
205-
if (nextSteps) p.note(nextSteps, 'Next steps', { format: (line: string) => line });
205+
if (nextSteps.length > 0) {
206+
p.note(nextSteps.join('\n'), 'Next steps', { format: (line) => line });
207+
}
206208
});
207209
});
208210

209211
type SelectedAddon = { type: 'official' | 'community'; addon: AddonWithoutExplicitArgs };
210212
export async function runAddCommand(
211213
options: Options,
212214
selectedAddonIds: string[]
213-
): Promise<{ nextSteps?: string; packageManager?: AgentName | null }> {
215+
): Promise<{ nextSteps: string[]; packageManager?: AgentName | null }> {
214216
const selectedAddons: SelectedAddon[] = selectedAddonIds.map((id) => ({
215217
type: 'official',
216218
addon: getAddonDetails(id)
@@ -534,7 +536,7 @@ export async function runAddCommand(
534536

535537
// we'll return early when no addons are selected,
536538
// indicating that installing deps was skipped and no PM was selected
537-
if (selectedAddons.length === 0) return { packageManager: null };
539+
if (selectedAddons.length === 0) return { packageManager: null, nextSteps: [] };
538540

539541
// apply addons
540542
const officialDetails = Object.keys(official).map((id) => getAddonDetails(id));
@@ -588,25 +590,17 @@ export async function runAddCommand(
588590
const highlighter = getHighlighter();
589591

590592
// print next steps
591-
const nextSteps =
592-
selectedAddons
593-
.filter(({ addon }) => addon.nextSteps)
594-
.map(({ addon }) => {
595-
let addonMessage = '';
596-
if (selectedAddons.length > 1) {
597-
addonMessage = `${pc.green(addon.id)}:\n`;
598-
}
599-
600-
const addonNextSteps = addon.nextSteps!({
601-
...workspace,
602-
options: official[addon.id]!,
603-
highlighter
604-
});
605-
addonMessage += `- ${addonNextSteps.join('\n- ')}`;
606-
return addonMessage;
607-
})
608-
// instead of returning an empty string, we'll return `undefined`
609-
.join('\n\n') || undefined;
593+
const nextSteps = selectedAddons
594+
.map(({ addon }) => {
595+
if (!addon.nextSteps) return;
596+
let addonMessage = `${pc.green(addon.id)}:\n`;
597+
598+
const options = official[addon.id];
599+
const addonNextSteps = addon.nextSteps({ ...workspace, options, highlighter });
600+
addonMessage += ` - ${addonNextSteps.join('\n - ')}`;
601+
return addonMessage;
602+
})
603+
.filter((msg) => msg !== undefined);
610604

611605
return { nextSteps, packageManager };
612606
}

β€Žpackages/cli/commands/create.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ export const create = new Command('create')
6666
const highlight = (str: string) => pc.bold(pc.cyan(str));
6767

6868
let i = 1;
69-
const initialSteps: string[] = [];
69+
const initialSteps: string[] = ['πŸ“ Project steps', ''];
7070
const relative = path.relative(process.cwd(), directory);
7171
const pm =
7272
packageManager ?? (await detect({ cwd: directory }))?.name ?? getUserAgent() ?? 'npm';
7373
if (relative !== '') {
7474
const pathHasSpaces = relative.includes(' ');
7575
initialSteps.push(
76-
`${i++}: ${highlight(`cd ${pathHasSpaces ? `"${relative}"` : relative}`)}`
76+
` ${i++}: ${highlight(`cd ${pathHasSpaces ? `"${relative}"` : relative}`)}`
7777
);
7878
}
7979
if (!packageManager) {
@@ -85,16 +85,23 @@ export const create = new Command('create')
8585
const pmRunCmd = `${command} ${args.join(' ')}`;
8686
const steps = [
8787
...initialSteps,
88-
`${i++}: ${highlight('git init && git add -A && git commit -m "Initial commit"')} (optional)`,
89-
`${i++}: ${highlight(pmRunCmd)}`,
88+
` ${i++}: ${highlight('git init && git add -A && git commit -m "Initial commit"')} (optional)`,
89+
` ${i++}: ${highlight(pmRunCmd)}`,
9090
'',
91-
`To close the dev server, hit ${highlight('Ctrl-C')}`,
92-
'',
93-
`Stuck? Visit us at ${pc.cyan('https://svelte.dev/chat')}`
91+
`To close the dev server, hit ${highlight('Ctrl-C')}`
9492
];
9593

96-
p.note(steps.join('\n'), 'Project next steps', { format: (line) => line });
97-
if (addOnNextSteps) p.note(addOnNextSteps, 'Add-on next steps', { format: (line) => line });
94+
if (addOnNextSteps.length > 0) {
95+
steps.push('', '🧩 Add-on steps', '');
96+
for (const step of addOnNextSteps) {
97+
const indented = step.replaceAll(' -', ' -');
98+
steps.push(` ${indented}`);
99+
}
100+
}
101+
102+
steps.push('', `Stuck? Visit us at ${pc.cyan('https://svelte.dev/chat')}`);
103+
104+
p.note(steps.join('\n'), "What's next?", { format: (line) => line });
98105
});
99106
});
100107

@@ -166,7 +173,7 @@ async function createProject(cwd: ProjectPath, options: Options) {
166173
p.log.success('Project created');
167174

168175
let packageManager: AgentName | undefined | null;
169-
let addOnNextSteps: string | undefined;
176+
let addOnNextSteps: string[] = [];
170177

171178
const installDeps = async (install: true | AgentName) => {
172179
packageManager = install === true ? await packageManagerPrompt(projectPath) : install;

0 commit comments

Comments
Β (0)