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 all commits
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
10 changes: 1 addition & 9 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,12 @@
"moduleDirectory": ["node_modules", "src/"]
}
},
"react": {
"version": "detect"
},
"ecmaFeatures": {
"jsx": true
}
},
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
Expand All @@ -41,12 +37,8 @@
"ecmaVersion": 11,
"sourceType": "module"
},
"plugins": ["import", "react", "react-hooks", "@typescript-eslint"],
"plugins": ["import", "@typescript-eslint"],
"rules": {
"react-hooks/rules-of-hooks": "error",
"react-hooks/exhaustive-deps": "warn",
"react/prop-types": "off",
"react/react-in-jsx-scope": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"import/order": [
"warn",
Expand Down
6 changes: 3 additions & 3 deletions lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ npm init eruption@latest -- --name my-project --kit core --yes
| Name | Description | Repository |
| ---- | -------------------------------------- | ---------------------------------- |
| core | The core kit (React, Vite and Vitest). | https://github.com/eruptionjs/core |
| react-full | The full kit (React, Vite, Vitest, Mantine, React Router, Zustand, React Hook Form, Axios, and more). | https://github.com/eruptionjs/react-full |
| react-lib | The library kit (React, Vite, Vitest, TypeScript). | https://github.com/eruptionjs/react-lib |

## CLI Flags

Expand All @@ -41,9 +43,7 @@ npm init eruption@latest -- --name my-project --kit core --yes
| `--yes` | Whether to skip the confirm prompt. | `false` |
| `--git` | Whether to initialize a git repository. | `true` |
| `--vscode` | Whether to include or not .vscode folder | `true` |
| `--docker` | Whether to include or not docker support | `false` |
| `--pm` | The package manager to use. | `npm` |

## License

MIT
MIT @ EruptionJS and it's contributors.
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
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-eruption",
"version": "0.5.1",
"version": "0.6.0",
"description": "The Eruption CLI 🌋",
"license": "MIT",
"author": "Raí Siqueira <[email protected]>",
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
1 change: 1 addition & 0 deletions lib/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export async function fileExists(path: string) {
await fs.stat(path);
return true;
} catch (error: unknown) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if ((error as any).code === 'ENOENT') {
return false;
} else {
Expand Down
48 changes: 23 additions & 25 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,29 @@
"description": "PNPM monorepo template",
"license": "MIT",
"devDependencies": {
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.0",
"@commitlint/config-conventional": "^17.4.0",
"@size-limit/preset-small-lib": "^8.2.4",
"@types/node": "^18.11.18",
"@typescript-eslint/eslint-plugin": "^5.48.0",
"@typescript-eslint/parser": "^5.48.0",
"commitlint": "^17.4.0",
"eslint": "^8.31.0",
"eslint-config-prettier": "^8.6.0",
"eslint-import-resolver-typescript": "^3.5.2",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.31.11",
"eslint-plugin-react-hooks": "^4.6.0",
"husky": "^8.0.3",
"lint-staged": "^13.1.0",
"prettier": "^2.8.2",
"size-limit": "^8.2.4",
"size-limit-node-esbuild": "^0.2.0",
"tsup": "^7.1.0",
"turbo": "^1.6.3",
"typescript": "^4.9.4",
"vite": "^3.2.5",
"vitest": "^0.24.5"
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@commitlint/config-conventional": "^19.1.0",
"@size-limit/preset-small-lib": "^11.1.2",
"@types/node": "^20.12.7",
"@typescript-eslint/eslint-plugin": "^7.6.0",
"@typescript-eslint/parser": "^7.6.0",
"commitlint": "^19.2.1",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^5.1.3",
"husky": "^9.0.11",
"lint-staged": "^15.2.2",
"prettier": "^3.2.5",
"size-limit": "^11.1.2",
"size-limit-node-esbuild": "^0.3.0",
"tsup": "^8.0.2",
"turbo": "^1.13.2",
"typescript": "^5.4.5",
"vite": "^5.2.8",
"vitest": "^1.5.0"
},
"size-limit": [
{
Expand Down
Loading
Loading