Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): casing for component and mdx route creation #5430

Merged
merged 1 commit into from
Nov 12, 2023
Merged
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
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('');
}
Loading