Skip to content

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

Merged
merged 4 commits into from
Jun 19, 2024

Conversation

SamVerschueren
Copy link
Contributor

This PR refactors the CLI (a bit).

  • It will now always ask which package manager to use.
  • The last question has now changed to Install dependencies and start project?
  • Added a new --start flag so you could do --install --no-start for instance.

I'll add some additional comments in the code.

@SamVerschueren SamVerschueren requested review from Nemikolh and d3lm June 19, 2024 10:29
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

changeset-bot bot commented Jun 19, 2024

⚠️ No Changeset found

Latest commit: 9843bea

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR


export async function initGitRepo(cwd: string, flags: CreateOptions) {
let shouldInitGitRepo = flags.git ?? DEFAULT_VALUES.git;
let shouldInitGitRepo = readFlag(flags, 'git');
Copy link
Contributor Author

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);
Copy link
Contributor Author

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.

Copy link
Contributor Author

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) {
Copy link
Contributor Author

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?',
Copy link
Contributor Author

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);
Copy link
Contributor Author

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}`);
Copy link
Contributor Author

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

Copy link
Member

@Nemikolh Nemikolh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 🎉

@Nemikolh Nemikolh merged commit c1be8fe into main Jun 19, 2024
6 checks passed
@Nemikolh Nemikolh deleted the refactor/cli branch June 19, 2024 15:07
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';
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants