Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAJ Node 14 #1333

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/netlify.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '12'
node-version: '14'
- uses: actions/cache@v2
with:
path: '**/node_modules'
Expand Down
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12.16.1
14.15.3
12 changes: 6 additions & 6 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ commands:
jobs:
lint:
docker:
- image: node:12.16.1-buster
- image: node:14.15.3-buster
steps:
- install
- run: |
Expand All @@ -43,13 +43,13 @@ jobs:
yarn lint:prettier
type-check:
docker:
- image: node:12.16.1-buster
- image: node:14.15.3-buster
steps:
- install
- run: yarn test:type
i18n-check:
docker:
- image: node:12.16.1-buster
- image: node:14.15.3-buster
steps:
- install
- run: |
Expand All @@ -59,7 +59,7 @@ jobs:

unit-test:
docker:
- image: node:12.16.1-buster
- image: node:14.15.3-buster
steps:
- install
- run: git config --global core.quotepath false
Expand All @@ -68,7 +68,7 @@ jobs:

end-to-end-test:
docker:
- image: cypress/base:12.16.1
- image: cypress/base:14.15.3
environment:
TERM: xterm
steps:
Expand All @@ -88,7 +88,7 @@ jobs:

production-end-to-end-test:
docker:
- image: cypress/base:12.16.1
- image: cypress/base:14.15.3
environment:
TERM: xterm
parallelism: 3
Expand Down
49 changes: 30 additions & 19 deletions modele-social/build.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
/* eslint-env node */

const fs = require('fs')
const path = require('path')
const yaml = require('yaml')

const publicodesDir = path.resolve(__dirname, './règles')
const outDir = path.resolve(__dirname, './dist')

if (!fs.existsSync(outDir)) {
fs.mkdirSync(outDir)
import {
existsSync,
mkdirSync,
readdirSync,
statSync,
readFileSync,
writeFileSync,
watch,
} from 'fs'
import { fileURLToPath } from 'url'
import { resolve, join } from 'path'
import yaml from 'yaml'

const __dirname = fileURLToPath(import.meta.url)
const publicodesDir = resolve(__dirname, '../règles')
const outDir = resolve(__dirname, '../dist')

if (!existsSync(outDir)) {
mkdirSync(outDir)
}

function concatenateFilesInDir(dirPath = publicodesDir) {
return fs
.readdirSync(dirPath)
return readdirSync(dirPath)
.map((filename) => {
const fullpath = path.join(dirPath, filename)
if (fs.statSync(fullpath).isDirectory()) {
const fullpath = join(dirPath, filename)
if (statSync(fullpath).isDirectory()) {
return concatenateFilesInDir(fullpath)
} else {
return filename.endsWith('.yaml') ? fs.readFileSync(fullpath) : ''
return filename.endsWith('.yaml') ? readFileSync(fullpath) : ''
}
})
.reduce((acc, cur) => acc + '\n' + cur, '')
Expand All @@ -34,13 +43,15 @@ function readRules() {
function writeJSFile() {
const rules = readRules()
const names = Object.keys(rules)
const jsString = `module.exports = ${JSON.stringify(rules, null, 2)}`
fs.writeFileSync(path.resolve(outDir, 'index.js'), jsString)
fs.writeFileSync(
path.resolve(outDir, 'names.ts'),
const jsString = `export default ${JSON.stringify(rules, null, 2)}`
writeFileSync(resolve(outDir, 'index.js'), jsString)
writeFileSync(
resolve(outDir, 'names.ts'),
`\nexport type Names = ${names.map((name) => `"${name}"`).join('\n | ')}\n`
)
}

writeJSFile()
exports.watchDottedNames = () => fs.watch(publicodesDir, writeJSFile)
export function watchDottedNames() {
return watch(publicodesDir, writeJSFile)
}
1 change: 1 addition & 0 deletions modele-social/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"url": "https://github.com/betagouv/mon-entreprise.git",
"directory": "modele-social"
},
"type": "module",
"bugs": "https://github.com/betagouv/mon-entreprise/issues?q=is%3Aopen+is%3Aissue+label%3A%22%F0%9F%93%95+l%C3%A9gislation%22",
"homepage": "https://mon-entreprise.fr/int%C3%A9gration/biblioth%C3%A8que-de-calcul",
"license": "MIT",
Expand Down
3 changes: 0 additions & 3 deletions mon-entreprise/cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,3 @@
// Import commands.js using ES2015 syntax:
import 'cypress-plugin-tab'
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
9 changes: 5 additions & 4 deletions mon-entreprise/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
"directory": "mon-entreprise"
},
"private": true,
"type": "module",
"engines": {
"node": ">=12.16.1"
"node": ">=14.15.3"
},
"browserslist": [
"> 1% in FR",
Expand Down Expand Up @@ -46,7 +47,7 @@
"cypress-plugin-tab": "^1.0.5",
"eslint-plugin-react": "^7.12.4",
"html-webpack-plugin": "^3.2.0",
"i18next-parser": "^3.3.0",
"i18next-parser": "^3.6.0",
"intl-locales-supported": "^1.0.0",
"mock-local-storage": "^1.0.5",
"monaco-editor-webpack-plugin": "^1.9.0",
Expand Down Expand Up @@ -119,8 +120,8 @@
"test:dev-e2e:mycompanyinfrance": "cypress open --browser chromium --config baseUrl=http://localhost:8080/infrance",
"i18n:rules:check": "node scripts/i18n/check-missing-rule-translation.js",
"i18n:rules:translate": "node scripts/i18n/translate-rules.js",
"i18n:ui:check": "yarn run i18next -c scripts/i18n/parser.config.js && node scripts/i18n/check-missing-UI-translation",
"i18n:ui:translate": "rm -rf source/locales/static-analysis-fr.json && yarn run i18next -c scripts/i18n/parser.config.js && node scripts/i18n/translate-ui.js",
"i18n:ui:check": "yarn run i18next -c scripts/i18n/parser.config.cjs && node scripts/i18n/check-missing-UI-translation",
"i18n:ui:translate": "rm -rf source/locales/static-analysis-fr.json && yarn run i18next -c scripts/i18n/parser.config.cjs && node scripts/i18n/translate-ui.js",
"start": "node source/server.js",
"serve:dev": "yarn run serve:dev:mon-entreprise & yarn run serve:dev:mycompanyinfrance & yarn run serve:dev:publicodes",
"serve:dev:mon-entreprise": "PORT=5000 serve --config serve.mon-entreprise.json --no-clipboard",
Expand Down
Empty file.
7 changes: 4 additions & 3 deletions mon-entreprise/scripts/fetch-releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
//
// If you want to fetch unpublished "draft" release, you should check the
// "public repo" authorization when generating the access token.
require('dotenv').config()
require('isomorphic-fetch')
var { createDataDir, writeInDataDir } = require('./utils.js')
import dotenv from 'dotenv'
dotenv.config()
import 'isomorphic-fetch'
import { createDataDir, writeInDataDir } from './utils.js'

// We use the GitHub API V4 in GraphQL to download the releases. A GraphQL
// explorer can be found here : https://developer.github.com/v4/explorer/
Expand Down
17 changes: 9 additions & 8 deletions mon-entreprise/scripts/fetch-stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
//
// Matomo API documentation:
// https://developer.matomo.org/api-reference/reporting-api
require('dotenv').config()
require('isomorphic-fetch')
const querystring = require('querystring')
const { createDataDir, writeInDataDir } = require('./utils.js')
const R = require('ramda')
import dotenv from 'dotenv'
dotenv.config()
import 'isomorphic-fetch'
import { stringify } from 'querystring'
import { createDataDir, writeInDataDir } from './utils.js'
import { reduceBy, map } from 'ramda'

const apiURL = (params) => {
const query = querystring.stringify({
const query = stringify({
period: 'month',
date: 'last1',
method: 'API.get',
Expand Down Expand Up @@ -189,7 +190,7 @@ async function fetchSimulators(dt) {
: label

const sumVisits = (acc, { nb_visits }) => acc + nb_visits
const results = R.reduceBy(
const results = reduceBy(
sumVisits,
0,
groupSimulateursIframesVisits,
Expand Down Expand Up @@ -345,7 +346,7 @@ async function fetchChannelType() {

const data = await response.json()

const result = R.map(
const result = map(
(date) =>
date
.filter((x) =>
Expand Down
3 changes: 2 additions & 1 deletion mon-entreprise/scripts/i18n/check-missing-UI-translation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { getUiMissingTranslations } = require('./utils')
import { getUiMissingTranslations } from './utils.js'

const missingTranslationKeys = Object.keys(getUiMissingTranslations())
if (missingTranslationKeys.length) {
throw new Error(`Il manque des traductions UI pour les clés suivantes : ${[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getRulesMissingTranslations } = require('./utils')
import { getRulesMissingTranslations } from './utils.js'

const missingTranslations = getRulesMissingTranslations()[0]

Expand Down
15 changes: 7 additions & 8 deletions mon-entreprise/scripts/i18n/translate-rules.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
var { stringify } = require('yaml')
var fs = require('fs')
var prettier = require('prettier')

const {
import { writeFileSync } from 'fs'
import { stringify } from 'yaml'
import prettier from 'prettier'
import {
getRulesMissingTranslations,
rulesTranslationPath,
fetchTranslation,
} = require('./utils')
} from './utils.js'

const [missingTranslations, resolved] = getRulesMissingTranslations()

fs.writeFileSync(
writeFileSync(
rulesTranslationPath,
stringify(resolved, { sortMapEntries: true })
)
Expand All @@ -34,6 +33,6 @@ fs.writeFileSync(
parser: 'yaml',
}
)
fs.writeFileSync(rulesTranslationPath, formattedYaml)
writeFileSync(rulesTranslationPath, formattedYaml)
})
})()
16 changes: 8 additions & 8 deletions mon-entreprise/scripts/i18n/translate-ui.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
var { stringify, parse } = require('yaml')
var R = require('ramda')
var fs = require('fs')
import { stringify, parse } from 'yaml'
import { assocPath } from 'ramda'
import { readFileSync, writeFileSync } from 'fs'

const {
import {
getUiMissingTranslations,
UiTranslationPath,
fetchTranslation,
} = require('./utils')
} from './utils.js'

const missingTranslations = getUiMissingTranslations()

let translatedKeys = parse(fs.readFileSync(UiTranslationPath, 'utf-8'))
let translatedKeys = parse(readFileSync(UiTranslationPath, 'utf-8'))

Object.entries(missingTranslations)
.map(([key, value]) => [key, value === 'NO_TRANSLATION' ? key : value])
.forEach(async ([key, value]) => {
try {
const translation = await fetchTranslation(value)
translatedKeys = R.assocPath(
translatedKeys = assocPath(
key.split(/(?<=[A-zÀ-ü0-9])\.(?=[A-zÀ-ü0-9])/),
translation,
translatedKeys
)
fs.writeFileSync(
writeFileSync(
UiTranslationPath,
stringify(translatedKeys, { sortMapEntries: true })
)
Expand Down