@odata2ts/odata2ts 0.23.1 → 0.25.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/CHANGELOG.md +22 -0
- package/lib/FactoryFunctionModel.d.ts +13 -13
- package/lib/FactoryFunctionModel.js +2 -2
- package/lib/FactoryFunctionModel.js.map +1 -1
- package/lib/NamingModel.d.ts +182 -182
- package/lib/NamingModel.js +11 -11
- package/lib/NamingModel.js.map +1 -1
- package/lib/OptionModel.d.ts +228 -223
- package/lib/OptionModel.js +23 -23
- package/lib/OptionModel.js.map +1 -1
- package/lib/app.d.ts +8 -8
- package/lib/app.js +67 -63
- package/lib/app.js.map +1 -1
- package/lib/cli.d.ts +3 -3
- package/lib/cli.js +153 -153
- package/lib/data-model/DataModel.d.ts +88 -85
- package/lib/data-model/DataModel.js +141 -134
- package/lib/data-model/DataModel.js.map +1 -1
- package/lib/data-model/DataModelDigestion.d.ts +48 -44
- package/lib/data-model/DataModelDigestion.js +299 -274
- package/lib/data-model/DataModelDigestion.js.map +1 -1
- package/lib/data-model/DataModelDigestionV2.d.ts +10 -10
- package/lib/data-model/DataModelDigestionV2.js +210 -200
- package/lib/data-model/DataModelDigestionV2.js.map +1 -1
- package/lib/data-model/DataModelDigestionV4.d.ts +3 -3
- package/lib/data-model/DataModelDigestionV4.js +197 -195
- package/lib/data-model/DataModelDigestionV4.js.map +1 -1
- package/lib/data-model/DataTypeModel.d.ts +102 -102
- package/lib/data-model/DataTypeModel.js +8 -8
- package/lib/data-model/DataTypeModel.js.map +1 -1
- package/lib/data-model/NamingHelper.d.ts +57 -55
- package/lib/data-model/NamingHelper.js +231 -214
- package/lib/data-model/NamingHelper.js.map +1 -1
- package/lib/data-model/ServiceConfigHelper.d.ts +21 -21
- package/lib/data-model/ServiceConfigHelper.js +113 -113
- package/lib/data-model/edmx/ODataEdmxModelBase.d.ts +92 -80
- package/lib/data-model/edmx/ODataEdmxModelBase.js +2 -2
- package/lib/data-model/edmx/ODataEdmxModelBase.js.map +1 -1
- package/lib/data-model/edmx/ODataEdmxModelV3.d.ts +63 -63
- package/lib/data-model/edmx/ODataEdmxModelV3.js +2 -2
- package/lib/data-model/edmx/ODataEdmxModelV4.d.ts +67 -67
- package/lib/data-model/edmx/ODataEdmxModelV4.js +2 -2
- package/lib/defaultConfig.d.ts +9 -9
- package/lib/defaultConfig.js +165 -164
- package/lib/defaultConfig.js.map +1 -1
- package/lib/evaluateConfig.d.ts +25 -25
- package/lib/evaluateConfig.js +82 -82
- package/lib/generator/ImportContainer.d.ts +16 -16
- package/lib/generator/ImportContainer.js +91 -91
- package/lib/generator/ModelGenerator.d.ts +2 -2
- package/lib/generator/ModelGenerator.js +211 -183
- package/lib/generator/ModelGenerator.js.map +1 -1
- package/lib/generator/QueryObjectGenerator.d.ts +2 -2
- package/lib/generator/QueryObjectGenerator.js +239 -239
- package/lib/generator/ServiceGenerator.d.ts +8 -8
- package/lib/generator/ServiceGenerator.js +422 -422
- package/lib/generator/index.d.ts +3 -3
- package/lib/generator/index.js +9 -9
- package/lib/index.d.ts +3 -3
- package/lib/index.js +6 -6
- package/lib/project/ProjectManager.d.ts +30 -30
- package/lib/project/ProjectManager.js +177 -175
- package/lib/project/ProjectManager.js.map +1 -1
- package/lib/project/formatter/BaseFormatter.d.ts +49 -49
- package/lib/project/formatter/BaseFormatter.js +30 -30
- package/lib/project/formatter/FileFormatter.d.ts +16 -16
- package/lib/project/formatter/FileFormatter.js +2 -2
- package/lib/project/formatter/NoopFormatter.d.ts +29 -29
- package/lib/project/formatter/NoopFormatter.js +42 -42
- package/lib/project/formatter/PrettierFormatter.d.ts +46 -46
- package/lib/project/formatter/PrettierFormatter.js +92 -92
- package/lib/project/formatter/index.d.ts +2 -2
- package/lib/project/formatter/index.js +14 -14
- package/lib/project/logger/logFilePath.d.ts +1 -1
- package/lib/project/logger/logFilePath.js +12 -12
- package/lib/run-cli.d.ts +2 -2
- package/lib/run-cli.js +6 -6
- package/package.json +27 -28
package/lib/app.js
CHANGED
|
@@ -1,64 +1,68 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.runApp = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const odata_core_1 = require("@odata2ts/odata-core");
|
|
6
|
-
const DataModelDigestionV2_1 = require("./data-model/DataModelDigestionV2");
|
|
7
|
-
const DataModelDigestionV4_1 = require("./data-model/DataModelDigestionV4");
|
|
8
|
-
const NamingHelper_1 = require("./data-model/NamingHelper");
|
|
9
|
-
const generator_1 = require("./generator");
|
|
10
|
-
const OptionModel_1 = require("./OptionModel");
|
|
11
|
-
const ProjectManager_1 = require("./project/ProjectManager");
|
|
12
|
-
function isQObjectGen(mode) {
|
|
13
|
-
return [OptionModel_1.Modes.qobjects, OptionModel_1.Modes.service, OptionModel_1.Modes.all].includes(mode);
|
|
14
|
-
}
|
|
15
|
-
function isServiceGen(mode) {
|
|
16
|
-
return [OptionModel_1.Modes.service, OptionModel_1.Modes.all].includes(mode);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
* @param metadataJson metadata of a given OData service already parsed as JSON
|
|
21
|
-
* @param options further options
|
|
22
|
-
*/
|
|
23
|
-
function runApp(metadataJson, options) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
//
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
(0,
|
|
48
|
-
// Generate
|
|
49
|
-
// supported edmx types: EntityType, ComplexType
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.runApp = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const odata_core_1 = require("@odata2ts/odata-core");
|
|
6
|
+
const DataModelDigestionV2_1 = require("./data-model/DataModelDigestionV2");
|
|
7
|
+
const DataModelDigestionV4_1 = require("./data-model/DataModelDigestionV4");
|
|
8
|
+
const NamingHelper_1 = require("./data-model/NamingHelper");
|
|
9
|
+
const generator_1 = require("./generator");
|
|
10
|
+
const OptionModel_1 = require("./OptionModel");
|
|
11
|
+
const ProjectManager_1 = require("./project/ProjectManager");
|
|
12
|
+
function isQObjectGen(mode) {
|
|
13
|
+
return [OptionModel_1.Modes.qobjects, OptionModel_1.Modes.service, OptionModel_1.Modes.all].includes(mode);
|
|
14
|
+
}
|
|
15
|
+
function isServiceGen(mode) {
|
|
16
|
+
return [OptionModel_1.Modes.service, OptionModel_1.Modes.all].includes(mode);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @param metadataJson metadata of a given OData service already parsed as JSON
|
|
21
|
+
* @param options further options
|
|
22
|
+
*/
|
|
23
|
+
function runApp(metadataJson, options) {
|
|
24
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
// determine edmx edmxVersion attribute
|
|
26
|
+
const edmxVersion = metadataJson["edmx:Edmx"].$.Version;
|
|
27
|
+
const version = edmxVersion === "1.0" ? odata_core_1.ODataVersions.V2 : odata_core_1.ODataVersions.V4;
|
|
28
|
+
const dataService = metadataJson["edmx:Edmx"]["edmx:DataServices"][0];
|
|
29
|
+
const schemas = dataService.Schema;
|
|
30
|
+
const detectedSchema = schemas.find((schema) => { var _a; return schema.$.Namespace && ((_a = schema.EntityType) === null || _a === void 0 ? void 0 : _a.length); }) || schemas[0];
|
|
31
|
+
const serviceName = options.serviceName || detectedSchema.$.Namespace;
|
|
32
|
+
const namespaces = [];
|
|
33
|
+
schemas.forEach((schema) => {
|
|
34
|
+
namespaces.push(schema.$.Namespace);
|
|
35
|
+
if (schema.$.Alias) {
|
|
36
|
+
namespaces.push(schema.$.Alias);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
// encapsulate the whole naming logic
|
|
40
|
+
const namingHelper = new NamingHelper_1.NamingHelper(options, serviceName, namespaces);
|
|
41
|
+
// parse model information from edmx into something we can really work with
|
|
42
|
+
// => that stuff is called dataModel!
|
|
43
|
+
const dataModel = version === odata_core_1.ODataVersions.V2
|
|
44
|
+
? yield (0, DataModelDigestionV2_1.digest)(dataService.Schema, options, namingHelper)
|
|
45
|
+
: yield (0, DataModelDigestionV4_1.digest)(dataService.Schema, options, namingHelper);
|
|
46
|
+
// handling the overall generation project
|
|
47
|
+
const project = yield (0, ProjectManager_1.createProjectManager)(namingHelper.getFileNames(), options.output, options.emitMode, options.prettier, options.tsconfig);
|
|
48
|
+
// Generate Model Interfaces
|
|
49
|
+
// supported edmx types: EntityType, ComplexType, EnumType
|
|
50
|
+
const modelsFile = yield project.createModelFile();
|
|
51
|
+
(0, generator_1.generateModels)(dataModel, modelsFile, version, options, namingHelper);
|
|
52
|
+
// Generate Query Objects
|
|
53
|
+
// supported edmx types: EntityType, ComplexType
|
|
54
|
+
// supported edmx prop types: primitive types, enum types, primitive collection (incl enum types), entity collection, entity object, complex object
|
|
55
|
+
if (isQObjectGen(options.mode)) {
|
|
56
|
+
const qFile = yield project.createQObjectFile();
|
|
57
|
+
(0, generator_1.generateQueryObjects)(dataModel, qFile, version, options, namingHelper);
|
|
58
|
+
}
|
|
59
|
+
// Generate Individual OData-Service
|
|
60
|
+
if (isServiceGen(options.mode)) {
|
|
61
|
+
yield project.cleanServiceDir();
|
|
62
|
+
yield (0, generator_1.generateServices)(dataModel, project, version, namingHelper);
|
|
63
|
+
}
|
|
64
|
+
yield project.writeFiles();
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
exports.runApp = runApp;
|
|
64
68
|
//# sourceMappingURL=app.js.map
|
package/lib/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":";;;;AAAA,qDAAqD;AAErD,4EAAuE;AACvE,4EAAuE;AAIvE,4DAAyD;AACzD,2CAAqF;AACrF,+CAAkD;AAClD,6DAAgE;AAEhE,SAAS,YAAY,CAAC,IAAW;IAC/B,OAAO,CAAC,mBAAK,CAAC,QAAQ,EAAE,mBAAK,CAAC,OAAO,EAAE,mBAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACnE,CAAC;AAED,SAAS,YAAY,CAAC,IAAW;IAC/B,OAAO,CAAC,mBAAK,CAAC,OAAO,EAAE,mBAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACnD,CAAC;AAED;;;;GAIG;AACH,SAAsB,MAAM,CAAC,YAAqC,EAAE,OAAmB
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"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","sourcesContent":["import { ODataVersions } from \"@odata2ts/odata-core\";\r\n\r\nimport { digest as digestV2 } from \"./data-model/DataModelDigestionV2\";\r\nimport { digest as digestV4 } from \"./data-model/DataModelDigestionV4\";\r\nimport { ODataEdmxModelBase, Schema } from \"./data-model/edmx/ODataEdmxModelBase\";\r\nimport { SchemaV3 } from \"./data-model/edmx/ODataEdmxModelV3\";\r\nimport { SchemaV4 } from \"./data-model/edmx/ODataEdmxModelV4\";\r\nimport { NamingHelper } from \"./data-model/NamingHelper\";\r\nimport { generateModels, generateQueryObjects, generateServices } from \"./generator\";\r\nimport { Modes, RunOptions } from \"./OptionModel\";\r\nimport { createProjectManager } from \"./project/ProjectManager\";\r\n\r\nfunction isQObjectGen(mode: Modes) {\r\n return [Modes.qobjects, Modes.service, Modes.all].includes(mode);\r\n}\r\n\r\nfunction isServiceGen(mode: Modes) {\r\n return [Modes.service, Modes.all].includes(mode);\r\n}\r\n\r\n/**\r\n *\r\n * @param metadataJson metadata of a given OData service already parsed as JSON\r\n * @param options further options\r\n */\r\nexport async function runApp(metadataJson: ODataEdmxModelBase<any>, options: RunOptions): Promise<void> {\r\n // determine edmx edmxVersion attribute\r\n const edmxVersion = metadataJson[\"edmx:Edmx\"].$.Version;\r\n const version = edmxVersion === \"1.0\" ? ODataVersions.V2 : ODataVersions.V4;\r\n\r\n const dataService = metadataJson[\"edmx:Edmx\"][\"edmx:DataServices\"][0];\r\n const schemas = dataService.Schema as Array<SchemaV3 | SchemaV4>;\r\n\r\n const detectedSchema = schemas.find((schema) => schema.$.Namespace && schema.EntityType?.length) || schemas[0];\r\n const serviceName = options.serviceName || detectedSchema.$.Namespace;\r\n\r\n const namespaces: Array<string> = [];\r\n schemas.forEach((schema) => {\r\n namespaces.push(schema.$.Namespace);\r\n if (schema.$.Alias) {\r\n namespaces.push(schema.$.Alias);\r\n }\r\n });\r\n\r\n // encapsulate the whole naming logic\r\n const namingHelper = new NamingHelper(options, serviceName, namespaces);\r\n // parse model information from edmx into something we can really work with\r\n // => that stuff is called dataModel!\r\n const dataModel =\r\n version === ODataVersions.V2\r\n ? await digestV2(dataService.Schema as Array<SchemaV3>, options, namingHelper)\r\n : await digestV4(dataService.Schema as Array<SchemaV4>, options, namingHelper);\r\n // handling the overall generation project\r\n const project = await createProjectManager(\r\n namingHelper.getFileNames(),\r\n options.output,\r\n options.emitMode,\r\n options.prettier,\r\n options.tsconfig\r\n );\r\n\r\n // Generate Model Interfaces\r\n // supported edmx types: EntityType, ComplexType, EnumType\r\n const modelsFile = await project.createModelFile();\r\n generateModels(dataModel, modelsFile, version, options, namingHelper);\r\n\r\n // Generate Query Objects\r\n // supported edmx types: EntityType, ComplexType\r\n // supported edmx prop types: primitive types, enum types, primitive collection (incl enum types), entity collection, entity object, complex object\r\n if (isQObjectGen(options.mode)) {\r\n const qFile = await project.createQObjectFile();\r\n generateQueryObjects(dataModel, qFile, version, options, namingHelper);\r\n }\r\n\r\n // Generate Individual OData-Service\r\n if (isServiceGen(options.mode)) {\r\n await project.cleanServiceDir();\r\n await generateServices(dataModel, project, version, namingHelper);\r\n }\r\n\r\n await project.writeFiles();\r\n}\r\n"]}
|
package/lib/cli.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare class Cli {
|
|
2
|
-
run(): Promise<void>;
|
|
3
|
-
}
|
|
1
|
+
export declare class Cli {
|
|
2
|
+
run(): Promise<void>;
|
|
3
|
+
}
|
package/lib/cli.js
CHANGED
|
@@ -1,154 +1,154 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Cli = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const commander_1 = tslib_1.__importStar(require("commander"));
|
|
6
|
-
const cosmiconfig_1 = require("cosmiconfig");
|
|
7
|
-
const cosmiconfig_typescript_loader_1 = require("cosmiconfig-typescript-loader");
|
|
8
|
-
const fs_extra_1 = require("fs-extra");
|
|
9
|
-
const xml2js_1 = require("xml2js");
|
|
10
|
-
const app_1 = require("./app");
|
|
11
|
-
const evaluateConfig_1 = require("./evaluateConfig");
|
|
12
|
-
const OptionModel_1 = require("./OptionModel");
|
|
13
|
-
const logFilePath_1 = require("./project/logger/logFilePath");
|
|
14
|
-
function parseMode(value, dummyPrevious) {
|
|
15
|
-
switch (value) {
|
|
16
|
-
case "models":
|
|
17
|
-
return OptionModel_1.Modes.models;
|
|
18
|
-
case "qobjects":
|
|
19
|
-
return OptionModel_1.Modes.qobjects;
|
|
20
|
-
case "service":
|
|
21
|
-
return OptionModel_1.Modes.service;
|
|
22
|
-
case "all":
|
|
23
|
-
return OptionModel_1.Modes.all;
|
|
24
|
-
default:
|
|
25
|
-
throw new Error(`Not a valid Mode: ${value}`);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function parseEmitMode(value, dummyPrevious) {
|
|
29
|
-
switch (value) {
|
|
30
|
-
case "dts":
|
|
31
|
-
return OptionModel_1.EmitModes.dts;
|
|
32
|
-
case "js":
|
|
33
|
-
return OptionModel_1.EmitModes.js;
|
|
34
|
-
case "ts":
|
|
35
|
-
return OptionModel_1.EmitModes.ts;
|
|
36
|
-
case "js_dts":
|
|
37
|
-
return OptionModel_1.EmitModes.js_dts;
|
|
38
|
-
default:
|
|
39
|
-
throw new Error(`Not a valid EmitMode: ${value}`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
function processCliArgs() {
|
|
43
|
-
var _a;
|
|
44
|
-
const cli = new commander_1.default.Command()
|
|
45
|
-
.version("0.3.0")
|
|
46
|
-
.description("CLI to generate Typescript Interfaces for models of a given OData service.")
|
|
47
|
-
.argument("[services...]", "Run the generation process only for certain services specified in config file", [])
|
|
48
|
-
.option("-s, --source <metadata.xml>", "Metadata file describing the OData service")
|
|
49
|
-
.option("-o, --output <path>", "Output location for generated files")
|
|
50
|
-
.addOption(new commander_1.Option("-m, --mode <mode>", "What kind of stuff gets generated")
|
|
51
|
-
.choices(Object.values(OptionModel_1.Modes).filter((t) => isNaN(Number(t))))
|
|
52
|
-
.argParser(parseMode))
|
|
53
|
-
.addOption(new commander_1.Option("-e, --emit-mode <mode>", "Output TS source files, compiled JS files with/wihthout generated d.ts files")
|
|
54
|
-
.choices(Object.values(OptionModel_1.EmitModes))
|
|
55
|
-
.argParser(parseEmitMode))
|
|
56
|
-
.option("-p, --prettier", "Format result with prettier (only applies if emitMode=ts)")
|
|
57
|
-
.option("-t, --tsconfig <path>", "Specify alternative to 'tsconfig.json' to use specific compilerOptions (applies if emitMode is not ts)")
|
|
58
|
-
.option("-d, --debug", "Verbose debug infos")
|
|
59
|
-
.option("-name, --service-name <serviceName>", "Give the service your own name")
|
|
60
|
-
.option("-n, --disable-auto-managed-key", "Give the service your own name")
|
|
61
|
-
.option("-r, --allow-renaming ", "Give the service your own name")
|
|
62
|
-
.parse(process.argv);
|
|
63
|
-
const args = ((_a = cli.args) === null || _a === void 0 ? void 0 : _a.length) ? { services: cli.args } : {};
|
|
64
|
-
return Object.assign(Object.assign({}, cli.opts()), args);
|
|
65
|
-
}
|
|
66
|
-
function processConfigFile() {
|
|
67
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
const moduleName = "odata2ts";
|
|
69
|
-
const explorer = (0, cosmiconfig_1.cosmiconfig)(moduleName, {
|
|
70
|
-
searchPlaces: [`${moduleName}.config.js`, `${moduleName}.config.ts`, `${moduleName}.config.cjs`],
|
|
71
|
-
loaders: {
|
|
72
|
-
".ts": (0, cosmiconfig_typescript_loader_1.TypeScriptLoader)(),
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
const discoveredConfig = yield explorer.search();
|
|
76
|
-
if (discoveredConfig === null || discoveredConfig === void 0 ? void 0 : discoveredConfig.config) {
|
|
77
|
-
console.log("Loaded config file: ", (0, logFilePath_1.logFilePath)(discoveredConfig.filepath));
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
console.log("No config file found.");
|
|
81
|
-
}
|
|
82
|
-
return discoveredConfig === null || discoveredConfig === void 0 ? void 0 : discoveredConfig.config;
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
class Cli {
|
|
86
|
-
run() {
|
|
87
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
88
|
-
let runs;
|
|
89
|
-
try {
|
|
90
|
-
const cliOpts = processCliArgs();
|
|
91
|
-
if (cliOpts.debug) {
|
|
92
|
-
console.log("CLI opts:", cliOpts);
|
|
93
|
-
}
|
|
94
|
-
const fileOpts = yield processConfigFile();
|
|
95
|
-
runs = (0, evaluateConfig_1.evaluateConfigOptions)(cliOpts, fileOpts);
|
|
96
|
-
}
|
|
97
|
-
catch (error) {
|
|
98
|
-
console.error("Bad arguments!", error === null || error === void 0 ? void 0 : error.message);
|
|
99
|
-
process.exit(1);
|
|
100
|
-
}
|
|
101
|
-
for (let run of runs) {
|
|
102
|
-
yield startServiceGenerationRun(run);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
exports.Cli = Cli;
|
|
108
|
-
function startServiceGenerationRun(options) {
|
|
109
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
110
|
-
const { source, output, debug, mode, emitMode, prettier, serviceName } = options;
|
|
111
|
-
console.log("---------------------------");
|
|
112
|
-
console.log("Starting generation process");
|
|
113
|
-
if (debug) {
|
|
114
|
-
console.log("Resolved config:", {
|
|
115
|
-
source,
|
|
116
|
-
output,
|
|
117
|
-
debug,
|
|
118
|
-
mode: OptionModel_1.Modes[mode],
|
|
119
|
-
emitMode,
|
|
120
|
-
prettier,
|
|
121
|
-
serviceName,
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
console.log("Reading file:", source);
|
|
125
|
-
const exists = yield (0, fs_extra_1.pathExists)(source);
|
|
126
|
-
if (!exists) {
|
|
127
|
-
console.error(`Input source [${source}] doesn't exist!`);
|
|
128
|
-
process.exit(2);
|
|
129
|
-
}
|
|
130
|
-
// read metadata file and convert to JSON
|
|
131
|
-
const metadataXml = yield (0, fs_extra_1.readFile)(source);
|
|
132
|
-
const metadataJson = (yield (0, xml2js_1.parseStringPromise)(metadataXml));
|
|
133
|
-
// TODO find out if "1.0" and "4.0" are really correct
|
|
134
|
-
// TODO exit here if no version not suitable version was detected
|
|
135
|
-
// console.log(`OData version detected: ${metadataJson["edmx:Edmx"].$.Version}`);
|
|
136
|
-
// ensure that output directory exists
|
|
137
|
-
try {
|
|
138
|
-
yield (0, fs_extra_1.emptyDir)(output);
|
|
139
|
-
}
|
|
140
|
-
catch (error) {
|
|
141
|
-
console.error(`Output path [${output}] couldn't be created!`, error);
|
|
142
|
-
process.exit(3);
|
|
143
|
-
}
|
|
144
|
-
// run the app
|
|
145
|
-
try {
|
|
146
|
-
yield (0, app_1.runApp)(metadataJson, options);
|
|
147
|
-
}
|
|
148
|
-
catch (err) {
|
|
149
|
-
console.error("Error while running the program", err);
|
|
150
|
-
process.exit(99);
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Cli = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const commander_1 = tslib_1.__importStar(require("commander"));
|
|
6
|
+
const cosmiconfig_1 = require("cosmiconfig");
|
|
7
|
+
const cosmiconfig_typescript_loader_1 = require("cosmiconfig-typescript-loader");
|
|
8
|
+
const fs_extra_1 = require("fs-extra");
|
|
9
|
+
const xml2js_1 = require("xml2js");
|
|
10
|
+
const app_1 = require("./app");
|
|
11
|
+
const evaluateConfig_1 = require("./evaluateConfig");
|
|
12
|
+
const OptionModel_1 = require("./OptionModel");
|
|
13
|
+
const logFilePath_1 = require("./project/logger/logFilePath");
|
|
14
|
+
function parseMode(value, dummyPrevious) {
|
|
15
|
+
switch (value) {
|
|
16
|
+
case "models":
|
|
17
|
+
return OptionModel_1.Modes.models;
|
|
18
|
+
case "qobjects":
|
|
19
|
+
return OptionModel_1.Modes.qobjects;
|
|
20
|
+
case "service":
|
|
21
|
+
return OptionModel_1.Modes.service;
|
|
22
|
+
case "all":
|
|
23
|
+
return OptionModel_1.Modes.all;
|
|
24
|
+
default:
|
|
25
|
+
throw new Error(`Not a valid Mode: ${value}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function parseEmitMode(value, dummyPrevious) {
|
|
29
|
+
switch (value) {
|
|
30
|
+
case "dts":
|
|
31
|
+
return OptionModel_1.EmitModes.dts;
|
|
32
|
+
case "js":
|
|
33
|
+
return OptionModel_1.EmitModes.js;
|
|
34
|
+
case "ts":
|
|
35
|
+
return OptionModel_1.EmitModes.ts;
|
|
36
|
+
case "js_dts":
|
|
37
|
+
return OptionModel_1.EmitModes.js_dts;
|
|
38
|
+
default:
|
|
39
|
+
throw new Error(`Not a valid EmitMode: ${value}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function processCliArgs() {
|
|
43
|
+
var _a;
|
|
44
|
+
const cli = new commander_1.default.Command()
|
|
45
|
+
.version("0.3.0")
|
|
46
|
+
.description("CLI to generate Typescript Interfaces for models of a given OData service.")
|
|
47
|
+
.argument("[services...]", "Run the generation process only for certain services specified in config file", [])
|
|
48
|
+
.option("-s, --source <metadata.xml>", "Metadata file describing the OData service")
|
|
49
|
+
.option("-o, --output <path>", "Output location for generated files")
|
|
50
|
+
.addOption(new commander_1.Option("-m, --mode <mode>", "What kind of stuff gets generated")
|
|
51
|
+
.choices(Object.values(OptionModel_1.Modes).filter((t) => isNaN(Number(t))))
|
|
52
|
+
.argParser(parseMode))
|
|
53
|
+
.addOption(new commander_1.Option("-e, --emit-mode <mode>", "Output TS source files, compiled JS files with/wihthout generated d.ts files")
|
|
54
|
+
.choices(Object.values(OptionModel_1.EmitModes))
|
|
55
|
+
.argParser(parseEmitMode))
|
|
56
|
+
.option("-p, --prettier", "Format result with prettier (only applies if emitMode=ts)")
|
|
57
|
+
.option("-t, --tsconfig <path>", "Specify alternative to 'tsconfig.json' to use specific compilerOptions (applies if emitMode is not ts)")
|
|
58
|
+
.option("-d, --debug", "Verbose debug infos")
|
|
59
|
+
.option("-name, --service-name <serviceName>", "Give the service your own name")
|
|
60
|
+
.option("-n, --disable-auto-managed-key", "Give the service your own name")
|
|
61
|
+
.option("-r, --allow-renaming ", "Give the service your own name")
|
|
62
|
+
.parse(process.argv);
|
|
63
|
+
const args = ((_a = cli.args) === null || _a === void 0 ? void 0 : _a.length) ? { services: cli.args } : {};
|
|
64
|
+
return Object.assign(Object.assign({}, cli.opts()), args);
|
|
65
|
+
}
|
|
66
|
+
function processConfigFile() {
|
|
67
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const moduleName = "odata2ts";
|
|
69
|
+
const explorer = (0, cosmiconfig_1.cosmiconfig)(moduleName, {
|
|
70
|
+
searchPlaces: [`${moduleName}.config.js`, `${moduleName}.config.ts`, `${moduleName}.config.cjs`],
|
|
71
|
+
loaders: {
|
|
72
|
+
".ts": (0, cosmiconfig_typescript_loader_1.TypeScriptLoader)(),
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
const discoveredConfig = yield explorer.search();
|
|
76
|
+
if (discoveredConfig === null || discoveredConfig === void 0 ? void 0 : discoveredConfig.config) {
|
|
77
|
+
console.log("Loaded config file: ", (0, logFilePath_1.logFilePath)(discoveredConfig.filepath));
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
console.log("No config file found.");
|
|
81
|
+
}
|
|
82
|
+
return discoveredConfig === null || discoveredConfig === void 0 ? void 0 : discoveredConfig.config;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
class Cli {
|
|
86
|
+
run() {
|
|
87
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
let runs;
|
|
89
|
+
try {
|
|
90
|
+
const cliOpts = processCliArgs();
|
|
91
|
+
if (cliOpts.debug) {
|
|
92
|
+
console.log("CLI opts:", cliOpts);
|
|
93
|
+
}
|
|
94
|
+
const fileOpts = yield processConfigFile();
|
|
95
|
+
runs = (0, evaluateConfig_1.evaluateConfigOptions)(cliOpts, fileOpts);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
console.error("Bad arguments!", error === null || error === void 0 ? void 0 : error.message);
|
|
99
|
+
process.exit(1);
|
|
100
|
+
}
|
|
101
|
+
for (let run of runs) {
|
|
102
|
+
yield startServiceGenerationRun(run);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
exports.Cli = Cli;
|
|
108
|
+
function startServiceGenerationRun(options) {
|
|
109
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
const { source, output, debug, mode, emitMode, prettier, serviceName } = options;
|
|
111
|
+
console.log("---------------------------");
|
|
112
|
+
console.log("Starting generation process");
|
|
113
|
+
if (debug) {
|
|
114
|
+
console.log("Resolved config:", {
|
|
115
|
+
source,
|
|
116
|
+
output,
|
|
117
|
+
debug,
|
|
118
|
+
mode: OptionModel_1.Modes[mode],
|
|
119
|
+
emitMode,
|
|
120
|
+
prettier,
|
|
121
|
+
serviceName,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
console.log("Reading file:", source);
|
|
125
|
+
const exists = yield (0, fs_extra_1.pathExists)(source);
|
|
126
|
+
if (!exists) {
|
|
127
|
+
console.error(`Input source [${source}] doesn't exist!`);
|
|
128
|
+
process.exit(2);
|
|
129
|
+
}
|
|
130
|
+
// read metadata file and convert to JSON
|
|
131
|
+
const metadataXml = yield (0, fs_extra_1.readFile)(source);
|
|
132
|
+
const metadataJson = (yield (0, xml2js_1.parseStringPromise)(metadataXml));
|
|
133
|
+
// TODO find out if "1.0" and "4.0" are really correct
|
|
134
|
+
// TODO exit here if no version not suitable version was detected
|
|
135
|
+
// console.log(`OData version detected: ${metadataJson["edmx:Edmx"].$.Version}`);
|
|
136
|
+
// ensure that output directory exists
|
|
137
|
+
try {
|
|
138
|
+
yield (0, fs_extra_1.emptyDir)(output);
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
console.error(`Output path [${output}] couldn't be created!`, error);
|
|
142
|
+
process.exit(3);
|
|
143
|
+
}
|
|
144
|
+
// run the app
|
|
145
|
+
try {
|
|
146
|
+
yield (0, app_1.runApp)(metadataJson, options);
|
|
147
|
+
}
|
|
148
|
+
catch (err) {
|
|
149
|
+
console.error("Error while running the program", err);
|
|
150
|
+
process.exit(99);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
154
|
//# sourceMappingURL=cli.js.map
|