260703_01_FST: First Commit
This commit is contained in:
114
src/create-project.ts
Normal file
114
src/create-project.ts
Normal file
@@ -0,0 +1,114 @@
|
||||
import { fileURLToPath } from "node:url";
|
||||
import path from "node:path";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { KRI_REGISTRY_ITEMS, REGISTRY_BASE_URL } from "./constants.js";
|
||||
import { copyTemplate, ensureTargetDirectory, removeJenkinsfile, replacePlaceholders } from "./files.js";
|
||||
import { run } from "./process.js";
|
||||
import type { CliOptions } from "./types.js";
|
||||
|
||||
const currentDir = path.dirname(fileURLToPath(import.meta.url));
|
||||
const templateDir = path.resolve(currentDir, "../templates/base");
|
||||
|
||||
function packageJson(options: CliOptions) {
|
||||
return {
|
||||
name: options.projectName,
|
||||
version: "0.1.0",
|
||||
private: true,
|
||||
scripts: {
|
||||
dev: `next dev -p ${options.port}`,
|
||||
build: "next build",
|
||||
start: `next start -p ${options.port}`,
|
||||
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",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export async function createProject(options: CliOptions): Promise<void> {
|
||||
await ensureTargetDirectory(options.targetDir, options.force);
|
||||
await copyTemplate(templateDir, options.targetDir);
|
||||
|
||||
if (!options.jenkins) await removeJenkinsfile(options.targetDir);
|
||||
|
||||
await replacePlaceholders(options.targetDir, {
|
||||
"__PROJECT_NAME__": options.projectName,
|
||||
"__DISPLAY_NAME__": options.displayName,
|
||||
"__DESCRIPTION__": options.description,
|
||||
"__PORT__": String(options.port),
|
||||
"__REPO_URL__": options.repoUrl,
|
||||
"__APP_ROOT__": options.appRoot,
|
||||
"__SERVICE_NAME__": options.serviceName,
|
||||
"__BRANCH__": options.branch,
|
||||
"__AGENT_LABEL__": options.agentLabel,
|
||||
});
|
||||
|
||||
await writeFile(
|
||||
path.join(options.targetDir, "package.json"),
|
||||
`${JSON.stringify(packageJson(options), null, 2)}
|
||||
`,
|
||||
"utf8",
|
||||
);
|
||||
|
||||
if (!options.install) {
|
||||
console.log("[SKIP] npm install");
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("\n[1/4] npm 의존성 설치");
|
||||
await run("npm", ["install"], options.targetDir);
|
||||
|
||||
console.log("\n[2/4] 최신 @kri/common 설치");
|
||||
await run("npm", ["install", "--save-exact", "@kri/common@latest"], options.targetDir);
|
||||
|
||||
if (options.installUi) {
|
||||
console.log("\n[3/4] shadcn 및 KRI UI Registry 설치");
|
||||
await run("npx", ["--yes", "shadcn@latest", "add", "card", "--yes", "--overwrite"], options.targetDir);
|
||||
for (const item of KRI_REGISTRY_ITEMS) {
|
||||
await run(
|
||||
"npx",
|
||||
["--yes", "shadcn@latest", "add", `${REGISTRY_BASE_URL}/${item}.json`, "--yes", "--overwrite"],
|
||||
options.targetDir,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
console.log("[SKIP] UI Registry 설치");
|
||||
}
|
||||
|
||||
if (options.build) {
|
||||
if (!options.installUi) {
|
||||
console.warn("[WARN] --skip-ui 때문에 typecheck/build를 생략합니다.");
|
||||
return;
|
||||
}
|
||||
console.log("\n[4/4] TypeScript 및 production build 검증");
|
||||
await run("npm", ["run", "typecheck"], options.targetDir);
|
||||
await run("npm", ["run", "build"], options.targetDir);
|
||||
} else {
|
||||
console.log("[SKIP] typecheck/build");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user