1
0
mirror of https://github.com/simple-icons/simple-icons.git synced 2025-11-23 21:34:49 +02:00

Fix add-icon-data script (#12908)

This commit is contained in:
LitoMore
2025-03-18 02:08:56 +08:00
committed by GitHub
parent 7ecce01c0d
commit b38c69869e

View File

@@ -20,6 +20,7 @@ import {
urlRegex,
} from '../sdk.mjs';
import {
formatIconData,
getJsonSchemaData,
getSpdxLicenseIds,
sortIconsCompare,
@@ -48,7 +49,10 @@ const aliasTypes = ['aka', 'old'].map((key) => ({
}));
const spdxLicenseIds = await getSpdxLicenseIds();
const licenseTypes = spdxLicenseIds.map((id) => ({name: id, value: id}));
const licenseTypes = [
{name: 'Custom', value: 'custom'},
...spdxLicenseIds.map((id) => ({name: id, value: id})),
];
/**
* Whether an input is a valid URL.
@@ -95,76 +99,95 @@ const previewHexColor = (input) => {
);
};
/** @type {IconData} */
const answers = {
title: await input({
message: 'What is the title of this icon?',
validate: (input) =>
input.trim().length > 0
? isNewIcon(input) || 'This icon title or slug already exists.'
: 'This field is required.',
title: '',
hex: '',
source: '',
};
answers.title = await input({
message: 'What is the title of this icon?',
validate: (input) =>
input.trim().length > 0
? isNewIcon(input) || 'This icon title or slug already exists.'
: 'This field is required.',
});
answers.hex = normalizeColor(
await input({
message: 'What is the brand color of this icon?',
validate: isValidHexColor,
transformer: previewHexColor,
}),
hex: normalizeColor(
await input({
message: 'What is the brand color of this icon?',
validate: isValidHexColor,
transformer: previewHexColor,
}),
),
source: await input({
message: 'What is the source URL of the icon?',
validate: isValidURL,
}),
guidelines: (await confirm({
);
answers.source = await input({
message: 'What is the source URL of the icon?',
validate: isValidURL,
});
if (
await confirm({
message: 'Does this icon have brand guidelines?',
}))
? await input({
message: 'What is the URL for the brand guidelines?',
validate: isValidURL,
})
: undefined,
license: (await confirm({
})
) {
answers.guidelines = await input({
message: 'What is the URL for the brand guidelines?',
validate: isValidURL,
});
}
if (
await confirm({
message: 'Does this icon have a license?',
}))
? {
type: await search({
message: "What is the icon's license?",
async source(input) {
input = (input || '').trim();
return input
? fuzzySearch(input, licenseTypes, {
keySelector: (x) => x.value,
})
: licenseTypes;
},
}),
url:
(await input({
message: `What is the URL for the license? (optional)`,
validate: (input) => input.length === 0 || isValidURL(input),
})) || undefined,
}
: undefined,
aliases: (await confirm({
})
) {
answers.license = {
type: await search({
message: "What is the icon's license?",
async source(input) {
input = (input || '').trim();
return input
? fuzzySearch(input, licenseTypes, {
keySelector: (x) => x.value,
})
: licenseTypes;
},
}),
};
if (answers.license.type === 'custom') {
// @ts-ignore
answers.license.url = await input({
message: `What is the URL for the license? (optional)`,
validate: (input) => input.length === 0 || isValidURL(input),
});
}
}
if (
await confirm({
message: 'Does this icon have brand aliases?',
default: false,
}))
? await checkbox({
message: 'What types of aliases do you want to add?',
choices: aliasTypes,
}).then(async (aliases) => {
/** @type {{[_: string]: string[]}} */
const result = {};
for (const alias of aliases) {
// eslint-disable-next-line no-await-in-loop
result[alias] = await input({
message: `What ${alias} aliases would you like to add? (separate with commas)`,
}).then((aliases) => aliases.split(',').map((alias) => alias.trim()));
}
})
) {
answers.aliases = await checkbox({
message: 'What types of aliases do you want to add?',
choices: aliasTypes,
}).then(async (aliases) => {
/** @type {{[_: string]: string[]}} */
const result = {};
for (const alias of aliases) {
// eslint-disable-next-line no-await-in-loop
result[alias] = await input({
message: `What ${alias} aliases would you like to add? (separate with commas)`,
}).then((aliases) => aliases.split(',').map((alias) => alias.trim()));
}
return result;
})
: undefined,
};
return aliases.length > 0 ? result : undefined;
});
}
process.stdout.write(
'About to write the following to simple-icons.json:\n' +
@@ -179,7 +202,7 @@ if (
) {
iconsData.push(answers);
iconsData.sort(sortIconsCompare);
await writeIconsData(iconsData);
await writeIconsData(formatIconData(iconsData));
process.stdout.write(chalk.green('\nData written successfully.\n'));
process.exit(0);
} else {