UNPKG

@gouvfr/dsfr-nexus

Version:

Le module `dsfr-nexus` est l'interface de ligne de commande (CLI) centrale du Système de Design de l’État - DSFR. Il offre des outils pour gérer et compiler les ressources du DSFR

55 lines (44 loc) 1.3 kB
import { PageInterpreter } from './page/page-interpreter.js'; import { createYAMLFile, readYAMLSync } from '@gouvfr/dsfr-forge'; class PartInterpreter { constructor (state) { this._state = state; } get id () { return this._data.id; } get src () { return this._state.src; } async read () { this._data = readYAMLSync(this._state.configFile('data.yml')); this._pages = []; for (const locale of this._state.i18n.locales) { const localState = this._state.localize(locale); const filenames = this._data?.doc?.pages?.[locale.code]; if (!filenames) continue; for (const filename of filenames) { const page = new PageInterpreter(localState, filename); await page.read(); this._pages.push(page); } } } async write () { const assets = []; for (const page of this._pages) { assets.push(...page.assets); await page.write(); } const assetMap = new Map(); for (const asset of assets) { const key = `${asset.url}|${asset.dest}`; if (!assetMap.has(key)) { assetMap.set(key, asset); } } const uniqueAssets = Array.from(assetMap.values()); createYAMLFile(this._state.configFile('assets.yml'), uniqueAssets); } } export { PartInterpreter };