From 56dbc13577e62fe463db01dd5bb0b5d7b6ea53d2 Mon Sep 17 00:00:00 2001 From: Nurul Akbar Al-Ghifari Date: Sat, 13 Jul 2024 23:07:57 +0700 Subject: [PATCH] Refactor(Project-Scaffold): Change generator name for Next.js App --- .../src/generators/create-next-app/index.ts | 48 ------------------- .../src/generators/next-app-biome/index.ts | 13 +++++ .../src/generators/next-app-clean/index.ts | 13 +++++ .../index.ts | 4 +- .../templates/.eslintignore | 0 .../templates/.eslintrc.json | 0 .../templates/.husky/pre-commit | 0 .../templates/.lintstagedrc.json | 0 .../templates/.prettierignore | 0 .../templates/.prettierrc.json | 0 .../templates/.vscode/settings.json | 0 .../generators/next-app-structure/index.ts | 13 +++++ packages/project-scaffold/src/index.ts | 6 ++- 13 files changed, 45 insertions(+), 52 deletions(-) delete mode 100644 packages/project-scaffold/src/generators/create-next-app/index.ts create mode 100644 packages/project-scaffold/src/generators/next-app-biome/index.ts create mode 100644 packages/project-scaffold/src/generators/next-app-clean/index.ts rename packages/project-scaffold/src/generators/{setup-prettier-eslint => next-app-prettier-eslint}/index.ts (96%) rename packages/project-scaffold/src/generators/{setup-prettier-eslint => next-app-prettier-eslint}/templates/.eslintignore (100%) rename packages/project-scaffold/src/generators/{setup-prettier-eslint => next-app-prettier-eslint}/templates/.eslintrc.json (100%) rename packages/project-scaffold/src/generators/{setup-prettier-eslint => next-app-prettier-eslint}/templates/.husky/pre-commit (100%) rename packages/project-scaffold/src/generators/{setup-prettier-eslint => next-app-prettier-eslint}/templates/.lintstagedrc.json (100%) rename packages/project-scaffold/src/generators/{setup-prettier-eslint => next-app-prettier-eslint}/templates/.prettierignore (100%) rename packages/project-scaffold/src/generators/{setup-prettier-eslint => next-app-prettier-eslint}/templates/.prettierrc.json (100%) rename packages/project-scaffold/src/generators/{setup-prettier-eslint => next-app-prettier-eslint}/templates/.vscode/settings.json (100%) create mode 100644 packages/project-scaffold/src/generators/next-app-structure/index.ts diff --git a/packages/project-scaffold/src/generators/create-next-app/index.ts b/packages/project-scaffold/src/generators/create-next-app/index.ts deleted file mode 100644 index 0c79151..0000000 --- a/packages/project-scaffold/src/generators/create-next-app/index.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { type NodePlopAPI } from 'plop' -import { spawnSync } from 'node:child_process' - -export default function (plop: NodePlopAPI) { - plop.setActionType('next-app', (answers, _config, _plop) => { - const result = spawnSync('npx', [`create-next-app@${answers.version}`], { - stdio: 'inherit', - shell: true, - }) - - if (result.error) { - throw result.error - } - - return 'Next.js app created!' - }) - - plop.setGenerator('create-next-app', { - description: 'Create a new Next.js app', - prompts: [ - { - type: 'list', - name: 'version', - message: 'Which version of Next.js would you like to use?', - default: 'latest', - choices: [ - { - name: 'Latest', - value: 'latest', - }, - { - name: '14', - value: '14', - }, - { - name: '13', - value: '13', - }, - ], - }, - ], - actions: [ - { - type: 'next-app', - }, - ], - }) -} diff --git a/packages/project-scaffold/src/generators/next-app-biome/index.ts b/packages/project-scaffold/src/generators/next-app-biome/index.ts new file mode 100644 index 0000000..d1601ac --- /dev/null +++ b/packages/project-scaffold/src/generators/next-app-biome/index.ts @@ -0,0 +1,13 @@ +import { type NodePlopAPI } from 'plop' + +export interface TAnswers { + packageManager: 'npm' | 'pnpm' | 'bun' +} + +export default function (plop: NodePlopAPI) { + plop.setGenerator('next-app-biome', { + description: 'Setup Biome for Next.js App', + prompts: [], + actions: [], + }) +} diff --git a/packages/project-scaffold/src/generators/next-app-clean/index.ts b/packages/project-scaffold/src/generators/next-app-clean/index.ts new file mode 100644 index 0000000..97fee04 --- /dev/null +++ b/packages/project-scaffold/src/generators/next-app-clean/index.ts @@ -0,0 +1,13 @@ +import { type NodePlopAPI } from 'plop' + +export interface TAnswers { + packageManager: 'npm' | 'pnpm' | 'bun' +} + +export default function (plop: NodePlopAPI) { + plop.setGenerator('next-app-clean', { + description: 'Clean Next.js App from Create Next App', + prompts: [], + actions: [], + }) +} diff --git a/packages/project-scaffold/src/generators/setup-prettier-eslint/index.ts b/packages/project-scaffold/src/generators/next-app-prettier-eslint/index.ts similarity index 96% rename from packages/project-scaffold/src/generators/setup-prettier-eslint/index.ts rename to packages/project-scaffold/src/generators/next-app-prettier-eslint/index.ts index bebf3a4..45feec7 100644 --- a/packages/project-scaffold/src/generators/setup-prettier-eslint/index.ts +++ b/packages/project-scaffold/src/generators/next-app-prettier-eslint/index.ts @@ -50,8 +50,8 @@ export default function (plop: NodePlopAPI) { return 'Husky initialized successfully!' }) - plop.setGenerator('setup-prettier-eslint', { - description: 'Setup Prettier and ESLint for Next.js project', + plop.setGenerator('next-app-prettier-eslint', { + description: 'Setup Prettier and ESLint for Next.js App', prompts: [ { name: 'confirm', diff --git a/packages/project-scaffold/src/generators/setup-prettier-eslint/templates/.eslintignore b/packages/project-scaffold/src/generators/next-app-prettier-eslint/templates/.eslintignore similarity index 100% rename from packages/project-scaffold/src/generators/setup-prettier-eslint/templates/.eslintignore rename to packages/project-scaffold/src/generators/next-app-prettier-eslint/templates/.eslintignore diff --git a/packages/project-scaffold/src/generators/setup-prettier-eslint/templates/.eslintrc.json b/packages/project-scaffold/src/generators/next-app-prettier-eslint/templates/.eslintrc.json similarity index 100% rename from packages/project-scaffold/src/generators/setup-prettier-eslint/templates/.eslintrc.json rename to packages/project-scaffold/src/generators/next-app-prettier-eslint/templates/.eslintrc.json diff --git a/packages/project-scaffold/src/generators/setup-prettier-eslint/templates/.husky/pre-commit b/packages/project-scaffold/src/generators/next-app-prettier-eslint/templates/.husky/pre-commit similarity index 100% rename from packages/project-scaffold/src/generators/setup-prettier-eslint/templates/.husky/pre-commit rename to packages/project-scaffold/src/generators/next-app-prettier-eslint/templates/.husky/pre-commit diff --git a/packages/project-scaffold/src/generators/setup-prettier-eslint/templates/.lintstagedrc.json b/packages/project-scaffold/src/generators/next-app-prettier-eslint/templates/.lintstagedrc.json similarity index 100% rename from packages/project-scaffold/src/generators/setup-prettier-eslint/templates/.lintstagedrc.json rename to packages/project-scaffold/src/generators/next-app-prettier-eslint/templates/.lintstagedrc.json diff --git a/packages/project-scaffold/src/generators/setup-prettier-eslint/templates/.prettierignore b/packages/project-scaffold/src/generators/next-app-prettier-eslint/templates/.prettierignore similarity index 100% rename from packages/project-scaffold/src/generators/setup-prettier-eslint/templates/.prettierignore rename to packages/project-scaffold/src/generators/next-app-prettier-eslint/templates/.prettierignore diff --git a/packages/project-scaffold/src/generators/setup-prettier-eslint/templates/.prettierrc.json b/packages/project-scaffold/src/generators/next-app-prettier-eslint/templates/.prettierrc.json similarity index 100% rename from packages/project-scaffold/src/generators/setup-prettier-eslint/templates/.prettierrc.json rename to packages/project-scaffold/src/generators/next-app-prettier-eslint/templates/.prettierrc.json diff --git a/packages/project-scaffold/src/generators/setup-prettier-eslint/templates/.vscode/settings.json b/packages/project-scaffold/src/generators/next-app-prettier-eslint/templates/.vscode/settings.json similarity index 100% rename from packages/project-scaffold/src/generators/setup-prettier-eslint/templates/.vscode/settings.json rename to packages/project-scaffold/src/generators/next-app-prettier-eslint/templates/.vscode/settings.json diff --git a/packages/project-scaffold/src/generators/next-app-structure/index.ts b/packages/project-scaffold/src/generators/next-app-structure/index.ts new file mode 100644 index 0000000..8fd135a --- /dev/null +++ b/packages/project-scaffold/src/generators/next-app-structure/index.ts @@ -0,0 +1,13 @@ +import { type NodePlopAPI } from 'plop' + +export interface TAnswers { + packageManager: 'npm' | 'pnpm' | 'bun' +} + +export default function (plop: NodePlopAPI) { + plop.setGenerator('next-app-structure', { + description: 'Setup Folder Structure for Next.js App (App Router)', + prompts: [], + actions: [], + }) +} diff --git a/packages/project-scaffold/src/index.ts b/packages/project-scaffold/src/index.ts index 288da3e..115629e 100644 --- a/packages/project-scaffold/src/index.ts +++ b/packages/project-scaffold/src/index.ts @@ -1,6 +1,8 @@ import { type NodePlopAPI } from 'plop' export default async function (plop: NodePlopAPI) { - await plop.load('./generators/create-next-app', {}, true) - await plop.load('./generators/setup-prettier-eslint', {}, true) + await plop.load('./generators/next-app-clean', {}, true) + await plop.load('./generators/next-app-structure', {}, true) + await plop.load('./generators/next-app-prettier-eslint', {}, true) + await plop.load('./generators/next-app-biome', {}, true) }