Files
lucide/scripts/rename/renamePattern.mts

67 lines
2.1 KiB
TypeScript
Raw Normal View History

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
import path from 'path';
import { getCurrentDirPath, readSvgDirectory } from '../../tools/build-helpers/helpers.ts';
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
import yargs from 'yargs/yargs';
import { hideBin } from 'yargs/helpers';
import { renameIcon } from './renameIcon.function.mts';
import { type Arguments } from 'yargs';
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
async function main() {
const currentDir = getCurrentDirPath(import.meta.url);
const ICONS_DIR = path.resolve(currentDir, '../../icons');
const svgFiles = await readSvgDirectory(ICONS_DIR);
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
const iconNames = svgFiles.map((icon) => icon.split('.')[0]).reverse();
const argv = (yargs(hideBin(process.argv))
// @ts-ignore
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
.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()) as unknown as Arguments<{
pattern: string;
replacement: string;
dryRun: boolean;
addAlias: boolean;
}>;
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
const pattern = new RegExp(argv?.pattern, 'g');
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
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 (const oldName of iconNames.filter((name) => pattern.test(name))) {
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
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) {
if(err instanceof Error) {
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
console.error(err.message);
} else {
console.error('An unexpected error occurred:', err);
}
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
}
}
}
main();