Files
lucide/packages/lucide-static/scripts/buildLib.mjs
Eric Fennis 318c024589 Migrate to PNPM (#777)
* add pnpm

* make it work

* fix comamnds in package.jsons

* move some scripts to modules

* workflow fixes

* test workflow

* test #2

* minor fix

* update lockflite

* create workflows

* update workflow

* Add copy license command

* Fix build

* update workflows

* update contributions.md

* migrate site directory to pnpm

* Fix peer dependencies when install

* fix types in lucide-angular

* fix testing
2022-08-10 09:10:53 +02:00

49 lines
1.5 KiB
JavaScript

/* eslint-disable import/no-extraneous-dependencies */
import fs from 'fs';
import path from 'path';
import getArgumentOptions from 'minimist';
import { parseSync } from 'svgson';
import { appendFile, readSvgDirectory, toCamelCase, getCurrentDirPath } from '../../../scripts/helpers.mjs';
import readSvgs from './readSvgs.mjs';
import generateSprite from './generateSprite.mjs';
import generateIconNodes from './generateIconNodes.mjs';
const cliArguments = getArgumentOptions(process.argv.slice(2));
const createDirectory = dir => {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
};
const currentDir = getCurrentDirPath(import.meta.url)
const PACKAGE_DIR = path.resolve(currentDir, '../');
const ICONS_DIR = path.join(PACKAGE_DIR, 'icons');
const LIB_DIR = path.join(PACKAGE_DIR, cliArguments.output || 'lib');
const ICON_MODULE_DIR = path.join(LIB_DIR, 'icons');
createDirectory(LIB_DIR);
createDirectory(ICON_MODULE_DIR);
const svgFiles = readSvgDirectory(ICONS_DIR);
const svgs = readSvgs(svgFiles, ICONS_DIR);
svgs.forEach(({ name, contents }) => {
const componentName = toCamelCase(name);
const importString = `module.exports.${componentName} = require('./icons/${name}');\n`;
appendFile(importString, `index.js`, LIB_DIR);
const exportString = `module.exports = \`${contents}\`;\n`;
appendFile(exportString, `${name}.js`, ICON_MODULE_DIR);
});
const parsedSvgs = svgs.map(({ name, contents }) => ({
name,
contents,
parsedSvg: parseSync(contents),
}));
generateSprite(parsedSvgs, PACKAGE_DIR);
generateIconNodes(parsedSvgs, PACKAGE_DIR);