@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
51 lines (43 loc) • 1.47 kB
JavaScript
import { createFile, log } from '@gouvfr/dsfr-forge';
import path from 'path';
let getExporters;
try {
const weave = await import('@gouvfr/dsfr-weave');
getExporters = weave.getExporters;
} catch (e) {
log.warn('Weave dependency is not available.');
getExporters = null;
}
class ExportComposer {
constructor (state, frameworkIds, description) {
this._state = state;
this._frameworkIds = frameworkIds;
this._description = description;
}
async write () {
if (!getExporters) {
log.warn('Weave dependency is not available. Exporter cannot be used.');
return;
}
for (const frameworkId of this._frameworkIds) {
const exporters = getExporters(frameworkId, this._description);
if (!exporters || exporters.length === 0) {
log.warn(`No exporter found for framework ID: ${frameworkId}`);
continue;
}
for (const exporter of exporters) {
const outputs = await exporter.output();
if (!outputs || outputs.length === 0) continue;
for (const output of outputs) {
if (!output || !output.filePath || !output.content) {
log.warn(`Invalid output from renderer ${exporter.constructor.name} for framework ${frameworkId}`);
continue;
}
const filePath = path.join(this._state.dest, exporter.path, output.filePath);
createFile(filePath, output.content);
}
}
}
}
}
export { ExportComposer };