@odata2ts/odata2ts 0.33.0 → 0.33.2

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.
Files changed (58) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/lib/FactoryFunctionModel.d.ts +3 -3
  3. package/lib/FactoryFunctionModel.js.map +1 -1
  4. package/lib/OptionModel.d.ts +9 -0
  5. package/lib/OptionModel.js.map +1 -1
  6. package/lib/app.js +18 -8
  7. package/lib/app.js.map +1 -1
  8. package/lib/data-model/DataModel.d.ts +12 -6
  9. package/lib/data-model/DataModel.js +10 -0
  10. package/lib/data-model/DataModel.js.map +1 -1
  11. package/lib/data-model/DataModelDigestion.js +37 -20
  12. package/lib/data-model/DataModelDigestion.js.map +1 -1
  13. package/lib/data-model/DataModelDigestionV4.js +0 -9
  14. package/lib/data-model/DataModelDigestionV4.js.map +1 -1
  15. package/lib/data-model/DataTypeModel.d.ts +17 -7
  16. package/lib/data-model/DataTypeModel.js.map +1 -1
  17. package/lib/data-model/NamingHelper.d.ts +1 -0
  18. package/lib/data-model/NamingHelper.js +4 -1
  19. package/lib/data-model/NamingHelper.js.map +1 -1
  20. package/lib/data-model/ServiceConfigHelper.js +2 -2
  21. package/lib/data-model/ServiceConfigHelper.js.map +1 -1
  22. package/lib/data-model/validation/NameClashValidator.d.ts +23 -0
  23. package/lib/data-model/validation/NameClashValidator.js +89 -0
  24. package/lib/data-model/validation/NameClashValidator.js.map +1 -0
  25. package/lib/data-model/validation/NameValidator.d.ts +6 -17
  26. package/lib/data-model/validation/NameValidator.js +0 -77
  27. package/lib/data-model/validation/NameValidator.js.map +1 -1
  28. package/lib/data-model/validation/NoopValidator.d.ts +12 -0
  29. package/lib/data-model/validation/NoopValidator.js +34 -0
  30. package/lib/data-model/validation/NoopValidator.js.map +1 -0
  31. package/lib/defaultConfig.js +1 -0
  32. package/lib/defaultConfig.js.map +1 -1
  33. package/lib/generator/ImportContainer.d.ts +44 -11
  34. package/lib/generator/ImportContainer.js +150 -47
  35. package/lib/generator/ImportContainer.js.map +1 -1
  36. package/lib/generator/ImportedNameValidator.d.ts +5 -0
  37. package/lib/generator/ImportedNameValidator.js +26 -0
  38. package/lib/generator/ImportedNameValidator.js.map +1 -0
  39. package/lib/generator/ModelGenerator.js +113 -72
  40. package/lib/generator/ModelGenerator.js.map +1 -1
  41. package/lib/generator/QueryObjectGenerator.js +134 -107
  42. package/lib/generator/QueryObjectGenerator.js.map +1 -1
  43. package/lib/generator/ServiceGenerator.d.ts +1 -1
  44. package/lib/generator/ServiceGenerator.js +160 -161
  45. package/lib/generator/ServiceGenerator.js.map +1 -1
  46. package/lib/generator/import/ImportObjects.d.ts +66 -0
  47. package/lib/generator/import/ImportObjects.js +83 -0
  48. package/lib/generator/import/ImportObjects.js.map +1 -0
  49. package/lib/project/FileHandler.d.ts +28 -0
  50. package/lib/project/FileHandler.js +66 -0
  51. package/lib/project/FileHandler.js.map +1 -0
  52. package/lib/project/ProjectManager.d.ts +44 -18
  53. package/lib/project/ProjectManager.js +155 -111
  54. package/lib/project/ProjectManager.js.map +1 -1
  55. package/lib/project/TsMorphHelper.d.ts +11 -0
  56. package/lib/project/TsMorphHelper.js +66 -0
  57. package/lib/project/TsMorphHelper.js.map +1 -0
  58. package/package.json +10 -8
@@ -2,156 +2,200 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ProjectManager = exports.createProjectManager = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const promises_1 = require("fs/promises");
6
5
  const path = tslib_1.__importStar(require("path"));
7
6
  const fs_extra_1 = require("fs-extra");
8
7
  const ts_morph_1 = require("ts-morph");
9
- const tsconfig_loader_1 = tslib_1.__importDefault(require("tsconfig-loader"));
10
- const typescript_1 = tslib_1.__importDefault(require("typescript"));
11
- const OptionModel_1 = require("../OptionModel");
8
+ const processors_1 = require("xml2js/lib/processors");
9
+ const FileHandler_1 = require("./FileHandler");
12
10
  const formatter_1 = require("./formatter");
13
- function createProjectManager(projectFiles, outputDir, emitMode, usePrettier, tsConfigPath = "tsconfig.json") {
11
+ const TsMorphHelper_1 = require("./TsMorphHelper");
12
+ function createProjectManager(outputDir, emitMode, namingHelper, dataModel, options) {
14
13
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
15
- const generateDeclarations = OptionModel_1.EmitModes.js_dts === emitMode || OptionModel_1.EmitModes.dts === emitMode;
16
- const conf = (0, tsconfig_loader_1.default)({ filename: tsConfigPath });
17
- const formatter = yield (0, formatter_1.createFormatter)(outputDir, usePrettier);
18
- const _a = (conf === null || conf === void 0 ? void 0 : conf.tsConfig.compilerOptions) || {}, {
19
- // ignored props
20
- noEmit, // we always want to emit
21
- importsNotUsedAsValues, // type is missing
22
- jsx, plugins,
23
- // mapped props
24
- moduleResolution, lib, module, newLine, target, rootDir, rootDirs } = _a, passThrough = tslib_1.__rest(_a, ["noEmit", "importsNotUsedAsValues", "jsx", "plugins", "moduleResolution", "lib", "module", "newLine", "target", "rootDir", "rootDirs"]);
25
- const compilerOpts = Object.assign(Object.assign({}, passThrough), { outDir: outputDir, declaration: generateDeclarations, moduleResolution: getModuleResolutionKind(moduleResolution), module: getModuleKind(module), target: getTarget(target), lib: lib, newLine: (newLine === null || newLine === void 0 ? void 0 : newLine.toLowerCase()) === "crlf"
26
- ? ts_morph_1.NewLineKind.CarriageReturnLineFeed
27
- : (newLine === null || newLine === void 0 ? void 0 : newLine.toLowerCase()) === "lf"
28
- ? ts_morph_1.NewLineKind.LineFeed
29
- : undefined });
30
- return new ProjectManager(projectFiles, outputDir, emitMode, formatter, compilerOpts);
14
+ const { usePrettier = false, tsConfigPath = "tsconfig.json" } = options;
15
+ const formatter = usePrettier ? yield (0, formatter_1.createFormatter)(outputDir, usePrettier) : undefined;
16
+ const compilerOpts = yield (0, TsMorphHelper_1.loadTsMorphCompilerOptions)(tsConfigPath, emitMode, outputDir);
17
+ const pm = new ProjectManager(outputDir, emitMode, namingHelper, dataModel, formatter, compilerOpts, Object.assign({ usePrettier,
18
+ tsConfigPath }, options));
19
+ yield pm.init();
20
+ return pm;
31
21
  });
32
22
  }
33
23
  exports.createProjectManager = createProjectManager;
34
- function getModuleResolutionKind(moduleResolution) {
35
- const modRes = typeof moduleResolution === "string"
36
- ? moduleResolution.toLowerCase() === "node"
37
- ? "nodejs"
38
- : moduleResolution.toLowerCase()
39
- : undefined;
40
- const matchedKey = Object.keys(typescript_1.default.ModuleResolutionKind).find((mk) => mk.toLowerCase() === modRes);
41
- return matchedKey ? typescript_1.default.ModuleResolutionKind[matchedKey] : undefined;
42
- }
43
- function getModuleKind(module) {
44
- const mod = typeof module === "string" ? module.toLowerCase() : undefined;
45
- const matchedKey = Object.keys(typescript_1.default.ModuleKind).find((mk) => mk.toLowerCase() === mod);
46
- return matchedKey ? typescript_1.default.ModuleKind[matchedKey] : undefined;
47
- }
48
- function getTarget(target) {
49
- const t = typeof target === "string" ? target.toLowerCase() : undefined;
50
- const matchedKey = Object.keys(typescript_1.default.ScriptTarget).find((st) => st.toLowerCase() === t);
51
- return matchedKey ? typescript_1.default.ScriptTarget[matchedKey] : undefined;
52
- }
53
24
  class ProjectManager {
54
- constructor(projectFiles, outputDir, emitMode, formatter, compilerOptions) {
55
- this.projectFiles = projectFiles;
25
+ constructor(outputDir, emitMode, namingHelper, dataModel, formatter, compilerOptions, options) {
56
26
  this.outputDir = outputDir;
57
27
  this.emitMode = emitMode;
28
+ this.namingHelper = namingHelper;
29
+ this.dataModel = dataModel;
58
30
  this.formatter = formatter;
59
- this.files = {};
60
- this.formatAndWriteFile = (file) => tslib_1.__awaiter(this, void 0, void 0, function* () {
61
- const fileName = file.getFilePath();
62
- const content = file.getFullText();
63
- try {
64
- const formatted = yield this.formatter.format(content);
65
- try {
66
- return (0, promises_1.writeFile)(fileName, formatted);
67
- }
68
- catch (writeError) {
69
- console.error(`Failed to write file [/${fileName}]`, writeError);
70
- process.exit(3);
71
- }
72
- }
73
- catch (formattingError) {
74
- console.error("Formatting failed", formattingError);
75
- yield (0, promises_1.writeFile)("error.log", (formattingError === null || formattingError === void 0 ? void 0 : formattingError.toString()) || "no error message!");
76
- process.exit(99);
77
- }
78
- });
31
+ this.options = options;
79
32
  // Create ts-morph project
80
33
  this.project = new ts_morph_1.Project({
81
- manipulationSettings: this.formatter.getSettings(),
34
+ // manipulationSettings: this.formatter.getSettings(),
82
35
  skipAddingFilesFromTsConfig: true,
83
36
  compilerOptions,
84
37
  });
38
+ if (options.noOutput) {
39
+ this.cachedFiles = new Map();
40
+ }
85
41
  }
86
- createFile(name) {
87
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
88
- const fileName = path.join(this.outputDir, `${name}.ts`);
89
- yield (0, fs_extra_1.remove)(fileName);
90
- return this.project.createSourceFile(fileName);
91
- });
42
+ getDataModel() {
43
+ return this.dataModel;
92
44
  }
93
- createModelFile() {
45
+ /**
46
+ * Only filled when noOutput=true
47
+ */
48
+ getCachedFiles() {
49
+ return this.cachedFiles;
50
+ }
51
+ writeFile(fileHandler) {
94
52
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
95
- this.files.model = yield this.createFile(this.projectFiles.model);
96
- return this.getModelFile();
53
+ if (this.options.noOutput) {
54
+ fileHandler.getFile().addImportDeclarations(fileHandler.getImports().getImportDeclarations());
55
+ this.cachedFiles.set(fileHandler.getFullFilePath(), fileHandler.getFile());
56
+ return;
57
+ }
58
+ return fileHandler.write(this.emitMode);
97
59
  });
98
60
  }
99
- getModelFile() {
100
- return this.files.model;
61
+ createFile(name, reservedNames, additionalPath = "") {
62
+ const fileName = path.join(this.outputDir, additionalPath, `${name}.ts`);
63
+ return new FileHandler_1.FileHandler(additionalPath, name, this.project.createSourceFile(fileName), this.dataModel, this.namingHelper.getFileNames(), !!this.options.bundledFileGeneration, this.formatter, reservedNames);
101
64
  }
102
- createQObjectFile() {
65
+ init() {
103
66
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
104
- this.files.qobject = yield this.createFile(this.projectFiles.qObject);
105
- return this.getQObjectFile();
67
+ if (!this.options.bundledFileGeneration) {
68
+ // ensure folder for each model: we do this at this point for performance reasons
69
+ yield Promise.all(this.dataModel.getModelTypes().map((mt) => (0, fs_extra_1.ensureDir)(path.join(this.outputDir, mt.folderPath))));
70
+ }
71
+ const typePart = this.emitMode.toUpperCase().replace("_", " & ");
72
+ console.log(`Prepared to emit ${typePart} files.`);
106
73
  });
107
74
  }
108
- getQObjectFile() {
109
- return this.files.qobject;
75
+ initModels() {
76
+ if (this.options.bundledFileGeneration) {
77
+ // collect reserved names, that is names of classes we're going to create => imports must take them into account
78
+ const reservedWords = this.dataModel.getModelTypes().reduce((collector, model) => {
79
+ var _a;
80
+ const asEntityType = model;
81
+ collector.push(model.modelName);
82
+ if (asEntityType.editableName) {
83
+ collector.push(asEntityType.editableName);
84
+ }
85
+ if ((_a = asEntityType.id) === null || _a === void 0 ? void 0 : _a.modelName) {
86
+ collector.push(asEntityType.id.modelName);
87
+ }
88
+ this.dataModel.getAllEntityOperations(model.fqName).forEach((op) => {
89
+ if (op.parameters.length) {
90
+ collector.push(op.paramsModelName);
91
+ }
92
+ });
93
+ return collector;
94
+ }, []);
95
+ this.dataModel.getUnboundOperationTypes().forEach((op) => {
96
+ if (op.parameters.length) {
97
+ reservedWords.push(op.paramsModelName);
98
+ }
99
+ });
100
+ this.mainModelFile = this.createFile(this.namingHelper.getFileNames().model, reservedWords);
101
+ }
110
102
  }
111
- createMainServiceFile() {
103
+ finalizeModels() {
112
104
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
113
- this.files.mainService = yield this.createFile(this.projectFiles.service);
114
- return this.getMainServiceFile();
105
+ if (this.mainModelFile) {
106
+ yield this.writeFile(this.mainModelFile);
107
+ }
115
108
  });
116
109
  }
117
- getMainServiceFile() {
118
- return this.files.mainService;
110
+ initQObjects() {
111
+ if (this.options.bundledFileGeneration) {
112
+ // collect reserved names, that is names of classes we're going to create => imports must take them into account
113
+ const reservedWords = this.dataModel.getModelTypes().reduce((collector, model) => {
114
+ var _a;
115
+ const asEntityType = model;
116
+ if (asEntityType.qName) {
117
+ collector.push(asEntityType.qName, (0, processors_1.firstCharLowerCase)(asEntityType.qName));
118
+ }
119
+ if ((_a = asEntityType.id) === null || _a === void 0 ? void 0 : _a.qName) {
120
+ collector.push(asEntityType.id.qName);
121
+ }
122
+ this.dataModel.getAllEntityOperations(model.fqName).forEach((op) => {
123
+ collector.push(op.qName);
124
+ });
125
+ return collector;
126
+ }, []);
127
+ this.dataModel.getUnboundOperationTypes().forEach((op) => {
128
+ reservedWords.push(op.qName);
129
+ });
130
+ this.mainQFile = this.createFile(this.namingHelper.getFileNames().qObject, reservedWords);
131
+ }
119
132
  }
120
- writeFiles() {
133
+ finalizeQObjects() {
121
134
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
122
- switch (this.emitMode) {
123
- case OptionModel_1.EmitModes.js:
124
- case OptionModel_1.EmitModes.js_dts:
125
- yield this.emitJsFiles();
126
- break;
127
- case OptionModel_1.EmitModes.dts:
128
- yield this.emitJsFiles(true);
129
- break;
130
- case OptionModel_1.EmitModes.ts:
131
- yield this.emitTsFiles();
132
- break;
133
- default:
134
- throw new Error(`Emit mode "${this.emitMode}" is invalid!`);
135
+ if (this.mainQFile) {
136
+ yield this.writeFile(this.mainQFile);
135
137
  }
136
138
  });
137
139
  }
138
- emitJsFiles(declarationOnly) {
140
+ initServices() {
141
+ const mainServiceName = this.namingHelper.getMainServiceName();
142
+ const reservedNames = [mainServiceName];
143
+ if (this.options.bundledFileGeneration) {
144
+ [...this.dataModel.getEntityTypes(), ...this.dataModel.getComplexTypes()].reduce((collector, model) => {
145
+ collector.push(model.serviceName, model.serviceCollectionName);
146
+ return collector;
147
+ }, reservedNames);
148
+ }
149
+ this.mainServiceFile = this.createFile(mainServiceName, reservedNames);
150
+ }
151
+ finalizeServices() {
139
152
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
140
- console.log(declarationOnly
141
- ? "Emitting declaration files"
142
- : `Emitting JS files (${this.emitMode === OptionModel_1.EmitModes.js_dts ? "including" : "without"} declaration files)`);
143
- yield this.project.emit({ emitOnlyDtsFiles: !!declarationOnly });
144
- /* for (const diagnostic of this.project.getPreEmitDiagnostics()) {
145
- console.log(diagnostic.getMessageText());
146
- } */
153
+ if (this.mainServiceFile) {
154
+ yield this.writeFile(this.mainServiceFile);
155
+ }
147
156
  });
148
157
  }
149
- emitTsFiles() {
158
+ getMainServiceFile() {
159
+ return this.mainServiceFile;
160
+ }
161
+ createOrGetMainModelFile(reservedNames) {
162
+ if (!this.mainModelFile) {
163
+ this.mainModelFile = this.createFile(this.namingHelper.getFileNames().model, reservedNames);
164
+ }
165
+ return this.mainModelFile;
166
+ }
167
+ createOrGetMainQObjectFile(reservedNames) {
168
+ if (!this.mainQFile) {
169
+ this.mainQFile = this.createFile(this.namingHelper.getFileNames().qObject, reservedNames);
170
+ }
171
+ return this.mainQFile;
172
+ }
173
+ createOrGetModelFile(folderPath, name, reservedNames) {
174
+ if (this.mainModelFile) {
175
+ return this.mainModelFile;
176
+ }
177
+ return this.createFile(name, reservedNames, folderPath);
178
+ }
179
+ createOrGetQObjectFile(folderPath, name, reservedNames) {
180
+ if (this.mainQFile) {
181
+ return this.mainQFile;
182
+ }
183
+ return this.createFile(name, reservedNames, folderPath);
184
+ }
185
+ createOrGetServiceFile(folderPath, name, reservedNames) {
186
+ if (this.options.bundledFileGeneration) {
187
+ return this.mainServiceFile;
188
+ }
189
+ return this.createFile(name, reservedNames, folderPath);
190
+ }
191
+ finalizeFile(file) {
150
192
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
151
- const files = [this.getModelFile(), this.getQObjectFile(), this.getMainServiceFile()].filter((file) => !!file);
152
- const text = files.length === 1 ? "Emitting 1 TS file" : `Emitting ${files.length} TS files`;
153
- console.log(`${text}: ${files.map((f) => path.basename(f.getFilePath())).join(", ")}`);
154
- return Promise.all(files.map(this.formatAndWriteFile));
193
+ // write individual files in unbundled mode & if this is not one of the main files on root level
194
+ if (!this.options.bundledFileGeneration &&
195
+ file.path !== "" &&
196
+ !Object.values(this.namingHelper.getFileNames()).includes(file.fileName)) {
197
+ yield this.writeFile(file);
198
+ }
155
199
  });
156
200
  }
157
201
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ProjectManager.js","sourceRoot":"","sources":["../../src/project/ProjectManager.ts"],"names":[],"mappings":";;;;AAAA,0CAAwC;AACxC,mDAA6B;AAE7B,uCAAkC;AAClC,uCAQkB;AAClB,8EAAmC;AACnC,oEAA4B;AAG5B,gDAA2C;AAC3C,2CAA8C;AAG9C,SAAsB,oBAAoB,CACxC,YAA0B,EAC1B,SAAiB,EACjB,QAAmB,EACnB,WAAoB,EACpB,eAAuB,eAAe;;QAEtC,MAAM,oBAAoB,GAAG,uBAAS,CAAC,MAAM,KAAK,QAAQ,IAAI,uBAAS,CAAC,GAAG,KAAK,QAAQ,CAAC;QACzF,MAAM,IAAI,GAAG,IAAA,yBAAI,EAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC,CAAC;QAC9C,MAAM,SAAS,GAAG,MAAM,IAAA,2BAAe,EAAC,SAAS,EAAE,WAAW,CAAC,CAAC;QAEhE,MAAM,KAeF,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,QAAQ,CAAC,eAAe,KAAI,EAAE,EAflC;QACJ,gBAAgB;QAChB,MAAM,EAAE,yBAAyB;QACjC,sBAAsB,EAAE,kBAAkB;QAC1C,GAAG,EACH,OAAO;QACP,eAAe;QACf,gBAAgB,EAChB,GAAG,EACH,MAAM,EACN,OAAO,EACP,MAAM,EACN,OAAO,EACP,QAAQ,OAE8B,EADnC,WAAW,sBAdV,uIAeL,CAAuC,CAAC;QAEzC,MAAM,YAAY,mCACb,WAAW,KACd,MAAM,EAAE,SAAS,EACjB,WAAW,EAAE,oBAAoB,EACjC,gBAAgB,EAAE,uBAAuB,CAAC,gBAAgB,CAAC,EAC3D,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,EAC7B,MAAM,EAA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IAAI,CAAC,EAAE,gBAAgB,EAAE,CAAC,CAAC,eAAe,EAAE,CAAC,CAAC;YAEjE;;gBAEI;QACN,CAAC;KAAA;IAEa,WAAW;;YACvB,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,IAAI,CAAC,cAAc,EAAE,EAAE,IAAI,CAAC,kBAAkB,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YAC/G,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,YAAY,KAAK,CAAC,MAAM,WAAW,CAAC;YAC7F,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,KAAK,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACvF,OAAO,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC;QACzD,CAAC;KAAA;CAqBF;AA9GD,wCA8GC","sourcesContent":["import { writeFile } from \"fs/promises\";\r\nimport * as path from \"path\";\r\n\r\nimport { remove } from \"fs-extra\";\r\nimport {\r\n CompilerOptions,\r\n ModuleKind,\r\n ModuleResolutionKind,\r\n NewLineKind,\r\n Project,\r\n ScriptTarget,\r\n SourceFile,\r\n} from \"ts-morph\";\r\nimport load from \"tsconfig-loader\";\r\nimport ts from \"typescript\";\r\n\r\nimport { ProjectFiles } from \"../data-model/DataModel\";\r\nimport { EmitModes } from \"../OptionModel\";\r\nimport { createFormatter } from \"./formatter\";\r\nimport { FileFormatter } from \"./formatter/FileFormatter\";\r\n\r\nexport async function createProjectManager(\r\n projectFiles: ProjectFiles,\r\n outputDir: string,\r\n emitMode: EmitModes,\r\n usePrettier: boolean,\r\n tsConfigPath: string = \"tsconfig.json\"\r\n): Promise<ProjectManager> {\r\n const generateDeclarations = EmitModes.js_dts === emitMode || EmitModes.dts === emitMode;\r\n const conf = load({ filename: tsConfigPath });\r\n const formatter = await createFormatter(outputDir, usePrettier);\r\n\r\n const {\r\n // ignored props\r\n noEmit, // we always want to emit\r\n importsNotUsedAsValues, // type is missing\r\n jsx,\r\n plugins,\r\n // mapped props\r\n moduleResolution,\r\n lib,\r\n module,\r\n newLine,\r\n target,\r\n rootDir,\r\n rootDirs,\r\n ...passThrough\r\n } = conf?.tsConfig.compilerOptions || {};\r\n\r\n const compilerOpts: CompilerOptions = {\r\n ...passThrough,\r\n outDir: outputDir,\r\n declaration: generateDeclarations,\r\n moduleResolution: getModuleResolutionKind(moduleResolution),\r\n module: getModuleKind(module),\r\n target: getTarget(target),\r\n lib: lib as string[],\r\n newLine:\r\n newLine?.toLowerCase() === \"crlf\"\r\n ? NewLineKind.CarriageReturnLineFeed\r\n : newLine?.toLowerCase() === \"lf\"\r\n ? NewLineKind.LineFeed\r\n : undefined,\r\n };\r\n\r\n return new ProjectManager(projectFiles, outputDir, emitMode, formatter, compilerOpts);\r\n}\r\n\r\nfunction getModuleResolutionKind(\r\n moduleResolution: string | undefined | Record<string, any>\r\n): ModuleResolutionKind | undefined {\r\n const modRes =\r\n typeof moduleResolution === \"string\"\r\n ? moduleResolution.toLowerCase() === \"node\"\r\n ? \"nodejs\"\r\n : moduleResolution.toLowerCase()\r\n : undefined;\r\n const matchedKey = Object.keys(ts.ModuleResolutionKind).find(\r\n (mk): mk is keyof typeof ModuleResolutionKind => mk.toLowerCase() === modRes\r\n );\r\n return matchedKey ? (ts.ModuleResolutionKind[matchedKey] as ModuleResolutionKind) : undefined;\r\n}\r\n\r\nfunction getModuleKind(module: string | undefined | Record<string, any>): ModuleKind | undefined {\r\n const mod = typeof module === \"string\" ? module.toLowerCase() : undefined;\r\n const matchedKey = Object.keys(ts.ModuleKind).find((mk): mk is keyof typeof ModuleKind => mk.toLowerCase() === mod);\r\n return matchedKey ? (ts.ModuleKind[matchedKey] as ModuleKind) : undefined;\r\n}\r\n\r\nfunction getTarget(target: string | undefined | Record<string, any>): ScriptTarget | undefined {\r\n const t = typeof target === \"string\" ? target.toLowerCase() : undefined;\r\n const matchedKey = Object.keys(ts.ScriptTarget).find((st): st is keyof typeof ScriptTarget => st.toLowerCase() === t);\r\n return matchedKey ? (ts.ScriptTarget[matchedKey] as ScriptTarget) : undefined;\r\n}\r\n\r\nexport class ProjectManager {\r\n private project!: Project;\r\n\r\n private files: { [name: string]: SourceFile } = {};\r\n\r\n constructor(\r\n private projectFiles: ProjectFiles,\r\n private outputDir: string,\r\n private emitMode: EmitModes,\r\n private formatter: FileFormatter,\r\n compilerOptions: CompilerOptions | undefined\r\n ) {\r\n // Create ts-morph project\r\n this.project = new Project({\r\n manipulationSettings: this.formatter.getSettings(),\r\n skipAddingFilesFromTsConfig: true,\r\n compilerOptions,\r\n });\r\n }\r\n\r\n private async createFile(name: string) {\r\n const fileName = path.join(this.outputDir, `${name}.ts`);\r\n await remove(fileName);\r\n return this.project.createSourceFile(fileName);\r\n }\r\n\r\n public async createModelFile() {\r\n this.files.model = await this.createFile(this.projectFiles.model);\r\n return this.getModelFile();\r\n }\r\n\r\n public getModelFile() {\r\n return this.files.model;\r\n }\r\n\r\n public async createQObjectFile() {\r\n this.files.qobject = await this.createFile(this.projectFiles.qObject);\r\n return this.getQObjectFile();\r\n }\r\n\r\n public getQObjectFile() {\r\n return this.files.qobject;\r\n }\r\n\r\n public async createMainServiceFile() {\r\n this.files.mainService = await this.createFile(this.projectFiles.service);\r\n return this.getMainServiceFile();\r\n }\r\n\r\n public getMainServiceFile() {\r\n return this.files.mainService;\r\n }\r\n\r\n public async writeFiles() {\r\n switch (this.emitMode) {\r\n case EmitModes.js:\r\n case EmitModes.js_dts:\r\n await this.emitJsFiles();\r\n break;\r\n case EmitModes.dts:\r\n await this.emitJsFiles(true);\r\n break;\r\n case EmitModes.ts:\r\n await this.emitTsFiles();\r\n break;\r\n default:\r\n throw new Error(`Emit mode \"${this.emitMode}\" is invalid!`);\r\n }\r\n }\r\n\r\n private async emitJsFiles(declarationOnly?: boolean) {\r\n console.log(\r\n declarationOnly\r\n ? \"Emitting declaration files\"\r\n : `Emitting JS files (${this.emitMode === EmitModes.js_dts ? \"including\" : \"without\"} declaration files)`\r\n );\r\n\r\n await this.project.emit({ emitOnlyDtsFiles: !!declarationOnly });\r\n\r\n /* for (const diagnostic of this.project.getPreEmitDiagnostics()) {\r\n console.log(diagnostic.getMessageText());\r\n } */\r\n }\r\n\r\n private async emitTsFiles() {\r\n const files = [this.getModelFile(), this.getQObjectFile(), this.getMainServiceFile()].filter((file) => !!file);\r\n const text = files.length === 1 ? \"Emitting 1 TS file\" : `Emitting ${files.length} TS files`;\r\n console.log(`${text}: ${files.map((f) => path.basename(f.getFilePath())).join(\", \")}`);\r\n return Promise.all(files.map(this.formatAndWriteFile));\r\n }\r\n\r\n private formatAndWriteFile = async (file: SourceFile) => {\r\n const fileName = file.getFilePath();\r\n const content = file.getFullText();\r\n\r\n try {\r\n const formatted = await this.formatter.format(content);\r\n\r\n try {\r\n return writeFile(fileName, formatted);\r\n } catch (writeError) {\r\n console.error(`Failed to write file [/${fileName}]`, writeError);\r\n process.exit(3);\r\n }\r\n } catch (formattingError) {\r\n console.error(\"Formatting failed\", formattingError);\r\n await writeFile(\"error.log\", formattingError?.toString() || \"no error message!\");\r\n process.exit(99);\r\n }\r\n };\r\n}\r\n"]}
1
+ {"version":3,"file":"ProjectManager.js","sourceRoot":"","sources":["../../src/project/ProjectManager.ts"],"names":[],"mappings":";;;;AAAA,mDAA6B;AAE7B,uCAAqC;AACrC,uCAAgE;AAChE,sDAA2D;AAM3D,+CAA4C;AAC5C,2CAA8C;AAE9C,mDAA6D;AAY7D,SAAsB,oBAAoB,CACxC,SAAiB,EACjB,QAAmB,EACnB,YAA0B,EA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MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,EACxE;gBACA,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;aAC5B;QACH,CAAC;KAAA;CACF;AA3ND,wCA2NC","sourcesContent":["import * as path from \"path\";\n\nimport { ensureDir } from \"fs-extra\";\nimport { CompilerOptions, Project, SourceFile } from \"ts-morph\";\nimport { firstCharLowerCase } from \"xml2js/lib/processors\";\n\nimport { DataModel } from \"../data-model/DataModel\";\nimport { EntityType } from \"../data-model/DataTypeModel\";\nimport { NamingHelper } from \"../data-model/NamingHelper\";\nimport { EmitModes } from \"../OptionModel\";\nimport { FileHandler } from \"./FileHandler\";\nimport { createFormatter } from \"./formatter\";\nimport { FileFormatter } from \"./formatter/FileFormatter\";\nimport { loadTsMorphCompilerOptions } from \"./TsMorphHelper\";\n\nexport interface ProjectManagerOptions {\n usePrettier?: boolean;\n tsConfigPath?: string;\n bundledFileGeneration?: boolean;\n /**\n * for testing purposes, turn this on and retrieve all generated files via getCachedFiles\n */\n noOutput?: boolean;\n}\n\nexport async function createProjectManager(\n outputDir: string,\n emitMode: EmitModes,\n namingHelper: NamingHelper,\n dataModel: DataModel,\n options: ProjectManagerOptions\n): Promise<ProjectManager> {\n const { usePrettier = false, tsConfigPath = \"tsconfig.json\" } = options;\n const formatter = usePrettier ? await createFormatter(outputDir, usePrettier) : undefined;\n\n const compilerOpts: CompilerOptions = await loadTsMorphCompilerOptions(tsConfigPath, emitMode, outputDir);\n\n const pm = new ProjectManager(outputDir, emitMode, namingHelper, dataModel, formatter, compilerOpts, {\n usePrettier,\n tsConfigPath,\n ...options,\n });\n\n await pm.init();\n\n return pm;\n}\n\nexport class ProjectManager {\n private project!: Project;\n\n private mainServiceFile: FileHandler | undefined;\n private mainModelFile: FileHandler | undefined;\n private mainQFile: FileHandler | undefined;\n\n private readonly cachedFiles: Map<string, SourceFile> | undefined;\n\n constructor(\n protected outputDir: string,\n protected emitMode: EmitModes,\n protected namingHelper: NamingHelper,\n protected dataModel: DataModel,\n protected formatter: FileFormatter | undefined,\n compilerOptions: CompilerOptions | undefined,\n protected options: ProjectManagerOptions\n ) {\n // Create ts-morph project\n this.project = new Project({\n // manipulationSettings: this.formatter.getSettings(),\n skipAddingFilesFromTsConfig: true,\n compilerOptions,\n });\n\n if (options.noOutput) {\n this.cachedFiles = new Map();\n }\n }\n\n public getDataModel() {\n return this.dataModel;\n }\n\n /**\n * Only filled when noOutput=true\n */\n public getCachedFiles() {\n return this.cachedFiles!;\n }\n\n private async writeFile(fileHandler: FileHandler) {\n if (this.options.noOutput) {\n fileHandler.getFile().addImportDeclarations(fileHandler.getImports().getImportDeclarations());\n this.cachedFiles!.set(fileHandler.getFullFilePath(), fileHandler.getFile());\n return;\n }\n\n return fileHandler.write(this.emitMode);\n }\n\n private createFile(\n name: string,\n reservedNames?: Array<string> | undefined,\n additionalPath: string = \"\"\n ): FileHandler {\n const fileName = path.join(this.outputDir, additionalPath, `${name}.ts`);\n\n return new FileHandler(\n additionalPath,\n name,\n this.project.createSourceFile(fileName),\n this.dataModel,\n this.namingHelper.getFileNames(),\n !!this.options.bundledFileGeneration,\n this.formatter,\n reservedNames\n );\n }\n\n public async init() {\n if (!this.options.bundledFileGeneration) {\n // ensure folder for each model: we do this at this point for performance reasons\n await Promise.all(\n this.dataModel.getModelTypes().map((mt) => ensureDir(path.join(this.outputDir, mt.folderPath)))\n );\n }\n\n const typePart = this.emitMode.toUpperCase().replace(\"_\", \" & \");\n console.log(`Prepared to emit ${typePart} files.`);\n }\n\n public initModels() {\n if (this.options.bundledFileGeneration) {\n // collect reserved names, that is names of classes we're going to create => imports must take them into account\n const reservedWords = this.dataModel.getModelTypes().reduce<Array<string>>((collector, model) => {\n const asEntityType = model as EntityType;\n collector.push(model.modelName);\n if (asEntityType.editableName) {\n collector.push(asEntityType.editableName);\n }\n if (asEntityType.id?.modelName) {\n collector.push(asEntityType.id.modelName);\n }\n this.dataModel.getAllEntityOperations(model.fqName).forEach((op) => {\n if (op.parameters.length) {\n collector.push(op.paramsModelName);\n }\n });\n\n return collector;\n }, []);\n this.dataModel.getUnboundOperationTypes().forEach((op) => {\n if (op.parameters.length) {\n reservedWords.push(op.paramsModelName);\n }\n });\n\n this.mainModelFile = this.createFile(this.namingHelper.getFileNames().model, reservedWords);\n }\n }\n\n public async finalizeModels() {\n if (this.mainModelFile) {\n await this.writeFile(this.mainModelFile);\n }\n }\n\n public initQObjects() {\n if (this.options.bundledFileGeneration) {\n // collect reserved names, that is names of classes we're going to create => imports must take them into account\n const reservedWords = this.dataModel.getModelTypes().reduce<Array<string>>((collector, model) => {\n const asEntityType = model as EntityType;\n if (asEntityType.qName) {\n collector.push(asEntityType.qName, firstCharLowerCase(asEntityType.qName));\n }\n if (asEntityType.id?.qName) {\n collector.push(asEntityType.id.qName);\n }\n this.dataModel.getAllEntityOperations(model.fqName).forEach((op) => {\n collector.push(op.qName);\n });\n\n return collector;\n }, []);\n this.dataModel.getUnboundOperationTypes().forEach((op) => {\n reservedWords.push(op.qName);\n });\n\n this.mainQFile = this.createFile(this.namingHelper.getFileNames().qObject, reservedWords);\n }\n }\n\n public async finalizeQObjects() {\n if (this.mainQFile) {\n await this.writeFile(this.mainQFile);\n }\n }\n\n public initServices() {\n const mainServiceName = this.namingHelper.getMainServiceName();\n const reservedNames = [mainServiceName];\n\n if (this.options.bundledFileGeneration) {\n [...this.dataModel.getEntityTypes(), ...this.dataModel.getComplexTypes()].reduce((collector, model) => {\n collector.push(model.serviceName, model.serviceCollectionName);\n return collector;\n }, reservedNames);\n }\n\n this.mainServiceFile = this.createFile(mainServiceName, reservedNames);\n }\n\n public async finalizeServices() {\n if (this.mainServiceFile) {\n await this.writeFile(this.mainServiceFile);\n }\n }\n\n public getMainServiceFile() {\n return this.mainServiceFile!;\n }\n\n public createOrGetMainModelFile(reservedNames?: Array<string>) {\n if (!this.mainModelFile) {\n this.mainModelFile = this.createFile(this.namingHelper.getFileNames().model, reservedNames);\n }\n return this.mainModelFile;\n }\n\n public createOrGetMainQObjectFile(reservedNames?: Array<string>) {\n if (!this.mainQFile) {\n this.mainQFile = this.createFile(this.namingHelper.getFileNames().qObject, reservedNames);\n }\n return this.mainQFile;\n }\n\n public createOrGetModelFile(folderPath: string, name: string, reservedNames?: Array<string> | undefined) {\n if (this.mainModelFile) {\n return this.mainModelFile;\n }\n\n return this.createFile(name, reservedNames, folderPath);\n }\n public createOrGetQObjectFile(folderPath: string, name: string, reservedNames?: Array<string> | undefined) {\n if (this.mainQFile) {\n return this.mainQFile;\n }\n\n return this.createFile(name, reservedNames, folderPath);\n }\n public createOrGetServiceFile(folderPath: string, name: string, reservedNames?: Array<string> | undefined) {\n if (this.options.bundledFileGeneration) {\n return this.mainServiceFile!;\n }\n\n return this.createFile(name, reservedNames, folderPath);\n }\n\n public async finalizeFile(file: FileHandler) {\n // write individual files in unbundled mode & if this is not one of the main files on root level\n if (\n !this.options.bundledFileGeneration &&\n file.path !== \"\" &&\n !Object.values(this.namingHelper.getFileNames()).includes(file.fileName)\n ) {\n await this.writeFile(file);\n }\n }\n}\n"]}
@@ -0,0 +1,11 @@
1
+ import { CompilerOptions } from "ts-morph";
2
+ import { EmitModes } from "../OptionModel";
3
+ /**
4
+ * Loads the TS configuration from the specified path.
5
+ * Then maps the appropriate options to ts-morph compiler options.
6
+ *
7
+ * @param tsConfigPath path to tsconfig.json
8
+ * @param emitMode the used emit mode
9
+ * @param outputDir the used output dir
10
+ */
11
+ export declare function loadTsMorphCompilerOptions(tsConfigPath: string, emitMode: EmitModes, outputDir: string): Promise<CompilerOptions>;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadTsMorphCompilerOptions = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const common_1 = require("@ts-morph/common");
6
+ const tsconfig_loader_1 = tslib_1.__importDefault(require("tsconfig-loader"));
7
+ const typescript_1 = tslib_1.__importDefault(require("typescript"));
8
+ const OptionModel_1 = require("../OptionModel");
9
+ /**
10
+ * Loads the TS configuration from the specified path.
11
+ * Then maps the appropriate options to ts-morph compiler options.
12
+ *
13
+ * @param tsConfigPath path to tsconfig.json
14
+ * @param emitMode the used emit mode
15
+ * @param outputDir the used output dir
16
+ */
17
+ function loadTsMorphCompilerOptions(tsConfigPath, emitMode, outputDir) {
18
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
19
+ const generateDeclarations = OptionModel_1.EmitModes.js_dts === emitMode || OptionModel_1.EmitModes.dts === emitMode;
20
+ // load config file
21
+ // NOTE: not async...
22
+ const conf = (0, tsconfig_loader_1.default)({ filename: tsConfigPath });
23
+ const _a = (conf === null || conf === void 0 ? void 0 : conf.tsConfig.compilerOptions) || {}, {
24
+ // ignored props
25
+ noEmit, // we always want to emit
26
+ importsNotUsedAsValues, // type is missing
27
+ jsx, plugins,
28
+ // mapped props
29
+ moduleResolution, lib, module, newLine, target, rootDir, rootDirs } = _a, passThrough = tslib_1.__rest(_a, ["noEmit", "importsNotUsedAsValues", "jsx", "plugins", "moduleResolution", "lib", "module", "newLine", "target", "rootDir", "rootDirs"]);
30
+ const compilerOpts = Object.assign(Object.assign({}, passThrough), { outDir: outputDir, declaration: generateDeclarations, moduleResolution: getModuleResolutionKind(moduleResolution), module: getModuleKind(module), target: getTarget(target) });
31
+ if (lib) {
32
+ compilerOpts.lib = lib;
33
+ }
34
+ if (newLine) {
35
+ compilerOpts.newLine = (newLine === null || newLine === void 0 ? void 0 : newLine.toLowerCase()) === "lf" ? common_1.NewLineKind.LineFeed : common_1.NewLineKind.CarriageReturnLineFeed;
36
+ }
37
+ return compilerOpts;
38
+ });
39
+ }
40
+ exports.loadTsMorphCompilerOptions = loadTsMorphCompilerOptions;
41
+ /**
42
+ * Maps to lower case.
43
+ * Also translates "node" to "nodejs".
44
+ *
45
+ * @param moduleResolution
46
+ */
47
+ function getModuleResolutionKind(moduleResolution) {
48
+ const modRes = typeof moduleResolution === "string"
49
+ ? moduleResolution.toLowerCase() === "node"
50
+ ? "nodejs"
51
+ : moduleResolution.toLowerCase()
52
+ : undefined;
53
+ const matchedKey = Object.keys(typescript_1.default.ModuleResolutionKind).find((mk) => mk.toLowerCase() === modRes);
54
+ return matchedKey ? typescript_1.default.ModuleResolutionKind[matchedKey] : undefined;
55
+ }
56
+ function getModuleKind(module) {
57
+ const mod = typeof module === "string" ? module.toLowerCase() : undefined;
58
+ const matchedKey = Object.keys(typescript_1.default.ModuleKind).find((mk) => mk.toLowerCase() === mod);
59
+ return matchedKey ? typescript_1.default.ModuleKind[matchedKey] : undefined;
60
+ }
61
+ function getTarget(target) {
62
+ const t = typeof target === "string" ? target.toLowerCase() : undefined;
63
+ const matchedKey = Object.keys(typescript_1.default.ScriptTarget).find((st) => st.toLowerCase() === t);
64
+ return matchedKey ? typescript_1.default.ScriptTarget[matchedKey] : undefined;
65
+ }
66
+ //# sourceMappingURL=TsMorphHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TsMorphHelper.js","sourceRoot":"","sources":["../../src/project/TsMorphHelper.ts"],"names":[],"mappings":";;;;AAAA,6CAA+C;AAE/C,8EAAmC;AACnC,oEAA4B;AAE5B,gDAA2C;AAE3C;;;;;;;GAOG;AACH,SAAsB,0BAA0B,CAAC,YAAoB,EAAE,QAAmB,EAAE,SAAiB;;QAC3G,MAAM,oBAAoB,GAAG,uBAAS,CAAC,MAAM,KAAK,QAAQ,IAAI,uBAAS,CAAC,GAAG,KAAK,QAAQ,CAAC;QAEzF,mBAAmB;QACnB,qBAAqB;QACrB,MAAM,IAAI,GAAG,IAAA,yBAAI,EAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC,CAAC;QAE9C,MAAM,KAeF,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,QAAQ,CAAC,eAAe,KAAI,EAAE,EAflC;QACJ,gBAAgB;QAChB,MAAM,E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CAAE,oBAAE,CAAC,oBAAoB,CAAC,UAAU,CAA0B,CAAC,CAAC,CAAC,SAAS,CAAC;AAChG,CAAC;AAED,SAAS,aAAa,CAAC,MAAgD;IACrE,MAAM,GAAG,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAC1E,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,oBAAE,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,EAAiC,EAAE,CAAC,EAAE,CAAC,WAAW,EAAE,KAAK,GAAG,CAAC,CAAC;IACpH,OAAO,UAAU,CAAC,CAAC,CAAE,oBAAE,CAAC,UAAU,CAAC,UAAU,CAAgB,CAAC,CAAC,CAAC,SAAS,CAAC;AAC5E,CAAC;AAED,SAAS,SAAS,CAAC,MAAgD;IACjE,MAAM,CAAC,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IACxE,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,oBAAE,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,EAAmC,EAAE,CAAC,EAAE,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;IACtH,OAAO,UAAU,CAAC,CAAC,CAAE,oBAAE,CAAC,YAAY,CAAC,UAAU,CAAkB,CAAC,CAAC,CAAC,SAAS,CAAC;AAChF,CAAC","sourcesContent":["import { NewLineKind } from \"@ts-morph/common\";\nimport { CompilerOptions, ModuleKind, ModuleResolutionKind, ScriptTarget } from \"ts-morph\";\nimport load from \"tsconfig-loader\";\nimport ts from \"typescript\";\n\nimport { EmitModes } from \"../OptionModel\";\n\n/**\n * Loads the TS configuration from the specified path.\n * Then maps the appropriate options to ts-morph compiler options.\n *\n * @param tsConfigPath path to tsconfig.json\n * @param emitMode the used emit mode\n * @param outputDir the used output dir\n */\nexport async function loadTsMorphCompilerOptions(tsConfigPath: string, emitMode: EmitModes, outputDir: string) {\n const generateDeclarations = EmitModes.js_dts === emitMode || EmitModes.dts === emitMode;\n\n // load config file\n // NOTE: not async...\n const conf = load({ filename: tsConfigPath });\n\n const {\n // ignored props\n noEmit, // we always want to emit\n importsNotUsedAsValues, // type is missing\n jsx,\n plugins,\n // mapped props\n moduleResolution,\n lib,\n module,\n newLine,\n target,\n rootDir,\n rootDirs,\n ...passThrough\n } = conf?.tsConfig.compilerOptions || {};\n\n const compilerOpts: CompilerOptions = {\n ...passThrough,\n outDir: outputDir,\n declaration: generateDeclarations,\n moduleResolution: getModuleResolutionKind(moduleResolution),\n module: getModuleKind(module),\n target: getTarget(target),\n };\n if (lib) {\n compilerOpts.lib = lib as string[];\n }\n if (newLine) {\n compilerOpts.newLine = newLine?.toLowerCase() === \"lf\" ? NewLineKind.LineFeed : NewLineKind.CarriageReturnLineFeed;\n }\n\n return compilerOpts;\n}\n\n/**\n * Maps to lower case.\n * Also translates \"node\" to \"nodejs\".\n *\n * @param moduleResolution\n */\nfunction getModuleResolutionKind(\n moduleResolution: string | undefined | Record<string, any>\n): ModuleResolutionKind | undefined {\n const modRes =\n typeof moduleResolution === \"string\"\n ? moduleResolution.toLowerCase() === \"node\"\n ? \"nodejs\"\n : moduleResolution.toLowerCase()\n : undefined;\n const matchedKey = Object.keys(ts.ModuleResolutionKind).find(\n (mk): mk is keyof typeof ModuleResolutionKind => mk.toLowerCase() === modRes\n );\n return matchedKey ? (ts.ModuleResolutionKind[matchedKey] as ModuleResolutionKind) : undefined;\n}\n\nfunction getModuleKind(module: string | undefined | Record<string, any>): ModuleKind | undefined {\n const mod = typeof module === \"string\" ? module.toLowerCase() : undefined;\n const matchedKey = Object.keys(ts.ModuleKind).find((mk): mk is keyof typeof ModuleKind => mk.toLowerCase() === mod);\n return matchedKey ? (ts.ModuleKind[matchedKey] as ModuleKind) : undefined;\n}\n\nfunction getTarget(target: string | undefined | Record<string, any>): ScriptTarget | undefined {\n const t = typeof target === \"string\" ? target.toLowerCase() : undefined;\n const matchedKey = Object.keys(ts.ScriptTarget).find((st): st is keyof typeof ScriptTarget => st.toLowerCase() === t);\n return matchedKey ? (ts.ScriptTarget[matchedKey] as ScriptTarget) : undefined;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@odata2ts/odata2ts",
3
- "version": "0.33.0",
3
+ "version": "0.33.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -14,12 +14,14 @@
14
14
  "scripts": {
15
15
  "build": "yarn clean && yarn compile",
16
16
  "check-circular-deps": "madge ./src --extensions ts --circular",
17
+ "check-circular-generated": "madge ./build --extensions ts --circular",
17
18
  "clean": "rimraf lib build",
18
19
  "clean-v2": "rimraf build/v2",
19
20
  "clean-v4": "rimraf build/v4",
20
21
  "clear-cache": "jest --clearCache",
21
22
  "compile": "tsc",
22
23
  "compile-fixtures": "tsc -p ./tsconfig.fixture.json",
24
+ "compile-generated": "tsc -p ./tsconfig.generated.json",
23
25
  "dev": "yarn generate trippin odata",
24
26
  "generate": "ts-node --cwd-mode src/run-cli.ts ",
25
27
  "int-test": "yarn clean && jest ./int-test",
@@ -45,14 +47,14 @@
45
47
  "v4"
46
48
  ],
47
49
  "peerDependencies": {
48
- "@odata2ts/odata-query-objects": "^0.20.0",
49
- "@odata2ts/odata-service": "^0.17.1"
50
+ "@odata2ts/odata-query-objects": "^0.20.2",
51
+ "@odata2ts/odata-service": "^0.18.0"
50
52
  },
51
53
  "dependencies": {
52
54
  "@odata2ts/converter-api": "^0.1.2",
53
55
  "@odata2ts/converter-runtime": "^0.2.2",
54
56
  "@odata2ts/http-client-api": "^0.5.1",
55
- "@odata2ts/odata-core": "^0.4.0",
57
+ "@odata2ts/odata-core": "^0.5.0",
56
58
  "@prettier/plugin-xml": "^2.2.0",
57
59
  "axios": "^1.4.0",
58
60
  "camel-case": "^4.1.2",
@@ -73,9 +75,9 @@
73
75
  },
74
76
  "devDependencies": {
75
77
  "@odata2ts/converter-v2-to-v4": "^0.1.4",
76
- "@odata2ts/odata-query-objects": "^0.20.0",
77
- "@odata2ts/odata-service": "^0.17.1",
78
- "@odata2ts/test-converters": "^0.3.0",
78
+ "@odata2ts/odata-query-objects": "^0.20.2",
79
+ "@odata2ts/odata-service": "^0.18.0",
80
+ "@odata2ts/test-converters": "^0.3.1",
79
81
  "@types/fs-extra": "^11.0.1",
80
82
  "@types/jest": "^29.5.2",
81
83
  "@types/node": "^20.3.0",
@@ -88,6 +90,6 @@
88
90
  "typescript": "^5.1.3"
89
91
  },
90
92
  "types": "./lib/index.d.ts",
91
- "gitHead": "76da31570a037c222fa40bc587694f371ef70c32",
93
+ "gitHead": "1e5119807992887ba96f8918b13bc51f55cbbe1c",
92
94
  "readme": "README.md"
93
95
  }