mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-08-29 09:28:23 +02:00
* chore: upgrade eslint to v9 latest with compatible lint deps Agent-Logs-Url: https://github.com/lucide-icons/lucide/sessions/f7c1f1b5-d213-4afa-91a8-b799a16397ec * Fix eslint config * Fix a lot of eslint errors * Fix eslint * Fix eslint errors * Fix eslint errors * Fix types * Fix eslint warning * Format code * Add eslint 10 * Remove unused vars * Update pnpm * Update deps --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Eric Fennis <eric.fennis@gmail.com>
67 lines
2.2 KiB
TypeScript
67 lines
2.2 KiB
TypeScript
import path from 'path';
|
|
import { getCurrentDirPath, readSvgDirectory } from '../../tools/build-helpers/helpers.ts';
|
|
import yargs from 'yargs/yargs';
|
|
import { hideBin } from 'yargs/helpers';
|
|
import { renameIcon } from './renameIcon.function.mts';
|
|
import { type Arguments } from 'yargs';
|
|
|
|
async function main() {
|
|
const currentDir = getCurrentDirPath(import.meta.url);
|
|
const ICONS_DIR = path.resolve(currentDir, '../../icons');
|
|
const svgFiles = await readSvgDirectory(ICONS_DIR);
|
|
const iconNames = svgFiles.map((icon) => icon.split('.')[0]).reverse();
|
|
const argv = (yargs(hideBin(process.argv))
|
|
// @ts-expect-error the builder callback overload is not picked up for a default command
|
|
.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;
|
|
}>;
|
|
|
|
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 (const 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) {
|
|
if(err instanceof Error) {
|
|
console.error(err.message);
|
|
} else {
|
|
console.error('An unexpected error occurred:', err);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
main();
|