Remplace le parseur yaml de modele-social par un autre qui supporte les ancres
parent
933e5363be
commit
600de13951
|
@ -2,7 +2,7 @@
|
|||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const yaml = require('yaml')
|
||||
const yaml = require('js-yaml')
|
||||
|
||||
const publicodesDir = path.resolve(__dirname, './règles')
|
||||
const outDir = path.resolve(__dirname, './dist')
|
||||
|
@ -11,22 +11,29 @@ if (!fs.existsSync(outDir)) {
|
|||
fs.mkdirSync(outDir)
|
||||
}
|
||||
|
||||
function concatenateFilesInDir(dirPath = publicodesDir) {
|
||||
function recursiveFindYamlFile(dirPath = publicodesDir) {
|
||||
return fs
|
||||
.readdirSync(dirPath)
|
||||
.map((filename) => {
|
||||
.flatMap((filename) => {
|
||||
const fullpath = path.join(dirPath, filename)
|
||||
if (fs.statSync(fullpath).isDirectory()) {
|
||||
return concatenateFilesInDir(fullpath)
|
||||
return recursiveFindYamlFile(fullpath)
|
||||
} else {
|
||||
return filename.endsWith('.yaml') ? fs.readFileSync(fullpath) : ''
|
||||
return filename.endsWith('.yaml') ? fullpath : false
|
||||
}
|
||||
})
|
||||
.reduce((acc, cur) => acc + '\n' + cur, '')
|
||||
}).filter(Boolean)
|
||||
}
|
||||
|
||||
function readRules() {
|
||||
return yaml.parse(concatenateFilesInDir())
|
||||
return recursiveFindYamlFile().reduce((rules, filePath) => {
|
||||
const newRules = yaml.load(fs.readFileSync(filePath, 'utf-8'), {filename: filePath})
|
||||
const duplicatedRule = Object.keys(newRules).find(ruleName => ruleName in rules)
|
||||
if (duplicatedRule) {
|
||||
throw new Error(`La règle ${duplicatedRule} a été redéfinie dans dans le fichier ${filePath}, alors qu'elle avait déjà été définie auparavant dans un autre fichier`)
|
||||
}
|
||||
return Object.assign(rules, newRules)
|
||||
}, {})
|
||||
|
||||
}
|
||||
|
||||
// Note: we can't put the output file in the fs.watched directory
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
"dist/index.js"
|
||||
],
|
||||
"devDependencies": {
|
||||
"publicodes": "^1.0.0-beta.23",
|
||||
"yaml": "^1.10.0"
|
||||
"js-yaml": "^4.1.0",
|
||||
"publicodes": "^1.0.0-beta.23"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"publicodes": "^1.0.0-beta.23"
|
||||
|
|
|
@ -9156,9 +9156,9 @@ js-tokens@^3.0.2:
|
|||
resolved "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz"
|
||||
integrity sha1-mGbfOVECEw449/mWvOtlRDIJwls=
|
||||
|
||||
js-yaml@4.1.0:
|
||||
js-yaml@4.1.0, js-yaml@^4.1.0:
|
||||
version "4.1.0"
|
||||
resolved "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz"
|
||||
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-4.1.0.tgz#c1fb65f8f5017901cdd2c951864ba18458a10602"
|
||||
integrity sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==
|
||||
dependencies:
|
||||
argparse "^2.0.1"
|
||||
|
@ -14974,7 +14974,7 @@ yaml-loader@^0.5.0:
|
|||
dependencies:
|
||||
js-yaml "^3.5.2"
|
||||
|
||||
yaml@^1.10.0, yaml@^1.9.2:
|
||||
yaml@^1.9.2:
|
||||
version "1.10.2"
|
||||
resolved "https://registry.npmjs.org/yaml/-/yaml-1.10.2.tgz"
|
||||
integrity sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==
|
||||
|
|
Loading…
Reference in New Issue