Skip to content

Commit

Permalink
fix(cli): casing for component and mdx route creation (QwikDev#5430)
Browse files Browse the repository at this point in the history
  • Loading branch information
sidmohanty11 authored Nov 12, 2023
1 parent c2bb819 commit 80b4107
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions packages/qwik/src/cli/new/run-new-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,7 @@ export async function runNewCommand(app: AppCommand) {

const fileOutput = await writeToFile(name, slug, template, outDir);

if (typeArg === 'markdown') {
log.success(`${green(`Markdown route "${name}" created!`)}`);
} else {
log.success(`${green(`${toPascal([typeArg])} "${name}" created!`)}`);
}
log.success(`${green(`${toPascal([typeArg])} "${slug}" created!`)}`);
log.message(`Emitted in ${dim(fileOutput)}`);
} catch (e) {
log.error(String(e));
Expand Down Expand Up @@ -160,17 +156,19 @@ async function selectName(type: 'route' | 'component' | 'markdown' | 'mdx') {
bye();
}

if (type === 'route' && !(nameAnswer as string).startsWith('/')) {
return `/${nameAnswer as string}`;
}
if (type === 'markdown' && !(nameAnswer as string).startsWith('/')) {
return `/${nameAnswer.replace(MARKDOWN_SUFFIX, '') as string}`;
let result = nameAnswer;

if (type !== 'component' && !nameAnswer.startsWith('/')) {
result = `/${result}`;
}
if (type === 'mdx' && !(nameAnswer as string).startsWith('/')) {
return `/${nameAnswer.replace(MDX_SUFFIX, '') as string}`;

if (type === 'markdown') {
result = result.replace(MARKDOWN_SUFFIX, '');
} else if (type === 'mdx') {
result = result.replace(MDX_SUFFIX, '');
}

return nameAnswer.replace(MARKDOWN_SUFFIX, '') as string;
return result;
}

async function selectTemplate(typeArg: (typeof POSSIBLE_TYPES)[number]) {
Expand Down Expand Up @@ -251,9 +249,9 @@ function parseInputName(input: string) {
}

function toSlug(list: string[]) {
return list.join('-').toLowerCase();
return list.join('-');
}

function toPascal(list: string[]) {
return list.map((p) => p[0].toUpperCase() + p.substring(1).toLowerCase()).join('');
return list.map((p) => p[0].toUpperCase() + p.substring(1)).join('');
}

0 comments on commit 80b4107

Please sign in to comment.