create-web-0to1 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -0
- package/internal/engine/create-feature-crud-script.ts +134 -0
- package/internal/engine/create-feature-crud.template.mjs +601 -0
- package/internal/engine/create-feature-script.ts +142 -0
- package/internal/engine/generator-engine.ts +546 -0
- package/internal/engine/standalone-feature-preset.ts +34 -0
- package/internal/meta/preset-plan.ts +41 -0
- package/internal/meta/runtime-copy-plan.ts +220 -0
- package/internal/meta/runtime-layout.ts +262 -0
- package/internal/meta/scaffold-manifest.ts +169 -0
- package/internal/meta/standalone-dependency-manifest.ts +75 -0
- package/package.json +45 -0
- package/scripts/create-app.mjs +1612 -0
- package/source/core/auth/auth-events.ts +13 -0
- package/source/core/error/app-error.ts +85 -0
- package/source/core/error/handle-app-error.client.ts +35 -0
- package/source/core/lib/dayjs.ts +25 -0
- package/source/core/query/query-client.ts +126 -0
- package/source/core/request/request-core.ts +210 -0
- package/source/core/routes/route-paths.ts +4 -0
- package/source/core/ui/button.tsx +24 -0
- package/source/core/ui/modal-store.ts +32 -0
- package/source/core/ui/text-input-field.tsx +36 -0
- package/source/core/utils/build-query-string.ts +30 -0
- package/source/core/utils/format/date.ts +41 -0
- package/source/core/utils/format/index.ts +3 -0
- package/source/core/utils/format/number.ts +13 -0
- package/source/core/utils/format/text.ts +15 -0
- package/source/core/utils/schema-utils.ts +27 -0
- package/source/wrappers/monorepo/core/internal.ts +21 -0
- package/source/wrappers/monorepo/core/src/index.ts +4 -0
- package/source/wrappers/monorepo/core-next/src/auth.client.ts +1 -0
- package/source/wrappers/monorepo/core-next/src/auth.server.ts +94 -0
- package/source/wrappers/monorepo/core-next/src/bootstrap.client.tsx +21 -0
- package/source/wrappers/monorepo/core-next/src/bootstrap.tsx +18 -0
- package/source/wrappers/monorepo/core-next/src/index.ts +1 -0
- package/source/wrappers/monorepo/core-react/src/app-providers.tsx +36 -0
- package/source/wrappers/monorepo/core-react/src/auth.ts +42 -0
- package/source/wrappers/monorepo/core-react/src/hydration.tsx +21 -0
- package/source/wrappers/monorepo/core-react/src/index.ts +7 -0
- package/source/wrappers/monorepo/core-react/src/provider.tsx +49 -0
- package/source/wrappers/monorepo/core-react/src/query-client.ts +48 -0
- package/source/wrappers/monorepo/core-react/src/query-error-handler.ts +62 -0
- package/source/wrappers/monorepo/core-react/src/query-keys.ts +22 -0
- package/source/wrappers/monorepo/request/core-fetch.ts +27 -0
- package/source/wrappers/monorepo/request/core-request.ts +93 -0
- package/source/wrappers/next/auth/auth-error-listener.tsx +34 -0
- package/source/wrappers/next/error/handle-app-error.server.ts +41 -0
- package/source/wrappers/next/query/hydration.tsx +20 -0
- package/source/wrappers/next/query/providers.tsx +35 -0
- package/source/wrappers/next/request/request.client.ts +24 -0
- package/source/wrappers/next/request/request.server.ts +64 -0
- package/source/wrappers/next/request/request.ts +52 -0
- package/source/wrappers/next/ui/global-modal.tsx +29 -0
- package/source/wrappers/react/auth/auth-error-listener.tsx +34 -0
- package/source/wrappers/react/query/providers.tsx +31 -0
- package/source/wrappers/react/request/request.client.ts +24 -0
- package/source/wrappers/react/request/request.ts +51 -0
- package/source/wrappers/react/ui/global-modal.tsx +27 -0
- package/templates/monorepo/.dockerignore +38 -0
- package/templates/monorepo/README.md +292 -0
- package/templates/monorepo/_gitignore +38 -0
- package/templates/monorepo/_npmrc +1 -0
- package/templates/monorepo/apps/project/Dockerfile +32 -0
- package/templates/monorepo/apps/project/eslint.config.mjs +4 -0
- package/templates/monorepo/apps/project/index.html +14 -0
- package/templates/monorepo/apps/project/index.ts +15 -0
- package/templates/monorepo/apps/project/package.json +21 -0
- package/templates/monorepo/apps/project/tsconfig.json +9 -0
- package/templates/monorepo/apps/project/vite.config.ts +6 -0
- package/templates/monorepo/apps/web/Dockerfile +43 -0
- package/templates/monorepo/apps/web/README.md +111 -0
- package/templates/monorepo/apps/web/_gitignore +36 -0
- package/templates/monorepo/apps/web/app/favicon.ico +0 -0
- package/templates/monorepo/apps/web/app/global-error.tsx +12 -0
- package/templates/monorepo/apps/web/app/globals.css +0 -0
- package/templates/monorepo/apps/web/app/layout.tsx +28 -0
- package/templates/monorepo/apps/web/app/page.tsx +7 -0
- package/templates/monorepo/apps/web/app/providers.tsx +25 -0
- package/templates/monorepo/apps/web/eslint.config.js +4 -0
- package/templates/monorepo/apps/web/next-env.d.ts +6 -0
- package/templates/monorepo/apps/web/next.config.js +4 -0
- package/templates/monorepo/apps/web/package.json +31 -0
- package/templates/monorepo/apps/web/public/file-text.svg +3 -0
- package/templates/monorepo/apps/web/public/globe.svg +10 -0
- package/templates/monorepo/apps/web/public/next.svg +1 -0
- package/templates/monorepo/apps/web/public/turborepo-dark.svg +19 -0
- package/templates/monorepo/apps/web/public/turborepo-light.svg +19 -0
- package/templates/monorepo/apps/web/public/vercel.svg +10 -0
- package/templates/monorepo/apps/web/public/window.svg +3 -0
- package/templates/monorepo/apps/web/tsconfig.json +20 -0
- package/templates/monorepo/package.json +24 -0
- package/templates/monorepo/packages/core/eslint.config.mjs +4 -0
- package/templates/monorepo/packages/core/package.json +32 -0
- package/templates/monorepo/packages/core/tsconfig.json +8 -0
- package/templates/monorepo/packages/core-next/eslint.config.mjs +13 -0
- package/templates/monorepo/packages/core-next/package.json +43 -0
- package/templates/monorepo/packages/core-next/tsconfig.json +8 -0
- package/templates/monorepo/packages/core-react/eslint.config.mjs +4 -0
- package/templates/monorepo/packages/core-react/package.json +34 -0
- package/templates/monorepo/packages/core-react/tsconfig.json +8 -0
- package/templates/monorepo/packages/eslint-config/README.md +3 -0
- package/templates/monorepo/packages/eslint-config/base.js +57 -0
- package/templates/monorepo/packages/eslint-config/next.js +22 -0
- package/templates/monorepo/packages/eslint-config/package.json +25 -0
- package/templates/monorepo/packages/eslint-config/react-internal.js +33 -0
- package/templates/monorepo/packages/typescript-config/base.json +19 -0
- package/templates/monorepo/packages/typescript-config/nextjs.json +12 -0
- package/templates/monorepo/packages/typescript-config/package.json +9 -0
- package/templates/monorepo/packages/typescript-config/react-library.json +7 -0
- package/templates/monorepo/packages/ui/eslint.config.mjs +4 -0
- package/templates/monorepo/packages/ui/package.json +26 -0
- package/templates/monorepo/packages/ui/src/button.tsx +20 -0
- package/templates/monorepo/packages/ui/src/card.tsx +27 -0
- package/templates/monorepo/packages/ui/src/code.tsx +11 -0
- package/templates/monorepo/packages/ui/tsconfig.json +8 -0
- package/templates/monorepo/pnpm-workspace.yaml +9 -0
- package/templates/monorepo/turbo/generators/config.js +1336 -0
- package/templates/monorepo/turbo/generators/templates/next-app/Dockerfile.tpl +30 -0
- package/templates/monorepo/turbo/generators/templates/next-app/README.md.tpl +118 -0
- package/templates/monorepo/turbo/generators/templates/next-app/app/global-error.tsx.tpl +12 -0
- package/templates/monorepo/turbo/generators/templates/next-app/app/globals.css.tpl +1 -0
- package/templates/monorepo/turbo/generators/templates/next-app/app/layout.tsx.tpl +29 -0
- package/templates/monorepo/turbo/generators/templates/next-app/app/page.tsx.tpl +7 -0
- package/templates/monorepo/turbo/generators/templates/next-app/app/providers.tsx.tpl +25 -0
- package/templates/monorepo/turbo/generators/templates/next-app/eslint.config.js.tpl +4 -0
- package/templates/monorepo/turbo/generators/templates/next-app/next.config.js.tpl +6 -0
- package/templates/monorepo/turbo/generators/templates/next-app/tsconfig.json.tpl +18 -0
- package/templates/monorepo/turbo/generators/templates/vite-app/Dockerfile.tpl +22 -0
- package/templates/monorepo/turbo/generators/templates/vite-app/README.plain.md.tpl +90 -0
- package/templates/monorepo/turbo/generators/templates/vite-app/README.react.md.tpl +107 -0
- package/templates/monorepo/turbo/generators/templates/vite-app/eslint.config.mjs.tpl +4 -0
- package/templates/monorepo/turbo/generators/templates/vite-app/index.html.tpl +12 -0
- package/templates/monorepo/turbo/generators/templates/vite-app/index.ts.tpl +22 -0
- package/templates/monorepo/turbo/generators/templates/vite-app/tsconfig.json.tpl +9 -0
- package/templates/monorepo/turbo/generators/templates/vite-app/vite.config.ts.tpl +6 -0
- package/templates/monorepo/turbo.json +28 -0
- package/templates/next/.env.example +2 -0
- package/templates/next/.prettierignore +9 -0
- package/templates/next/.prettierrc.json +9 -0
- package/templates/next/README.md +246 -0
- package/templates/next/_gitignore +44 -0
- package/templates/next/eslint.config.mjs +51 -0
- package/templates/next/next.config.ts +7 -0
- package/templates/next/package.json +24 -0
- package/templates/next/postcss.config.mjs +7 -0
- package/templates/next/scripts/create-feature-crud.mjs +5 -0
- package/templates/next/scripts/create-feature.mjs +5 -0
- package/templates/next/src/app/error.tsx +33 -0
- package/templates/next/src/app/globals.css +35 -0
- package/templates/next/src/app/layout.tsx +39 -0
- package/templates/next/src/app/login/page.tsx +17 -0
- package/templates/next/src/app/page.tsx +32 -0
- package/templates/next/src/app/providers.tsx +20 -0
- package/templates/next/tsconfig.json +34 -0
- package/templates/react/.env.example +1 -0
- package/templates/react/.prettierignore +10 -0
- package/templates/react/.prettierrc.json +9 -0
- package/templates/react/README.md +250 -0
- package/templates/react/_gitignore +31 -0
- package/templates/react/eslint.config.mjs +64 -0
- package/templates/react/package.json +19 -0
- package/templates/react/scripts/create-feature-crud.mjs +5 -0
- package/templates/react/scripts/create-feature.mjs +5 -0
- package/templates/react/src/app/app.tsx +15 -0
- package/templates/react/src/app/error-boundary.tsx +59 -0
- package/templates/react/src/app/frame.tsx +32 -0
- package/templates/react/src/app/globals.css +43 -0
- package/templates/react/src/app/not-found-page.tsx +23 -0
- package/templates/react/src/app/providers.tsx +16 -0
- package/templates/react/src/app/router.tsx +62 -0
- package/templates/react/src/main.tsx +12 -0
- package/templates/react/src/pages/index/page.tsx +36 -0
- package/templates/react/src/pages/login/page.tsx +18 -0
- package/templates/react/tsconfig.app.json +30 -0
- package/templates/react/tsconfig.json +4 -0
- package/templates/react/tsconfig.node.json +24 -0
- package/templates/react/vite.config.ts +14 -0
- package/templates/shared/docs//352/260/234/353/260/234/354/233/220/354/271/231/00-/354/240/204/353/260/230/354/240/201/354/235/270-/355/217/264/353/215/224/352/265/254/354/241/260.md +150 -0
- package/templates/shared/docs//352/260/234/353/260/234/354/233/220/354/271/231/01-/352/265/254/354/241/260/354/231/200-/353/235/274/354/232/260/355/214/205.md +186 -0
- package/templates/shared/docs//352/260/234/353/260/234/354/233/220/354/271/231/02-/354/204/234/353/262/204/354/231/200-/355/201/264/353/235/274/354/235/264/354/226/270/355/212/270.md +86 -0
- package/templates/shared/docs//352/260/234/353/260/234/354/233/220/354/271/231/03-/354/203/201/355/203/234/352/264/200/353/246/254.md +84 -0
- package/templates/shared/docs//352/260/234/353/260/234/354/233/220/354/271/231/04-API/354/231/200-/353/215/260/354/235/264/355/204/260.md +199 -0
- package/templates/shared/docs//352/260/234/353/260/234/354/233/220/354/271/231/05-/354/227/220/353/237/254/354/231/200-UI-/354/203/201/355/203/234.md +159 -0
- package/templates/shared/docs//352/260/234/353/260/234/354/233/220/354/271/231/06-/355/217/274.md +116 -0
- package/templates/shared/docs//352/260/234/353/260/234/354/233/220/354/271/231/07-/354/212/244/355/203/200/354/235/274/353/247/201/352/263/274-/354/240/221/352/267/274/354/204/261.md +73 -0
- package/templates/shared/docs//352/260/234/353/260/234/354/233/220/354/271/231/08-/353/204/244/354/235/264/353/260/215-/354/204/244/354/240/225-/355/217/254/353/247/267/355/214/205.md +98 -0
- package/templates/shared/docs//352/260/234/353/260/234/354/233/220/354/271/231/09-/353/235/274/354/232/260/355/212/270-/354/240/225/354/235/230.md +169 -0
- package/templates/shared/docs//352/260/234/353/260/234/354/233/220/354/271/231/10-/354/273/244/353/260/213-/354/273/250/353/262/244/354/205/230.md +64 -0
- package/templates/shared/docs//352/260/234/353/260/234/354/233/220/354/271/231/11-/352/270/260/355/203/200-/354/233/220/354/271/231.md +187 -0
- package/templates/shared/docs//352/260/234/353/260/234/354/233/220/354/271/231/12-/354/213/244/353/254/264-/353/215/260/354/235/264/355/204/260-/355/214/250/355/204/264.md +302 -0
- package/templates/shared/docs//352/260/234/353/260/234/354/233/220/354/271/231/13-/354/204/261/353/212/245-/354/233/220/354/271/231.md +175 -0
- package/templates/shared/docs//352/260/234/353/260/234/354/233/220/354/271/231/README.md +39 -0
|
@@ -0,0 +1,601 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
const rootDir = process.cwd();
|
|
6
|
+
const srcDir = path.join(rootDir, 'src');
|
|
7
|
+
const __ROUTE_ROOT_CONST__ = path.join(srcDir, '__ROUTE_ROOT_NAME__');
|
|
8
|
+
const featuresDir = path.join(srcDir, 'features');
|
|
9
|
+
|
|
10
|
+
const rawName = process.argv[2];
|
|
11
|
+
|
|
12
|
+
if (!rawName) {
|
|
13
|
+
console.error('사용법: npm run create:feature:crud -- <feature-name>');
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (!/^[a-z][a-z0-9-]*$/.test(rawName)) {
|
|
18
|
+
console.error('feature 이름은 영문 소문자 kebab-case 형식이어야 하며 문자로 시작해야 합니다.');
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function toPascalCase(value) {
|
|
23
|
+
return value
|
|
24
|
+
.split('-')
|
|
25
|
+
.filter(Boolean)
|
|
26
|
+
.map((part) => part[0].toUpperCase() + part.slice(1))
|
|
27
|
+
.join('');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function toCamelCase(value) {
|
|
31
|
+
const pascal = toPascalCase(value);
|
|
32
|
+
return pascal[0].toLowerCase() + pascal.slice(1);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function toSingular(value) {
|
|
36
|
+
if (value.endsWith('ies')) {
|
|
37
|
+
return `${value.slice(0, -3)}y`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (value.endsWith('s')) {
|
|
41
|
+
return value.slice(0, -1);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function ensureFile(filePath, content) {
|
|
48
|
+
const exists = fs.existsSync(filePath);
|
|
49
|
+
|
|
50
|
+
if (exists) {
|
|
51
|
+
console.log(`skip: ${path.relative(rootDir, filePath)}`);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
56
|
+
fs.writeFileSync(filePath, content, 'utf8');
|
|
57
|
+
console.log(`create: ${path.relative(rootDir, filePath)}`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function getStyleMode() {
|
|
61
|
+
const packageJsonPath = path.join(rootDir, 'package.json');
|
|
62
|
+
|
|
63
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
64
|
+
return 'tailwind';
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
|
|
69
|
+
return packageJson['__PACKAGE_JSON_KEY__']?.style === 'none' ? 'none' : 'tailwind';
|
|
70
|
+
} catch {
|
|
71
|
+
return 'tailwind';
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const featureName = rawName;
|
|
76
|
+
const featureNamePascal = toPascalCase(featureName);
|
|
77
|
+
const featureNameCamel = toCamelCase(featureName);
|
|
78
|
+
const entityName = toSingular(featureName);
|
|
79
|
+
const entityNamePascal = toPascalCase(entityName);
|
|
80
|
+
const entityNameCamel = toCamelCase(entityName);
|
|
81
|
+
const createRouteKey = `${entityNameCamel}Create`;
|
|
82
|
+
const featurePath = `/${featureName}`;
|
|
83
|
+
const featureCreatePath = `${featurePath}/new`;
|
|
84
|
+
const collectionLabel = featureNamePascal;
|
|
85
|
+
const entityLabel = entityNamePascal;
|
|
86
|
+
const useStyles = getStyleMode() !== 'none';
|
|
87
|
+
|
|
88
|
+
const featureDir = path.join(featuresDir, featureName);
|
|
89
|
+
const routeDir = path.join(__ROUTE_ROOT_CONST__, featureName);
|
|
90
|
+
const routeNewDir = path.join(routeDir, 'new');
|
|
91
|
+
|
|
92
|
+
function getListSectionContent() {
|
|
93
|
+
if (!useStyles) {
|
|
94
|
+
return `__LIST_IMPORTS__
|
|
95
|
+
|
|
96
|
+
import { get${featureNamePascal} } from '@/features/${featureName}/api/get-${featureName}';
|
|
97
|
+
import { ${entityNameCamel}QueryKeys } from '@/features/${featureName}/api/${entityName}-query-keys';
|
|
98
|
+
import { formatDate, truncateText } from '@/shared/utils/format';
|
|
99
|
+
|
|
100
|
+
export function ${entityNamePascal}ListSection() {
|
|
101
|
+
const [search, setSearch] = useState('');
|
|
102
|
+
const { data, isLoading, error } = useQuery({
|
|
103
|
+
queryKey: ${entityNameCamel}QueryKeys.list({ search }),
|
|
104
|
+
queryFn: ({ signal }) => get${featureNamePascal}(search, signal),
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<section>
|
|
109
|
+
<div>
|
|
110
|
+
<div>
|
|
111
|
+
<h2>${collectionLabel}</h2>
|
|
112
|
+
<p>TanStack Query와 검색 상태를 포함한 외부 API 연동 예시 목록입니다.</p>
|
|
113
|
+
</div>
|
|
114
|
+
<div>
|
|
115
|
+
<input
|
|
116
|
+
value={search}
|
|
117
|
+
onChange={(event) => setSearch(event.target.value)}
|
|
118
|
+
placeholder="${collectionLabel} 검색"
|
|
119
|
+
/>
|
|
120
|
+
<Link __LIST_LINK_PROP__="${featureCreatePath}">${entityLabel} 추가</Link>
|
|
121
|
+
</div>
|
|
122
|
+
</div>
|
|
123
|
+
|
|
124
|
+
{isLoading ? <p>불러오는 중...</p> : null}
|
|
125
|
+
{error ? <p>목록을 불러오지 못했습니다.</p> : null}
|
|
126
|
+
{!isLoading && !error && data?.length === 0 ? <p>조건에 맞는 항목이 없습니다.</p> : null}
|
|
127
|
+
|
|
128
|
+
<div>
|
|
129
|
+
{data?.map((item) => (
|
|
130
|
+
<article key={item.id}>
|
|
131
|
+
<h3>{item.title}</h3>
|
|
132
|
+
<p>{formatDate(item.createdAt)}</p>
|
|
133
|
+
<p>{truncateText(item.description, 140)}</p>
|
|
134
|
+
</article>
|
|
135
|
+
))}
|
|
136
|
+
</div>
|
|
137
|
+
</section>
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
`;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return `__LIST_IMPORTS__
|
|
144
|
+
|
|
145
|
+
import { get${featureNamePascal} } from '@/features/${featureName}/api/get-${featureName}';
|
|
146
|
+
import { ${entityNameCamel}QueryKeys } from '@/features/${featureName}/api/${entityName}-query-keys';
|
|
147
|
+
import { formatDate, truncateText } from '@/shared/utils/format';
|
|
148
|
+
|
|
149
|
+
export function ${entityNamePascal}ListSection() {
|
|
150
|
+
const [search, setSearch] = useState('');
|
|
151
|
+
const { data, isLoading, error } = useQuery({
|
|
152
|
+
queryKey: ${entityNameCamel}QueryKeys.list({ search }),
|
|
153
|
+
queryFn: ({ signal }) => get${featureNamePascal}(search, signal),
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<section className="rounded-3xl border border-zinc-200 bg-white p-6 shadow-sm">
|
|
158
|
+
<div className="flex flex-col gap-4 border-b border-zinc-200 pb-5 sm:flex-row sm:items-center sm:justify-between">
|
|
159
|
+
<div>
|
|
160
|
+
<h2 className="text-xl font-semibold text-zinc-950">${collectionLabel}</h2>
|
|
161
|
+
<p className="mt-1 text-sm text-zinc-500">
|
|
162
|
+
TanStack Query와 검색 상태를 포함한 외부 API 연동 예시 목록입니다.
|
|
163
|
+
</p>
|
|
164
|
+
</div>
|
|
165
|
+
<div className="flex gap-3">
|
|
166
|
+
<input
|
|
167
|
+
value={search}
|
|
168
|
+
onChange={(event) => setSearch(event.target.value)}
|
|
169
|
+
placeholder="${collectionLabel} 검색"
|
|
170
|
+
className="rounded-xl border border-zinc-300 px-4 py-2 text-sm outline-none"
|
|
171
|
+
/>
|
|
172
|
+
<Link
|
|
173
|
+
__LIST_LINK_PROP__="${featureCreatePath}"
|
|
174
|
+
className="inline-flex items-center rounded-xl bg-zinc-950 px-4 py-2 text-sm font-medium text-white"
|
|
175
|
+
>
|
|
176
|
+
${entityLabel} 추가
|
|
177
|
+
</Link>
|
|
178
|
+
</div>
|
|
179
|
+
</div>
|
|
180
|
+
|
|
181
|
+
{isLoading ? <p className="py-8 text-sm text-zinc-500">불러오는 중...</p> : null}
|
|
182
|
+
{error ? <p className="py-8 text-sm text-rose-600">목록을 불러오지 못했습니다.</p> : null}
|
|
183
|
+
{!isLoading && !error && data?.length === 0 ? (
|
|
184
|
+
<p className="py-8 text-sm text-zinc-500">조건에 맞는 항목이 없습니다.</p>
|
|
185
|
+
) : null}
|
|
186
|
+
|
|
187
|
+
<div className="mt-6 grid gap-4">
|
|
188
|
+
{data?.map((item) => (
|
|
189
|
+
<article key={item.id} className="rounded-2xl border border-zinc-200 p-5">
|
|
190
|
+
<h3 className="text-lg font-semibold text-zinc-950">{item.title}</h3>
|
|
191
|
+
<p className="mt-1 text-sm text-zinc-500">{formatDate(item.createdAt)}</p>
|
|
192
|
+
<p className="mt-4 text-sm leading-6 text-zinc-700">
|
|
193
|
+
{truncateText(item.description, 140)}
|
|
194
|
+
</p>
|
|
195
|
+
</article>
|
|
196
|
+
))}
|
|
197
|
+
</div>
|
|
198
|
+
</section>
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
`;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function getFormContent() {
|
|
205
|
+
if (!useStyles) {
|
|
206
|
+
return `__FORM_IMPORTS__
|
|
207
|
+
|
|
208
|
+
import { ${entityNameCamel}FormSchema, type ${entityNamePascal}FormValues } from '@/features/${featureName}/lib/${entityName}-schema';
|
|
209
|
+
import { Button } from '@/shared/ui/button';
|
|
210
|
+
import { TextInputField } from '@/shared/ui/text-input-field';
|
|
211
|
+
|
|
212
|
+
type ${entityNamePascal}FormProps = {
|
|
213
|
+
onSubmit: (values: ${entityNamePascal}FormValues) => Promise<unknown>;
|
|
214
|
+
submitLabel: string;
|
|
215
|
+
successPath?: string;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
export function ${entityNamePascal}Form({ onSubmit, submitLabel, successPath }: ${entityNamePascal}FormProps) {
|
|
219
|
+
__FORM_NAVIGATION_HOOK__
|
|
220
|
+
const {
|
|
221
|
+
register,
|
|
222
|
+
handleSubmit,
|
|
223
|
+
formState: { errors, isSubmitting },
|
|
224
|
+
} = useForm<${entityNamePascal}FormValues>({
|
|
225
|
+
resolver: zodResolver(${entityNameCamel}FormSchema),
|
|
226
|
+
defaultValues: {
|
|
227
|
+
title: '',
|
|
228
|
+
description: '',
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
const submit = handleSubmit(async (values) => {
|
|
233
|
+
await onSubmit(values);
|
|
234
|
+
|
|
235
|
+
if (successPath) {
|
|
236
|
+
__FORM_SUCCESS_NAVIGATION__
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
return (
|
|
241
|
+
<form onSubmit={submit}>
|
|
242
|
+
<TextInputField
|
|
243
|
+
label="제목"
|
|
244
|
+
required
|
|
245
|
+
error={errors.title?.message}
|
|
246
|
+
placeholder="${entityLabel} 제목"
|
|
247
|
+
{...register('title')}
|
|
248
|
+
/>
|
|
249
|
+
__FORM_DESCRIPTION_BLOCK_NO_STYLE__
|
|
250
|
+
<div>
|
|
251
|
+
<Button type="submit" isLoading={isSubmitting}>
|
|
252
|
+
{submitLabel}
|
|
253
|
+
</Button>
|
|
254
|
+
</div>
|
|
255
|
+
</form>
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
`;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return `__FORM_IMPORTS__
|
|
262
|
+
|
|
263
|
+
import { ${entityNameCamel}FormSchema, type ${entityNamePascal}FormValues } from '@/features/${featureName}/lib/${entityName}-schema';
|
|
264
|
+
import { Button } from '@/shared/ui/button';
|
|
265
|
+
import { TextInputField } from '@/shared/ui/text-input-field';
|
|
266
|
+
|
|
267
|
+
type ${entityNamePascal}FormProps = {
|
|
268
|
+
onSubmit: (values: ${entityNamePascal}FormValues) => Promise<unknown>;
|
|
269
|
+
submitLabel: string;
|
|
270
|
+
successPath?: string;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
export function ${entityNamePascal}Form({ onSubmit, submitLabel, successPath }: ${entityNamePascal}FormProps) {
|
|
274
|
+
__FORM_NAVIGATION_HOOK__
|
|
275
|
+
const {
|
|
276
|
+
register,
|
|
277
|
+
handleSubmit,
|
|
278
|
+
formState: { errors, isSubmitting },
|
|
279
|
+
} = useForm<${entityNamePascal}FormValues>({
|
|
280
|
+
resolver: zodResolver(${entityNameCamel}FormSchema),
|
|
281
|
+
defaultValues: {
|
|
282
|
+
title: '',
|
|
283
|
+
description: '',
|
|
284
|
+
},
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
const submit = handleSubmit(async (values) => {
|
|
288
|
+
await onSubmit(values);
|
|
289
|
+
|
|
290
|
+
if (successPath) {
|
|
291
|
+
__FORM_SUCCESS_NAVIGATION__
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
return (
|
|
296
|
+
<form onSubmit={submit} className="flex flex-col gap-5 rounded-3xl border border-zinc-200 bg-white p-6 shadow-sm">
|
|
297
|
+
<TextInputField
|
|
298
|
+
label="제목"
|
|
299
|
+
required
|
|
300
|
+
error={errors.title?.message}
|
|
301
|
+
placeholder="${entityLabel} 제목"
|
|
302
|
+
{...register('title')}
|
|
303
|
+
/>
|
|
304
|
+
<div className="flex flex-col gap-2">
|
|
305
|
+
<label htmlFor="description" className="text-sm font-semibold text-zinc-900">
|
|
306
|
+
설명
|
|
307
|
+
<span className="ml-1 text-rose-600">*</span>
|
|
308
|
+
</label>
|
|
309
|
+
<textarea
|
|
310
|
+
id="description"
|
|
311
|
+
className={\`min-h-40 rounded-xl border px-4 py-3 text-sm text-zinc-950 outline-none transition \${errors.description ? 'border-rose-500' : 'border-zinc-300'}\`}
|
|
312
|
+
placeholder="${entityLabel} 설명"
|
|
313
|
+
{...register('description')}
|
|
314
|
+
/>
|
|
315
|
+
{errors.description ? <p className="text-sm text-rose-600">{errors.description.message}</p> : null}
|
|
316
|
+
</div>
|
|
317
|
+
<div className="flex justify-end">
|
|
318
|
+
<Button type="submit" isLoading={isSubmitting}>
|
|
319
|
+
{submitLabel}
|
|
320
|
+
</Button>
|
|
321
|
+
</div>
|
|
322
|
+
</form>
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
`;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function getListPageContent() {
|
|
329
|
+
if (!useStyles) {
|
|
330
|
+
return `import { ${entityNamePascal}ListSection } from '@/features/${featureName}/components/${entityName}-list-section';
|
|
331
|
+
|
|
332
|
+
export default function ${featureNamePascal}Page() {
|
|
333
|
+
return (
|
|
334
|
+
<main>
|
|
335
|
+
<div>
|
|
336
|
+
<p>${featureNamePascal}</p>
|
|
337
|
+
<h1>${collectionLabel} 목록</h1>
|
|
338
|
+
<p>이 예시 화면을 실제 ${featureName} 도메인 화면으로 교체하세요.</p>
|
|
339
|
+
</div>
|
|
340
|
+
|
|
341
|
+
<${entityNamePascal}ListSection />
|
|
342
|
+
</main>
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
`;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
return `import { ${entityNamePascal}ListSection } from '@/features/${featureName}/components/${entityName}-list-section';
|
|
349
|
+
|
|
350
|
+
export default function ${featureNamePascal}Page() {
|
|
351
|
+
return (
|
|
352
|
+
<main className="mx-auto flex min-h-screen w-full max-w-5xl flex-col gap-8 px-6 py-16">
|
|
353
|
+
<div>
|
|
354
|
+
<p className="text-sm font-medium uppercase tracking-[0.2em] text-zinc-500">${featureNamePascal}</p>
|
|
355
|
+
<h1 className="mt-3 text-3xl font-semibold tracking-tight text-zinc-950">
|
|
356
|
+
${collectionLabel} 목록
|
|
357
|
+
</h1>
|
|
358
|
+
<p className="mt-3 text-sm leading-6 text-zinc-600">
|
|
359
|
+
이 예시 화면을 실제 ${featureName} 도메인 화면으로 교체하세요.
|
|
360
|
+
</p>
|
|
361
|
+
</div>
|
|
362
|
+
|
|
363
|
+
<${entityNamePascal}ListSection />
|
|
364
|
+
</main>
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
`;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function getCreatePageContent() {
|
|
371
|
+
if (!useStyles) {
|
|
372
|
+
return `import { ${entityNamePascal}CreateFormSection } from '@/features/${featureName}/components/${entityName}-create-form-section';
|
|
373
|
+
|
|
374
|
+
export default function Create${entityNamePascal}Page() {
|
|
375
|
+
return (
|
|
376
|
+
<main>
|
|
377
|
+
<div>
|
|
378
|
+
<p>${featureNamePascal}</p>
|
|
379
|
+
<h1>${entityLabel} 생성</h1>
|
|
380
|
+
<p>React Hook Form, Zod, React Query mutation을 포함한 예시 폼입니다.</p>
|
|
381
|
+
</div>
|
|
382
|
+
|
|
383
|
+
<${entityNamePascal}CreateFormSection />
|
|
384
|
+
</main>
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
`;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
return `import { ${entityNamePascal}CreateFormSection } from '@/features/${featureName}/components/${entityName}-create-form-section';
|
|
391
|
+
|
|
392
|
+
export default function Create${entityNamePascal}Page() {
|
|
393
|
+
return (
|
|
394
|
+
<main className="mx-auto flex min-h-screen w-full max-w-3xl flex-col gap-8 px-6 py-16">
|
|
395
|
+
<div>
|
|
396
|
+
<p className="text-sm font-medium uppercase tracking-[0.2em] text-zinc-500">${featureNamePascal}</p>
|
|
397
|
+
<h1 className="mt-3 text-3xl font-semibold tracking-tight text-zinc-950">
|
|
398
|
+
${entityLabel} 생성
|
|
399
|
+
</h1>
|
|
400
|
+
<p className="mt-3 text-sm leading-6 text-zinc-600">
|
|
401
|
+
React Hook Form, Zod, React Query mutation을 포함한 예시 폼입니다.
|
|
402
|
+
</p>
|
|
403
|
+
</div>
|
|
404
|
+
|
|
405
|
+
<${entityNamePascal}CreateFormSection />
|
|
406
|
+
</main>
|
|
407
|
+
);
|
|
408
|
+
}
|
|
409
|
+
`;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
ensureFile(
|
|
413
|
+
path.join(featureDir, 'api', `get-${featureName}.ts`),
|
|
414
|
+
`import { map${entityNamePascal}, type ${entityNamePascal}, type ${entityNamePascal}ResponseDto } from '@/features/${featureName}/lib/${entityName}-schema';
|
|
415
|
+
import { requestClient } from '@/shared/api/request.client';
|
|
416
|
+
|
|
417
|
+
export async function get${featureNamePascal}(search?: string, signal?: AbortSignal): Promise<${entityNamePascal}[]> {
|
|
418
|
+
const response = await requestClient<${entityNamePascal}ResponseDto[]>({
|
|
419
|
+
method: 'GET',
|
|
420
|
+
url: '/${featureName}',
|
|
421
|
+
params: { search },
|
|
422
|
+
signal,
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
return response.map(map${entityNamePascal});
|
|
426
|
+
}
|
|
427
|
+
`,
|
|
428
|
+
);
|
|
429
|
+
|
|
430
|
+
ensureFile(
|
|
431
|
+
path.join(featureDir, 'api', `create-${entityName}.ts`),
|
|
432
|
+
`import {
|
|
433
|
+
map${entityNamePascal},
|
|
434
|
+
type ${entityNamePascal},
|
|
435
|
+
type ${entityNamePascal}FormValues,
|
|
436
|
+
type ${entityNamePascal}ResponseDto,
|
|
437
|
+
} from '@/features/${featureName}/lib/${entityName}-schema';
|
|
438
|
+
import { requestClient } from '@/shared/api/request.client';
|
|
439
|
+
|
|
440
|
+
export async function create${entityNamePascal}(values: ${entityNamePascal}FormValues): Promise<${entityNamePascal}> {
|
|
441
|
+
const response = await requestClient<${entityNamePascal}ResponseDto>({
|
|
442
|
+
method: 'POST',
|
|
443
|
+
url: '/${featureName}',
|
|
444
|
+
data: values,
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
return map${entityNamePascal}(response);
|
|
448
|
+
}
|
|
449
|
+
`,
|
|
450
|
+
);
|
|
451
|
+
|
|
452
|
+
ensureFile(
|
|
453
|
+
path.join(featureDir, 'api', `${entityName}-query-keys.ts`),
|
|
454
|
+
`export const ${entityNameCamel}QueryKeys = {
|
|
455
|
+
all: ['${featureName}'] as const,
|
|
456
|
+
lists: () => [...${entityNameCamel}QueryKeys.all, 'list'] as const,
|
|
457
|
+
list: (params: { search?: string }) => [...${entityNameCamel}QueryKeys.lists(), params] as const,
|
|
458
|
+
};
|
|
459
|
+
`,
|
|
460
|
+
);
|
|
461
|
+
|
|
462
|
+
ensureFile(
|
|
463
|
+
path.join(featureDir, 'api', 'index.ts'),
|
|
464
|
+
`export * from './create-${entityName}';
|
|
465
|
+
export * from './get-${featureName}';
|
|
466
|
+
export * from './${entityName}-query-keys';
|
|
467
|
+
`,
|
|
468
|
+
);
|
|
469
|
+
|
|
470
|
+
ensureFile(
|
|
471
|
+
path.join(featureDir, 'components', `${entityName}-list-section.tsx`),
|
|
472
|
+
getListSectionContent(),
|
|
473
|
+
);
|
|
474
|
+
|
|
475
|
+
ensureFile(
|
|
476
|
+
path.join(featureDir, 'components', `${entityName}-form.tsx`),
|
|
477
|
+
getFormContent(),
|
|
478
|
+
);
|
|
479
|
+
|
|
480
|
+
ensureFile(
|
|
481
|
+
path.join(featureDir, 'components', `${entityName}-create-form-section.tsx`),
|
|
482
|
+
`__CREATE_FORM_SECTION_IMPORTS__
|
|
483
|
+
|
|
484
|
+
export function ${entityNamePascal}CreateFormSection() {
|
|
485
|
+
const { mutation, submitLabel, successPath } = useCreate${entityNamePascal}Form();
|
|
486
|
+
|
|
487
|
+
return (
|
|
488
|
+
<${entityNamePascal}Form
|
|
489
|
+
onSubmit={(values) => mutation.mutateAsync(values)}
|
|
490
|
+
submitLabel={submitLabel}
|
|
491
|
+
successPath={successPath}
|
|
492
|
+
/>
|
|
493
|
+
);
|
|
494
|
+
}
|
|
495
|
+
`,
|
|
496
|
+
);
|
|
497
|
+
|
|
498
|
+
ensureFile(
|
|
499
|
+
path.join(featureDir, 'components', 'index.ts'),
|
|
500
|
+
`export * from './${entityName}-create-form-section';
|
|
501
|
+
export * from './${entityName}-form';
|
|
502
|
+
export * from './${entityName}-list-section';
|
|
503
|
+
`,
|
|
504
|
+
);
|
|
505
|
+
|
|
506
|
+
ensureFile(
|
|
507
|
+
path.join(featureDir, 'hooks', `use-create-${entityName}-form.ts`),
|
|
508
|
+
`__HOOK_IMPORTS__
|
|
509
|
+
|
|
510
|
+
import { create${entityNamePascal} } from '@/features/${featureName}/api/create-${entityName}';
|
|
511
|
+
import { ${entityNameCamel}QueryKeys } from '@/features/${featureName}/api/${entityName}-query-keys';
|
|
512
|
+
import type { ${entityNamePascal}FormValues } from '@/features/${featureName}/lib/${entityName}-schema';
|
|
513
|
+
|
|
514
|
+
export function useCreate${entityNamePascal}Form() {
|
|
515
|
+
const queryClient = useQueryClient();
|
|
516
|
+
|
|
517
|
+
const mutation = useMutation({
|
|
518
|
+
mutationFn: (values: ${entityNamePascal}FormValues) => create${entityNamePascal}(values),
|
|
519
|
+
onSuccess: () => {
|
|
520
|
+
queryClient.invalidateQueries({
|
|
521
|
+
queryKey: ${entityNameCamel}QueryKeys.lists(),
|
|
522
|
+
});
|
|
523
|
+
},
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
return {
|
|
527
|
+
submitLabel: '${entityLabel} 저장',
|
|
528
|
+
successPath: '${featurePath}',
|
|
529
|
+
mutation,
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
`,
|
|
533
|
+
);
|
|
534
|
+
|
|
535
|
+
ensureFile(
|
|
536
|
+
path.join(featureDir, 'hooks', 'index.ts'),
|
|
537
|
+
`export * from './use-create-${entityName}-form';
|
|
538
|
+
`,
|
|
539
|
+
);
|
|
540
|
+
|
|
541
|
+
ensureFile(
|
|
542
|
+
path.join(featureDir, 'lib', `${entityName}-schema.ts`),
|
|
543
|
+
`import { z } from 'zod';
|
|
544
|
+
|
|
545
|
+
export const ${entityNameCamel}FormSchema = z.object({
|
|
546
|
+
title: z.string().min(1, '제목을 입력해주세요.'),
|
|
547
|
+
description: z.string().min(1, '설명을 입력해주세요.'),
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
export type ${entityNamePascal}FormValues = z.infer<typeof ${entityNameCamel}FormSchema>;
|
|
551
|
+
|
|
552
|
+
export type ${entityNamePascal}ResponseDto = {
|
|
553
|
+
id: string;
|
|
554
|
+
title: string;
|
|
555
|
+
description: string;
|
|
556
|
+
created_at: string;
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
export type ${entityNamePascal} = {
|
|
560
|
+
id: string;
|
|
561
|
+
title: string;
|
|
562
|
+
description: string;
|
|
563
|
+
createdAt: Date;
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
export function map${entityNamePascal}(dto: ${entityNamePascal}ResponseDto): ${entityNamePascal} {
|
|
567
|
+
return {
|
|
568
|
+
id: dto.id,
|
|
569
|
+
title: dto.title,
|
|
570
|
+
description: dto.description,
|
|
571
|
+
createdAt: new Date(dto.created_at),
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
`,
|
|
575
|
+
);
|
|
576
|
+
|
|
577
|
+
ensureFile(
|
|
578
|
+
path.join(featureDir, 'lib', 'index.ts'),
|
|
579
|
+
`export * from './${entityName}-schema';
|
|
580
|
+
`,
|
|
581
|
+
);
|
|
582
|
+
|
|
583
|
+
ensureFile(
|
|
584
|
+
path.join(routeDir, 'page.tsx'),
|
|
585
|
+
getListPageContent(),
|
|
586
|
+
);
|
|
587
|
+
|
|
588
|
+
ensureFile(
|
|
589
|
+
path.join(routeNewDir, 'page.tsx'),
|
|
590
|
+
getCreatePageContent(),
|
|
591
|
+
);
|
|
592
|
+
|
|
593
|
+
console.log('');
|
|
594
|
+
console.log(`"${featureName}" feature CRUD 예시 스캐폴드 생성이 완료되었습니다.`);
|
|
595
|
+
__OUTPUT_SUMMARY_LINE__
|
|
596
|
+
__OPTIONAL_ROUTE_HINT__console.log(`중앙 route 상수가 필요하면 src/shared/routes/route-paths.ts에 직접 추가하세요:`);
|
|
597
|
+
console.log(` ${featureNameCamel}: '${featurePath}',`);
|
|
598
|
+
console.log(` ${createRouteKey}: '${featureCreatePath}',`);
|
|
599
|
+
console.log('');
|
|
600
|
+
console.log('주의: 생성된 API 함수는 외부 백엔드 연동을 전제로 합니다.');
|
|
601
|
+
__ENV_HINT__
|