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

50 lines (42 loc) 1.5 kB
import fs from 'fs'; import { DirectiveNode } from './directive-node.js'; import { parseMarkdown } from '../../../../../../common/markdown/parse.js' import { pageNodeFactory } from '../page-node-factory.js'; import { readYAMLSync } from '@gouvfr/dsfr-forge'; class ChangelogLeafDirectiveNode extends DirectiveNode { constructor (data, state) { super(data, state); this.parse(); } parse () { if (fs.existsSync(this.state.configFile('changelog.yml'))) { const changelog = readYAMLSync(this.state.configFile('changelog.yml')); if (changelog) { changelog.map(version => version.commits = version.commits.map(commit => { if (commit.hasOwnProperty('description')) { const nodes = parseMarkdown(commit.description); commit.description = nodes.map(node => pageNodeFactory(node, this.state)).map(node => node.data); } if (commit.hasOwnProperty('change')) { const nodes = parseMarkdown(commit.change); commit.change = nodes.map(node => pageNodeFactory(node, this.state)).map(node => node.data); } return commit; })); this._changelog = changelog; } } } get changelog () { return this._changelog; } get data () { return { ...super.data, changelog: this.changelog, dateFormat: this.state.i18n.current.code }; } } ChangelogLeafDirectiveNode.NAME = 'dsfr-doc-changelog'; export { ChangelogLeafDirectiveNode };