Files
lucide/scripts/rename/renameIcon.function.mjs
Karsa 6fbd5ee06a 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>
2024-03-08 16:55:46 +01:00

66 lines
2.1 KiB
JavaScript

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;');
}
}