MCPcopy
hub / github.com/QwikDev/qwik / runNewCommand

Function runNewCommand

packages/qwik/src/cli/new/run-new-command.ts:17–105  ·  view source on GitHub ↗
(app: AppCommand)

Source from the content-addressed store, hash-verified

15const MDX_SUFFIX = '.mdx';
16
17export async function runNewCommand(app: AppCommand) {
18 try {
19 // render help
20 if (app.args.length > 1 && app.args[1] === 'help') {
21 intro(`🔭 ${bgMagenta(' Qwik Help ')}`);
22 await printNewHelp();
23 bye();
24 } else {
25 intro(`✨ ${bgMagenta(' Create a new Qwik component or route ')}`);
26 }
27
28 const args = app.args.filter((a) => !a.startsWith('--'));
29
30 const mainInput = args.slice(1).join(' ');
31 let typeArg: 'route' | 'component' | 'markdown' | 'mdx' | undefined = undefined;
32 let nameArg: string | undefined;
33 let outDir: string | undefined;
34 if (mainInput && mainInput.startsWith('/')) {
35 if (mainInput.endsWith(MARKDOWN_SUFFIX)) {
36 typeArg = 'markdown';
37 nameArg = mainInput.replace(MARKDOWN_SUFFIX, '');
38 } else if (mainInput.endsWith(MDX_SUFFIX)) {
39 typeArg = 'mdx';
40 nameArg = mainInput.replace(MDX_SUFFIX, '');
41 } else {
42 typeArg = 'route';
43 nameArg = mainInput;
44 }
45 } else if (mainInput) {
46 typeArg = 'component';
47 nameArg = mainInput;
48 }
49
50 let templateArg = app.args
51 .filter((a) => a.startsWith('--'))
52 .map((a) => a.substring(2))
53 .join('');
54
55 if (!templateArg && mainInput) {
56 templateArg = 'qwik';
57 }
58
59 if (!typeArg) {
60 typeArg = await selectType();
61 }
62
63 if (!POSSIBLE_TYPES.includes(typeArg)) {
64 throw new Error(`Invalid type: ${typeArg}`);
65 }
66
67 if (!nameArg) {
68 nameArg = await selectName(typeArg);
69 }
70
71 const { name, slug } = parseInputName(nameArg);
72
73 let template: Template | undefined;
74 if (!templateArg) {

Callers 2

run.tsFile · 0.90
runCommandFunction · 0.90

Calls 11

printNewHelpFunction · 0.90
byeFunction · 0.90
loadTemplatesFunction · 0.90
joinFunction · 0.90
selectTypeFunction · 0.85
selectNameFunction · 0.85
parseInputNameFunction · 0.85
selectTemplateFunction · 0.85
writeToFileFunction · 0.85
toPascalFunction · 0.85
joinMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…