Files
lucide/scripts/buildIcons.mjs
Louis Bailleau 55ae908018 Update all packages dependencies in project root (#863)
* Update `svgo` and `svgson` version and fix some tests

* Update eslint-related packages and fix all linter errors

* Update all rollup-related packages version

* Update all rollup-related packages (part 2)

* Update the rest of package which need to be updated

* Fix unwanted comment

* Fix unwanted comment (again)
2022-11-07 22:29:19 +01:00

66 lines
1.7 KiB
JavaScript

import fs from 'fs';
import path from 'path';
import getArgumentOptions from 'minimist';
import renderIconsObject from './render/renderIconsObject.mjs';
import generateIconFiles from './building/generateIconFiles.mjs';
import generateExportsFile from './building/generateExportsFile.mjs';
import { readSvgDirectory, getCurrentDirPath } from './helpers.mjs';
const cliArguments = getArgumentOptions(process.argv.slice(2));
const currentDir = getCurrentDirPath(import.meta.url);
const ICONS_DIR = path.resolve(currentDir, '../icons');
const OUTPUT_DIR = path.resolve(process.cwd(), cliArguments.output || '../build');
if (!fs.existsSync(OUTPUT_DIR)) {
fs.mkdirSync(OUTPUT_DIR);
}
const {
renderUniqueKey = false,
templateSrc,
silent = false,
iconFileExtention = '.js',
exportFileName = 'index.js',
pretty = true,
} = cliArguments;
async function buildIcons() {
if (templateSrc == null) {
throw new Error('No `templateSrc` argument given.');
}
const svgFiles = readSvgDirectory(ICONS_DIR);
const icons = renderIconsObject(svgFiles, ICONS_DIR, renderUniqueKey);
const { default: iconFileTemplate } = await import(path.resolve(process.cwd(), templateSrc));
// Generates iconsNodes files for each icon
generateIconFiles({
iconNodes: icons,
outputDirectory: OUTPUT_DIR,
template: iconFileTemplate,
showLog: !silent,
iconFileExtention,
pretty: JSON.parse(pretty),
});
// Generates entry files for the compiler filled with icons exports
generateExportsFile(
path.join(OUTPUT_DIR, 'icons', exportFileName),
path.join(OUTPUT_DIR, 'icons'),
icons,
iconFileExtention,
);
}
try {
buildIcons();
} catch (error) {
console.error(error);
}