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

feat: update the CLI to support the new versions and packages #17

Merged
merged 5 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: update the CLI to consider the new packages, also consider Bun …
…as pkg manager

Signed-off-by: Rai Siqueira <[email protected]>
  • Loading branch information
raisiqueira committed Apr 11, 2024
commit 314ac5aec5b570122f37ed59714dc3e6b3f0ca74
15 changes: 0 additions & 15 deletions lib/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ describe('eruption-cli', () => {
// Simulate the user pressing the down arrow key and then the enter key. (We're removing vscode folder)
userEvent.keyboard(`${CLIUserEvents.ArrowDown}${CLIUserEvents.Enter}`);

const docker = await findByText(/Do you want to include Docker support?/i);
expect(docker).toBeTruthy();
// Simulate the user pressing the enter key. By default we aren't including docker support.
userEvent.keyboard(`${CLIUserEvents.Enter}`);

const packageManager = await findByText(/Select your package manager/i);
expect(packageManager).toBeTruthy();
// Simulate the user pressing the down arrow key and then the enter key. (For now, we are selecting yarn)
userEvent.keyboard(`${CLIUserEvents.ArrowDown}${CLIUserEvents.Enter}`);

// Simulate the user pressing the down arrow key and then the enter key. (For now, we are selecting the core kit)
const confirm = await findByText(/Do you want to continue/i);
expect(confirm).toBeTruthy();
Expand Down Expand Up @@ -79,11 +69,6 @@ describe('eruption-cli', () => {
// Simulate the user pressing the down arrow key and then the enter key. (We're removing vscode folder)
userEvent.keyboard(`${CLIUserEvents.ArrowDown}${CLIUserEvents.Enter}`);

const docker = await findByText(/Do you want to include Docker support?/i);
expect(docker).toBeTruthy();
// Simulate the user pressing the enter key. By default we aren't including docker support.
userEvent.keyboard(`${CLIUserEvents.Enter}`);

const packageManager = await findByText(/Select your package manager/i);
expect(packageManager).toBeTruthy();
// Simulate the user pressing the down arrow key and then the enter key. (For now, we are selecting yarn)
Expand Down
5 changes: 5 additions & 0 deletions lib/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ export const AVAILABLE_KITS: Kit[] = [
value: 'core',
hint: 'The core kit for Eruption',
},
{
label: "React Full (React, Vite, Vitest, React Router, Mantine and more)",
value: 'react-full',
hint: 'An opinionated React setup with Vite, Vitest, React Router and more',
}
];

/**
Expand Down
58 changes: 3 additions & 55 deletions lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@ import path from 'path';
import parser from 'yargs-parser';

import { AVAILABLE_KITS, AVAILABLE_LIBRARIES } from './constants';
import { PackageManagers } from './types';
import {
handleCancelation,
getKitFromGitHub,
initGitRepo as initializeGit,
initNodeProject,
removeFolder,
removeFile,
getPmInstallCommands,
} from './utils';

export async function main() {
const cleanArgv = process.argv.filter((arg) => arg !== '--');
const args = parser(cleanArgv, {
string: ['name', 'kit', 'pm'], // --pm is the package manager. E.g: --pm yarn
string: ['name', 'kit'],
boolean: ['git', 'yes', 'vscode'],
default: {
git: true,
Expand Down Expand Up @@ -88,42 +86,6 @@ export async function main() {

handleCancelation(useVscode);

let dockerSupport = false;
if (flavor === 'application') {
dockerSupport =
'docker' in args
? args.vscode
: await confirm({
message: 'Do you want to include Docker support?',
initialValue: false,
});
}

// NPM will be the default package manager.
const packageManager: PackageManagers = args.pm
? args.pm
: await select({
message: 'Select your package manager',
options: [
{
value: 'npm',
label: 'NPM',
hint: 'Default package manager',
},
{
value: 'yarn',
label: 'Yarn',
},
{
value: 'pnpm',
label: 'PNPM',
},
],
});

// If the user cancel the package manager selection, we will use NPM as default.
handleCancelation(packageManager);

const install =
'yes' in args
? args.yes
Expand Down Expand Up @@ -152,15 +114,6 @@ export async function main() {
await removeFolder('.vscode', destPath);
}

if (!dockerSupport) {
const destPath = path.join(process.cwd(), projectName as string);
await removeFile('.dockerignore', destPath);
await removeFile('Dockerfile', destPath);
await removeFile('dockerfile.dev', destPath);
await removeFile('docker-compose-dev.yml', destPath);
await removeFile('docker-compose.yml', destPath);
}

if (initGitRepo) {
const projectFolder = path.join(process.cwd(), projectName as string);
try {
Expand All @@ -171,14 +124,9 @@ export async function main() {
}
}

if (packageManager !== 'npm') {
const destPath = path.join(process.cwd(), projectName as string);
await removeFile('package-lock.json', destPath);
}

const nextSteps = `cd ${projectName as string} \n${
install ? `${green(getPmInstallCommands(packageManager))} to install the dependencies\n` : ''
}and ${green(`${packageManager} run dev`)} to start the development server`;
install ? `${green(getPmInstallCommands("bun"))} to install the dependencies\n` : ''
}and ${green(`bun dev`)} to start the development server`;

note(nextSteps, 'Next steps:');

Expand Down