ondc-code-generator 0.3.4 → 0.3.6

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.
@@ -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
- if (!this.buildData)
35
- throw new Error("Build data not initialized");
36
- if (!this.jsonSchemas)
37
- throw new Error("Schemas not initialized");
38
- if (!this.possibleJsonPaths)
39
- throw new Error("Possible paths not initialized");
40
- if (!this.errorDefinitions)
41
- throw new Error("Error definitions not initialized");
42
- await new ConfigValidator("", valConfig, this.possibleJsonPaths, this.errorDefinitions).validate();
43
- }
44
- catch (e) {
45
- logger.error(e);
46
- throw new Error("Validation failed");
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
- await new ConfigValidator("", valConfig, {}, [], {
52
- minimal: true,
53
- }).validate();
54
- }
55
- catch (e) {
56
- logger.error(e);
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) {
@@ -73,9 +70,9 @@ export class ConfigCompiler {
73
70
  const targetPath = path.resolve(outputPath, `/generated/${codeName}`);
74
71
  switch (this.language) {
75
72
  case SupportedLanguages.Typescript:
76
- await new TypescriptGenerator(valConfig, this.errorDefinitions ?? [],
77
- // `./generated/${codeName}`
78
- targetPath).generateCode({
73
+ await new TypescriptGenerator(valConfig, this.errorDefinitions ?? [], `./generated/${codeName}`
74
+ // targetPath
75
+ ).generateCode({
79
76
  codeName: codeName,
80
77
  });
81
78
  break;
package/dist/index.js CHANGED
@@ -1,23 +1,20 @@
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
- // 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
- // })();
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(__dirname, "../samples/validation-config.json");
13
+ const buildYaml = readFileSync(buildPath, "utf-8");
14
+ const valConfig = JSON.parse(readFileSync(valConfigPath, "utf-8"));
15
+ await compiler.initialize(buildYaml);
16
+ await compiler.generateCode(valConfig, "L1-validations", true);
17
+ };
18
+ (async () => {
19
+ await main();
20
+ })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ondc-code-generator",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "description": "generate code from build.yaml ",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",