🧰 Change le parseur yaml
parent
7dfb11066d
commit
4f92268345
|
@ -62,7 +62,8 @@
|
|||
"regenerator-runtime": "^0.13.3",
|
||||
"reselect": "^4.0.0",
|
||||
"swr": "^0.1.16",
|
||||
"whatwg-fetch": "^3.0.0"
|
||||
"whatwg-fetch": "^3.0.0",
|
||||
"yaml": "^1.9.2"
|
||||
},
|
||||
"scripts": {
|
||||
"prepare": "node source/scripts/prepare.js",
|
||||
|
@ -101,7 +102,7 @@
|
|||
"mon-entreprise:serve": "PORT=5000 serve --config serve.mon-entreprise.json --no-clipboard",
|
||||
"mon-entreprise:test": "cypress open --browser chromium",
|
||||
"mycompanyinfrance:serve": "PORT=5001 serve --config serve.infrance.json --no-clipboard",
|
||||
"mycompanyinfrance:test": "cypress open --browser chromium --env language=en --config baseUrl=http://localhost:8080/infrance",
|
||||
"mycompanyinfrance:test": "cypress open --browser chromium --config baseUrl=http://localhost:8080/infrance",
|
||||
"serve-dev": "yarn run mon-entreprise:serve & yarn run mycompanyinfrance:serve"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { ParsedRule } from 'Engine/types'
|
||||
import { safeDump } from 'js-yaml'
|
||||
import yaml from 'yaml'
|
||||
import React from 'react'
|
||||
import rules from 'Rules'
|
||||
import PublicodeHighlighter from '../ui/PublicodeHighlighter'
|
||||
|
@ -12,7 +12,7 @@ export default function RuleSource({ dottedName }: RuleSourceProps) {
|
|||
return (
|
||||
<section>
|
||||
<h3>Source publicode</h3>
|
||||
<PublicodeHighlighter source={safeDump({ [dottedName]: source })} />
|
||||
<PublicodeHighlighter source={yaml.stringify({ [dottedName]: source })} />
|
||||
<p className="ui__ notice">
|
||||
Ci-dessus la règle d'origine, écrite en publicode. Publicode est un
|
||||
langage déclaratif développé par beta.gouv.fr en partenariat avec
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import parseRule from 'Engine/parseRule'
|
||||
import { safeLoad } from 'js-yaml'
|
||||
import yaml from 'yaml'
|
||||
import { lensPath, set } from 'ramda'
|
||||
import { compilationError } from './error'
|
||||
import { parseReference } from './parseReference'
|
||||
|
@ -10,7 +10,7 @@ export default function parseRules<Names extends string>(
|
|||
): ParsedRules<Names> {
|
||||
const rules =
|
||||
typeof rawRules === 'string'
|
||||
? (safeLoad(rawRules.replace(/\t/g, ' ')) as Rules<Names>)
|
||||
? (yaml.parse(rawRules.replace(/\t/g, ' ')) as Rules<Names>)
|
||||
: { ...rawRules }
|
||||
|
||||
extractInlinedNames(rules)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var { safeDump } = require('js-yaml')
|
||||
var { stringify } = require('yaml')
|
||||
var fs = require('fs')
|
||||
|
||||
const {
|
||||
|
@ -9,7 +9,10 @@ const {
|
|||
|
||||
const [missingTranslations, resolved] = getRulesMissingTranslations()
|
||||
|
||||
fs.writeFileSync(rulesTranslationPath, safeDump(resolved, { sortKeys: true }))
|
||||
fs.writeFileSync(
|
||||
rulesTranslationPath,
|
||||
stringify(resolved, { sortMapEntries: true })
|
||||
)
|
||||
|
||||
missingTranslations.forEach(async ([dottedName, attr, value]) => {
|
||||
try {
|
||||
|
@ -18,7 +21,7 @@ missingTranslations.forEach(async ([dottedName, attr, value]) => {
|
|||
// C'est très bourrin, mais on ne veut pas perdre une traduction qu'on a payé
|
||||
fs.writeFileSync(
|
||||
rulesTranslationPath,
|
||||
safeDump(resolved, { sortKeys: true })
|
||||
stringify(resolved, { sortMapEntries: true })
|
||||
)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var { safeDump, safeLoad } = require('js-yaml')
|
||||
var { stringify, parse } = require('yaml')
|
||||
var R = require('ramda')
|
||||
var fs = require('fs')
|
||||
|
||||
|
@ -9,7 +9,7 @@ const {
|
|||
} = require('./utils')
|
||||
|
||||
const missingTranslations = getUiMissingTranslations()
|
||||
let translatedKeys = safeLoad(fs.readFileSync(UiTranslationPath, 'utf-8'))
|
||||
let translatedKeys = parse(fs.readFileSync(UiTranslationPath, 'utf-8'))
|
||||
|
||||
Object.entries(missingTranslations)
|
||||
.map(([key, value]) => [key, value === 'NO_TRANSLATION' ? key : value])
|
||||
|
@ -23,7 +23,7 @@ Object.entries(missingTranslations)
|
|||
)
|
||||
fs.writeFileSync(
|
||||
UiTranslationPath,
|
||||
safeDump(translatedKeys, { sortKeys: true })
|
||||
stringify(translatedKeys, { sortMapEntries: true })
|
||||
)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
|
|
|
@ -6,7 +6,7 @@ let R = require('ramda')
|
|||
var querystring = require('querystring')
|
||||
let { readRules } = require('../rules')
|
||||
|
||||
let { safeLoad } = require('js-yaml')
|
||||
let { parse } = require('yaml')
|
||||
let rulesTranslationPath = path.resolve('source/locales/rules-en.yaml')
|
||||
let UiTranslationPath = path.resolve('source/locales/en.yaml')
|
||||
|
||||
|
@ -23,7 +23,7 @@ let attributesToTranslate = [
|
|||
function getRulesMissingTranslations() {
|
||||
let rules = readRules()
|
||||
|
||||
let currentExternalization = safeLoad(
|
||||
let currentExternalization = parse(
|
||||
fs.readFileSync(rulesTranslationPath, 'utf-8')
|
||||
)
|
||||
|
||||
|
@ -119,7 +119,7 @@ const getUiMissingTranslations = () => {
|
|||
const staticKeys = require(path.resolve(
|
||||
'source/locales/static-analysis-fr.json'
|
||||
))
|
||||
const translatedKeys = safeLoad(fs.readFileSync(UiTranslationPath, 'utf-8'))
|
||||
const translatedKeys = parse(fs.readFileSync(UiTranslationPath, 'utf-8'))
|
||||
|
||||
const missingTranslations = Object.keys(staticKeys).filter(key => {
|
||||
if (key.match(/^\{.*\}$/)) {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const yaml = require('js-yaml')
|
||||
const yaml = require('yaml')
|
||||
|
||||
const publicodesDir = path.resolve(__dirname, '../rules')
|
||||
|
||||
|
@ -22,7 +22,7 @@ function concatenateFilesInDir(dirPath = publicodesDir) {
|
|||
}
|
||||
|
||||
function readRules() {
|
||||
return yaml.safeLoad(concatenateFilesInDir())
|
||||
return yaml.parse(concatenateFilesInDir())
|
||||
}
|
||||
|
||||
exports.readRules = readRules
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
// import { ControlledEditor } from '@monaco-editor/react'
|
||||
import Engine from 'Engine'
|
||||
import { formatValue } from 'Engine/format'
|
||||
import { safeLoad } from 'js-yaml'
|
||||
import yaml from 'yaml'
|
||||
import { last } from 'ramda'
|
||||
import React, { useCallback, useEffect, useMemo, useState } from 'react'
|
||||
import emoji from 'react-easy-emoji'
|
||||
import MonacoEditor from 'react-monaco-editor'
|
||||
import { useLocation } from 'react-router'
|
||||
import { DottedName } from 'Rules'
|
||||
import styled from 'styled-components'
|
||||
|
||||
const EXAMPLE_CODE = `
|
||||
|
@ -58,7 +57,7 @@ export default function Studio() {
|
|||
|
||||
const targets = useMemo(() => {
|
||||
try {
|
||||
return Object.keys(safeLoad(debouncedEditorValue) ?? {})
|
||||
return Object.keys(yaml.parse(debouncedEditorValue) ?? {})
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
return []
|
||||
|
|
|
@ -12598,6 +12598,13 @@ yaml@^1.7.2:
|
|||
dependencies:
|
||||
"@babel/runtime" "^7.8.7"
|
||||
|
||||
yaml@^1.9.2:
|
||||
version "1.9.2"
|
||||
resolved "https://registry.yarnpkg.com/yaml/-/yaml-1.9.2.tgz#f0cfa865f003ab707663e4f04b3956957ea564ed"
|
||||
integrity sha512-HPT7cGGI0DuRcsO51qC1j9O16Dh1mZ2bnXwsi0jrSpsLz0WxOLSLXfkABVl6bZO629py3CU+OMJtpNHDLB97kg==
|
||||
dependencies:
|
||||
"@babel/runtime" "^7.9.2"
|
||||
|
||||
yamljs@^0.3.0:
|
||||
version "0.3.0"
|
||||
resolved "https://registry.yarnpkg.com/yamljs/-/yamljs-0.3.0.tgz#dc060bf267447b39f7304e9b2bfbe8b5a7ddb03b"
|
||||
|
|
Loading…
Reference in New Issue