From 00dab2c4549adfc4cce5d3f159f224e83f58b0b3 Mon Sep 17 00:00:00 2001 From: qcqcqc <1220204124@zust.edu.cn> Date: Tue, 4 Nov 2025 10:28:15 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E5=8C=96=E9=A1=B9=E7=9B=AE=E5=88=9B=E5=BB=BA=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=E6=96=87=E4=BB=B6=E9=97=AE=E9=A2=98=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E9=87=8D=E5=91=BD=E5=90=8D=E9=A1=B9=E7=9B=AE=E5=90=8D?= =?UTF-8?q?=E7=A7=B0=E9=97=AE=E9=A2=98=20fix:=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E7=9B=AE=E5=BD=95=E4=B8=AD=E4=B8=8D=E5=AD=98?= =?UTF-8?q?=E5=9C=A8entities=E7=9A=84=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/create.js | 35 +++++++++++++++++++++++++++++---- scripts/make-app-domain.js | 8 +++++++- src/create.ts | 40 +++++++++++++++++++++++++++++++++----- 3 files changed, 73 insertions(+), 10 deletions(-) diff --git a/lib/create.js b/lib/create.js index f1a5b1b..350a1a7 100644 --- a/lib/create.js +++ b/lib/create.js @@ -191,8 +191,22 @@ async function create(dirName, cmd) { (0, file_handle_1.checkFileExistsAndCreate)(rootPath); // 复制项目文件 if (isModule) { - // 模块化的项目,只拷贝src和typings目录 - (0, file_handle_1.copyFolder)((0, path_1.join)(emptyTemplatePath, 'src'), (0, path_1.join)(rootPath, 'src')); + // 模块化的项目,只拷贝 src 下的内容,但跳过 pages 目录;同时拷贝 typings + const templateSrc = (0, path_1.join)(emptyTemplatePath, 'src'); + const destSrc = (0, path_1.join)(rootPath, 'src'); + // 确保目标 src 目录存在 + if (!(0, fs_1.existsSync)(destSrc)) { + (0, fs_1.mkdirSync)(destSrc, { recursive: true }); + } + const entries = (0, fs_1.readdirSync)(templateSrc, { withFileTypes: true }); + for (const entry of entries) { + if (entry.name === 'pages') { + continue; // 模块模式下跳过 pages + } + const from = (0, path_1.join)(templateSrc, entry.name); + const to = (0, path_1.join)(destSrc, entry.name); + (0, file_handle_1.copyFolder)(from, to); + } (0, file_handle_1.copyFolder)((0, path_1.join)(emptyTemplatePath, 'typings'), (0, path_1.join)(rootPath, 'typings')); } else { @@ -256,8 +270,21 @@ async function create(dirName, cmd) { }); // 创建package.json (0, file_handle_1.checkFileExistsAndCreate)(packageJsonPath, packageJson, enum_1.checkFileExistsAndCreateType.FILE); - (0, rename_1.renameProject)(rootPath, name, title, DEFAULT_PROJECT_NAME, DEFAULT_PROJECT_TITLE); - if (example) { + // 只在非模块化模式下重命名整个项目(包括web、wechatMp等) + if (!isModule) { + (0, rename_1.renameProject)(rootPath, name, title, DEFAULT_PROJECT_NAME, DEFAULT_PROJECT_TITLE); + } + else { + // 模块化模式下只更新 package.json 的 name + const packageJsonFilePath = (0, path_1.join)(rootPath, 'package.json'); + const packageJsonContent = (0, fs_1.readFileSync)(packageJsonFilePath, 'utf-8'); + const packageJsonJson = JSON.parse(packageJsonContent); + packageJsonJson.name = name; + const newPackageJsonContent = JSON.stringify(packageJsonJson, undefined, 4); + (0, fs_1.writeFileSync)(packageJsonFilePath, newPackageJsonContent); + (0, tip_style_1.Success)(`${(0, tip_style_1.success)(`Change project name to ${(0, tip_style_1.primary)(name)}`)}`); + } + if (example && !isModule) { // todo: copy template example files (0, file_handle_1.copyFolder)(examplePath, rootPath, true); } diff --git a/scripts/make-app-domain.js b/scripts/make-app-domain.js index aa274a9..115ac69 100644 --- a/scripts/make-app-domain.js +++ b/scripts/make-app-domain.js @@ -19,6 +19,12 @@ dependencies.forEach( } ); -analyzeEntities(join(process.cwd(), 'src', 'entities')); +const projectEntitiesPath = join(process.cwd(), 'src', 'entities'); +if (existsSync(projectEntitiesPath)) { + analyzeEntities(projectEntitiesPath, 'src/entities'); +} else { + console.warn('no project entities found'); +} + removeSync(join(process.cwd(), 'src', 'oak-app-domain')); buildSchema(join(process.cwd(), 'src', 'oak-app-domain')); \ No newline at end of file diff --git a/src/create.ts b/src/create.ts index d26c1ef..6e6c817 100644 --- a/src/create.ts +++ b/src/create.ts @@ -1,5 +1,5 @@ import * as ts from 'typescript'; -import { writeFileSync } from 'fs'; +import { writeFileSync, readFileSync, readdirSync, existsSync, mkdirSync } from 'fs'; const { factory } = ts; import { @@ -279,8 +279,22 @@ export async function create(dirName: string, cmd: any) { checkFileExistsAndCreate(rootPath); // 复制项目文件 if (isModule) { - // 模块化的项目,只拷贝src和typings目录 - copyFolder(join(emptyTemplatePath, 'src'), join(rootPath, 'src')); + // 模块化的项目,只拷贝 src 下的内容,但跳过 pages 目录;同时拷贝 typings + const templateSrc = join(emptyTemplatePath, 'src'); + const destSrc = join(rootPath, 'src'); + // 确保目标 src 目录存在 + if (!existsSync(destSrc)) { + mkdirSync(destSrc, { recursive: true }); + } + const entries = readdirSync(templateSrc, { withFileTypes: true }); + for (const entry of entries) { + if (entry.name === 'pages') { + continue; // 模块模式下跳过 pages + } + const from = join(templateSrc, entry.name); + const to = join(destSrc, entry.name); + copyFolder(from, to); + } copyFolder(join(emptyTemplatePath, 'typings'), join(rootPath, 'typings')); } else { @@ -392,9 +406,25 @@ export async function create(dirName: string, cmd: any) { checkFileExistsAndCreateType.FILE ); - renameProject(rootPath, name, title, DEFAULT_PROJECT_NAME, DEFAULT_PROJECT_TITLE); + // 只在非模块化模式下重命名整个项目(包括web、wechatMp等) + if (!isModule) { + renameProject(rootPath, name, title, DEFAULT_PROJECT_NAME, DEFAULT_PROJECT_TITLE); + } else { + // 模块化模式下只更新 package.json 的 name + const packageJsonFilePath = join(rootPath, 'package.json'); + const packageJsonContent = readFileSync(packageJsonFilePath, 'utf-8'); + const packageJsonJson = JSON.parse(packageJsonContent); + packageJsonJson.name = name; + const newPackageJsonContent = JSON.stringify(packageJsonJson, undefined, 4); + writeFileSync(packageJsonFilePath, newPackageJsonContent); + Success( + `${success( + `Change project name to ${primary(name)}` + )}` + ); + } - if (example) { + if (example && !isModule) { // todo: copy template example files copyFolder(examplePath, rootPath, true); }