ondc-code-generator 0.5.2 → 0.5.4
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.
|
@@ -21,7 +21,7 @@ export declare class ConfigCompiler {
|
|
|
21
21
|
performValidations: (valConfig: ValidationConfig) => Promise<void>;
|
|
22
22
|
withMinimalValidations: (valConfig: ValidationConfig) => Promise<void>;
|
|
23
23
|
generateCode: (valConfig: ValidationConfig, codeName?: string, minimal?: boolean, outputPath?: string) => Promise<void>;
|
|
24
|
-
generateL0Schema: () => Promise<void>;
|
|
24
|
+
generateL0Schema: (outputPath?: string, type?: "json" | "typescript") => Promise<void>;
|
|
25
25
|
generateValidPaths: () => Promise<Record<string, string[]>>;
|
|
26
26
|
}
|
|
27
27
|
export {};
|
|
@@ -84,23 +84,31 @@ export class ConfigCompiler {
|
|
|
84
84
|
throw new Error("Language not supported");
|
|
85
85
|
}
|
|
86
86
|
};
|
|
87
|
-
this.generateL0Schema = async () => {
|
|
87
|
+
this.generateL0Schema = async (outputPath = "./", type = "typescript") => {
|
|
88
88
|
if (!this.jsonSchemas) {
|
|
89
89
|
throw new Error("Schemas not initialized");
|
|
90
90
|
}
|
|
91
|
+
const targetPath = `${outputPath}generated/L0-schemas/`;
|
|
91
92
|
for (const schema in this.jsonSchemas) {
|
|
92
93
|
const json = this.jsonSchemas[schema];
|
|
93
|
-
|
|
94
|
+
if (type === "typescript") {
|
|
95
|
+
writeAndFormatCode(targetPath, `${schema}.ts`, `export const ${schema} = ${JSON.stringify(json, null, 2)}`, "typescript");
|
|
96
|
+
}
|
|
97
|
+
else if (type === "json") {
|
|
98
|
+
writeAndFormatCode(targetPath, `${schema}.json`, JSON.stringify(json, null, 2), "json");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (type === "typescript") {
|
|
102
|
+
const actions = Object.keys(this.jsonSchemas).map((schema) => {
|
|
103
|
+
return {
|
|
104
|
+
action: schema,
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
const template = readFileSync(path.resolve(__dirname, "../generator/generators/typescript/templates/schema-template.mustache"), "utf-8");
|
|
108
|
+
console.log(actions);
|
|
109
|
+
const l0 = Mustache.render(template, { actions });
|
|
110
|
+
await writeAndFormatCode(`./generated/L0-schemas`, `index.ts`, l0, "typescript");
|
|
94
111
|
}
|
|
95
|
-
const actions = Object.keys(this.jsonSchemas).map((schema) => {
|
|
96
|
-
return {
|
|
97
|
-
action: schema,
|
|
98
|
-
};
|
|
99
|
-
});
|
|
100
|
-
const template = readFileSync(path.resolve(__dirname, "../generator/generators/typescript/templates/schema-template.mustache"), "utf-8");
|
|
101
|
-
console.log(actions);
|
|
102
|
-
const l0 = Mustache.render(template, { actions });
|
|
103
|
-
await writeAndFormatCode(`./generated/L0-schemas`, `index.ts`, l0, "typescript");
|
|
104
112
|
};
|
|
105
113
|
this.generateValidPaths = async () => {
|
|
106
114
|
if (!this.possibleJsonPaths)
|