ondc-code-generator 0.3.3 → 0.3.5

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.
@@ -20,7 +20,7 @@ export declare class ConfigCompiler {
20
20
  initialize: (buildYaml: string, generatorConfig?: Partial<CodeGeneratorConfig>) => Promise<void>;
21
21
  performValidations: (valConfig: ValidationConfig) => Promise<void>;
22
22
  withMinimalValidations: (valConfig: ValidationConfig) => Promise<void>;
23
- generateCode: (valConfig: ValidationConfig, codeName?: string, minimal?: boolean) => Promise<void>;
23
+ generateCode: (valConfig: ValidationConfig, codeName?: string, minimal?: boolean, outputPath?: string) => Promise<void>;
24
24
  generateL0Schema: () => Promise<void>;
25
25
  generateValidPaths: () => Promise<Record<string, string[]>>;
26
26
  }
@@ -57,7 +57,7 @@ export class ConfigCompiler {
57
57
  throw new Error("validation failed");
58
58
  }
59
59
  };
60
- this.generateCode = async (valConfig, codeName = "L1-Validations", minimal = false) => {
60
+ this.generateCode = async (valConfig, codeName = "L1-Validations", minimal = false, outputPath = "./") => {
61
61
  valConfig = JSON.parse(JSON.stringify(valConfig));
62
62
  if (this.generatorConfig?.duplicateVariablesInChildren) {
63
63
  console.log("Duplicating variables");
@@ -70,9 +70,12 @@ export class ConfigCompiler {
70
70
  await this.performValidations(valConfig);
71
71
  }
72
72
  // Generate code based on the language
73
+ const targetPath = path.resolve(outputPath, `/generated/${codeName}`);
73
74
  switch (this.language) {
74
75
  case SupportedLanguages.Typescript:
75
- await new TypescriptGenerator(valConfig, this.errorDefinitions ?? [], `./generated/${codeName}`).generateCode({
76
+ await new TypescriptGenerator(valConfig, this.errorDefinitions ?? [], `./generated/${codeName}`
77
+ // targetPath
78
+ ).generateCode({
76
79
  codeName: codeName,
77
80
  });
78
81
  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.3",
3
+ "version": "0.3.5",
4
4
  "description": "generate code from build.yaml ",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",