Skip to content

Commit

Permalink
Add templatePositional argument
Browse files Browse the repository at this point in the history
Replace `p.log.info` with `p.note`
Fix awful error messages
  • Loading branch information
Tommypop2 committed Apr 14, 2024
1 parent b1f69dd commit 3451177
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
33 changes: 23 additions & 10 deletions packages/commands/src/handlers/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ const startSupported = [
const localSupported = ["ts", "js"] as const;
const stackblitzSupported = ["bare"] as const;

type AllSupported = (typeof localSupported)[number] | (typeof stackblitzSupported)[number];

export type AllSupported = (typeof localSupported)[number] | (typeof stackblitzSupported)[number];
export const isSupported = (template: string): template is AllSupported => {
return localSupported.indexOf(template as any) !== -1;
};
const modifyReadme = async (name: string) => {
await insertAtEnd(
`${name}/README.md`,
Expand Down Expand Up @@ -162,10 +164,12 @@ const handleNewStartProject = async (projectName: string, variation?: AllSupport
writeFileSync(join(projectName, ".gitignore"), gitIgnore);
if (!readmeAlreadyExists) await modifyReadme(projectName);
const pM = detectPackageManager();
p.log.info(`${t.GET_STARTED}
- cd ${projectName}
- ${pM.name} install
- ${pM.name} ${pM.runScriptCommand("dev")}`);
p.note(
`cd ${projectName}
${pM.name} install
${pM.name} ${pM.runScriptCommand("dev")}`,
t.GET_STARTED,
);
};

const handleAutocompleteNew = async (name: string, isStart?: boolean) => {
Expand Down Expand Up @@ -195,6 +199,13 @@ export const handleNew = async (
name ??= await cancelable(
p.text({ message: t.PROJECT_NAME, placeholder: "solid-project", defaultValue: "solid-project" }),
);
await spinnerify({
startText: "This will break",
finishText: "Should've broken",
fn: async () => {
throw new Error("Very broken");
},
});

if (!variation) {
await handleAutocompleteNew(name, isStart);
Expand Down Expand Up @@ -230,8 +241,10 @@ export const handleNew = async (
writeFileSync(join(name, ".gitignore"), gitIgnore);
if (!readmeAlreadyExists) await modifyReadme(name ?? variation);
const pM = detectPackageManager();
p.log.info(`${t.GET_STARTED}
- cd ${name}
- ${pM.name} install
- ${pM.name} ${pM.runScriptCommand("dev")}`);
p.note(
`cd ${name}
${pM.name} install
${pM.name} ${pM.runScriptCommand("dev")}`,
t.GET_STARTED,
);
};
25 changes: 22 additions & 3 deletions packages/create-solid/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#! /usr/bin/env node
import { handleNew } from "@solid-cli/commands/new";
import { AllSupported, handleNew, isSupported } from "@solid-cli/commands/new";
import color from "picocolors";
import { intro } from "@clack/prompts";
import { version } from "../package.json";
Expand All @@ -16,6 +16,11 @@ const app = command({
displayName: "Project Name",
description: "The name of the project to be generated",
}),
templatePositional: positional({
type: optional(string),
displayName: "Template name",
description: "Name of template to be initialised",
}),
projectNameOption: option({
type: optional(string),
long: "project-name",
Expand All @@ -29,8 +34,22 @@ const app = command({
description: "Create a SolidStart project",
}),
},
handler: async ({ projectNameOption, solidStart, projectNamePositional }) => {
await handleNew(undefined, projectNamePositional ?? projectNameOption, false, solidStart);
handler: async ({ projectNameOption, solidStart, projectNamePositional, templatePositional }) => {
if (templatePositional && !isSupported(templatePositional)) {
console.error(`Template "${templatePositional}" is not supported`);
process.exit(0);
}
try {
await handleNew(
templatePositional as AllSupported,
projectNamePositional ?? projectNameOption,
false,
solidStart,
);
} catch (e) {
console.error(e);
process.exit(1);
}
},
});
run(app, process.argv.slice(2));

0 comments on commit 3451177

Please sign in to comment.