mirror of
https://github.com/lucide-icons/lucide.git
synced 2025-12-16 07:27:42 +01:00
Improve license notice in packages (#1657)
* Improve license message * Implement license notice in lucide-static * Tighten package PR workflows * Update lockfile
This commit is contained in:
@@ -22,10 +22,9 @@
|
||||
],
|
||||
"main": "lib/index.js",
|
||||
"scripts": {
|
||||
"copy:icons": "cp -r ../../icons icons",
|
||||
"copy:license": "cp ../../LICENSE ./LICENSE",
|
||||
"build:tags": "node ../../scripts/migrateIconsToTags.mjs",
|
||||
"build": "pnpm clean && pnpm copy:license && pnpm copy:icons && pnpm build:lib && pnpm build:tags",
|
||||
"build": "pnpm clean && pnpm copy:license && pnpm build:lib && pnpm build:tags",
|
||||
"build:lib": "node ./scripts/buildLib.mjs",
|
||||
"clean": "rm -rf lib && rm -rf build && rm -rf icons && rm -f sprite.svg",
|
||||
"version": "pnpm version --git-tag-version=false"
|
||||
|
||||
@@ -4,37 +4,51 @@ import path from 'path';
|
||||
import getArgumentOptions from 'minimist';
|
||||
import { parseSync } from 'svgson';
|
||||
|
||||
import { appendFile, readSvgDirectory, toCamelCase, getCurrentDirPath } from '../../../scripts/helpers.mjs';
|
||||
import {
|
||||
appendFile,
|
||||
readSvgDirectory,
|
||||
toCamelCase,
|
||||
getCurrentDirPath,
|
||||
} from '../../../scripts/helpers.mjs';
|
||||
import readSvgs from './readSvgs.mjs';
|
||||
import generateSprite from './generateSprite.mjs';
|
||||
import generateIconNodes from './generateIconNodes.mjs';
|
||||
import copyIcons from './copyIcons.mjs';
|
||||
|
||||
import pkg from '../package.json' assert { type: 'json' };
|
||||
|
||||
const cliArguments = getArgumentOptions(process.argv.slice(2));
|
||||
const createDirectory = dir => {
|
||||
const createDirectory = (dir) => {
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir);
|
||||
}
|
||||
};
|
||||
|
||||
const currentDir = getCurrentDirPath(import.meta.url)
|
||||
const currentDir = getCurrentDirPath(import.meta.url);
|
||||
|
||||
const PACKAGE_DIR = path.resolve(currentDir, '../');
|
||||
const ICONS_DIR = path.join(PACKAGE_DIR, 'icons');
|
||||
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');
|
||||
|
||||
const license = `@license ${pkg.name} v${pkg.version} - ${pkg.license}`;
|
||||
|
||||
createDirectory(LIB_DIR);
|
||||
createDirectory(ICON_MODULE_DIR);
|
||||
|
||||
const svgFiles = readSvgDirectory(ICONS_DIR);
|
||||
const svgs = readSvgs(svgFiles, ICONS_DIR);
|
||||
|
||||
const jsLicense = `/**\n * ${license}\n */\n`;
|
||||
|
||||
appendFile(jsLicense, `index.js`, LIB_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`;
|
||||
const exportString = `${jsLicense}module.exports = \`${contents}\`;\n`;
|
||||
appendFile(exportString, `${name}.js`, ICON_MODULE_DIR);
|
||||
});
|
||||
|
||||
@@ -44,5 +58,6 @@ const parsedSvgs = svgs.map(({ name, contents }) => ({
|
||||
parsedSvg: parseSync(contents),
|
||||
}));
|
||||
|
||||
generateSprite(parsedSvgs, PACKAGE_DIR);
|
||||
generateSprite(parsedSvgs, PACKAGE_DIR, license);
|
||||
generateIconNodes(parsedSvgs, PACKAGE_DIR);
|
||||
copyIcons(parsedSvgs, PACKAGE_DIR, license);
|
||||
|
||||
22
packages/lucide-static/scripts/copyIcons.mjs
Normal file
22
packages/lucide-static/scripts/copyIcons.mjs
Normal file
@@ -0,0 +1,22 @@
|
||||
import { writeFile } from 'fs/promises';
|
||||
import { existsSync, unlinkSync, mkdirSync } from 'fs';
|
||||
|
||||
export default async function copyIcons(parsedSvgs, packageDir, license) {
|
||||
const iconsDirectory = `${packageDir}/icons`;
|
||||
|
||||
if (existsSync(iconsDirectory)) {
|
||||
unlinkSync(iconsDirectory);
|
||||
}
|
||||
|
||||
if (!existsSync(iconsDirectory)) {
|
||||
mkdirSync(iconsDirectory);
|
||||
}
|
||||
// eslint-disable-next-line arrow-body-style
|
||||
const writeIconPromises = parsedSvgs.map(({ name, contents }) => {
|
||||
const content = `<!-- ${license} -->\n${contents}`;
|
||||
|
||||
return writeFile(`${iconsDirectory}/${name}.svg`, content);
|
||||
});
|
||||
|
||||
await Promise.all(writeIconPromises);
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import { stringify } from 'svgson';
|
||||
import { format } from 'prettier';
|
||||
import { appendFile } from '../../../scripts/helpers.mjs';
|
||||
|
||||
export default function generateSprite(svgs, packageDir) {
|
||||
export default function generateSprite(svgs, packageDir, license) {
|
||||
const symbols = svgs.map(({ name, parsedSvg }) => ({
|
||||
name: 'symbol',
|
||||
type: 'element',
|
||||
@@ -32,7 +32,7 @@ export default function generateSprite(svgs, packageDir) {
|
||||
const spriteSvg = stringify(spriteSvgObject);
|
||||
const prettifiedSprite = format(spriteSvg, { parser: 'babel' }).replace(/;/g, '');
|
||||
|
||||
const xmlMeta = `<?xml version="1.0" encoding="utf-8"?>\n`;
|
||||
const xmlMeta = `<?xml version="1.0" encoding="utf-8"?>\n<!-- ${license} -->\n`;
|
||||
|
||||
appendFile(xmlMeta, `sprite.svg`, packageDir);
|
||||
appendFile(prettifiedSprite, `sprite.svg`, packageDir);
|
||||
|
||||
@@ -8,10 +8,11 @@ import { readSvg } from '../../../scripts/helpers.mjs';
|
||||
* @param {Function} getSvg - A function that returns the contents of an SVG file given a filename.
|
||||
* @returns {Object}
|
||||
*/
|
||||
export default (svgFiles, iconsDirectory) =>
|
||||
svgFiles.map(svgFile => {
|
||||
export default function readSVGs(svgFiles, iconsDirectory) {
|
||||
return svgFiles.map((svgFile) => {
|
||||
const name = basename(svgFile, '.svg');
|
||||
const contents = readSvg(svgFile, iconsDirectory);
|
||||
|
||||
return { name, contents };
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user