diff --git a/build.js b/build.js index c366207..9245879 100644 --- a/build.js +++ b/build.js @@ -10,10 +10,11 @@ const destPath = "model-template.model.json" // Resolves all rules and their dependencies into a single JSON object const model = getModelFromSource(srcFiles, { verbose: true }) +let engine // Try to create a new engine with the model to check for parsing errors try { - const _ = new Engine(model) + engine = new Engine(model) } catch (e) { console.error(`❌ There is an error in the model:`) console.error(e) @@ -30,18 +31,18 @@ writeFileSync( `import rules from "./${destPath}" assert { type: "json" }; export default rules; -` +`, ) console.log(`✅ index.js generated`) // Generate an index.d.ts file to export the model types // where each rule name is a case in the DottedName type -let indexDTypes = Object.keys(model).reduce( +let indexDTypes = Object.keys(engine.getParsedRules()).reduce( (acc, dottedName) => acc + `| "${dottedName}"\n`, `import { Rule } from "publicodes"; export type DottedName = -` +`, ) indexDTypes += `