fix: 修复模块化项目创建时的模板文件问题以及重命名项目名称问题
fix: 新增项目目录中不存在entities的检查
This commit is contained in:
parent
e46c41812d
commit
00dab2c454
|
|
@ -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);
|
||||
// 只在非模块化模式下重命名整个项目(包括web、wechatMp等)
|
||||
if (!isModule) {
|
||||
(0, rename_1.renameProject)(rootPath, name, title, DEFAULT_PROJECT_NAME, DEFAULT_PROJECT_TITLE);
|
||||
if (example) {
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
|
|
@ -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
|
||||
);
|
||||
|
||||
// 只在非模块化模式下重命名整个项目(包括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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue