@hadss/turbo-trans-json-plugin 1.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +177 -0
- package/README.md +253 -0
- package/dist/core/Types.d.ts +196 -0
- package/dist/core/Types.js +47 -0
- package/dist/core/analyzers/ClassAnalyzer.d.ts +23 -0
- package/dist/core/analyzers/ClassAnalyzer.js +480 -0
- package/dist/core/analyzers/CustomTypeAnalyzer.d.ts +21 -0
- package/dist/core/analyzers/CustomTypeAnalyzer.js +243 -0
- package/dist/core/analyzers/SendableMergeChecker.d.ts +9 -0
- package/dist/core/analyzers/SendableMergeChecker.js +100 -0
- package/dist/core/analyzers/SendableMergeabilityRegistry.d.ts +7 -0
- package/dist/core/analyzers/SendableMergeabilityRegistry.js +23 -0
- package/dist/core/constants/DecoratorConstants.d.ts +7 -0
- package/dist/core/constants/DecoratorConstants.js +13 -0
- package/dist/core/constants/PathConstants.d.ts +6 -0
- package/dist/core/constants/PathConstants.js +10 -0
- package/dist/core/constants/StringConstants.d.ts +83 -0
- package/dist/core/constants/StringConstants.js +87 -0
- package/dist/core/constants/index.d.ts +3 -0
- package/dist/core/constants/index.js +19 -0
- package/dist/core/handlers/BaseTypeHandler.d.ts +23 -0
- package/dist/core/handlers/BaseTypeHandler.js +57 -0
- package/dist/core/handlers/CustomClassHandler.d.ts +21 -0
- package/dist/core/handlers/CustomClassHandler.js +191 -0
- package/dist/core/handlers/DateHandler.d.ts +2 -0
- package/dist/core/handlers/DateHandler.js +60 -0
- package/dist/core/handlers/DecimalHandler.d.ts +2 -0
- package/dist/core/handlers/DecimalHandler.js +60 -0
- package/dist/core/handlers/EnumHandler.d.ts +2 -0
- package/dist/core/handlers/EnumHandler.js +89 -0
- package/dist/core/handlers/GenericContainerHandler.d.ts +2 -0
- package/dist/core/handlers/GenericContainerHandler.js +440 -0
- package/dist/core/handlers/GenericHandler.d.ts +18 -0
- package/dist/core/handlers/GenericHandler.js +92 -0
- package/dist/core/handlers/HandlerBootstrap.d.ts +2 -0
- package/dist/core/handlers/HandlerBootstrap.js +28 -0
- package/dist/core/handlers/ITypeHandler.d.ts +23 -0
- package/dist/core/handlers/ITypeHandler.js +8 -0
- package/dist/core/handlers/PrimitiveHandler.d.ts +2 -0
- package/dist/core/handlers/PrimitiveHandler.js +127 -0
- package/dist/core/handlers/TupleHandler.d.ts +2 -0
- package/dist/core/handlers/TupleHandler.js +98 -0
- package/dist/core/handlers/TypeHandlerRegistry.d.ts +20 -0
- package/dist/core/handlers/TypeHandlerRegistry.js +113 -0
- package/dist/core/handlers/UnionTypeHandler.d.ts +2 -0
- package/dist/core/handlers/UnionTypeHandler.js +263 -0
- package/dist/core/handlers/index.d.ts +2 -0
- package/dist/core/handlers/index.js +5 -0
- package/dist/core/import-rewrite/services/BuildProfileUpdater.d.ts +8 -0
- package/dist/core/import-rewrite/services/BuildProfileUpdater.js +92 -0
- package/dist/core/import-rewrite/services/ImportRewriteService.d.ts +9 -0
- package/dist/core/import-rewrite/services/ImportRewriteService.js +61 -0
- package/dist/core/import-rewrite/services/ImportTransformService.d.ts +15 -0
- package/dist/core/import-rewrite/services/ImportTransformService.js +109 -0
- package/dist/core/import-rewrite/strategies/ImportScanStrategy.d.ts +17 -0
- package/dist/core/import-rewrite/strategies/ImportScanStrategy.js +137 -0
- package/dist/core/import-rewrite/types/ImportRewriteTypes.d.ts +17 -0
- package/dist/core/import-rewrite/types/ImportRewriteTypes.js +2 -0
- package/dist/core/index.d.ts +9 -0
- package/dist/core/index.js +27 -0
- package/dist/core/interfaces/ITask.d.ts +7 -0
- package/dist/core/interfaces/ITask.js +2 -0
- package/dist/core/interfaces/ITaskContext.d.ts +11 -0
- package/dist/core/interfaces/ITaskContext.js +2 -0
- package/dist/core/interfaces/index.d.ts +2 -0
- package/dist/core/interfaces/index.js +2 -0
- package/dist/core/logger/Logger.d.ts +13 -0
- package/dist/core/logger/Logger.js +78 -0
- package/dist/core/services/CodeAnalysisService.d.ts +7 -0
- package/dist/core/services/CodeAnalysisService.js +43 -0
- package/dist/core/services/CodeGenerationEngine.d.ts +12 -0
- package/dist/core/services/CodeGenerationEngine.js +102 -0
- package/dist/core/services/CodeGenerationService/CodeGenerationService.d.ts +13 -0
- package/dist/core/services/CodeGenerationService/CodeGenerationService.js +110 -0
- package/dist/core/services/CodeGenerationService/generators/MergedSendableClassGenerator.d.ts +13 -0
- package/dist/core/services/CodeGenerationService/generators/MergedSendableClassGenerator.js +119 -0
- package/dist/core/services/CodeGenerationService/generators/OriginalClassGenerator.d.ts +21 -0
- package/dist/core/services/CodeGenerationService/generators/OriginalClassGenerator.js +224 -0
- package/dist/core/services/CodeGenerationService/generators/SendableClassGenerator.d.ts +24 -0
- package/dist/core/services/CodeGenerationService/generators/SendableClassGenerator.js +307 -0
- package/dist/core/services/CodeGenerationService/generators/SerializerGenerator.d.ts +28 -0
- package/dist/core/services/CodeGenerationService/generators/SerializerGenerator.js +259 -0
- package/dist/core/services/CodeGenerationService/generators/TempSerializerGenerator.d.ts +19 -0
- package/dist/core/services/CodeGenerationService/generators/TempSerializerGenerator.js +178 -0
- package/dist/core/services/CodeGenerationService/index.d.ts +1 -0
- package/dist/core/services/CodeGenerationService/index.js +5 -0
- package/dist/core/services/CodeGenerationService/shared/ImportManager.d.ts +27 -0
- package/dist/core/services/CodeGenerationService/shared/ImportManager.js +127 -0
- package/dist/core/template/HandlebarsTemplateEngine.d.ts +26 -0
- package/dist/core/template/HandlebarsTemplateEngine.js +226 -0
- package/dist/core/utils/ConfigManager.d.ts +10 -0
- package/dist/core/utils/ConfigManager.js +32 -0
- package/dist/core/utils/CustomError.d.ts +30 -0
- package/dist/core/utils/CustomError.js +37 -0
- package/dist/core/utils/DeepCopyUtil.d.ts +15 -0
- package/dist/core/utils/DeepCopyUtil.js +138 -0
- package/dist/core/utils/GenericTypeSubstitutionUtil.d.ts +9 -0
- package/dist/core/utils/GenericTypeSubstitutionUtil.js +68 -0
- package/dist/core/utils/SerializationPathUtil.d.ts +18 -0
- package/dist/core/utils/SerializationPathUtil.js +107 -0
- package/dist/core/utils/TsMorphUtil.d.ts +8 -0
- package/dist/core/utils/TsMorphUtil.js +34 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +57 -0
- package/dist/json-plugin/JSONExecuteController.d.ts +13 -0
- package/dist/json-plugin/JSONExecuteController.js +103 -0
- package/dist/json-plugin/constants/TaskConstants.d.ts +7 -0
- package/dist/json-plugin/constants/TaskConstants.js +11 -0
- package/dist/json-plugin/interfaces/IModuleContext.d.ts +10 -0
- package/dist/json-plugin/interfaces/IModuleContext.js +2 -0
- package/dist/json-plugin/interfaces/ITargetContext.d.ts +8 -0
- package/dist/json-plugin/interfaces/ITargetContext.js +2 -0
- package/dist/json-plugin/interfaces/impl/ModuleContext.d.ts +12 -0
- package/dist/json-plugin/interfaces/impl/ModuleContext.js +24 -0
- package/dist/json-plugin/interfaces/impl/TargetContext.d.ts +23 -0
- package/dist/json-plugin/interfaces/impl/TargetContext.js +113 -0
- package/dist/json-plugin/tasks/BaseTask.d.ts +14 -0
- package/dist/json-plugin/tasks/BaseTask.js +53 -0
- package/dist/json-plugin/tasks/CleanTask.d.ts +8 -0
- package/dist/json-plugin/tasks/CleanTask.js +25 -0
- package/dist/json-plugin/tasks/CodeProcessingTask.d.ts +8 -0
- package/dist/json-plugin/tasks/CodeProcessingTask.js +26 -0
- package/dist/json-plugin/tasks/SyncTask.d.ts +8 -0
- package/dist/json-plugin/tasks/SyncTask.js +21 -0
- package/dist/json-plugin/tasks/WatchTask.d.ts +11 -0
- package/dist/json-plugin/tasks/WatchTask.js +102 -0
- package/package.json +46 -0
- package/src/core/Types.ts +356 -0
- package/src/core/analyzers/ClassAnalyzer.ts +824 -0
- package/src/core/analyzers/CustomTypeAnalyzer.ts +337 -0
- package/src/core/analyzers/SendableMergeChecker.ts +195 -0
- package/src/core/analyzers/SendableMergeabilityRegistry.ts +72 -0
- package/src/core/constants/DecoratorConstants.ts +27 -0
- package/src/core/constants/PathConstants.ts +31 -0
- package/src/core/constants/StringConstants.ts +152 -0
- package/src/core/constants/index.ts +21 -0
- package/src/core/handlers/BaseTypeHandler.ts +121 -0
- package/src/core/handlers/CustomClassHandler.ts +278 -0
- package/src/core/handlers/DateHandler.ts +75 -0
- package/src/core/handlers/DecimalHandler.ts +75 -0
- package/src/core/handlers/EnumHandler.ts +142 -0
- package/src/core/handlers/GenericContainerHandler.ts +621 -0
- package/src/core/handlers/GenericHandler.ts +130 -0
- package/src/core/handlers/HandlerBootstrap.ts +64 -0
- package/src/core/handlers/ITypeHandler.ts +133 -0
- package/src/core/handlers/PrimitiveHandler.ts +159 -0
- package/src/core/handlers/TupleHandler.ts +145 -0
- package/src/core/handlers/TypeHandlerRegistry.ts +236 -0
- package/src/core/handlers/UnionTypeHandler.ts +400 -0
- package/src/core/handlers/index.ts +18 -0
- package/src/core/import-rewrite/services/BuildProfileUpdater.ts +145 -0
- package/src/core/import-rewrite/services/ImportRewriteService.ts +129 -0
- package/src/core/import-rewrite/services/ImportTransformService.ts +200 -0
- package/src/core/import-rewrite/strategies/ImportScanStrategy.ts +303 -0
- package/src/core/import-rewrite/types/ImportRewriteTypes.ts +100 -0
- package/src/core/index.ts +31 -0
- package/src/core/interfaces/ITask.ts +23 -0
- package/src/core/interfaces/ITaskContext.ts +94 -0
- package/src/core/interfaces/index.ts +17 -0
- package/src/core/logger/Logger.ts +149 -0
- package/src/core/services/CodeAnalysisService.ts +67 -0
- package/src/core/services/CodeGenerationEngine.ts +181 -0
- package/src/core/services/CodeGenerationService/CodeGenerationService.ts +159 -0
- package/src/core/services/CodeGenerationService/generators/MergedSendableClassGenerator.ts +189 -0
- package/src/core/services/CodeGenerationService/generators/OriginalClassGenerator.ts +314 -0
- package/src/core/services/CodeGenerationService/generators/SendableClassGenerator.ts +421 -0
- package/src/core/services/CodeGenerationService/generators/SerializerGenerator.ts +392 -0
- package/src/core/services/CodeGenerationService/generators/TempSerializerGenerator.ts +277 -0
- package/src/core/services/CodeGenerationService/index.ts +16 -0
- package/src/core/services/CodeGenerationService/shared/ImportManager.ts +191 -0
- package/src/core/template/HandlebarsTemplateEngine.ts +282 -0
- package/src/core/utils/ConfigManager.ts +49 -0
- package/src/core/utils/CustomError.ts +51 -0
- package/src/core/utils/DeepCopyUtil.ts +185 -0
- package/src/core/utils/GenericTypeSubstitutionUtil.ts +136 -0
- package/src/core/utils/SerializationPathUtil.ts +142 -0
- package/src/core/utils/TsMorphUtil.ts +50 -0
- package/src/index.ts +81 -0
- package/src/json-plugin/JSONExecuteController.ts +134 -0
- package/src/json-plugin/constants/TaskConstants.ts +22 -0
- package/src/json-plugin/interfaces/IModuleContext.ts +27 -0
- package/src/json-plugin/interfaces/ITargetContext.ts +25 -0
- package/src/json-plugin/interfaces/impl/ModuleContext.ts +45 -0
- package/src/json-plugin/interfaces/impl/TargetContext.ts +196 -0
- package/src/json-plugin/tasks/BaseTask.ts +94 -0
- package/src/json-plugin/tasks/CleanTask.ts +36 -0
- package/src/json-plugin/tasks/CodeProcessingTask.ts +41 -0
- package/src/json-plugin/tasks/SyncTask.ts +33 -0
- package/src/json-plugin/tasks/WatchTask.ts +99 -0
- package/template/SerializerPerformanceTemplate.hbs +35 -0
- package/template/SerializerRegisterTemplate.hbs +10 -0
- package/template/SerializerStrictTemplate.hbs +89 -0
- package/template/SerializerTemplate.hbs +176 -0
- package/tsconfig.json +17 -0
- package/tslint.json +3 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TempSerializerGenerator = void 0;
|
|
7
|
+
const __1 = require("../../..");
|
|
8
|
+
const ImportManager_1 = require("../shared/ImportManager");
|
|
9
|
+
const SerializerGenerator_1 = require("./SerializerGenerator");
|
|
10
|
+
const SerializationPathUtil_1 = __importDefault(require("../../../utils/SerializationPathUtil"));
|
|
11
|
+
const TsMorphUtil_1 = require("../../../utils/TsMorphUtil");
|
|
12
|
+
class TempSerializerGenerator {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.TEMP_SERIALIZER_DIR_NAME = 'tempSerializer';
|
|
15
|
+
this.context = null;
|
|
16
|
+
this.serializerFiles = new Map();
|
|
17
|
+
}
|
|
18
|
+
static getInstance() {
|
|
19
|
+
return this.INSTANCE;
|
|
20
|
+
}
|
|
21
|
+
init(context) {
|
|
22
|
+
this.context = context;
|
|
23
|
+
const tempDir = this.getTempSerializerDir();
|
|
24
|
+
if (!SerializationPathUtil_1.default.exist(tempDir)) {
|
|
25
|
+
SerializationPathUtil_1.default.ensureDirSync(tempDir);
|
|
26
|
+
}
|
|
27
|
+
this.serializerFiles.clear();
|
|
28
|
+
}
|
|
29
|
+
getTempSerializerDir() {
|
|
30
|
+
return SerializationPathUtil_1.default.pathResolve(this.context.getOutputRoot(), this.TEMP_SERIALIZER_DIR_NAME);
|
|
31
|
+
}
|
|
32
|
+
generateSerializer(classAnalysis) {
|
|
33
|
+
const uniqueKey = this.getUniqueKey(classAnalysis);
|
|
34
|
+
if (this.serializerFiles.has(uniqueKey)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const uniqueFileName = this.generateUniqueFileName(classAnalysis);
|
|
38
|
+
const filePath = SerializationPathUtil_1.default.pathResolve(this.getTempSerializerDir(), uniqueFileName);
|
|
39
|
+
const sourceFile = TsMorphUtil_1.TsMorphUtil.getProject().createSourceFile(filePath, '', { overwrite: true });
|
|
40
|
+
const importManager = new ImportManager_1.ImportManager();
|
|
41
|
+
importManager.setContext(this.context);
|
|
42
|
+
this.registerImports(classAnalysis, importManager);
|
|
43
|
+
const serializerGenerator = new SerializerGenerator_1.SerializerGenerator(importManager);
|
|
44
|
+
const serializableGeneratorContext = serializerGenerator.generate(sourceFile, classAnalysis, this.context);
|
|
45
|
+
serializerGenerator.generateRegistration(sourceFile, serializableGeneratorContext);
|
|
46
|
+
const pathPrefix = this.extractPathPrefix(classAnalysis.sourceFilePath);
|
|
47
|
+
this.serializerFiles.set(uniqueKey, {
|
|
48
|
+
className: classAnalysis.className,
|
|
49
|
+
isGeneric: classAnalysis.generics.isGeneric,
|
|
50
|
+
sourceFile,
|
|
51
|
+
importManager,
|
|
52
|
+
uniqueFileName,
|
|
53
|
+
pathPrefix
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
registerImports(classAnalysis, importManager) {
|
|
57
|
+
importManager.registerCustomTypeImport(classAnalysis.sourceFilePath, classAnalysis.className);
|
|
58
|
+
let sourceFile;
|
|
59
|
+
if (classAnalysis.originalClass) {
|
|
60
|
+
sourceFile = classAnalysis.originalClass.getSourceFile();
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
sourceFile = classAnalysis.originalInterface.getSourceFile();
|
|
64
|
+
}
|
|
65
|
+
sourceFile.getSourceFile().getImportDeclarations().forEach(importDecl => {
|
|
66
|
+
const specifier = importDecl.getModuleSpecifierValue();
|
|
67
|
+
const names = importDecl.getNamedImports().map((names) => names.getName());
|
|
68
|
+
const defaultImport = importDecl.getDefaultImport();
|
|
69
|
+
const originalDir = SerializationPathUtil_1.default.dirname(classAnalysis.sourceFilePath);
|
|
70
|
+
const importOriginAbs = SerializationPathUtil_1.default.pathResolve(originalDir, specifier);
|
|
71
|
+
if (SerializationPathUtil_1.default.exist(importOriginAbs + '.ets')) {
|
|
72
|
+
const importOriginAbsWithExt = importOriginAbs + '.ets';
|
|
73
|
+
names.forEach((name) => {
|
|
74
|
+
importManager.registerCustomTypeImport(importOriginAbsWithExt, name);
|
|
75
|
+
});
|
|
76
|
+
if (defaultImport) {
|
|
77
|
+
importManager.registerDefaultImport(importOriginAbsWithExt, defaultImport.getText());
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
names.forEach((name) => {
|
|
82
|
+
importManager.registerCustomImport(specifier, name);
|
|
83
|
+
});
|
|
84
|
+
if (defaultImport) {
|
|
85
|
+
importManager.registerDefaultImport(specifier, defaultImport.getText());
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
saveFile() {
|
|
91
|
+
for (const [_, fileInfo] of this.serializerFiles) {
|
|
92
|
+
fileInfo.importManager.getImportDeclarations().forEach((importDeclaration) => {
|
|
93
|
+
fileInfo.sourceFile.addImportDeclaration({
|
|
94
|
+
moduleSpecifier: importDeclaration.specifier,
|
|
95
|
+
namedImports: [...new Set(importDeclaration.names)]
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
fileInfo.importManager.getDefaultImport().forEach((importDeclaration) => {
|
|
99
|
+
fileInfo.sourceFile.addImportDeclaration({
|
|
100
|
+
moduleSpecifier: importDeclaration.specifier,
|
|
101
|
+
defaultImport: importDeclaration.name
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
fileInfo.sourceFile.formatText();
|
|
105
|
+
fileInfo.sourceFile.saveSync();
|
|
106
|
+
}
|
|
107
|
+
this.generateIndexFile();
|
|
108
|
+
}
|
|
109
|
+
generateIndexFile() {
|
|
110
|
+
const indexFilePath = SerializationPathUtil_1.default.pathResolve(this.getTempSerializerDir(), 'index.ets');
|
|
111
|
+
const indexSourceFile = TsMorphUtil_1.TsMorphUtil.getProject().createSourceFile(indexFilePath, '', { overwrite: true });
|
|
112
|
+
const classNameMap = new Map();
|
|
113
|
+
for (const [_, fileInfo] of this.serializerFiles) {
|
|
114
|
+
const serializerName = `${fileInfo.className}${fileInfo.isGeneric ? __1.StringConstants.SERIALIZER_FACTORY : __1.StringConstants.SERIALIZER}`;
|
|
115
|
+
if (!classNameMap.has(serializerName)) {
|
|
116
|
+
classNameMap.set(serializerName, []);
|
|
117
|
+
}
|
|
118
|
+
classNameMap.get(serializerName).push(fileInfo);
|
|
119
|
+
}
|
|
120
|
+
const exportStatements = [];
|
|
121
|
+
for (const [serializerName, fileInfos] of classNameMap) {
|
|
122
|
+
if (fileInfos.length === 1) {
|
|
123
|
+
const fileInfo = fileInfos[0];
|
|
124
|
+
const importPath = `./${fileInfo.uniqueFileName.replace('.ets', '')}`;
|
|
125
|
+
exportStatements.push(`export { ${serializerName} } from '${importPath}';`);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
for (const fileInfo of fileInfos) {
|
|
129
|
+
const alias = this.generateExportAlias(fileInfo);
|
|
130
|
+
const importPath = `./${fileInfo.uniqueFileName.replace('.ets', '')}`;
|
|
131
|
+
exportStatements.push(`export { ${serializerName} as ${alias} } from '${importPath}';`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
indexSourceFile.addStatements(exportStatements.join('\n'));
|
|
136
|
+
indexSourceFile.formatText();
|
|
137
|
+
indexSourceFile.saveSync();
|
|
138
|
+
}
|
|
139
|
+
generateExportAlias(fileInfo) {
|
|
140
|
+
if (!fileInfo.pathPrefix) {
|
|
141
|
+
return `${fileInfo.className}${__1.StringConstants.SERIALIZER}`;
|
|
142
|
+
}
|
|
143
|
+
const pascalPrefix = fileInfo.pathPrefix
|
|
144
|
+
.split('_')
|
|
145
|
+
.map((part) => part.charAt(0).toUpperCase() + part.slice(1))
|
|
146
|
+
.join('');
|
|
147
|
+
return `${pascalPrefix}${fileInfo.className}${__1.StringConstants.SERIALIZER}`;
|
|
148
|
+
}
|
|
149
|
+
generateUniqueFileName(classAnalysis) {
|
|
150
|
+
const prefix = this.extractPathPrefix(classAnalysis.sourceFilePath);
|
|
151
|
+
if (prefix) {
|
|
152
|
+
return `${prefix}_${classAnalysis.className}${__1.StringConstants.SERIALIZER}.ets`;
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
return `${classAnalysis.className}${__1.StringConstants.SERIALIZER}.ets`;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
extractPathPrefix(sourceFilePath) {
|
|
159
|
+
const relativePath = this.context.calculateSourceRootToModuleRoot(sourceFilePath);
|
|
160
|
+
const dirPath = SerializationPathUtil_1.default.dirname(relativePath);
|
|
161
|
+
if (dirPath === '.' || dirPath === '' || dirPath === 'ets') {
|
|
162
|
+
return '';
|
|
163
|
+
}
|
|
164
|
+
let cleanedDirPath = dirPath;
|
|
165
|
+
if (cleanedDirPath.startsWith('ets/') || cleanedDirPath.startsWith('ets\\')) {
|
|
166
|
+
cleanedDirPath = cleanedDirPath.substring(4);
|
|
167
|
+
}
|
|
168
|
+
if (cleanedDirPath === '' || cleanedDirPath === '.') {
|
|
169
|
+
return '';
|
|
170
|
+
}
|
|
171
|
+
return cleanedDirPath.replace(/[\\/]/g, '_').replace(/[^a-zA-Z0-9_]/g, '_');
|
|
172
|
+
}
|
|
173
|
+
getUniqueKey(classAnalysis) {
|
|
174
|
+
return `${classAnalysis.sourceFilePath}#${classAnalysis.className}`;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
exports.TempSerializerGenerator = TempSerializerGenerator;
|
|
178
|
+
TempSerializerGenerator.INSTANCE = new TempSerializerGenerator();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { CodeGenerationService } from './CodeGenerationService';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CodeGenerationService = void 0;
|
|
4
|
+
var CodeGenerationService_1 = require("./CodeGenerationService");
|
|
5
|
+
Object.defineProperty(exports, "CodeGenerationService", { enumerable: true, get: function () { return CodeGenerationService_1.CodeGenerationService; } });
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ITaskContext } from '../../..';
|
|
2
|
+
export declare class ImportManager {
|
|
3
|
+
private imports;
|
|
4
|
+
private defaultImports;
|
|
5
|
+
private typeToModulePath;
|
|
6
|
+
private context;
|
|
7
|
+
registerCoreImports(interfaceNames: string[]): void;
|
|
8
|
+
registerJsonImports(names: string[]): void;
|
|
9
|
+
registerArkTSImports(names: string[]): void;
|
|
10
|
+
registerCustomImport(modulePath: string, importedName: string): void;
|
|
11
|
+
registerDefaultImport(modulePath: string, importedName: string): void;
|
|
12
|
+
private isModularPath;
|
|
13
|
+
private isRelativePath;
|
|
14
|
+
private removeImportFromModule;
|
|
15
|
+
getImportDeclarations(): {
|
|
16
|
+
specifier: string;
|
|
17
|
+
names: string[];
|
|
18
|
+
}[];
|
|
19
|
+
getDefaultImport(): Array<{
|
|
20
|
+
specifier: string;
|
|
21
|
+
name: string;
|
|
22
|
+
}>;
|
|
23
|
+
clear(): void;
|
|
24
|
+
setContext(context: ITaskContext): void;
|
|
25
|
+
registerCustomTypeImport(customTypeFilePath: string, typeName: string): void;
|
|
26
|
+
registerTempSerializerImport(serializerName: string): void;
|
|
27
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ImportManager = void 0;
|
|
7
|
+
const SerializationPathUtil_1 = __importDefault(require("../../../utils/SerializationPathUtil"));
|
|
8
|
+
class ImportManager {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.imports = new Map();
|
|
11
|
+
this.defaultImports = new Map();
|
|
12
|
+
this.typeToModulePath = new Map();
|
|
13
|
+
this.context = null;
|
|
14
|
+
}
|
|
15
|
+
registerCoreImports(interfaceNames) {
|
|
16
|
+
const coreModule = '@hadss/turbo-trans-core';
|
|
17
|
+
for (const interfaceName of interfaceNames) {
|
|
18
|
+
this.registerCustomImport(coreModule, interfaceName);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
registerJsonImports(names) {
|
|
22
|
+
const jsonModule = '@hadss/turbo-trans-json';
|
|
23
|
+
for (const name of names) {
|
|
24
|
+
this.registerCustomImport(jsonModule, name);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
registerArkTSImports(names) {
|
|
28
|
+
const arkTSModule = '@kit.ArkTS';
|
|
29
|
+
for (const name of names) {
|
|
30
|
+
this.registerCustomImport(arkTSModule, name);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
registerCustomImport(modulePath, importedName) {
|
|
34
|
+
if (this.typeToModulePath.has(importedName)) {
|
|
35
|
+
const existingModulePath = this.typeToModulePath.get(importedName);
|
|
36
|
+
if (this.isModularPath(modulePath) && this.isRelativePath(existingModulePath)) {
|
|
37
|
+
this.removeImportFromModule(existingModulePath, importedName);
|
|
38
|
+
this.typeToModulePath.set(importedName, modulePath);
|
|
39
|
+
}
|
|
40
|
+
else if (this.isRelativePath(modulePath) && this.isModularPath(existingModulePath)) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
this.typeToModulePath.set(importedName, modulePath);
|
|
46
|
+
}
|
|
47
|
+
if (this.imports.has(modulePath)) {
|
|
48
|
+
const existingInfo = this.imports.get(modulePath);
|
|
49
|
+
const names = new Set(existingInfo.importedNames);
|
|
50
|
+
names.add(importedName);
|
|
51
|
+
this.imports.set(modulePath, {
|
|
52
|
+
...existingInfo,
|
|
53
|
+
importedNames: Array.from(names)
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
this.imports.set(modulePath, {
|
|
58
|
+
modulePath,
|
|
59
|
+
importedNames: [importedName],
|
|
60
|
+
isDefaultImport: false,
|
|
61
|
+
isNamespaceImport: false
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
registerDefaultImport(modulePath, importedName) {
|
|
66
|
+
if (this.defaultImports.has(modulePath)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
this.defaultImports.set(modulePath, importedName);
|
|
70
|
+
}
|
|
71
|
+
isModularPath(modulePath) {
|
|
72
|
+
return !modulePath.startsWith('.') &&
|
|
73
|
+
!modulePath.startsWith('/') &&
|
|
74
|
+
!modulePath.startsWith('@') &&
|
|
75
|
+
modulePath.includes('/');
|
|
76
|
+
}
|
|
77
|
+
isRelativePath(modulePath) {
|
|
78
|
+
return modulePath.startsWith('./') || modulePath.startsWith('../');
|
|
79
|
+
}
|
|
80
|
+
removeImportFromModule(modulePath, importedName) {
|
|
81
|
+
if (this.imports.has(modulePath)) {
|
|
82
|
+
const existingInfo = this.imports.get(modulePath);
|
|
83
|
+
const filteredNames = existingInfo.importedNames.filter(name => name !== importedName);
|
|
84
|
+
if (filteredNames.length === 0) {
|
|
85
|
+
this.imports.delete(modulePath);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
this.imports.set(modulePath, {
|
|
89
|
+
...existingInfo,
|
|
90
|
+
importedNames: filteredNames
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
getImportDeclarations() {
|
|
96
|
+
const imports = [];
|
|
97
|
+
for (const [specifier, infos] of this.imports) {
|
|
98
|
+
imports.push({ specifier: specifier, names: infos.importedNames });
|
|
99
|
+
}
|
|
100
|
+
return imports;
|
|
101
|
+
}
|
|
102
|
+
getDefaultImport() {
|
|
103
|
+
const defaultImports = [];
|
|
104
|
+
for (const [specifier, info] of this.defaultImports) {
|
|
105
|
+
defaultImports.push({ specifier: specifier, name: info });
|
|
106
|
+
}
|
|
107
|
+
return defaultImports;
|
|
108
|
+
}
|
|
109
|
+
clear() {
|
|
110
|
+
this.imports.clear();
|
|
111
|
+
this.typeToModulePath.clear();
|
|
112
|
+
}
|
|
113
|
+
setContext(context) {
|
|
114
|
+
this.context = context;
|
|
115
|
+
}
|
|
116
|
+
registerCustomTypeImport(customTypeFilePath, typeName) {
|
|
117
|
+
const modularImportPath = SerializationPathUtil_1.default.calculateModularImportPath(customTypeFilePath, this.context);
|
|
118
|
+
this.registerCustomImport(modularImportPath, typeName);
|
|
119
|
+
}
|
|
120
|
+
registerTempSerializerImport(serializerName) {
|
|
121
|
+
const outputRoot = this.context.getOutputRoot();
|
|
122
|
+
const tempSerializerPath = SerializationPathUtil_1.default.pathResolve(outputRoot, 'tempSerializer');
|
|
123
|
+
const modularImportPath = SerializationPathUtil_1.default.calculateModularImportPath(tempSerializerPath, this.context);
|
|
124
|
+
this.registerCustomImport(modularImportPath, serializerName);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.ImportManager = ImportManager;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as Handlebars from 'handlebars';
|
|
2
|
+
import { GenerationContext } from '..';
|
|
3
|
+
export declare class HandlebarsTemplateEngine {
|
|
4
|
+
private serializationTemplate?;
|
|
5
|
+
private serializationRegisterTemplate?;
|
|
6
|
+
private readonly registerTemplatePath;
|
|
7
|
+
private readonly performanceTemplatePath;
|
|
8
|
+
private readonly strictTemplatePath;
|
|
9
|
+
private readonly commonTemplatePath;
|
|
10
|
+
constructor();
|
|
11
|
+
render(templateName: string, context: GenerationContext): string;
|
|
12
|
+
renderRegister(context: GenerationContext): string;
|
|
13
|
+
registerTemplate(): void;
|
|
14
|
+
registerHelper(name: string, helper: Handlebars.HelperDelegate): void;
|
|
15
|
+
loadTemplateFromString(template: string): HandlebarsTemplateDelegate;
|
|
16
|
+
private registerBuiltinHelpers;
|
|
17
|
+
private registerComparisonHelpers;
|
|
18
|
+
private registerTypeCheckHelpers;
|
|
19
|
+
private hasNonSerializableClassDecorator;
|
|
20
|
+
private hasNonSerializablePropertyDecorators;
|
|
21
|
+
private isPropertyValidForDirectReturn;
|
|
22
|
+
private registerFormattingHelpers;
|
|
23
|
+
private registerPropertyAnalysisHelpers;
|
|
24
|
+
private registerConstructorHelpers;
|
|
25
|
+
private registerLogicHelpers;
|
|
26
|
+
}
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.HandlebarsTemplateEngine = void 0;
|
|
40
|
+
const Handlebars = __importStar(require("handlebars"));
|
|
41
|
+
const __1 = require("..");
|
|
42
|
+
const SerializationPathUtil_1 = __importDefault(require("../utils/SerializationPathUtil"));
|
|
43
|
+
const CustomError_1 = require("../utils/CustomError");
|
|
44
|
+
class HandlebarsTemplateEngine {
|
|
45
|
+
constructor() {
|
|
46
|
+
this.registerTemplatePath = SerializationPathUtil_1.default.pathResolve(__dirname, '../../../template/SerializerRegisterTemplate.hbs');
|
|
47
|
+
this.performanceTemplatePath = SerializationPathUtil_1.default.pathResolve(__dirname, '../../../template/SerializerPerformanceTemplate.hbs');
|
|
48
|
+
this.strictTemplatePath = SerializationPathUtil_1.default.pathResolve(__dirname, '../../../template/SerializerStrictTemplate.hbs');
|
|
49
|
+
this.commonTemplatePath = SerializationPathUtil_1.default.pathResolve(__dirname, '../../../template/SerializerTemplate.hbs');
|
|
50
|
+
this.registerBuiltinHelpers();
|
|
51
|
+
this.registerTemplate();
|
|
52
|
+
}
|
|
53
|
+
render(templateName, context) {
|
|
54
|
+
const template = this.serializationTemplate;
|
|
55
|
+
if (!template) {
|
|
56
|
+
throw new CustomError_1.CustomError(`Template '${templateName}' not found.`, CustomError_1.ErrorCodes.TEMPLATE_NOT_FOUND);
|
|
57
|
+
}
|
|
58
|
+
return template({ deserializeTemplate: templateName, ...context });
|
|
59
|
+
}
|
|
60
|
+
renderRegister(context) {
|
|
61
|
+
const template = this.serializationRegisterTemplate;
|
|
62
|
+
if (!template) {
|
|
63
|
+
throw new CustomError_1.CustomError(`Template not found.`, CustomError_1.ErrorCodes.TEMPLATE_NOT_FOUND);
|
|
64
|
+
}
|
|
65
|
+
return template(context);
|
|
66
|
+
}
|
|
67
|
+
registerTemplate() {
|
|
68
|
+
try {
|
|
69
|
+
const performanceTemplateContent = SerializationPathUtil_1.default.readFileSync(this.performanceTemplatePath).toString();
|
|
70
|
+
Handlebars.registerPartial(__1.DeserializationMode.PERFORMANCE, performanceTemplateContent);
|
|
71
|
+
const strictTemplateContent = SerializationPathUtil_1.default.readFileSync(this.strictTemplatePath).toString();
|
|
72
|
+
Handlebars.registerPartial(__1.DeserializationMode.STRICT, strictTemplateContent);
|
|
73
|
+
const commonTemplateContent = SerializationPathUtil_1.default.readFileSync(this.commonTemplatePath).toString();
|
|
74
|
+
this.serializationTemplate = this.loadTemplateFromString(commonTemplateContent);
|
|
75
|
+
const registerTemplateContent = SerializationPathUtil_1.default.readFileSync(this.registerTemplatePath).toString();
|
|
76
|
+
this.serializationRegisterTemplate = this.loadTemplateFromString(registerTemplateContent);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
throw new CustomError_1.CustomError(`Failed to register template ${error instanceof Error ? error.message : String(error)}`, CustomError_1.ErrorCodes.TEMPLATE_REGISTER_FAIL);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
registerHelper(name, helper) {
|
|
83
|
+
Handlebars.registerHelper(name, helper);
|
|
84
|
+
}
|
|
85
|
+
loadTemplateFromString(template) {
|
|
86
|
+
return Handlebars.compile(template, { noEscape: true });
|
|
87
|
+
}
|
|
88
|
+
registerBuiltinHelpers() {
|
|
89
|
+
this.registerComparisonHelpers();
|
|
90
|
+
this.registerTypeCheckHelpers();
|
|
91
|
+
this.registerFormattingHelpers();
|
|
92
|
+
this.registerPropertyAnalysisHelpers();
|
|
93
|
+
this.registerConstructorHelpers();
|
|
94
|
+
this.registerLogicHelpers();
|
|
95
|
+
}
|
|
96
|
+
registerComparisonHelpers() {
|
|
97
|
+
this.registerHelper('eq', (arg1, arg2) => {
|
|
98
|
+
return (arg1 === arg2);
|
|
99
|
+
});
|
|
100
|
+
this.registerHelper('eqPrimitiveType', (kind) => {
|
|
101
|
+
const primitives = ['string', 'number', 'boolean', 'bigint', 'undefined', 'null'];
|
|
102
|
+
return primitives.includes(kind);
|
|
103
|
+
});
|
|
104
|
+
this.registerHelper('eqEmptyType', (kind) => {
|
|
105
|
+
return ['null', 'undefined'].includes(kind);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
registerTypeCheckHelpers() {
|
|
109
|
+
this.registerHelper('isNumericPropertyName', (propertyName) => {
|
|
110
|
+
return /^\d+$/.test(propertyName);
|
|
111
|
+
});
|
|
112
|
+
this.registerHelper('containsUndefined', (typeText) => {
|
|
113
|
+
return typeText.includes('undefined');
|
|
114
|
+
});
|
|
115
|
+
this.registerHelper('canReturnDirectly', (classAnalysis) => {
|
|
116
|
+
if (this.hasNonSerializableClassDecorator(classAnalysis)) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
if (this.hasNonSerializablePropertyDecorators(classAnalysis)) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
const properties = classAnalysis.properties;
|
|
123
|
+
if (!Array.isArray(properties)) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
return properties.every(prop => this.isPropertyValidForDirectReturn(prop));
|
|
127
|
+
});
|
|
128
|
+
this.registerHelper('isClassType', (cls) => {
|
|
129
|
+
return !!cls.originalClass;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
hasNonSerializableClassDecorator(classAnalysis) {
|
|
133
|
+
const classDecorators = classAnalysis.originalClass?.getDecorators() || [];
|
|
134
|
+
return classDecorators.some(decorator => decorator.getName() !== 'Serializable');
|
|
135
|
+
}
|
|
136
|
+
hasNonSerializablePropertyDecorators(classAnalysis) {
|
|
137
|
+
const props = classAnalysis.originalClass?.getProperties();
|
|
138
|
+
if (!props || !Array.isArray(props)) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
for (const prop of props) {
|
|
142
|
+
const decorators = prop.getDecorators();
|
|
143
|
+
if (decorators && Array.isArray(decorators)) {
|
|
144
|
+
const hasNonSerializableDecorator = decorators.some(decorator => !__1.DecoratorConstants.SERIAL_DECORATORS.includes(decorator.getName()));
|
|
145
|
+
if (hasNonSerializableDecorator) {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
isPropertyValidForDirectReturn(prop) {
|
|
153
|
+
if (prop.decorators?.isTransient) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
if (prop.decorators?.serialName && prop.decorators.serialName !== prop.name) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
if (prop.decorators?.with) {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
const kind = prop.type?.kind;
|
|
163
|
+
const primitives = ['null', 'boolean', 'number', 'string', 'bigint'];
|
|
164
|
+
if (!primitives.includes(kind)) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
if (kind === 'undefined' || kind === 'null') {
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
if (kind === __1.PropertyKind.UNION) {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
registerFormattingHelpers() {
|
|
176
|
+
this.registerHelper('formatGenericArgs', (args) => {
|
|
177
|
+
return Array.isArray(args) && args.length > 0 ? `<${args.join(', ')}>` : '';
|
|
178
|
+
});
|
|
179
|
+
this.registerHelper('formatPropertyName', (property) => {
|
|
180
|
+
return property.decorators?.serialName || property.name;
|
|
181
|
+
});
|
|
182
|
+
this.registerHelper('toLowerCase', (str) => {
|
|
183
|
+
return str.toLowerCase();
|
|
184
|
+
});
|
|
185
|
+
this.registerHelper('genericParametersString', (parameters) => {
|
|
186
|
+
return parameters.join(', ');
|
|
187
|
+
});
|
|
188
|
+
this.registerHelper('genericParametersESObjString', (parameters) => {
|
|
189
|
+
return parameters.map(() => 'ESObject').join(', ');
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
registerPropertyAnalysisHelpers() {
|
|
193
|
+
this.registerHelper('getPropertyIndex', (property, properties) => {
|
|
194
|
+
return properties.findIndex(p => p.analysis.name === property.analysis.name);
|
|
195
|
+
});
|
|
196
|
+
this.registerHelper('postConstructorAssignments', (constructorParam, properties) => {
|
|
197
|
+
return properties?.filter(prop => {
|
|
198
|
+
return !constructorParam?.some((cp) => cp.name === prop.analysis.name);
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
registerConstructorHelpers() {
|
|
203
|
+
this.registerHelper('getCtorProperties', (constructorParam, properties) => {
|
|
204
|
+
return constructorParam?.map(param => {
|
|
205
|
+
const prop = properties?.find(p => p.analysis.name === param.name);
|
|
206
|
+
if (!prop) {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
return prop;
|
|
210
|
+
}).filter(p => p !== null);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
registerLogicHelpers() {
|
|
214
|
+
this.registerHelper('and', (...args) => {
|
|
215
|
+
const values = args.slice(0, -1);
|
|
216
|
+
return values.every(val => !!val);
|
|
217
|
+
});
|
|
218
|
+
this.registerHelper('not', (value) => {
|
|
219
|
+
return !value;
|
|
220
|
+
});
|
|
221
|
+
this.registerHelper('hasDecoratorWith', (decorators) => {
|
|
222
|
+
return !!(decorators?.with);
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
exports.HandlebarsTemplateEngine = HandlebarsTemplateEngine;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TurboTransJsonPluginOptions, ImportRewriteOptions } from '..';
|
|
2
|
+
export declare class ConfigManager {
|
|
3
|
+
private static instance;
|
|
4
|
+
private config;
|
|
5
|
+
private constructor();
|
|
6
|
+
static getInstance(): ConfigManager;
|
|
7
|
+
setConfig(config: TurboTransJsonPluginOptions): void;
|
|
8
|
+
getConfig(): TurboTransJsonPluginOptions;
|
|
9
|
+
getImportRewriteConfig(): ImportRewriteOptions;
|
|
10
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConfigManager = void 0;
|
|
4
|
+
const __1 = require("..");
|
|
5
|
+
class ConfigManager {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.config = null;
|
|
8
|
+
}
|
|
9
|
+
static getInstance() {
|
|
10
|
+
if (!ConfigManager.instance) {
|
|
11
|
+
ConfigManager.instance = new ConfigManager();
|
|
12
|
+
}
|
|
13
|
+
return ConfigManager.instance;
|
|
14
|
+
}
|
|
15
|
+
setConfig(config) {
|
|
16
|
+
this.config = config;
|
|
17
|
+
}
|
|
18
|
+
getConfig() {
|
|
19
|
+
return this.config || {
|
|
20
|
+
ignoreModuleNames: [],
|
|
21
|
+
scanDir: __1.PathConstants.DEFAULT_SCAN_DIRS,
|
|
22
|
+
deserializationMode: __1.DeserializationMode.PERFORMANCE,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
getImportRewriteConfig() {
|
|
26
|
+
return this.config?.importRewrite || {
|
|
27
|
+
scanPaths: ['src/main/ets'],
|
|
28
|
+
preserveOriginalImports: false
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.ConfigManager = ConfigManager;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export declare class CustomError extends Error {
|
|
2
|
+
name: string;
|
|
3
|
+
code: ErrorCodes;
|
|
4
|
+
constructor(message: string, code: ErrorCodes);
|
|
5
|
+
}
|
|
6
|
+
export declare enum ErrorCodes {
|
|
7
|
+
INTERNAL_ERROR = 3000,
|
|
8
|
+
TEMPLATE_NOT_FOUND = 3011,
|
|
9
|
+
TEMPLATE_REGISTER_FAIL = 3012,
|
|
10
|
+
ROOT_DIRECTROY_NOT_FOUND = 3021,
|
|
11
|
+
INVALID_OUTPUT_FAIL = 3022,
|
|
12
|
+
INVALID_FILE_CONTENT = 3023,
|
|
13
|
+
HANDLER_NOT_FOUND = 3031,
|
|
14
|
+
CLASS_DECLARATION_NOT_FOUND = 3032,
|
|
15
|
+
IS_NOT_ENUM = 3033,
|
|
16
|
+
ENUM_STRUCTURE_NOT_FOUND = 3034,
|
|
17
|
+
TYPE_NOT_SUPPORT = 3041,
|
|
18
|
+
LITERAL_NOT_SOPPORT = 3042,
|
|
19
|
+
TRANSIENT_ATTR_OPTIONAL = 3043,
|
|
20
|
+
ANNOTATION_CONFLICT = 3044,
|
|
21
|
+
UNEXPECTED_GENERIC = 3051,
|
|
22
|
+
GENERIC_NOT_MATCH = 3052,
|
|
23
|
+
UNION_STRUCTURE_NOT_FOUND = 3061,
|
|
24
|
+
UNION_EXPEDTED_TWO = 3062,
|
|
25
|
+
UNION_INNER_NOT_FOUND = 3063,
|
|
26
|
+
UNION_UNSUPPORTED_PATTERN = 3064,
|
|
27
|
+
UNION_EXPEDTED_THREE = 3065,
|
|
28
|
+
REWRITE_IMPORT_FAIL = 3071,
|
|
29
|
+
NOT_SENDABLE = 3072
|
|
30
|
+
}
|