2019-12-13 10:01:02 +00:00
|
|
|
// 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')
|
2020-02-04 17:35:21 +00:00
|
|
|
const { readRules } = require('./rules')
|
2019-12-13 10:01:02 +00:00
|
|
|
|
2020-04-05 21:27:31 +00:00
|
|
|
const sourceDirPath = path.resolve(__dirname, '../rules')
|
|
|
|
const outPath = path.resolve(__dirname, '../rules/dottednames.json')
|
2019-12-13 10:01:02 +00:00
|
|
|
|
|
|
|
function persistJsonFileFromYaml() {
|
2020-02-04 17:35:21 +00:00
|
|
|
const rules = readRules()
|
|
|
|
const jsonString = JSON.stringify(rules, null, 2)
|
2019-12-13 10:01:02 +00:00
|
|
|
fs.writeFileSync(outPath, jsonString)
|
|
|
|
}
|
|
|
|
|
|
|
|
persistJsonFileFromYaml()
|
2020-02-04 17:35:21 +00:00
|
|
|
exports.watchDottedNames = () =>
|
|
|
|
fs.watch(sourceDirPath, persistJsonFileFromYaml)
|