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

57 lines (45 loc) 1.37 kB
import { PagePublisher } from './page/page-publisher.js'; import { copyFile, readYAMLSync } from '@gouvfr/dsfr-forge'; import { DocumentCollection } from '../integration/search/document-collection.js' class PartPublisher { constructor (state) { this._state = state; } get id () { return this._data.id; } get src () { return this._state.src; } get collections () { return this._collections; } async read () { this._assets = readYAMLSync(this._state.configFile('assets.yml')); this._assets.forEach(asset => { copyFile(asset.src, asset.dest); }); this._data = readYAMLSync(this._state.configFile('data.yml')); this._pages = []; this._collections = []; for (const locale of this._state.i18n.locales) { const localState = this._state.localize(locale); const filenames = this._data?.doc?.pages?.[locale.code]; const collection = new DocumentCollection(locale); this._collections.push(collection); if (!filenames) continue; for (const filename of filenames) { const page = new PagePublisher(localState, filename); await page.read(); collection.add(page.document); this._pages.push(page); } } } async write () { for (const page of this._pages) { await page.write(); } } } export { PartPublisher };