ondc-code-generator 0.3.5 → 0.3.7
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/dist/generator/config-compiler.js +22 -25
- package/dist/index.js +21 -18
- package/package.json +1 -1
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { loadAndDereferenceYaml } from "../utils/config-utils/yaml.js";
|
|
2
2
|
import { SchemaExtactionService as SchemaExtractionService } from "../services/schema-service.js";
|
|
3
|
-
import logger from "../utils/logger.js";
|
|
4
3
|
import { SupportedLanguages } from "../types/compiler-types.js";
|
|
5
4
|
import { TypescriptGenerator } from "./generators/typescript/ts-generator.js";
|
|
6
5
|
import { ConfigValidator } from "./validators/config-validator.js";
|
|
@@ -30,33 +29,31 @@ export class ConfigCompiler {
|
|
|
30
29
|
this.errorDefinitions = errors.code;
|
|
31
30
|
};
|
|
32
31
|
this.performValidations = async (valConfig) => {
|
|
33
|
-
try {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
32
|
+
// try {
|
|
33
|
+
if (!this.buildData)
|
|
34
|
+
throw new Error("Build data not initialized");
|
|
35
|
+
if (!this.jsonSchemas)
|
|
36
|
+
throw new Error("Schemas not initialized");
|
|
37
|
+
if (!this.possibleJsonPaths)
|
|
38
|
+
throw new Error("Possible paths not initialized");
|
|
39
|
+
if (!this.errorDefinitions)
|
|
40
|
+
throw new Error("Error definitions not initialized");
|
|
41
|
+
await new ConfigValidator("", valConfig, this.possibleJsonPaths, this.errorDefinitions).validate();
|
|
42
|
+
// } catch (e) {
|
|
43
|
+
// logger.error(e);
|
|
44
|
+
// throw new Error(e as any);
|
|
45
|
+
// }
|
|
48
46
|
};
|
|
49
47
|
this.withMinimalValidations = async (valConfig) => {
|
|
50
|
-
try {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
throw new Error("validation failed");
|
|
58
|
-
}
|
|
48
|
+
// try {
|
|
49
|
+
await new ConfigValidator("", valConfig, {}, [], {
|
|
50
|
+
minimal: true,
|
|
51
|
+
}).validate();
|
|
52
|
+
// } catch (e) {
|
|
53
|
+
// logger.error(e);
|
|
54
|
+
// throw new Error("validation failed");
|
|
59
55
|
};
|
|
56
|
+
// };
|
|
60
57
|
this.generateCode = async (valConfig, codeName = "L1-Validations", minimal = false, outputPath = "./") => {
|
|
61
58
|
valConfig = JSON.parse(JSON.stringify(valConfig));
|
|
62
59
|
if (this.generatorConfig?.duplicateVariablesInChildren) {
|
package/dist/index.js
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { ConfigCompiler } from "./generator/config-compiler.js";
|
|
2
2
|
export { ConfigCompiler };
|
|
3
|
-
import { readFileSync } from "fs";
|
|
4
|
-
import path from "path";
|
|
5
|
-
import { fileURLToPath } from "url";
|
|
6
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
-
const __dirname = path.dirname(__filename);
|
|
8
|
-
import { SupportedLanguages } from "./types/compiler-types.js";
|
|
9
|
-
const main = async () => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
3
|
+
// import { readFileSync } from "fs";
|
|
4
|
+
// import path from "path";
|
|
5
|
+
// import { fileURLToPath } from "url";
|
|
6
|
+
// const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
// const __dirname = path.dirname(__filename);
|
|
8
|
+
// import { SupportedLanguages } from "./types/compiler-types.js";
|
|
9
|
+
// const main = async () => {
|
|
10
|
+
// const compiler = new ConfigCompiler(SupportedLanguages.Typescript);
|
|
11
|
+
// const buildPath = path.resolve(__dirname, "../samples/build.yaml");
|
|
12
|
+
// const valConfigPath = path.resolve(
|
|
13
|
+
// __dirname,
|
|
14
|
+
// "../samples/validation-config.json"
|
|
15
|
+
// );
|
|
16
|
+
// const buildYaml = readFileSync(buildPath, "utf-8");
|
|
17
|
+
// const valConfig = JSON.parse(readFileSync(valConfigPath, "utf-8"));
|
|
18
|
+
// await compiler.initialize(buildYaml);
|
|
19
|
+
// await compiler.generateCode(valConfig, "L1-validations", true);
|
|
20
|
+
// };
|
|
21
|
+
// (async () => {
|
|
22
|
+
// await main();
|
|
23
|
+
// })();
|