Skip to content

Commit

Permalink
build: disable optim in dev mode for rule compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
EmileRolley committed Dec 18, 2023
1 parent cd8329d commit 8c17af6
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 36 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ yarn doc
```

> [!TIP]
> Pour rapidement itérer sur le modèle, nous vous conseillons de lancer `yarn
> doc` dans un terminal et d'exécuter `yarn compile:rules-watch:fr dans un
> autre terminal pour recompiler le modèle à chaque modification. La
> documentation sera automatiquement mise à jour à la fin de la compilation.
> Pour rapidement itérer sur le modèle, nous vous conseillons de lancer `yarn dev`.
> Cela va lancer un serveur de développement qui va recompiler le modèle à
> chaque modification ainsi que les personas. Puis avec `yarn doc`, vous pouvez
> visualiser les résultats de la compilation dans votre navigateur, les
> modifications seront automatiquement prises en compte.

### CI

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"compile:personas": "node scripts/personasToJSON.js",
"compile:rules": "node scripts/rulesToJSON.mjs",
"compile:rules-watch": "nodemon -e \"publicodes js mjs\" --watch data/ --watch scripts/ scripts/rulesToJSON.mjs",
"compile:rules-watch:fr": "nodemon -e \"publicodes js mjs\" --watch data/ --watch scripts/ scripts/rulesToJSON.mjs -t fr -o FR",
"compile-watch": "yarn compile:rules-watch & nodemon -e publicodes --watch personas/ scripts/personasToJSON.js",
"compile:personas-watch": "nodemon -e \".yaml\" --watch personas/ scripts/personasToJSON.js",
"dev": "yarn compile:rules-watch -t fr -o FR --disable-optim & yarn compile:personas-watch",
"doc": "yarn --cwd quick-doc run dev",
"test:personas": "node tests/testPersonas.mjs",
"test:optim": "node tests/testOptim.mjs",
Expand Down Expand Up @@ -59,7 +59,7 @@
"yaml": "^2.2.2"
},
"devDependencies": {
"@incubateur-ademe/nosgestesclimat-scripts": "^0.3.1",
"@incubateur-ademe/nosgestesclimat-scripts": "^0.3.2",
"@incubateur-ademe/publicodes-commun": "^0.1.2",
"@publicodes/tools": "^0.4.4",
"@types/glob": "^8.1.0",
Expand Down
19 changes: 11 additions & 8 deletions scripts/rulesToJSON.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@ import rulesToJSONWorker from './rulesToJSON.worker.mjs'

const t9nDir = 'data/i18n/t9n'

const { srcLang, srcFile, destLangs, destRegions, markdown } = cli.getArgs(
`Aggregates the model to an unique JSON file.`,
{
const { srcLang, srcFile, destLangs, destRegions, markdown, optimDisabled } =
cli.getArgs(`Aggregates the model to an unique JSON file.`, {
source: true,
target: true,
model: { supportedRegionCodes },
file: true,
defaultSrcFile: 'data',
markdown: true
}
)
markdown: true,
optimCanBeDisabled: true
})

/// ---------------------- Helper functions ----------------------

Expand Down Expand Up @@ -139,6 +138,9 @@ if (!markdown) {
'ℹ️ Multi-threading mode:',
multiThread ? c.green('ON') : c.yellow('OFF')
)
console.log(
`ℹ️ Optimization mode: ${optimDisabled ? c.yellow('OFF') : c.green('ON')}`
)
}

const piscina = multiThread
Expand All @@ -155,6 +157,7 @@ const printErrorAndExit = (err, regionCode, destLang) => {
exit(-1)
}

const opts = { markdown, optimDisabled }
destLangs.unshift(srcLang)
const resultOfCompilationAndOptim = await Promise.all(
destLangs.flatMap((destLang) => {
Expand All @@ -166,7 +169,7 @@ const resultOfCompilationAndOptim = await Promise.all(
regionCode,
destLang,
translatedBaseRules,
markdown
opts
})
.catch((err) => printErrorAndExit(err, regionCode, destLang))
}
Expand All @@ -176,7 +179,7 @@ const resultOfCompilationAndOptim = await Promise.all(
regionCode,
destLang,
translatedBaseRules,
markdown
opts
})
} catch (err) {
printErrorAndExit(err, regionCode, destLang)
Expand Down
34 changes: 17 additions & 17 deletions scripts/rulesToJSON.worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,9 @@ function getLocalizedRules(translatedBaseRules, regionCode, destLang) {
}
}

export default ({
regionCode,
destLang,
translatedBaseRules,
markdown = false
}) => {
export default ({ regionCode, destLang, translatedBaseRules, opts }) => {
const { markdown, optimDisabled } = opts

const localizedTranslatedBaseRules = getLocalizedRules(
translatedBaseRules,
regionCode,
Expand All @@ -74,19 +71,22 @@ export default ({
regionCode,
markdown
)
const start = Date.now()
const nbRules = compressRules(engine, destPathWithoutExtension)
const optimDuration = Date.now() - start

if (!markdown) {
console.log(
getStyledReportString(
`${regionCode}-${destLang}`,
'optimized',
nbRules,
optimDuration
if (!optimDisabled) {
const start = Date.now()
const nbRules = compressRules(engine, destPathWithoutExtension)
const optimDuration = Date.now() - start

if (!markdown) {
console.log(
getStyledReportString(
`${regionCode}-${destLang}`,
'optimized',
nbRules,
optimDuration
)
)
)
}
}

return `<li>${regionCode}-${destLang}</li>`
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
resolved "https://registry.yarnpkg.com/@assemblyscript/loader/-/loader-0.10.1.tgz#70e45678f06c72fa2e350e8553ec4a4d72b92e06"
integrity sha512-H71nDOOL8Y7kWRLqf6Sums+01Q5msqBW2KhDUTemh1tvY04eSkSXrK0uj/4mmY0Xr16/3zyZmsrxN7CKuRbNRg==

"@incubateur-ademe/nosgestesclimat-scripts@^0.3.1":
version "0.3.1"
resolved "https://registry.yarnpkg.com/@incubateur-ademe/nosgestesclimat-scripts/-/nosgestesclimat-scripts-0.3.1.tgz#e0e4aba88c73e5f7be2cc900d8a1dd389807bc00"
integrity sha512-V6ewYvY/up/8utjyHRJyClCeIvorsB+7iSjxir0QETZNwfIPe14AlmbSx/BcHxZBSy4myJzM2oDpXB94/l8Oog==
"@incubateur-ademe/nosgestesclimat-scripts@^0.3.2":
version "0.3.2"
resolved "https://registry.yarnpkg.com/@incubateur-ademe/nosgestesclimat-scripts/-/nosgestesclimat-scripts-0.3.2.tgz#df1d1d58c67ce9a08107c7f6436b99f571518036"
integrity sha512-sD/ISqLH3Stas4AEOoF+43GNVXKOknoOhn1Rar5sFnavSSKPuuYPZL0Sw2tpykdaSRccR6QwlkFcTWtyFN35Zw==
dependencies:
"@types/node" "^18.11.18"
ansi-colors "^4.1.3"
Expand Down

0 comments on commit 8c17af6

Please sign in to comment.