261117_01_ENH: 생성 의존성 실제 버전으로 기록, cn을 @kri/common과 동기화하고 clsx·tailwind-merge 제거
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { fileURLToPath } from "node:url";
|
||||
import path from "node:path";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import { KRI_REGISTRY_ITEMS, REGISTRY_BASE_URL } from "./constants.js";
|
||||
import { copyTemplate, ensureTargetDirectory, removeJenkinsfile, replacePlaceholders } from "./files.js";
|
||||
import { composeAgentHarness } from "./harness.js";
|
||||
@@ -10,8 +10,39 @@ import type { CliOptions } from "./types.js";
|
||||
const currentDir = path.dirname(fileURLToPath(import.meta.url));
|
||||
const templateDir = path.resolve(currentDir, "../templates/base");
|
||||
|
||||
// 설치 시점에 각 spec을 해석해 npm이 실제 버전 범위(예: ^19.2.1)로 package.json에 기록한다.
|
||||
// `@kri/common`은 별도 단계에서 exact 버전으로, `cn`은 `@kri/common`과 같은 exact 버전으로 설치한다.
|
||||
const DEPENDENCY_SPECS: Record<string, string> = {
|
||||
"@tanstack/react-query": "latest",
|
||||
"class-variance-authority": "latest",
|
||||
jotai: "latest",
|
||||
"lucide-react": "latest",
|
||||
next: "latest",
|
||||
react: "latest",
|
||||
"react-dom": "latest",
|
||||
"server-only": "latest",
|
||||
sonner: "latest",
|
||||
};
|
||||
|
||||
const DEV_DEPENDENCY_SPECS: Record<string, string> = {
|
||||
"@tailwindcss/postcss": "latest",
|
||||
"@types/node": "latest",
|
||||
"@types/react": "latest",
|
||||
"@types/react-dom": "latest",
|
||||
"babel-plugin-react-compiler": "latest",
|
||||
// `^`는 Windows cmd.exe 이스케이프 문자라 메이저 버전만 지정한다(9 = 최신 9.x).
|
||||
eslint: "9",
|
||||
"eslint-config-next": "latest",
|
||||
tailwindcss: "latest",
|
||||
"tw-animate-css": "latest",
|
||||
typescript: "5",
|
||||
};
|
||||
|
||||
const toInstallArgs = (specs: Record<string, string>): string[] =>
|
||||
Object.entries(specs).map(([name, spec]) => `${name}@${spec}`);
|
||||
|
||||
function packageJson(options: CliOptions) {
|
||||
return {
|
||||
const base = {
|
||||
name: options.projectName,
|
||||
version: "0.1.0",
|
||||
private: true,
|
||||
@@ -22,33 +53,39 @@ function packageJson(options: CliOptions) {
|
||||
lint: "eslint",
|
||||
typecheck: "tsc --noEmit",
|
||||
},
|
||||
dependencies: {
|
||||
"@kri/common": "latest",
|
||||
"@tanstack/react-query": "latest",
|
||||
"class-variance-authority": "latest",
|
||||
clsx: "latest",
|
||||
jotai: "latest",
|
||||
"lucide-react": "latest",
|
||||
next: "latest",
|
||||
react: "latest",
|
||||
"react-dom": "latest",
|
||||
"server-only": "latest",
|
||||
sonner: "latest",
|
||||
"tailwind-merge": "latest",
|
||||
},
|
||||
devDependencies: {
|
||||
"@tailwindcss/postcss": "latest",
|
||||
"@types/node": "latest",
|
||||
"@types/react": "latest",
|
||||
"@types/react-dom": "latest",
|
||||
"babel-plugin-react-compiler": "latest",
|
||||
eslint: "^9",
|
||||
"eslint-config-next": "latest",
|
||||
tailwindcss: "latest",
|
||||
"tw-animate-css": "latest",
|
||||
typescript: "^5",
|
||||
},
|
||||
};
|
||||
|
||||
if (options.install) return base;
|
||||
|
||||
// --skip-install: 설치하지 않으므로 나중에 `npm install`할 수 있도록 spec을 그대로 기록한다.
|
||||
return {
|
||||
...base,
|
||||
dependencies: { "@kri/common": "latest", ...DEPENDENCY_SPECS },
|
||||
devDependencies: { ...DEV_DEPENDENCY_SPECS },
|
||||
};
|
||||
}
|
||||
|
||||
async function readKriCommonCnVersion(targetDir: string): Promise<string | null> {
|
||||
const manifestPath = path.join(targetDir, "node_modules", "@kri", "common", "package.json");
|
||||
const manifest: unknown = JSON.parse(await readFile(manifestPath, "utf8"));
|
||||
if (typeof manifest !== "object" || manifest === null) return null;
|
||||
|
||||
const dependencies = (manifest as { dependencies?: unknown }).dependencies;
|
||||
if (typeof dependencies !== "object" || dependencies === null) return null;
|
||||
|
||||
const cnVersion = (dependencies as Record<string, unknown>).cn;
|
||||
return typeof cnVersion === "string" && cnVersion.trim() !== "" ? cnVersion.trim() : null;
|
||||
}
|
||||
|
||||
// shadcn 기본 컴포넌트는 `cn` 패키지를 직접 import한다. `@kri/common`과 같은 버전으로 맞춰 중복 설치를 막는다.
|
||||
async function syncCnWithKriCommon(targetDir: string): Promise<void> {
|
||||
const cnVersion = await readKriCommonCnVersion(targetDir);
|
||||
if (!cnVersion) {
|
||||
console.warn("[WARN] @kri/common이 cn에 의존하지 않아 cn 버전 동기화를 생략합니다.");
|
||||
return;
|
||||
}
|
||||
|
||||
await run("npm", ["install", "--save-exact", `cn@${cnVersion}`], targetDir);
|
||||
}
|
||||
|
||||
export async function createProject(options: CliOptions): Promise<void> {
|
||||
@@ -86,7 +123,8 @@ export async function createProject(options: CliOptions): Promise<void> {
|
||||
}
|
||||
|
||||
console.log("\n[1/4] npm 의존성 설치");
|
||||
await run("npm", ["install"], options.targetDir);
|
||||
await run("npm", ["install", ...toInstallArgs(DEPENDENCY_SPECS)], options.targetDir);
|
||||
await run("npm", ["install", "--save-dev", ...toInstallArgs(DEV_DEPENDENCY_SPECS)], options.targetDir);
|
||||
|
||||
console.log("\n[2/4] 최신 @kri/common 설치");
|
||||
await run("npm", ["install", "--save-exact", "@kri/common@latest"], options.targetDir);
|
||||
@@ -105,6 +143,10 @@ export async function createProject(options: CliOptions): Promise<void> {
|
||||
console.log("[SKIP] UI Registry 설치");
|
||||
}
|
||||
|
||||
// shadcn 설치가 cn 의존성을 추가·변경할 수 있으므로 UI 설치 뒤에 맞춘다.
|
||||
console.log("\ncn 버전을 @kri/common과 동기화");
|
||||
await syncCnWithKriCommon(options.targetDir);
|
||||
|
||||
if (options.build) {
|
||||
if (!options.installUi) {
|
||||
console.warn("[WARN] --skip-ui 때문에 typecheck/build를 생략합니다.");
|
||||
|
||||
Reference in New Issue
Block a user