From 2693d5adf0dafecc1c8e63e0c95c8d19cc4586c1 Mon Sep 17 00:00:00 2001 From: choi1five Date: Wed, 26 Feb 2025 23:33:53 +0900 Subject: [PATCH 1/6] =?UTF-8?q?chore:=20@turbo/gen=20=EC=84=A4=EC=B9=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + pnpm-lock.yaml | 68 +++++++++++++++++++++++++++++++++++ turbo/generators/package.json | 3 ++ 3 files changed, 72 insertions(+) create mode 100644 turbo/generators/package.json diff --git a/package.json b/package.json index 3949c50..1809ef9 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "lint-staged": "lint-staged" }, "devDependencies": { + "@turbo/gen": "^2.2.3", "@workspace/eslint-config": "workspace:*", "@workspace/typescript-config": "workspace:*", "husky": "^9.0.11", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0afe5dc..f535b32 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ importers: .: devDependencies: + '@turbo/gen': + specifier: ^2.2.3 + version: 2.3.3(@types/node@22.10.2)(typescript@5.5.4) '@workspace/eslint-config': specifier: workspace:* version: link:packages/eslint-config @@ -182,6 +185,33 @@ importers: specifier: ^8.15.0 version: 8.18.1(eslint@9.17.0(jiti@1.21.6))(typescript@5.7.2) + packages/test: + devDependencies: + '@types/react': + specifier: 18.3.0 + version: 18.3.0 + '@types/react-dom': + specifier: 18.3.1 + version: 18.3.1 + '@workspace/build-config': + specifier: workspace:* + version: link:../build-config + '@workspace/eslint-config': + specifier: workspace:* + version: link:../eslint-config + '@workspace/typescript-config': + specifier: workspace:* + version: link:../typescript-config + react: + specifier: ^19.0.0 + version: 19.0.0 + react-dom: + specifier: ^19.0.0 + version: 19.0.0(react@19.0.0) + typescript: + specifier: ^5.6.3 + version: 5.7.2 + packages/typescript-config: {} packages/ui: @@ -4745,6 +4775,26 @@ snapshots: '@tsconfig/node16@1.0.4': {} + '@turbo/gen@2.3.3(@types/node@22.10.2)(typescript@5.5.4)': + dependencies: + '@turbo/workspaces': 2.3.3 + commander: 10.0.1 + fs-extra: 10.1.0 + inquirer: 8.2.6 + minimatch: 9.0.5 + node-plop: 0.26.3 + picocolors: 1.0.1 + proxy-agent: 6.5.0 + ts-node: 10.9.2(@types/node@22.10.2)(typescript@5.5.4) + update-check: 1.5.4 + validate-npm-package-name: 5.0.1 + transitivePeerDependencies: + - '@swc/core' + - '@swc/wasm' + - '@types/node' + - supports-color + - typescript + '@turbo/gen@2.3.3(@types/node@22.10.2)(typescript@5.7.2)': dependencies: '@turbo/workspaces': 2.3.3 @@ -7800,6 +7850,24 @@ snapshots: yn: 3.1.1 optional: true + ts-node@10.9.2(@types/node@22.10.2)(typescript@5.5.4): + dependencies: + '@cspotcode/source-map-support': 0.8.1 + '@tsconfig/node10': 1.0.11 + '@tsconfig/node12': 1.0.11 + '@tsconfig/node14': 1.0.3 + '@tsconfig/node16': 1.0.4 + '@types/node': 22.10.2 + acorn: 8.14.0 + acorn-walk: 8.3.4 + arg: 4.1.3 + create-require: 1.1.1 + diff: 4.0.2 + make-error: 1.3.6 + typescript: 5.5.4 + v8-compile-cache-lib: 3.0.1 + yn: 3.1.1 + ts-node@10.9.2(@types/node@22.10.2)(typescript@5.7.2): dependencies: '@cspotcode/source-map-support': 0.8.1 diff --git a/turbo/generators/package.json b/turbo/generators/package.json new file mode 100644 index 0000000..5bbefff --- /dev/null +++ b/turbo/generators/package.json @@ -0,0 +1,3 @@ +{ + "type": "commonjs" +} From 3564d3e69efacda39fbf7857e8aa4a670c6091a8 Mon Sep 17 00:00:00 2001 From: choi1five Date: Wed, 26 Feb 2025 23:34:22 +0900 Subject: [PATCH 2/6] =?UTF-8?q?chore:=20=ED=85=9C=ED=94=8C=EB=A6=BF=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC(.hbs)=20prettierignore=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .prettierignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .prettierignore diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..7cd88a8 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +turbo/**/*.hbs \ No newline at end of file From a02b285fe51f768dd7ff230c1d93f2d0230b56f8 Mon Sep 17 00:00:00 2001 From: choi1five Date: Wed, 26 Feb 2025 23:36:28 +0900 Subject: [PATCH 3/6] =?UTF-8?q?chore:=20=EC=9D=BC=EB=B0=98=20=ED=8C=A8?= =?UTF-8?q?=ED=82=A4=EC=A7=80=20=ED=85=9C=ED=94=8C=EB=A6=BF=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- turbo/generators/templates/build.js.hbs | 5 ++++ .../generators/templates/eslint.config.js.hbs | 4 ++++ turbo/generators/templates/package.json.hbs | 24 +++++++++++++++++++ turbo/generators/templates/src/index.ts.hbs | 1 + turbo/generators/templates/tsconfig.json.hbs | 12 ++++++++++ 5 files changed, 46 insertions(+) create mode 100644 turbo/generators/templates/build.js.hbs create mode 100644 turbo/generators/templates/eslint.config.js.hbs create mode 100644 turbo/generators/templates/package.json.hbs create mode 100644 turbo/generators/templates/src/index.ts.hbs create mode 100644 turbo/generators/templates/tsconfig.json.hbs diff --git a/turbo/generators/templates/build.js.hbs b/turbo/generators/templates/build.js.hbs new file mode 100644 index 0000000..fff58ef --- /dev/null +++ b/turbo/generators/templates/build.js.hbs @@ -0,0 +1,5 @@ +import {run} from '@workspace/build-config'; + +import pkg from './package.json' assert { type: 'json' }; + +run({ pkg }); diff --git a/turbo/generators/templates/eslint.config.js.hbs b/turbo/generators/templates/eslint.config.js.hbs new file mode 100644 index 0000000..6ca7bdb --- /dev/null +++ b/turbo/generators/templates/eslint.config.js.hbs @@ -0,0 +1,4 @@ +import { config } from '@nettee-sample/eslint-config/base'; + +/** @type {import("eslint").Linter.Config} */ +export default config; \ No newline at end of file diff --git a/turbo/generators/templates/package.json.hbs b/turbo/generators/templates/package.json.hbs new file mode 100644 index 0000000..a584469 --- /dev/null +++ b/turbo/generators/templates/package.json.hbs @@ -0,0 +1,24 @@ +{ + "name": "@workspace/{{name}}", + "version": "0.0.1", + "type": "module", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js", + "require": "./dist/index.cjs" + } + }, + "main": "dist/index.js", + "types": "dist/index.d.ts", + "scripts": { + "build": "node build.js", + "dev": "node build.js --watch" + }, + "devDependencies": { + "@workspace/build-config": "workspace:*", + "@workspace/eslint-config": "workspace:*", + "@workspace/typescript-config": "workspace:*", + "typescript": "^5.6.3" + } +} diff --git a/turbo/generators/templates/src/index.ts.hbs b/turbo/generators/templates/src/index.ts.hbs new file mode 100644 index 0000000..4da7ae4 --- /dev/null +++ b/turbo/generators/templates/src/index.ts.hbs @@ -0,0 +1 @@ +//package \ No newline at end of file diff --git a/turbo/generators/templates/tsconfig.json.hbs b/turbo/generators/templates/tsconfig.json.hbs new file mode 100644 index 0000000..a9a0960 --- /dev/null +++ b/turbo/generators/templates/tsconfig.json.hbs @@ -0,0 +1,12 @@ +{ + "extends": "@workspace/typescript-config/base.json", + "compilerOptions": { + "baseUrl": ".", + "paths": { + "@/*": ["./src/*"] + }, + "module": "ESNext", + "moduleResolution": "Bundler" + }, + "exclude": ["node_modules", "dist"] +} \ No newline at end of file From ac94d7deefd806c3c8fcf123f4ce12083e9fb32d Mon Sep 17 00:00:00 2001 From: choi1five Date: Wed, 26 Feb 2025 23:36:48 +0900 Subject: [PATCH 4/6] =?UTF-8?q?chore:=20react=20=ED=8C=A8=ED=82=A4?= =?UTF-8?q?=EC=A7=80=20=ED=85=9C=ED=94=8C=EB=A6=BF=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/react/eslint.config.js.hbs | 4 +++ .../templates/react/package.json.hbs | 32 +++++++++++++++++++ .../templates/react/tsconfig.json.hbs | 12 +++++++ 3 files changed, 48 insertions(+) create mode 100644 turbo/generators/templates/react/eslint.config.js.hbs create mode 100644 turbo/generators/templates/react/package.json.hbs create mode 100644 turbo/generators/templates/react/tsconfig.json.hbs diff --git a/turbo/generators/templates/react/eslint.config.js.hbs b/turbo/generators/templates/react/eslint.config.js.hbs new file mode 100644 index 0000000..0303990 --- /dev/null +++ b/turbo/generators/templates/react/eslint.config.js.hbs @@ -0,0 +1,4 @@ +import { config } from '@nettee-sample/eslint-config/react-internal'; + +/** @type {import("eslint").Linter.Config} */ +export default config; diff --git a/turbo/generators/templates/react/package.json.hbs b/turbo/generators/templates/react/package.json.hbs new file mode 100644 index 0000000..c14d78c --- /dev/null +++ b/turbo/generators/templates/react/package.json.hbs @@ -0,0 +1,32 @@ +{ + "name": "@workspace/{{name}}", + "version": "0.0.1", + "type": "module", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "import": "./dist/index.js", + "require": "./dist/index.cjs" + } + }, + "main": "dist/index.js", + "types": "dist/index.d.ts", + "scripts": { + "build": "node build.js", + "dev": "node build.js --watch" + }, + "devDependencies": { + "@workspace/build-config": "workspace:*", + "@workspace/eslint-config": "workspace:*", + "@workspace/typescript-config": "workspace:*", + "@types/react": "18.3.0", + "@types/react-dom": "18.3.1", + "react": "^19.0.0", + "react-dom": "^19.0.0", + "typescript": "^5.6.3" + }, + "peerDependencies": { + "react": ">=19.0.0", + "react-dom": ">=19.0.0" + } +} diff --git a/turbo/generators/templates/react/tsconfig.json.hbs b/turbo/generators/templates/react/tsconfig.json.hbs new file mode 100644 index 0000000..8142ace --- /dev/null +++ b/turbo/generators/templates/react/tsconfig.json.hbs @@ -0,0 +1,12 @@ +{ + "extends": "@workspace/typescript-config/react-library.json", + "compilerOptions": { + "baseUrl": ".", + "paths": { + "@/*": ["./src/*"] + }, + "module": "ESNext", + "moduleResolution": "Bundler" + }, + "exclude": ["node_modules", "dist"] +} From 254e40ea9f206cb2089121590acd4b725619cd63 Mon Sep 17 00:00:00 2001 From: choi1five Date: Wed, 26 Feb 2025 23:42:50 +0900 Subject: [PATCH 5/6] =?UTF-8?q?feat:=20code=20gen=20config=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- turbo/generators/config.ts | 109 +++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 turbo/generators/config.ts diff --git a/turbo/generators/config.ts b/turbo/generators/config.ts new file mode 100644 index 0000000..5f5e42c --- /dev/null +++ b/turbo/generators/config.ts @@ -0,0 +1,109 @@ +/* eslint-disable import/no-default-export */ +import type { PlopTypes } from '@turbo/gen'; +import { execSync } from 'child_process'; +import fs from 'fs'; +import path from 'path'; + +export default function generator(plop: PlopTypes.NodePlopAPI) { + plop.setActionType('postInstall', () => { + try { + execSync('pnpm install', { stdio: 'inherit' }); + + return '✅ pnpm install 완료'; + } catch (error) { + console.error('❌ pnpm install 실행 중 오류 발생:', error); + return '❌ pnpm install 실행 실패'; + } + }); + + plop.setGenerator('package', { + description: 'packages 폴더 내부에 package를 생성합니다.', + prompts: [ + { + type: 'input', + name: 'packageName', + message: '패키지 이름 입력 >', + validate: (input) => { + const kebabCaseRegex = /^[a-z]+(-[a-z]+)*$/; + if (!kebabCaseRegex.test(input)) { + return '패키지명은 kebab-case로 작성해주세요.'; + } + + const packagePath = path.join(process.cwd(), 'packages', input); + if (fs.existsSync(packagePath)) { + return '이미 존재하는 패키지 이름입니다. 다른 이름을 입력해주세요.'; + } + + return true; + }, + }, + { + type: 'list', + name: 'packageType', + message: '패키지 유형을 선택해주세요 >', + choices: [ + { name: '일반 패키지', value: 'regular' }, + { name: 'React 패키지', value: 'react' }, + ], + default: 'regular', + }, + ], + actions: (data) => { + const actions = []; + const { packageType } = data as { packageType: 'regular' | 'react' }; + + const pathPrefix = + packageType === 'react' ? './templates/react' : './templates'; + + // 1. package.json 생성 + actions.push({ + type: 'add', + path: 'packages/{{packageName}}/package.json', + templateFile: `${pathPrefix}/package.json.hbs`, + }); + + // 2. tsconfig.json 생성 + actions.push({ + type: 'add', + path: 'packages/{{packageName}}/tsconfig.json', + templateFile: `${pathPrefix}/tsconfig.json.hbs`, + }); + + // 3. esliont.config.js 생성 + actions.push({ + type: 'add', + path: 'packages/{{packageName}}/eslint.config.js', + templateFile: `${pathPrefix}/eslint.config.js.hbs`, + }); + + // 4. build.js 생성 + actions.push({ + type: 'add', + path: 'packages/{{packageName}}/build.js', + templateFile: './templates/build.js.hbs', + }); + + // 5. src 디렉토리 및 기본 파일 생성 + actions.push({ + type: 'add', + path: 'packages/{{packageName}}/src/index.ts', + templateFile: './templates/src/index.ts.hbs', + }); + + // 6. package.json 이름 업데이트 + actions.push({ + type: 'modify', + path: 'packages/{{packageName}}/package.json', + pattern: /"name": ".*"/, + template: '"name": "@workspace/{{packageName}}"', + }); + + // 7. pnpm install 실행 + actions.push({ + type: 'postInstall', + }); + + return actions; + }, + }); +} From 5f8133631469921b5ff631228b8dc63a7404bbaa Mon Sep 17 00:00:00 2001 From: choi1five Date: Thu, 27 Feb 2025 23:28:05 +0900 Subject: [PATCH 6/6] =?UTF-8?q?docs:=20README=EC=97=90=20turbo=20gen=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9=EB=B2=95=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 82 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 68 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index b907dd6..02dbc51 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,85 @@ -# shadcn/ui monorepo template +## packages 워크스페이스 내 pacakge 추가 -This template is for creating a monorepo with shadcn/ui. +### 기능 -## Usage +- 패키지 이름의 kebab-case 형식 검증 +- 이미 존재하는 패키지 이름 중복 확인 +- 일반 패키지 또는 React 패키지 생성 선택 가능 +- 패키지 생성 후 자동 `pnpm install` 실행 +- 패키지 사용법 안내 + +### 사용 방법 ```bash -pnpm dlx shadcn@latest init +turbo gen package ``` -## Adding components +명령어 실행 후 다음 과정을 따라주세요: + +1. 패키지 이름 입력 (kebab-case 형식) +2. 패키지 유형 선택 + - 일반 패키지: 기본 TypeScript 패키지 + - React 패키지: React 라이브러리 패키지 -To add components to your app, run the following command at the root of your `web` app: +#### 일반 패키지 생성 예제 ```bash -pnpm dlx shadcn@latest add button -c apps/web +$ turbo gen package +? 패키지 이름 입력 > utils +? 패키지 유형을 선택해주세요 > 일반 패키지 ``` -This will place the ui components in the `packages/ui/src/components` directory. +#### React 패키지 생성 예제 -## Tailwind +```bash +$ turbo gen package +? 패키지 이름 입력 > ui-components +? 패키지 유형을 선택해주세요 > React 패키지 +``` -Your `tailwind.config.ts` and `globals.css` are already set up to use the components from the `ui` package. +#### 생성 파일 구조 -## Using components +``` +//일반 패키지 + +packages/your-package/ +├── package.json +├── tsconfig.json +├── eslint.config.js +├── build.js +└── src/ + └── index.ts +``` -To use the components in your app, import them from the `ui` package. +``` +//React 패키지 -```tsx -import { Button } from "@workspace/ui/components/ui/button" +packages/your-react-package/ +├── package.json (React 의존성 포함) +├── tsconfig.json +├── eslint.config.js +├── build.js +└── src/ + ├── index.ts + └── components/ ``` + +### 템플릿 파일 + +패키지 생성 도구는 다음 위치의 템플릿 파일을 사용합니다. + +#### 일반 패키지 템플릿 + +- `./templates/package.json.hbs`: 패키지 기본 구성 +- `./templates/tsconfig.json.hbs`: TypeScript 설정 +- `./templates/eslint.config.js.hbs`: ESLint 설정 +- `./templates/build.js.hbs`: 빌드 스크립트(공통) +- `./templates/src/index.ts.hbs`: 소스 코드 진입점 (공통) + +#### React 패키지 템플릿 + +- `./templates/react/package.json.hbs`: React 의존성을 포함한 패키지 구성 +- `./templates/react/tsconfig.json.hbs`: React 프로젝트에 맞는 TypeScript 설정 +- `./templates/react/eslint.config.js.hbs`: React 프로젝트에 맞는 ESLint 설정 +- `./templates/build.js.hbs`: 빌드 스크립트(공통) +- `./templates/src/index.ts.hbs`: 소스 코드 진입점 (공통)