-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env node | ||
/** | ||
* @file | ||
* Script to remove an icon and its data. | ||
*/ | ||
|
||
import fs from 'node:fs/promises'; | ||
import path from 'node:path'; | ||
import process from 'node:process'; | ||
import {search} from 'fast-fuzzy'; | ||
import autocomplete from 'inquirer-autocomplete-standalone'; | ||
import {getDirnameFromImportMeta, getIconSlug, getIconsData} from '../sdk.mjs'; | ||
import {writeIconsData} from './utils.js'; | ||
|
||
const __dirname = getDirnameFromImportMeta(import.meta.url); | ||
const rootDirectory = path.resolve(__dirname, '..'); | ||
const svgFilesDirectory = path.resolve(rootDirectory, 'icons'); | ||
|
||
const iconsData = await getIconsData(); | ||
const icons = iconsData.map((icon, index) => { | ||
const slug = getIconSlug(icon); | ||
return { | ||
name: `${icon.title} (${slug})`, | ||
value: {title: icon.title, slug, index}, | ||
}; | ||
}); | ||
|
||
const found = await autocomplete({ | ||
message: 'Select an icon to remove:', | ||
name: 'icon', | ||
async source(input) { | ||
if (!input) return icons; | ||
return search(input, icons, { | ||
keySelector: (icon) => [icon.value.title, icon.value.slug], | ||
}); | ||
}, | ||
}); | ||
|
||
if (!found) { | ||
console.error('No icon selected.'); | ||
process.exit(1); | ||
} | ||
|
||
iconsData.splice(found.index, 1); | ||
await writeIconsData(iconsData); | ||
await fs.unlink(path.resolve(svgFilesDirectory, `${found.slug}.svg`)); | ||
process.stdout.write(`Icon "${found.title} (${found.slug}.svg)" removed.\n`); |