-
Notifications
You must be signed in to change notification settings - Fork 18
feat: updating CLI options #1280
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
Changes from all commits
9244924
ff40f55
8404bb0
0f7bda9
7159100
edda4b0
5476232
43f528e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,13 @@ import { trackSelectedKit } from './metrics'; | |
| const STARTER_KITS_JSON_URL = 'https://raw.githubusercontent.com/thisdot/starter.dev/main/starter-kits.json'; | ||
| const EXCLUDED_PACKAGE_JSON_FIELDS = ['hasShowcase']; | ||
|
|
||
| type Package = { | ||
| scripts: { | ||
| dev: string; | ||
| start: string; | ||
| }; | ||
| }; | ||
|
|
||
| export async function main() { | ||
| console.log(`\n${bold('Welcome to starter.dev!')} ${gray('(create-starter)')}`); | ||
|
|
||
|
|
@@ -55,11 +62,21 @@ export async function main() { | |
| }, | ||
| ]); | ||
|
|
||
| if (!options.kit || !options.name) { | ||
| const packageOptions = await prompts([ | ||
| { | ||
| type: 'autocomplete', | ||
| name: 'packageManager', | ||
| message: 'Which package manager would you like to use?', | ||
| choices: packageSelection(options.kit).map((pm) => ({ title: pm, value: pm })), | ||
| suggest: (input, choices) => Promise.resolve(choices.filter((c) => c.title.includes(input))), | ||
| }, | ||
| ]); | ||
|
|
||
| if (!options.kit || !options.name || !packageOptions) { | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const [createSelectedKitResult] = await Promise.allSettled([createStarter(options), trackSelectedKit(options.kit)]); | ||
| const [createSelectedKitResult] = await Promise.allSettled([createStarter(options, packageOptions), trackSelectedKit(options.kit)]); | ||
|
|
||
| if (createSelectedKitResult.status === 'rejected') { | ||
| const err = createSelectedKitResult.reason; | ||
|
|
@@ -68,9 +85,23 @@ export async function main() { | |
| } | ||
| } | ||
|
|
||
| async function createStarter(options: prompts.Answers<'name' | 'kit'>): Promise<void> { | ||
| function packageSelection(selection: string): Array<string> { | ||
| let packageOptions; | ||
| switch (selection) { | ||
| case 'deno-oak-denodb': | ||
| packageOptions = ['deno']; | ||
| break; | ||
| default: | ||
| packageOptions = ['npm', 'pnpm', 'yarn']; | ||
| } | ||
| return packageOptions; | ||
| } | ||
|
|
||
| async function createStarter(options: prompts.Answers<'name' | 'kit'>, packageOptions: prompts.Answers<'packageManager'>): Promise<void> { | ||
| const repoPath = `thisdot/starter.dev/starters/${options.kit}`; | ||
| const destPath = path.join(process.cwd(), options.name); | ||
| const packageManager = packageOptions.packageManager; | ||
| const kit = options.kit; | ||
|
|
||
| const emitter = degit(repoPath, { | ||
| cache: false, | ||
|
|
@@ -98,13 +129,32 @@ async function createStarter(options: prompts.Answers<'name' | 'kit'>): Promise< | |
| await initNodeProject(packageJsonPath, destPath, options); | ||
| } | ||
|
|
||
| await initGitRepo(destPath); | ||
| const packageCommand = `https://raw.githubusercontent.com/thisdot/starter.dev/main/starters/${kit}/${packageManager === 'deno' ? 'deno' : 'package'}.json`; | ||
| const res = await fetch(packageCommand); | ||
| let packageJSON: Package; | ||
|
|
||
| if (res.ok) { | ||
| packageJSON = (await res.json()) as Package; | ||
| } else { | ||
| throw new Error(); | ||
| } | ||
|
|
||
| const startAction = packageJSON?.scripts?.dev !== undefined ? 'dev' : 'start'; | ||
|
|
||
| await initGitRepo(destPath, packageManager); | ||
| console.log(bold(green('✔') + ' Done!')); | ||
| console.log('\nNext steps:'); | ||
| console.log(` ${bold(cyan(`cd ${options.name}`))}`); | ||
|
Comment on lines
146
to
147
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think Dustin wanted to update the language here to be this based on the slack thread disucssion: oh update next steps to say "npm start" (or equivalent based on package manager selected" instead of "npm install" I double check with him on that.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the kit is created we would still be outside of the newly created directory though and would still need to cd into it. |
||
|
|
||
| if (packageJsonExists) { | ||
| console.log(` ${bold(cyan('npm install'))} (or pnpm install, yarn, etc)`); | ||
| console.log(` ${bold(cyan(`${packageManager} ${startAction}`))}`); | ||
| } else if (packageManager === 'deno') { | ||
| console.log(` ${bold(cyan('Make sure you have Docker & docker-compose installed on your machine'))}`); | ||
| console.log(` ${bold(cyan('Create a .env file and copy the contents of .env.example into it'))}`); | ||
| console.log(` ${bold(cyan('Run deno task start-db to start the local PostgreSQL and Redis'))}`); | ||
| console.log(` ${bold(cyan('Run deno task start-web to start the development server'))}`); | ||
| console.log(` ${bold(cyan('Open your browser to http://localhost:3333/health to see the API running'))}`); | ||
| console.log(` ${bold(cyan('Proceed to the Seeding chapter to seed the database with some sample data'))}`); | ||
| } | ||
| } catch (err: unknown) { | ||
| throw new Error('Failed to initialize the starter kit. This probably means that you provided an invalid kit name.'); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.