refactor: 采用方案A - 手工编写配置,删除Common Generator
✅ 删除文件: - tools/.../generators/common-generator.js (已删除) ✅ 新增文件: - libs/wwjcloud-boot/src/config/app-config.service.ts (手工编写) ✅ 修改文件: - migration-coordinator.js: 移除CommonGenerator集成 - config.converter.js: 转换GlobalConfig/WebAppEnvs → this.appConfig - service-method-converter.js: 集成AppConfigService imports分析 - libs/wwjcloud-boot/src/index.ts: 导出AppConfigService 📦 AppConfigService 功能: 1. 整合 Java GlobalConfig (表前缀、版本、域名等) 2. 整合 Java WebAppEnvs (路径配置) 3. 统一配置访问接口 4. 从环境变量/ConfigService读取 🔄 转换策略: - GlobalConfig.tablePrefix → this.appConfig.tablePrefix - WebAppEnvs.get().webRoot → this.appConfig.webRoot - 自动注入 AppConfigService 到需要的Service 📋 架构说明: - GlobalConfig/WebAppEnvs是混合配置(框架+业务) - 不应该由迁移工具自动生成 - 手工编写到 @wwjBoot/config,架构更清晰
This commit is contained in:
@@ -165,10 +165,10 @@ class ServiceMethodConverter {
|
|||||||
jsonImports.forEach(imp => imports.boot.add(imp));
|
jsonImports.forEach(imp => imports.boot.add(imp));
|
||||||
|
|
||||||
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||||
// 【Core层业务配置类】(未迁移,暂时标记TODO)
|
// 【配置访问】AppConfigService (Boot层)
|
||||||
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||||
const configImports = this.config.analyzeImports(convertedBody);
|
const configImports = this.config.analyzeImports(convertedBody);
|
||||||
// 注意:WebAppEnvs/GlobalConfig未来需要从@wwjCore导入,暂时不添加
|
configImports.forEach(imp => imports.boot.add(imp));
|
||||||
|
|
||||||
return {
|
return {
|
||||||
nestjs: Array.from(imports.nestjs),
|
nestjs: Array.from(imports.nestjs),
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
/**
|
/**
|
||||||
* 配置访问转换器
|
* 配置访问转换器
|
||||||
*
|
*
|
||||||
* WebAppEnvs / GlobalConfig → ✅ 保留原样(Core层业务配置类)
|
* WebAppEnvs / GlobalConfig → AppConfigService (Boot层)
|
||||||
*
|
*
|
||||||
* 重要说明:
|
* 策略:
|
||||||
* - WebAppEnvs:应用路径环境配置(projectRoot、webRoot等)
|
* - GlobalConfig.xxx → this.appConfig.xxx
|
||||||
* - GlobalConfig:全局业务配置(表前缀、域名、语言等)
|
* - WebAppEnvs.get().xxx → this.appConfig.xxx
|
||||||
* - 这些是业务配置,不是框架配置!
|
* - 不生成独立的配置类,统一使用 AppConfigService
|
||||||
* - ❌ 不应该转换为 NestJS ConfigService(框架配置)
|
|
||||||
* - ✅ 保留原样,它们会被迁移到 @wwjCore 层
|
|
||||||
*/
|
*/
|
||||||
class ConfigConverter {
|
class ConfigConverter {
|
||||||
/**
|
/**
|
||||||
@@ -18,11 +16,79 @@ class ConfigConverter {
|
|||||||
let tsCode = javaCode;
|
let tsCode = javaCode;
|
||||||
|
|
||||||
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||||
// 【策略】保留原样,不做任何转换!
|
// 【GlobalConfig 转换】
|
||||||
// WebAppEnvs 和 GlobalConfig 会作为业务类迁移到 Core 层
|
|
||||||
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||||
|
|
||||||
// 不做任何转换,直接返回原代码
|
// GlobalConfig.tablePrefix → this.appConfig.tablePrefix
|
||||||
|
tsCode = tsCode.replace(/GlobalConfig\.tablePrefix/g, 'this.appConfig.tablePrefix');
|
||||||
|
|
||||||
|
// GlobalConfig.applicationName → this.appConfig.applicationName
|
||||||
|
tsCode = tsCode.replace(/GlobalConfig\.applicationName/g, 'this.appConfig.applicationName');
|
||||||
|
|
||||||
|
// GlobalConfig.runActive → this.appConfig.runActive
|
||||||
|
tsCode = tsCode.replace(/GlobalConfig\.runActive/g, 'this.appConfig.runActive');
|
||||||
|
|
||||||
|
// GlobalConfig.defaultLanguage → this.appConfig.defaultLanguage
|
||||||
|
tsCode = tsCode.replace(/GlobalConfig\.defaultLanguage/g, 'this.appConfig.defaultLanguage');
|
||||||
|
|
||||||
|
// GlobalConfig.version → this.appConfig.version
|
||||||
|
tsCode = tsCode.replace(/GlobalConfig\.version/g, 'this.appConfig.version');
|
||||||
|
|
||||||
|
// GlobalConfig.appKey → this.appConfig.appKey
|
||||||
|
tsCode = tsCode.replace(/GlobalConfig\.appKey/g, 'this.appConfig.appKey');
|
||||||
|
|
||||||
|
// GlobalConfig.adminDomain → this.appConfig.adminDomain
|
||||||
|
tsCode = tsCode.replace(/GlobalConfig\.adminDomain/g, 'this.appConfig.adminDomain');
|
||||||
|
|
||||||
|
// GlobalConfig.wapDomain → this.appConfig.wapDomain
|
||||||
|
tsCode = tsCode.replace(/GlobalConfig\.wapDomain/g, 'this.appConfig.wapDomain');
|
||||||
|
|
||||||
|
// GlobalConfig.webDomain → this.appConfig.webDomain
|
||||||
|
tsCode = tsCode.replace(/GlobalConfig\.webDomain/g, 'this.appConfig.webDomain');
|
||||||
|
|
||||||
|
// GlobalConfig.defaultAccessPath → this.appConfig.defaultAccessPath
|
||||||
|
tsCode = tsCode.replace(/GlobalConfig\.defaultAccessPath/g, 'this.appConfig.defaultAccessPath');
|
||||||
|
|
||||||
|
// GlobalConfig.isDemo → this.appConfig.isDemo
|
||||||
|
tsCode = tsCode.replace(/GlobalConfig\.isDemo/g, 'this.appConfig.isDemo');
|
||||||
|
|
||||||
|
// GlobalConfig.language() → this.appConfig.language()
|
||||||
|
tsCode = tsCode.replace(/GlobalConfig\.language\(\)/g, 'this.appConfig.language()');
|
||||||
|
|
||||||
|
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||||
|
// 【WebAppEnvs 转换】
|
||||||
|
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||||
|
|
||||||
|
// WebAppEnvs.get().envType → this.appConfig.envType
|
||||||
|
tsCode = tsCode.replace(/WebAppEnvs\.get\(\)\.envType/g, 'this.appConfig.envType');
|
||||||
|
|
||||||
|
// WebAppEnvs.get().projectRoot → this.appConfig.projectRoot
|
||||||
|
tsCode = tsCode.replace(/WebAppEnvs\.get\(\)\.projectRoot/g, 'this.appConfig.projectRoot');
|
||||||
|
|
||||||
|
// WebAppEnvs.get().projectNiucloudAddon → this.appConfig.projectNiucloudAddon
|
||||||
|
tsCode = tsCode.replace(/WebAppEnvs\.get\(\)\.projectNiucloudAddon/g, 'this.appConfig.projectNiucloudAddon');
|
||||||
|
|
||||||
|
// WebAppEnvs.get().webRoot → this.appConfig.webRoot
|
||||||
|
tsCode = tsCode.replace(/WebAppEnvs\.get\(\)\.webRoot/g, 'this.appConfig.webRoot');
|
||||||
|
|
||||||
|
// WebAppEnvs.get().webRootDownAddon → this.appConfig.webRootDownAddon
|
||||||
|
tsCode = tsCode.replace(/WebAppEnvs\.get\(\)\.webRootDownAddon/g, 'this.appConfig.webRootDownAddon');
|
||||||
|
|
||||||
|
// WebAppEnvs.get().webRootDownJar → this.appConfig.webRootDownJar
|
||||||
|
tsCode = tsCode.replace(/WebAppEnvs\.get\(\)\.webRootDownJar/g, 'this.appConfig.webRootDownJar');
|
||||||
|
|
||||||
|
// WebAppEnvs.get().webRootDownPublic → this.appConfig.webRootDownPublic
|
||||||
|
tsCode = tsCode.replace(/WebAppEnvs\.get\(\)\.webRootDownPublic/g, 'this.appConfig.webRootDownPublic');
|
||||||
|
|
||||||
|
// WebAppEnvs.get().webRootDownResource → this.appConfig.webRootDownResource
|
||||||
|
tsCode = tsCode.replace(/WebAppEnvs\.get\(\)\.webRootDownResource/g, 'this.appConfig.webRootDownResource');
|
||||||
|
|
||||||
|
// WebAppEnvs.get().webRootDownRuntime → this.appConfig.webRootDownRuntime
|
||||||
|
tsCode = tsCode.replace(/WebAppEnvs\.get\(\)\.webRootDownRuntime/g, 'this.appConfig.webRootDownRuntime');
|
||||||
|
|
||||||
|
// WebAppEnvs.get() → this.appConfig (兜底)
|
||||||
|
tsCode = tsCode.replace(/WebAppEnvs\.get\(\)/g, 'this.appConfig');
|
||||||
|
|
||||||
return tsCode;
|
return tsCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,17 +98,20 @@ class ConfigConverter {
|
|||||||
analyzeImports(tsCode) {
|
analyzeImports(tsCode) {
|
||||||
const imports = new Set();
|
const imports = new Set();
|
||||||
|
|
||||||
// 检查是否使用了WebAppEnvs或GlobalConfig
|
// 检查是否使用了appConfig
|
||||||
// 这些将来会从 @wwjCore/common 导入
|
if (tsCode.includes('this.appConfig.')) {
|
||||||
if (tsCode.includes('WebAppEnvs')) {
|
imports.add('AppConfigService');
|
||||||
imports.add('WebAppEnvs');
|
|
||||||
}
|
|
||||||
if (tsCode.includes('GlobalConfig')) {
|
|
||||||
imports.add('GlobalConfig');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Array.from(imports);
|
return Array.from(imports);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查是否需要AppConfigService注入
|
||||||
|
*/
|
||||||
|
needsAppConfig(tsCode) {
|
||||||
|
return tsCode.includes('this.appConfig.');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = ConfigConverter;
|
module.exports = ConfigConverter;
|
||||||
|
|||||||
@@ -1,242 +0,0 @@
|
|||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Common层生成器
|
|
||||||
*
|
|
||||||
* 负责迁移Java common层的配置类和工具类到NestJS Core层
|
|
||||||
* 包括:GlobalConfig、WebAppEnvs等业务配置类
|
|
||||||
*/
|
|
||||||
class CommonGenerator {
|
|
||||||
constructor() {
|
|
||||||
this.javaPath = '';
|
|
||||||
this.outputPath = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成Common层文件
|
|
||||||
*/
|
|
||||||
async generate(scanResults, outputPath) {
|
|
||||||
console.log('📦 开始生成Common层配置类...');
|
|
||||||
this.outputPath = outputPath;
|
|
||||||
|
|
||||||
const commonClasses = scanResults.common || [];
|
|
||||||
let generated = 0;
|
|
||||||
|
|
||||||
for (const commonClass of commonClasses) {
|
|
||||||
const className = commonClass.className;
|
|
||||||
|
|
||||||
// 只处理GlobalConfig和WebAppEnvs
|
|
||||||
if (className === 'GlobalConfig' || className === 'WebAppEnvs') {
|
|
||||||
await this.generateCommonClass(commonClass);
|
|
||||||
generated++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`✅ 生成了 ${generated} 个Common配置类`);
|
|
||||||
return generated;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成Common配置类
|
|
||||||
*/
|
|
||||||
async generateCommonClass(commonClass) {
|
|
||||||
const className = commonClass.className;
|
|
||||||
console.log(` 📄 生成 ${className}...`);
|
|
||||||
|
|
||||||
let content = '';
|
|
||||||
|
|
||||||
if (className === 'GlobalConfig') {
|
|
||||||
content = this.generateGlobalConfig(commonClass);
|
|
||||||
} else if (className === 'WebAppEnvs') {
|
|
||||||
content = this.generateWebAppEnvs(commonClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 写入文件
|
|
||||||
const fileName = this.toKebabCase(className) + '.ts';
|
|
||||||
const filePath = path.join(this.outputPath, 'common', fileName);
|
|
||||||
|
|
||||||
// 确保目录存在
|
|
||||||
const dir = path.dirname(filePath);
|
|
||||||
if (!fs.existsSync(dir)) {
|
|
||||||
fs.mkdirSync(dir, { recursive: true });
|
|
||||||
}
|
|
||||||
|
|
||||||
fs.writeFileSync(filePath, content, 'utf8');
|
|
||||||
console.log(` ✅ 已生成: ${filePath}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成GlobalConfig类
|
|
||||||
*/
|
|
||||||
generateGlobalConfig(commonClass) {
|
|
||||||
return `import { Injectable } from '@nestjs/common';
|
|
||||||
import { ConfigService } from '@nestjs/config';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 全局配置
|
|
||||||
*
|
|
||||||
* 从Java GlobalConfig迁移
|
|
||||||
* 原路径: com.niu.core.common.config.GlobalConfig
|
|
||||||
*/
|
|
||||||
@Injectable()
|
|
||||||
export class GlobalConfig {
|
|
||||||
constructor(private readonly configService: ConfigService) {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 表前缀配置
|
|
||||||
*/
|
|
||||||
static tablePrefix = 'nc_';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 配置的默认语言包
|
|
||||||
*/
|
|
||||||
static defaultLanguage = 'zh_CN';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 应用名称
|
|
||||||
*/
|
|
||||||
static applicationName: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 运行环境(dev、prod)
|
|
||||||
*/
|
|
||||||
static runActive: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 后端域名
|
|
||||||
*/
|
|
||||||
static adminDomain: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 手机端域名
|
|
||||||
*/
|
|
||||||
static wapDomain: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* web端域名
|
|
||||||
*/
|
|
||||||
static webDomain: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 版本
|
|
||||||
*/
|
|
||||||
static version = '1.0.1';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 应用key
|
|
||||||
*/
|
|
||||||
static appKey = 'niucloud-admin';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 默认访问路径
|
|
||||||
*/
|
|
||||||
static defaultAccessPath: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否是演示站点
|
|
||||||
*/
|
|
||||||
static isDemo = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取默认语言
|
|
||||||
*/
|
|
||||||
static language(): string {
|
|
||||||
return GlobalConfig.defaultLanguage;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取默认访问路径
|
|
||||||
*/
|
|
||||||
static getDefaultAccessPath(): string {
|
|
||||||
return GlobalConfig.defaultAccessPath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成WebAppEnvs类
|
|
||||||
*/
|
|
||||||
generateWebAppEnvs(commonClass) {
|
|
||||||
return `/**
|
|
||||||
* Web应用环境配置
|
|
||||||
*
|
|
||||||
* 从Java WebAppEnvs迁移
|
|
||||||
* 原路径: com.niu.core.common.component.context.WebAppEnvs
|
|
||||||
*/
|
|
||||||
export class WebAppEnvs {
|
|
||||||
envType: string;
|
|
||||||
projectRoot: string;
|
|
||||||
projectNiucloudAddon: string;
|
|
||||||
webRoot: string;
|
|
||||||
webRootDownAddon: string;
|
|
||||||
webRootDownJar: string;
|
|
||||||
webRootDownPublic: string;
|
|
||||||
webRootDownResource: string;
|
|
||||||
webRootDownRuntime: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取应用环境配置
|
|
||||||
*/
|
|
||||||
static get(active?: string): WebAppEnvs {
|
|
||||||
const runActive = active || process.env.NODE_ENV || 'dev';
|
|
||||||
const appEnvs = new WebAppEnvs();
|
|
||||||
|
|
||||||
if (runActive === 'dev') {
|
|
||||||
appEnvs.envType = 'dev';
|
|
||||||
appEnvs.projectRoot = process.cwd();
|
|
||||||
appEnvs.projectNiucloudAddon = appEnvs.projectRoot + '/niucloud-addon/';
|
|
||||||
appEnvs.webRoot = appEnvs.projectRoot + '/webroot/';
|
|
||||||
appEnvs.webRootDownAddon = appEnvs.projectRoot + '/webroot/addon/';
|
|
||||||
appEnvs.webRootDownJar = appEnvs.projectRoot + '/webroot/jar/';
|
|
||||||
appEnvs.webRootDownPublic = appEnvs.projectRoot + '/webroot/public/';
|
|
||||||
appEnvs.webRootDownResource = appEnvs.projectRoot + '/webroot/resource/';
|
|
||||||
appEnvs.webRootDownRuntime = appEnvs.projectRoot + '/webroot/runtime/';
|
|
||||||
} else {
|
|
||||||
appEnvs.envType = 'prod';
|
|
||||||
// TODO: 生产环境路径配置需要根据实际部署调整
|
|
||||||
appEnvs.webRoot = process.cwd() + '/webroot/';
|
|
||||||
appEnvs.projectRoot = process.cwd();
|
|
||||||
appEnvs.projectNiucloudAddon = appEnvs.projectRoot + '/niucloud-addon/';
|
|
||||||
appEnvs.webRootDownAddon = appEnvs.projectRoot + '/webroot/addon/';
|
|
||||||
appEnvs.webRootDownJar = appEnvs.projectRoot + '/webroot/jar/';
|
|
||||||
appEnvs.webRootDownPublic = appEnvs.projectRoot + '/webroot/public/';
|
|
||||||
appEnvs.webRootDownResource = appEnvs.projectRoot + '/webroot/resource/';
|
|
||||||
appEnvs.webRootDownRuntime = appEnvs.projectRoot + '/webroot/runtime/';
|
|
||||||
}
|
|
||||||
|
|
||||||
return appEnvs;
|
|
||||||
}
|
|
||||||
|
|
||||||
toString(): string {
|
|
||||||
return \`WebAppEnvs
|
|
||||||
{
|
|
||||||
envType='\${this.envType}',
|
|
||||||
projectRoot='\${this.projectRoot}',
|
|
||||||
projectNiucloudAddon='\${this.projectNiucloudAddon}',
|
|
||||||
webRoot='\${this.webRoot}',
|
|
||||||
webRootDownAddon='\${this.webRootDownAddon}',
|
|
||||||
webRootDownJar='\${this.webRootDownJar}',
|
|
||||||
webRootDownPublic='\${this.webRootDownPublic}',
|
|
||||||
webRootDownResource='\${this.webRootDownResource}',
|
|
||||||
webRootDownRuntime='\${this.webRootDownRuntime}'
|
|
||||||
}\`;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 转换为kebab-case
|
|
||||||
*/
|
|
||||||
toKebabCase(str) {
|
|
||||||
return str
|
|
||||||
.replace(/([a-z0-9])([A-Z])/g, '$1-$2')
|
|
||||||
.replace(/([A-Z])([A-Z])(?=[a-z])/g, '$1-$2')
|
|
||||||
.toLowerCase();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = CommonGenerator;
|
|
||||||
|
|
||||||
@@ -5,7 +5,6 @@ const path = require('path');
|
|||||||
const JavaScanner = require('./scanners/java-scanner');
|
const JavaScanner = require('./scanners/java-scanner');
|
||||||
const LayerMapper = require('./mappers/layer-mapper');
|
const LayerMapper = require('./mappers/layer-mapper');
|
||||||
const ModuleGenerator = require('./generators/module-generator');
|
const ModuleGenerator = require('./generators/module-generator');
|
||||||
const CommonGenerator = require('./generators/common-generator');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Java到NestJS迁移协调器
|
* Java到NestJS迁移协调器
|
||||||
@@ -18,14 +17,12 @@ class JavaToNestJSMigrationCoordinator {
|
|||||||
this.scanner = new JavaScanner();
|
this.scanner = new JavaScanner();
|
||||||
this.mapper = new LayerMapper();
|
this.mapper = new LayerMapper();
|
||||||
this.moduleGenerator = new ModuleGenerator();
|
this.moduleGenerator = new ModuleGenerator();
|
||||||
this.commonGenerator = new CommonGenerator();
|
|
||||||
|
|
||||||
this.stats = {
|
this.stats = {
|
||||||
startTime: null,
|
startTime: null,
|
||||||
endTime: null,
|
endTime: null,
|
||||||
filesProcessed: 0,
|
filesProcessed: 0,
|
||||||
modulesGenerated: 0,
|
modulesGenerated: 0,
|
||||||
commonGenerated: 0,
|
|
||||||
errors: []
|
errors: []
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -46,16 +43,12 @@ class JavaToNestJSMigrationCoordinator {
|
|||||||
console.log('\n🔄 第2阶段:映射层级关系...');
|
console.log('\n🔄 第2阶段:映射层级关系...');
|
||||||
const nestJSModules = this.mapLayers();
|
const nestJSModules = this.mapLayers();
|
||||||
|
|
||||||
// 第3阶段:生成Common层配置类
|
// 第3阶段:生成NestJS模块
|
||||||
console.log('\n📦 第3阶段:生成Common层配置类...');
|
console.log('\n🔧 第3阶段:生成NestJS模块...');
|
||||||
await this.generateCommonLayer();
|
|
||||||
|
|
||||||
// 第4阶段:生成NestJS模块
|
|
||||||
console.log('\n🔧 第4阶段:生成NestJS模块...');
|
|
||||||
await this.generateModules(nestJSModules);
|
await this.generateModules(nestJSModules);
|
||||||
|
|
||||||
// 第5阶段:生成报告
|
// 第4阶段:生成报告
|
||||||
console.log('\n📋 第5阶段:生成迁移报告...');
|
console.log('\n📋 第4阶段:生成迁移报告...');
|
||||||
this.generateReport();
|
this.generateReport();
|
||||||
|
|
||||||
this.stats.endTime = new Date();
|
this.stats.endTime = new Date();
|
||||||
@@ -257,17 +250,6 @@ class JavaToNestJSMigrationCoordinator {
|
|||||||
return nestJSModules;
|
return nestJSModules;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 生成Common层配置类
|
|
||||||
*/
|
|
||||||
async generateCommonLayer() {
|
|
||||||
const scanResults = this.scanner.getScanResults();
|
|
||||||
const generated = await this.commonGenerator.generate(scanResults, this.nestJSPath);
|
|
||||||
|
|
||||||
this.stats.commonGenerated = generated;
|
|
||||||
console.log(`✅ 生成了 ${generated} 个Common配置类`);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成NestJS模块
|
* 生成NestJS模块
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,195 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
import * as path from 'path';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用配置服务
|
||||||
|
*
|
||||||
|
* 整合了Java的GlobalConfig和WebAppEnvs的配置
|
||||||
|
* 提供统一的配置访问接口
|
||||||
|
*/
|
||||||
|
@Injectable()
|
||||||
|
export class AppConfigService {
|
||||||
|
constructor(private readonly configService: ConfigService) {}
|
||||||
|
|
||||||
|
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||||
|
// 【框架配置】- 对应 Java GlobalConfig 的框架部分
|
||||||
|
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表前缀配置
|
||||||
|
* 对应 Java: GlobalConfig.tablePrefix
|
||||||
|
*/
|
||||||
|
get tablePrefix(): string {
|
||||||
|
return this.configService.get<string>('TABLE_PREFIX', 'nc_');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用名称
|
||||||
|
* 对应 Java: GlobalConfig.applicationName
|
||||||
|
*/
|
||||||
|
get applicationName(): string {
|
||||||
|
return this.configService.get<string>('APP_NAME', 'niucloud-admin');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 运行环境(dev、prod)
|
||||||
|
* 对应 Java: GlobalConfig.runActive
|
||||||
|
*/
|
||||||
|
get runActive(): string {
|
||||||
|
return process.env.NODE_ENV || 'dev';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否是演示站点
|
||||||
|
* 对应 Java: GlobalConfig.isDemo
|
||||||
|
*/
|
||||||
|
get isDemo(): boolean {
|
||||||
|
return this.configService.get<string>('IS_DEMO', 'false') === 'true';
|
||||||
|
}
|
||||||
|
|
||||||
|
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||||
|
// 【业务配置】- 对应 Java GlobalConfig 的业务部分
|
||||||
|
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置的默认语言包
|
||||||
|
* 对应 Java: GlobalConfig.defaultLanguage
|
||||||
|
*/
|
||||||
|
get defaultLanguage(): string {
|
||||||
|
return this.configService.get<string>('DEFAULT_LANGUAGE', 'zh_CN');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 版本号
|
||||||
|
* 对应 Java: GlobalConfig.version
|
||||||
|
*/
|
||||||
|
get version(): string {
|
||||||
|
return '1.0.1';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用key
|
||||||
|
* 对应 Java: GlobalConfig.appKey
|
||||||
|
*/
|
||||||
|
get appKey(): string {
|
||||||
|
return 'niucloud-admin';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 后端域名
|
||||||
|
* 对应 Java: GlobalConfig.adminDomain
|
||||||
|
*/
|
||||||
|
get adminDomain(): string {
|
||||||
|
return this.configService.get<string>('ADMIN_DOMAIN', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机端域名
|
||||||
|
* 对应 Java: GlobalConfig.wapDomain
|
||||||
|
*/
|
||||||
|
get wapDomain(): string {
|
||||||
|
return this.configService.get<string>('WAP_DOMAIN', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* web端域名
|
||||||
|
* 对应 Java: GlobalConfig.webDomain
|
||||||
|
*/
|
||||||
|
get webDomain(): string {
|
||||||
|
return this.configService.get<string>('WEB_DOMAIN', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认访问路径
|
||||||
|
* 对应 Java: GlobalConfig.defaultAccessPath
|
||||||
|
*/
|
||||||
|
get defaultAccessPath(): string {
|
||||||
|
return this.configService.get<string>('DEFAULT_ACCESS_PATH', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取默认语言
|
||||||
|
* 对应 Java: GlobalConfig.language()
|
||||||
|
*/
|
||||||
|
language(): string {
|
||||||
|
return this.defaultLanguage;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||||
|
// 【路径配置】- 对应 Java WebAppEnvs
|
||||||
|
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 环境类型
|
||||||
|
* 对应 Java: WebAppEnvs.get().envType
|
||||||
|
*/
|
||||||
|
get envType(): string {
|
||||||
|
return this.runActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 项目根目录
|
||||||
|
* 对应 Java: WebAppEnvs.get().projectRoot
|
||||||
|
*/
|
||||||
|
get projectRoot(): string {
|
||||||
|
return process.cwd();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* niucloud插件目录
|
||||||
|
* 对应 Java: WebAppEnvs.get().projectNiucloudAddon
|
||||||
|
*/
|
||||||
|
get projectNiucloudAddon(): string {
|
||||||
|
return path.join(this.projectRoot, 'niucloud-addon/');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* web根目录
|
||||||
|
* 对应 Java: WebAppEnvs.get().webRoot
|
||||||
|
*/
|
||||||
|
get webRoot(): string {
|
||||||
|
return path.join(this.projectRoot, 'webroot/');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 插件下载目录
|
||||||
|
* 对应 Java: WebAppEnvs.get().webRootDownAddon
|
||||||
|
*/
|
||||||
|
get webRootDownAddon(): string {
|
||||||
|
return path.join(this.projectRoot, 'webroot/addon/');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JAR包目录
|
||||||
|
* 对应 Java: WebAppEnvs.get().webRootDownJar
|
||||||
|
*/
|
||||||
|
get webRootDownJar(): string {
|
||||||
|
return path.join(this.projectRoot, 'webroot/jar/');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公共资源目录
|
||||||
|
* 对应 Java: WebAppEnvs.get().webRootDownPublic
|
||||||
|
*/
|
||||||
|
get webRootDownPublic(): string {
|
||||||
|
return path.join(this.projectRoot, 'webroot/public/');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源目录
|
||||||
|
* 对应 Java: WebAppEnvs.get().webRootDownResource
|
||||||
|
*/
|
||||||
|
get webRootDownResource(): string {
|
||||||
|
return path.join(this.projectRoot, 'webroot/resource/');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 运行时目录
|
||||||
|
* 对应 Java: WebAppEnvs.get().webRootDownRuntime
|
||||||
|
*/
|
||||||
|
get webRootDownRuntime(): string {
|
||||||
|
return path.join(this.projectRoot, 'webroot/runtime/');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -40,3 +40,4 @@ export * from "./infra/events/event-listener.service";
|
|||||||
export * from "./infra/events/event-bus";
|
export * from "./infra/events/event-bus";
|
||||||
export * from "./infra/common/result";
|
export * from "./infra/common/result";
|
||||||
export { ConfigService } from "@nestjs/config";
|
export { ConfigService } from "@nestjs/config";
|
||||||
|
export { AppConfigService } from "./config/app-config.service";
|
||||||
|
|||||||
Reference in New Issue
Block a user