Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions scripts/check-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
const fs = require('fs');
const path = require('path');

// Load the mapping file to get all icon names
const mappingPath = path.join(__dirname, '..', 'src', 'template', 'mapping.json');
// Load the icons directory to get all icon names
const iconsDir = path.join(__dirname, '..', 'src', 'icons');
const metadataPath = path.join(__dirname, '..', 'src', 'template', 'metadata.json');

if (!fs.existsSync(mappingPath)) {
console.error('Error: mapping.json not found at', mappingPath);
if (!fs.existsSync(iconsDir)) {
console.error('Error: icons directory not found at', iconsDir);
process.exit(1);
}

Expand All @@ -22,17 +22,15 @@ if (!fs.existsSync(metadataPath)) {
process.exit(1);
}

const mapping = JSON.parse(fs.readFileSync(mappingPath, 'utf8'));
const metadata = JSON.parse(fs.readFileSync(metadataPath, 'utf8'));

// Collect all unique icon names from mapping
const allIconNames = new Set();
Object.values(mapping).forEach(aliases => {
// For each code point, add the first alias (primary name)
if (aliases && aliases.length > 0) {
allIconNames.add(aliases[0]);
}
});
// Collect all icon names from the actual SVG files. Metadata is keyed by the
// SVG file name, which is the canonical identity for each icon.
const allIconNames = new Set(
fs.readdirSync(iconsDir)
.filter(file => file.endsWith('.svg'))
.map(file => path.basename(file, '.svg'))
);

// Find icons without metadata
const missingMetadata = [];
Expand Down
48 changes: 27 additions & 21 deletions scripts/svg-sprite.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,31 +65,37 @@ let processedFiles = 0;
const processedIcons = new Set();

Object.entries(mapping).forEach(([code, aliases]) => {
// Use the first alias as the primary SVG file name
const primaryAlias = aliases[0];

// The SVG file backing this icon may be named after any of its aliases,
// not necessarily the primary one, so pick whichever file actually exists.
const sourceAlias = aliases.find(alias =>
fs.existsSync(path.resolve(iconsDir, `${alias}.svg`))
);

if (!sourceAlias) {
console.warn(`Warning: no SVG file found for code ${code} (aliases: ${aliases.join(", ")})`);
return;
}

// Skip if we've already processed this icon
if (processedIcons.has(primaryAlias)) {
if (processedIcons.has(sourceAlias)) {
return;
}

// Use path.resolve for cross-platform compatibility
const file = path.resolve(iconsDir, `${primaryAlias}.svg`);

if (fs.existsSync(file)) {
processedFiles++;
processedIcons.add(primaryAlias);

// Add sprite entries for all aliases of this icon
for (const name of aliases) {
// Use path.resolve for cross-platform compatibility
const svgPath = path.resolve(iconsDir, `${name}.svg`);
spriter.add(
svgPath,
name + ".svg",
fs.readFileSync(file, "utf-8"),
);
}
const file = path.resolve(iconsDir, `${sourceAlias}.svg`);

processedFiles++;
processedIcons.add(sourceAlias);

// Add sprite entries for all aliases of this icon
for (const name of aliases) {
// Use path.resolve for cross-platform compatibility
const svgPath = path.resolve(iconsDir, `${name}.svg`);
spriter.add(
svgPath,
name + ".svg",
fs.readFileSync(file, "utf-8"),
);
}
});

Expand Down
60 changes: 30 additions & 30 deletions src/template/mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
"repo-delete"
],
"60003": [
"gist-fork",
"repo-forked"
"repo-forked",
"gist-fork"
],
"60004": [
"git-pull-request",
Expand Down Expand Up @@ -45,30 +45,30 @@
"mirror-public"
],
"60010": [
"star-empty",
"star",
"star-add",
"star-delete",
"star-empty"
"star-delete"
],
"60011": [
"comment",
"comment-add"
],
"60012": [
"alert",
"warning"
"warning",
"alert"
],
"60013": [
"search",
"search-save"
],
"60014": [
"log-out",
"sign-out"
"sign-out",
"log-out"
],
"60015": [
"log-in",
"sign-in"
"sign-in",
"log-in"
],
"60016": [
"eye",
Expand Down Expand Up @@ -96,9 +96,9 @@
"issue-opened"
],
"60021": [
"lock",
"gist-private",
"git-fork-private",
"lock",
"mirror-private"
],
"60022": [
Expand All @@ -107,12 +107,12 @@
"x"
],
"60023": [
"repo-sync",
"sync"
"sync",
"repo-sync"
],
"60024": [
"clone",
"desktop-download"
"desktop-download",
"clone"
],
"60025": [
"beaker",
Expand All @@ -126,13 +126,13 @@
"file"
],
"60028": [
"more",
"ellipsis",
"more",
"kebab-horizontal"
],
"60029": [
"mail-reply",
"reply"
"reply",
"mail-reply"
],
"60030": [
"organization",
Expand Down Expand Up @@ -161,35 +161,35 @@
"symbol-folder"
],
"60036": [
"github",
"logo-github",
"mark-github",
"github"
"mark-github"
],
"60037": [
"terminal",
"console",
"repl"
],
"60038": [
"zap",
"symbol-event"
"symbol-event",
"zap"
],
"60039": [
"error",
"stop"
],
"60040": [
"variable",
"symbol-variable"
"symbol-variable",
"variable"
],
"60042": [
"array",
"symbol-array"
"symbol-array",
"array"
],
"60043": [
"symbol-namespace",
"symbol-module",
"symbol-package",
"symbol-namespace",
"symbol-object"
],
"60044": [
Expand Down Expand Up @@ -218,8 +218,8 @@
"symbol-text"
],
"60052": [
"symbol-reference",
"go-to-file"
"go-to-file",
"symbol-reference"
],
"60053": [
"symbol-enum",
Expand Down Expand Up @@ -344,8 +344,8 @@
"chrome-restore"
],
"60092": [
"circle-outline",
"circle",
"circle-outline",
"debug-breakpoint-unverified",
"terminal-decoration-incomplete"
],
Expand Down
Loading