mon-entreprise/scripts/build-rules.js

24 lines
752 B
JavaScript
Raw Normal View History

import { writeFileSync } from 'fs'
import path from 'path'
2023-06-15 13:57:48 +00:00
import { getModelFromSource } from '@publicodes/tools/compilation'
import Engine from 'publicodes'
const outDir = './dist'
const rules = getModelFromSource(path.resolve('./règles/**/*.yaml'), {
verbose: true,
})
export default function writeJSFile() {
2023-09-25 18:02:13 +00:00
const json = JSON.stringify(JSON.stringify(rules))
2023-12-15 11:12:26 +00:00
const names = Object.keys(new Engine(rules).getParsedRules())
2023-09-25 18:02:13 +00:00
const jsString = `export const json = /*@__PURE__*/ ${json};\nexport default /*@__PURE__*/ JSON.parse(json);`
writeFileSync(path.resolve(outDir, 'index.js'), jsString)
writeFileSync(
path.resolve(outDir, 'names.ts'),
`\nexport type Names = ${names.map((name) => `"${name}"`).join('\n | ')}\n`
)
}
writeJSFile()