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 5d75bfe
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 31 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
4 changes: 2 additions & 2 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
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

0 comments on commit 5d75bfe

Please sign in to comment.