1
0
Fork 0
mirror of https://github.com/betagouv/mon-entreprise synced 2025-02-09 04:05:01 +00:00
mon-entreprise/source/scripts/dottednames.js
Maxime Quandalle dff4236e0d Typage du nom des règles
Pour éviter de référencer des règles qui auraient été renommées.
À permis de détecter deux usages de règles "mortes".
2019-12-16 13:21:04 +01:00

25 lines
974 B
JavaScript

// It is currently not possible to automatically type yaml import with
// Typescript types, so we manually watch the yaml file containing the rules,
// convert it to json and persit it on the file system so that we can access the
// list of dotted names in the Typescript types.
//
// A fututre version of typescript may support "plugin" to type files such as
// yaml.
const fs = require('fs')
const path = require('path')
const yaml = require('js-yaml')
// eslint-disable-next-line no-undef
const sourcePath = path.resolve(__dirname, '../règles/base.yaml')
// eslint-disable-next-line no-undef
const outPath = path.resolve(__dirname, '../types/dottednames.json')
function persistJsonFileFromYaml() {
const source = fs.readFileSync(sourcePath)
const jsonString = JSON.stringify(yaml.safeLoad(source.toString()), null, 2)
fs.writeFileSync(outPath, jsonString)
}
persistJsonFileFromYaml()
exports.watchDottedNames = () => fs.watch(sourcePath, persistJsonFileFromYaml)