mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-11-14 13:58:21 +00:00
chore(icons): update icon names to match naming guidelines no. 7 to 9 (#1906)
* Update icon names to match naming guidelines no. 7 to 9 Update and extend rename icon helper script. * Ran prettier * Refactor rename scripts so that simplegit import doesn't cause other helper script usages to crash. * Revert renaming key-square * Revert renaming message-circle|square * Fix square-dashed-kanban * Optimize circle power * pnpm rename square-dashed-bottom-scissors square-bottom-dashed-scissors * Fix linting * Fix file name linting issues via cspell configuration * Rename unlock => lock-open * Rename (square|circle)-check-2 => (square|circle)-check-small * pnpm rename code-2 code-xml pnpm rename contact-2 contact-round * rename test-tube-2 test-tube-diagonal rename mic-2 mic-vocal rename loader-2 loader-circle rename test-tube-2 test-tube-diagonal rename school-2 university * fix icons linting * rename ice-cream => ice-cream-cone rename ice-cream-2 => ice-cream-bowl rename laptop-2 => laptop-abstract * renamePattern "^(square|circle)-arrow-([a-z-]+)-from$" "\\1-arrow-out-\\2" * rename wand-2 => wand-sparkles * Update university.json tags. * fix(icons): renamePattern '^(.+)-abstract$' '\1-minimal' --add-alias=false feat(scripts): added yargs option parsing to renamePattern * fix(packages): Remove protractor and puppeteer from lucide-angular, they are no longer in use but cause pnpm install to fail * Lint fix, this is starting to get ridiculous. * fix(packages): fix lucide-angular karma config. * chore(icons): renamePattern '^(square|circle)-check$' '\1-check-big' chore(icons): renamePattern '^(square|circle)-check-small$' '\1-check' --------- Co-authored-by: Karsa <karsa@sztaki.hu>
This commit is contained in:
+4
-3
@@ -48,7 +48,7 @@ export const resetFile = (fileName, outputDirectory) =>
|
||||
* @param {string} path
|
||||
* @returns {string} The contents of a file
|
||||
*/
|
||||
export const readFile = (entry) => fs.readFileSync(path.resolve(__dirname, '../', entry), 'utf-8');
|
||||
export const readFile = (path) => fs.readFileSync(path.resolve(__dirname, '../', path), 'utf-8');
|
||||
|
||||
/**
|
||||
* append content to a file
|
||||
@@ -93,7 +93,7 @@ export const readAllMetadata = (directory) =>
|
||||
fs
|
||||
.readdirSync(directory)
|
||||
.filter((file) => path.extname(file) === '.json')
|
||||
.reduce((acc, fileName, i) => {
|
||||
.reduce((acc, fileName) => {
|
||||
acc[path.basename(fileName, '.json')] = readMetadata(fileName, directory);
|
||||
return acc;
|
||||
}, {});
|
||||
@@ -112,6 +112,7 @@ export const readMetadata = (fileName, directory) =>
|
||||
* reads the icon directory
|
||||
*
|
||||
* @param {string} directory
|
||||
* @param {string} fileExtension
|
||||
* @returns {array} An array of file paths containing svgs
|
||||
*/
|
||||
export const readSvgDirectory = (directory, fileExtension = '.svg') =>
|
||||
@@ -218,7 +219,7 @@ export const shuffle = (array) => {
|
||||
export function minifySvg(string) {
|
||||
return string
|
||||
? string
|
||||
.replace(/\>[\r\n ]+</g, '><')
|
||||
.replace(/>[\r\n ]+</g, '><')
|
||||
.replace(/(<.*?>)|\s+/g, (m, $1) => $1 || ' ')
|
||||
.trim()
|
||||
: '';
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import process from 'process';
|
||||
import { spawn } from 'child_process';
|
||||
|
||||
const regex = /(?<file>[^:]+):(?<line>\d+):(?<column>\d+)\s-\s+(?<message>.+)/;
|
||||
const fileList = (process.env.CHANGED_FILES || '').split(' ');
|
||||
const fileList = process.env.CHANGED_FILES
|
||||
? (process.env.CHANGED_FILES || '').split(' ')
|
||||
: fs.readdirSync('./icons').map((fileName) => path.join('./icons', fileName));
|
||||
|
||||
const cspell = spawn('npx', ['cspell', 'stdin'], { stdio: ['pipe', 'pipe', 'inherit'] });
|
||||
cspell.stdin.write(fileList.join('\n'));
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { promisify } from 'util';
|
||||
import simpleGit from 'simple-git';
|
||||
|
||||
/**
|
||||
* Renames an icon and adds the old name as an alias.
|
||||
* @param {string} ICONS_DIR
|
||||
* @param {string} oldName
|
||||
* @param {string} newName
|
||||
* @param {boolean} logInfo
|
||||
* @param {boolean} addAlias
|
||||
*/
|
||||
export async function renameIcon(ICONS_DIR, oldName, newName, logInfo = true, addAlias = true) {
|
||||
const git = simpleGit();
|
||||
|
||||
async function fileExists(filePath) {
|
||||
try {
|
||||
await promisify(fs.access)(filePath);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const oldSvgPath = path.join(ICONS_DIR, `${oldName}.svg`);
|
||||
const newSvgPath = path.join(ICONS_DIR, `${newName}.svg`);
|
||||
const oldJsonPath = path.join(ICONS_DIR, `${oldName}.json`);
|
||||
const newJsonPath = path.join(ICONS_DIR, `${newName}.json`);
|
||||
|
||||
if (await fileExists(newSvgPath)) {
|
||||
throw new Error(`ERROR: Icon icons/${newName}.svg already exists`);
|
||||
}
|
||||
if (await fileExists(newJsonPath)) {
|
||||
throw new Error(`ERROR: Metadata file icons/${newName}.json already exists`);
|
||||
}
|
||||
if (!(await fileExists(oldSvgPath))) {
|
||||
throw new Error(`ERROR: Icon icons/${oldName}.svg doesn't exist`);
|
||||
}
|
||||
if (!(await fileExists(oldJsonPath))) {
|
||||
throw new Error(`ERROR: Metadata file icons/${oldName}.json doesn't exist`);
|
||||
}
|
||||
|
||||
await git.mv(oldSvgPath, newSvgPath);
|
||||
await git.mv(oldJsonPath, newJsonPath);
|
||||
if (addAlias) {
|
||||
const json = fs.readFileSync(newJsonPath, 'utf8');
|
||||
const jsonData = JSON.parse(json);
|
||||
if (Array.isArray(jsonData.aliases)) {
|
||||
jsonData.aliases = jsonData.aliases.filter((name) => name !== newName);
|
||||
jsonData.aliases.push(oldName);
|
||||
} else {
|
||||
jsonData.aliases = [oldName];
|
||||
}
|
||||
fs.writeFileSync(newJsonPath, JSON.stringify(jsonData, null, 2));
|
||||
await git.add(newJsonPath);
|
||||
}
|
||||
|
||||
if (logInfo) {
|
||||
console.log('SUCCESS: Next steps:');
|
||||
console.log(`git checkout -b rename/${oldName}-to-${newName};`);
|
||||
console.log(`git commit -m 'Renamed ${oldName} to ${newName}';`);
|
||||
console.log(`gh pr create --title 'Renamed ${oldName} to ${newName}';`);
|
||||
console.log('git checkout main;');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import path from 'path';
|
||||
import { getCurrentDirPath } from '../helpers.mjs';
|
||||
import { renameIcon } from './renameIcon.function.mjs';
|
||||
|
||||
async function main() {
|
||||
const oldName = path.basename(process.argv[2]).replace(/\.[^/.]+$/, '');
|
||||
const newName = path.basename(process.argv[3]).replace(/\.[^/.]+$/, '');
|
||||
|
||||
if (!newName || !oldName) {
|
||||
console.error('Usage: node ./scripts/renameIcon.mjs <oldIcon> <newIcon>');
|
||||
process.exit(1);
|
||||
}
|
||||
if (oldName === newName) {
|
||||
console.error('ERROR: Old name and new name are the same');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
const currentDir = getCurrentDirPath(import.meta.url);
|
||||
const ICONS_DIR = path.resolve(currentDir, '../../icons');
|
||||
await renameIcon(ICONS_DIR, oldName, newName);
|
||||
} catch (err) {
|
||||
console.error(err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -0,0 +1,55 @@
|
||||
import path from 'path';
|
||||
import { getCurrentDirPath, readSvgDirectory } from '../helpers.mjs';
|
||||
import { renameIcon } from './renameIcon.function.mjs';
|
||||
import yargs from 'yargs/yargs';
|
||||
import { hideBin } from 'yargs/helpers';
|
||||
|
||||
async function main() {
|
||||
const currentDir = getCurrentDirPath(import.meta.url);
|
||||
const ICONS_DIR = path.resolve(currentDir, '../../icons');
|
||||
const svgFiles = readSvgDirectory(ICONS_DIR);
|
||||
const iconNames = svgFiles.map((icon) => icon.split('.')[0]).reverse();
|
||||
const argv = yargs(hideBin(process.argv))
|
||||
.usage('$0 <pattern> <replacement>', 'Renames all icons matching a pattern', (yargs) => {
|
||||
yargs
|
||||
.positional('pattern', {
|
||||
type: 'string',
|
||||
demandOption: true,
|
||||
describe: 'A regular expression, e.g. "^rhombus-(.+)$"',
|
||||
})
|
||||
.positional('replacement', {
|
||||
type: 'string',
|
||||
demandOption: true,
|
||||
describe: 'A replacement string, e.g. "diamond-\\1"',
|
||||
});
|
||||
})
|
||||
.strictCommands()
|
||||
.options({
|
||||
'dry-run': { type: 'boolean', default: false, alias: 'd' },
|
||||
'add-alias': { type: 'boolean', default: true, alias: 'a' },
|
||||
})
|
||||
.parse();
|
||||
|
||||
const pattern = new RegExp(argv.pattern, 'g');
|
||||
const replacement = argv.replacement.replaceAll(/\\([0-9]+)/g, (s, i) => `$${i}`);
|
||||
|
||||
if (!(pattern instanceof RegExp)) {
|
||||
console.error(`${pattern} is not a valid regular expression.`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
for (let oldName of iconNames.filter((name) => pattern.test(name))) {
|
||||
const newName = oldName.replaceAll(pattern, replacement);
|
||||
console.log(`Renaming ${oldName} => ${newName}`);
|
||||
|
||||
try {
|
||||
if (!argv.dryRun) {
|
||||
await renameIcon(ICONS_DIR, oldName, newName, false, argv.addAlias);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -1,71 +0,0 @@
|
||||
import simpleGit from 'simple-git';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { promisify } from 'util';
|
||||
|
||||
const oldName = path.basename(process.argv[2]).replace(/\.[^/.]+$/, '');
|
||||
const newName = path.basename(process.argv[3]).replace(/\.[^/.]+$/, '');
|
||||
|
||||
if (!newName || !oldName) {
|
||||
console.error('Usage: node ./scripts/renameIcon.mjs <oldIcon> <newIcon>');
|
||||
process.exit(1);
|
||||
}
|
||||
if (oldName === newName) {
|
||||
console.error('ERROR: Old name and new name are the same');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const git = simpleGit();
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
if (await fileExists(`icons/${newName}.svg`)) {
|
||||
console.error(`ERROR: Icon icons/${newName}.svg already exists`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (await fileExists(`icons/${newName}.json`)) {
|
||||
console.error(`ERROR: Metadata file icons/${newName}.json already exists`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (!(await fileExists(`icons/${oldName}.svg`))) {
|
||||
console.error(`ERROR: Icon icons/${oldName}.svg doesn't exist`);
|
||||
process.exit(1);
|
||||
}
|
||||
if (!(await fileExists(`icons/${oldName}.json`))) {
|
||||
console.error(`ERROR: Metadata file icons/${oldName}.json doesn't exist`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
await git.mv(`icons/${oldName}.svg`, `icons/${newName}.svg`);
|
||||
await git.mv(`icons/${oldName}.json`, `icons/${newName}.json`);
|
||||
const json = fs.readFileSync(`icons/${newName}.json`, 'utf8');
|
||||
const jsonData = JSON.parse(json);
|
||||
if (Array.isArray(jsonData.aliases)) {
|
||||
jsonData.aliases.push(oldName);
|
||||
} else {
|
||||
jsonData.aliases = [oldName];
|
||||
}
|
||||
fs.writeFileSync(`icons/${newName}.json`, JSON.stringify(jsonData, null, 2));
|
||||
await git.add(`icons/${newName}.json`);
|
||||
|
||||
console.log('SUCCESS: Next steps:');
|
||||
console.log(`git checkout -b rename/${oldName}-to-${newName};`);
|
||||
console.log(`git commit -m 'Renamed ${oldName} to ${newName}';`);
|
||||
console.log(`gh pr create --title 'Renamed ${oldName} to ${newName}';`);
|
||||
console.log('git checkout main;');
|
||||
} catch (err) {
|
||||
console.error(err.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
async function fileExists(filePath) {
|
||||
try {
|
||||
await promisify(fs.access)(filePath);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user