mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-11-13 13:48:26 +00:00
Merge branch 'master' into categories
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import path from 'path';
|
||||
import tags from '../tags.json';
|
||||
import { readSvgDirectory, writeFile } from './helpers';
|
||||
import tags from '../tags.json' assert { type: 'json' };
|
||||
import { readSvgDirectory, writeFile, getCurrentDirPath } from './helpers.mjs';
|
||||
|
||||
const ICONS_DIR = path.resolve(__dirname, '../icons');
|
||||
const currentDir = getCurrentDirPath(import.meta.url)
|
||||
const ICONS_DIR = path.resolve(currentDir, '../icons');
|
||||
|
||||
console.log(`Read all tags`);
|
||||
|
||||
@@ -38,4 +39,4 @@ const newTags = iconTags.reduce((acc, { name, tags }) => {
|
||||
|
||||
const tagsContent = JSON.stringify(newTags, null, 2);
|
||||
|
||||
writeFile(tagsContent, 'tags.json', path.resolve(__dirname, '..'));
|
||||
writeFile(tagsContent, 'tags.json', path.resolve(currentDir, '..'));
|
||||
@@ -1,52 +0,0 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import getArgumentOptions from 'minimist'; // eslint-disable-line import/no-extraneous-dependencies
|
||||
|
||||
import renderIconsObject from './render/renderIconsObject';
|
||||
import generateIconFiles from './build/generateIconFiles';
|
||||
import generateExportsFile from './build/generateExportsFile';
|
||||
|
||||
import { readSvgDirectory } from './helpers';
|
||||
|
||||
const cliArguments = getArgumentOptions(process.argv.slice(2));
|
||||
|
||||
const ICONS_DIR = path.resolve(__dirname, '../icons');
|
||||
const OUTPUT_DIR = path.resolve(__dirname, cliArguments.output || '../build');
|
||||
|
||||
if (!fs.existsSync(OUTPUT_DIR)) {
|
||||
fs.mkdirSync(OUTPUT_DIR);
|
||||
}
|
||||
|
||||
const {
|
||||
renderUniqueKey = false,
|
||||
templateSrc = './templates/defaultIconFileTemplate',
|
||||
silent = false,
|
||||
iconFileExtention = '.js',
|
||||
exportFileName = 'index.js',
|
||||
pretty = true,
|
||||
} = cliArguments;
|
||||
|
||||
const svgFiles = readSvgDirectory(ICONS_DIR);
|
||||
|
||||
const icons = renderIconsObject(svgFiles, ICONS_DIR, renderUniqueKey);
|
||||
|
||||
// eslint-disable-next-line import/no-dynamic-require
|
||||
const iconFileTemplate = require(templateSrc).default;
|
||||
|
||||
// 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,
|
||||
);
|
||||
@@ -0,0 +1,67 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import getArgumentOptions from 'minimist'; // eslint-disable-line import/no-extraneous-dependencies
|
||||
|
||||
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)
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import path from 'path';
|
||||
|
||||
import { toPascalCase, resetFile, appendFile } from '../helpers';
|
||||
import { toPascalCase, resetFile, appendFile } from '../helpers.mjs';
|
||||
|
||||
export default function(inputEntry, outputDirectory, iconNodes, iconFileExtention = '') {
|
||||
const fileName = path.basename(inputEntry);
|
||||
@@ -10,7 +10,8 @@ export default function(inputEntry, outputDirectory, iconNodes, iconFileExtentio
|
||||
|
||||
const icons = Object.keys(iconNodes);
|
||||
|
||||
const fileExtention = iconFileExtention === '.ts' || iconFileExtention === '.js' ? '' : iconFileExtention
|
||||
const fileExtention =
|
||||
iconFileExtention === '.ts' || iconFileExtention === '.js' ? '' : iconFileExtention;
|
||||
|
||||
// Generate Import for Icon VNodes
|
||||
icons.forEach(iconName => {
|
||||
@@ -2,10 +2,16 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import prettier from 'prettier';
|
||||
import { promises } from 'stream';
|
||||
import { toPascalCase } from '../helpers';
|
||||
import { toPascalCase } from '../helpers.mjs';
|
||||
|
||||
export default function({ iconNodes, outputDirectory, template, showLog = true, iconFileExtention = '.js', pretty = true }) {
|
||||
export default function({
|
||||
iconNodes,
|
||||
outputDirectory,
|
||||
template,
|
||||
showLog = true,
|
||||
iconFileExtention = '.js',
|
||||
pretty = true,
|
||||
}) {
|
||||
const icons = Object.keys(iconNodes);
|
||||
const iconsDistDirectory = path.join(outputDirectory, `icons`);
|
||||
|
||||
@@ -18,28 +24,27 @@ export default function({ iconNodes, outputDirectory, template, showLog = true,
|
||||
const componentName = toPascalCase(iconName);
|
||||
|
||||
let { children } = iconNodes[iconName];
|
||||
children = children.map(({name, attributes}) => ([name, attributes]))
|
||||
children = children.map(({ name, attributes }) => [name, attributes]);
|
||||
|
||||
const elementTemplate = template({ componentName, iconName, children });
|
||||
const output =
|
||||
pretty
|
||||
const output = pretty
|
||||
? prettier.format(elementTemplate, {
|
||||
singleQuote: true,
|
||||
trailingComma: 'all',
|
||||
parser: 'babel',
|
||||
})
|
||||
: elementTemplate
|
||||
singleQuote: true,
|
||||
trailingComma: 'all',
|
||||
parser: 'babel',
|
||||
})
|
||||
: elementTemplate;
|
||||
|
||||
await fs.promises.writeFile(location, output, 'utf-8');
|
||||
});
|
||||
|
||||
Promise.all(writeIconFiles)
|
||||
.then(() => {
|
||||
if(showLog) {
|
||||
if (showLog) {
|
||||
console.log('Successfully built', icons.length, 'icons.');
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
throw new Error(`Something went wrong generating icon files,\n ${error}`)
|
||||
})
|
||||
.catch(error => {
|
||||
throw new Error(`Something went wrong generating icon files,\n ${error}`);
|
||||
});
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
import getArgumentOptions from 'minimist'; // eslint-disable-line import/no-extraneous-dependencies
|
||||
import githubApi from './githubApi';
|
||||
import githubApi from './githubApi.mjs';
|
||||
|
||||
const fetchCompareTags = oldTag =>
|
||||
githubApi(`https://api.github.com/repos/lucide-icons/lucide/compare/${oldTag}...master`);
|
||||
githubApi(`https://api.github.com/repos/lucide-icons/lucide/compare/${oldTag}...main`);
|
||||
|
||||
const iconRegex = /icons\/(.*)\.svg/g;
|
||||
const iconTemplate = ({ name, pullNumber, author }) =>
|
||||
@@ -41,6 +41,11 @@ const cliArguments = getArgumentOptions(process.argv.slice(2));
|
||||
(async function() {
|
||||
try {
|
||||
const output = await fetchCompareTags(cliArguments['old-tag']);
|
||||
|
||||
if (output?.files == null) {
|
||||
throw new Error('Tag not found!')
|
||||
}
|
||||
|
||||
const changedFiles = output.files.filter(
|
||||
({ filename }) => !filename.match(/site\/(.*)|(.*)package\.json|tags.json/g),
|
||||
);
|
||||
@@ -1,14 +1,16 @@
|
||||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
import path from 'path';
|
||||
import { stringify, parseSync } from 'svgson';
|
||||
import { format } from 'prettier';
|
||||
import { appendFile, readSvgDirectory } from './helpers';
|
||||
import prettier from 'prettier';
|
||||
import { appendFile, readSvgDirectory, getCurrentDirPath } from './helpers.mjs';
|
||||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
|
||||
import readSvgs from '../packages/lucide-static/scripts/readSvgs';
|
||||
import readSvgs from '../packages/lucide-static/scripts/readSvgs.mjs';
|
||||
|
||||
const currentDir = getCurrentDirPath(import.meta.url)
|
||||
|
||||
const ICONS_DIR = path.resolve('icons');
|
||||
const PACKAGE_DIR = path.resolve(__dirname);
|
||||
const PACKAGE_DIR = path.resolve(currentDir);
|
||||
|
||||
export default function generateSprite(svgs, packageDir) {
|
||||
const symbols = svgs.map(({ name, parsedSvg }, index) => {
|
||||
@@ -37,7 +39,7 @@ export default function generateSprite(svgs, packageDir) {
|
||||
};
|
||||
|
||||
const spriteSvg = stringify(spriteSvgObject);
|
||||
const prettifiedSprite = format(spriteSvg, { parser: 'babel' }).replace(/;/g, '');
|
||||
const prettifiedSprite = prettier.format(spriteSvg, { parser: 'babel' }).replace(/;/g, '');
|
||||
|
||||
const xmlMeta = `<?xml version="1.0" encoding="utf-8"?>\n`;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
/**
|
||||
* Converts string to CamelCase
|
||||
@@ -150,3 +151,5 @@ export const mergeArrays = (a, b) => {
|
||||
a = a.filter((i, p) => a.indexOf(i) === p);
|
||||
return a;
|
||||
};
|
||||
|
||||
export const getCurrentDirPath = currentPath => path.dirname(fileURLToPath(currentPath));
|
||||
@@ -1,5 +1,5 @@
|
||||
import fs from 'fs';
|
||||
import processSvg from './render/processSvg';
|
||||
import processSvg from './render/processSvg.mjs';
|
||||
|
||||
const svgFiles = process.argv.slice(4);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import processSvg from './render/processSvg';
|
||||
import { readSvgDirectory, writeSvgFile } from './helpers';
|
||||
import processSvg from './render/processSvg.mjs';
|
||||
import { readSvgDirectory, writeSvgFile } from './helpers.mjs';
|
||||
|
||||
const ICONS_DIR = path.resolve(process.cwd(), 'icons');
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
import { optimize } from 'svgo';
|
||||
import { format } from 'prettier';
|
||||
import prettier from 'prettier';
|
||||
import { parseSync, stringify } from 'svgson';
|
||||
import DEFAULT_ATTRS from './default-attrs.json';
|
||||
import DEFAULT_ATTRS from './default-attrs.json' assert { type: 'json' };
|
||||
|
||||
/**
|
||||
* Optimize SVG with `svgo`.
|
||||
@@ -52,7 +52,7 @@ function processSvg(svg) {
|
||||
return (
|
||||
optimizeSvg(svg)
|
||||
.then(setAttrs)
|
||||
.then(optimizedSvg => format(optimizedSvg, { parser: 'babel' }))
|
||||
.then(optimizedSvg => prettier.format(optimizedSvg, { parser: 'babel' }))
|
||||
// remove semicolon inserted by prettier
|
||||
// because prettier thinks it's formatting JSX not HTML
|
||||
.then(svg => svg.replace(/;/g, ''))
|
||||
@@ -1,7 +1,7 @@
|
||||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
import { basename } from 'path';
|
||||
import { parseSync } from 'svgson';
|
||||
import { generateHashedKey, readSvg, hasDuplicatedChildren } from '../helpers';
|
||||
import { generateHashedKey, readSvg, hasDuplicatedChildren } from '../helpers.mjs';
|
||||
|
||||
/**
|
||||
* Build an object in the format: `{ <name>: <contents> }`.
|
||||
File diff suppressed because it is too large
Load Diff
|
Before Width: | Height: | Size: 238 KiB |
Reference in New Issue
Block a user