1
0
Fork 0
mirror of https://github.com/betagouv/mon-entreprise synced 2025-02-11 12:05:02 +00:00
mon-entreprise/scripts/build-rules.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

29 lines
888 B
JavaScript
Raw Normal View History

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