-
Notifications
You must be signed in to change notification settings - Fork 85
refactor(cli): only install and start project after all questions #77
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
Conversation
|
|
|
||
export async function initGitRepo(cwd: string, flags: CreateOptions) { | ||
let shouldInitGitRepo = flags.git ?? DEFAULT_VALUES.git; | ||
let shouldInitGitRepo = readFlag(flags, 'git'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created a small readFlag()
utility which returns the value of the flag, or if the flag doesn't have a value, it will return the default ONLY if flags.default
is true
. It makes the logic a bit easier because you know that if the value is undefined
, you can prompt the user for the question because it also means --defaults
was not provided.
applyAliases(flags); | ||
|
||
try { | ||
verifyFlags(flags); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not possible to do --start --no-install
. You can't start the project without installing the dependencies. If that happens, we throw. This method could have additional checks in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic here is extracted from dependencies.ts
.
import { DEFAULT_VALUES, readFlag, type CreateOptions } from './options.js'; | ||
import { assertNotCanceled } from '../../utils/tasks.js'; | ||
|
||
export async function installAndStart(flags: CreateOptions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function combines both the --install
and --start
flags.
} else { | ||
// the user explicitly wants to install the dependencies, but we don't know if they want to start the project | ||
const answer = await prompts.confirm({ | ||
message: 'Start project?', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If --install
is provided, but not --start
, we change the question to just Start project?
.
|
||
console.log('Until next time 👋'); | ||
// print the next steps without the install step in case we only install dependencies | ||
printNextSteps(dest, selectedPackageManager, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we install the dependencies, but we don't start the project, we still print the next steps without the install
step.
◆ Tutorial successfully created!
│
│ Next Steps
│
◇ 1. cd ./dry-king - Navigate to project
│
◇ 2. npm run dev - Start development server
│
◇ 3. Head over to http://localhost:4321
│
└ Please wait while we install the dependencies...
? 'Skipped dependency installation and project start' | ||
: 'Skipped dependency installation'; | ||
|
||
console.warn(`${warnLabel('DRY RUN')} ${message}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't do anything in case of a dry run.
◆ Tutorial successfully created!
│
└ Please wait while we install the dependencies and start your project...
DRY RUN Skipped dependency installation and project start
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 🎉
import { initGitRepo } from './git.js'; | ||
import { DEFAULT_VALUES, type CreateOptions } from './options.js'; | ||
import { setupEnterpriseConfig } from './enterprise.js'; | ||
import { copyTemplate } from './template.js'; | ||
import { selectPackageManager, type PackageManager } from './package-manager.js'; | ||
import { installAndStart } from './install-start.js'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Late to the party, but should we call the file install-and-start.js
?
This PR refactors the CLI (a bit).
Install dependencies and start project?
--start
flag so you could do--install --no-start
for instance.I'll add some additional comments in the code.