Skip to content
Closed
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
30 changes: 19 additions & 11 deletions packages/typegpu-cli/src/create.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path';
import * as p from '@clack/prompts';

import { pmFromUserAgent, pmInstall, pmRun } from './utils/pm.ts';
import { pmFromUserAgent, pmInstall } from './utils/pm.ts';
import { cancelExit, confirmStep, rgbText } from './utils/prompts.ts';
import { copyTemplate, prepareDirectory } from './utils/files.ts';
import { getPackageName, getProjectDirectory } from './utils/inputs.ts';
Expand Down Expand Up @@ -46,25 +46,33 @@ export async function createProject(cwd: string) {

const detected = await detect({ cwd });
const pm = detected?.agent ?? pmFromUserAgent(process.env.npm_config_user_agent);
const installAndRun = await confirmStep(`Install with ${pm} and start now?`, true);
const shouldInstall = await confirmStep(`Install dependencies with ${pm}?`, true);

if (installAndRun) {
if (shouldInstall) {
process.chdir(root);
pmInstall(pm);
pmRun(pm, ['dev']);
return;
}

let msg = 'Done!\n';
const cdPath = path.relative(cwd, root);
const installCmd = resolveCommand(pm, 'install', []);
const runCmd = resolveCommand(pm, 'run', ['dev']);

if (installCmd && runCmd) {
msg += ` To have a shaderful experience run:\n\n`;
msg += ` cd ${cdPath}\n`;
msg += ` ${installCmd.command} ${installCmd.args.join(' ')}\n`;
msg += ` ${runCmd.command} ${runCmd.args.join(' ')}`;
const steps: string[] = [];
const shouldCd = (!shouldInstall && !!installCmd) || !!runCmd || !!cdPath;
if (shouldCd && cdPath) {
steps.push(` cd ${cdPath}`);
}
if (!shouldInstall && installCmd) {
steps.push(` ${installCmd.command} ${installCmd.args.join(' ')}`);
}
if (runCmd) {
steps.push(` ${runCmd.command} ${runCmd.args.join(' ')}`);
}

let msg = 'Done!\n';
if (steps.length > 0) {
msg += ` To get started run:\n\n`;
msg += steps.join('\n');
}

p.outro(msg);
Expand Down
8 changes: 4 additions & 4 deletions packages/typegpu-cli/src/utils/pm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ export function pmInstall(pm: Agent) {
failAndExit(`Cannot resolve install command for ${pm}`);
}

const s = p.spinner();
s.start('Installing dependencies');
runCommand(cmd.command, cmd.args);
s.stop('Installed dependencies');
const label = `${cmd.command}${cmd.args.length ? ` ${cmd.args.join(' ')}` : ''}`;
p.log.step(`Running ${label}...`);
runCommand(cmd.command, cmd.args, true);
p.log.success('Installed dependencies.');
}

export function pmRun(pm: Agent, args: string[]) {
Expand Down
Loading