1
0
mirror of https://github.com/simple-icons/simple-icons.git synced 2024-12-16 01:10:30 +02:00

Allow to select between licenses in add-icon-data script (#10564)

* Improve add-icon-data script

* Handle force closed prompts, add success message

* Remove Boolean casting

* Remove try/catch
This commit is contained in:
uncenter 2024-03-04 16:59:32 -05:00 committed by GitHub
parent f4954d9e0d
commit dcb07310d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 11 deletions

View File

@ -92,6 +92,7 @@
"fake-diff": "1.0.0",
"get-relative-luminance": "1.0.0",
"husky": "9.0.10",
"inquirer-autocomplete-standalone": "0.8.1",
"is-ci": "3.0.1",
"jsonschema": "1.4.1",
"markdown-link-check": "3.11.2",

View File

@ -1,6 +1,7 @@
import process from 'node:process';
import chalk from 'chalk';
import { input, confirm, checkbox } from '@inquirer/prompts';
import autocomplete from 'inquirer-autocomplete-standalone';
import getRelativeLuminance from 'get-relative-luminance';
import {
URL_REGEX,
@ -89,18 +90,18 @@ const getIconDataFromAnswers = (answers) => ({
const answers = {};
answers.title = await input({
message: 'Title',
message: 'Title:',
validate: titleValidator,
});
answers.hex = await input({
message: 'Hex',
message: 'Hex:',
validate: hexValidator,
transformer: hexTransformer,
});
answers.source = await input({
message: 'Source',
message: 'Source URL:',
validate: sourceValidator,
});
@ -110,7 +111,7 @@ answers.hasGuidelines = await confirm({
if (answers.hasGuidelines) {
answers.guidelines = await input({
message: 'Guidelines',
message: 'Guidelines URL:',
validate: sourceValidator,
});
}
@ -120,19 +121,32 @@ answers.hasLicense = await confirm({
});
if (answers.hasLicense) {
answers.licenseType = await input({
message: 'License type',
validate: (text) => Boolean(text),
const licenseTypes =
jsonSchema.definitions.brand.properties.license.oneOf[0].properties.type.enum.map(
(license) => {
return { value: license };
},
);
answers.licenseType = await autocomplete({
message: 'License type:',
source: async (input) => {
input = (input || '').trim();
return input
? licenseTypes.filter((license) =>
license.value.toLowerCase().includes(input.toLowerCase()),
)
: licenseTypes;
},
});
answers.licenseUrl = await input({
message: 'License URL' + chalk.reset(' (optional)'),
message: `License URL ${chalk.reset('(optional)')}:`,
validate: (text) => !Boolean(text) || sourceValidator(text),
});
}
answers.hasAliases = await confirm({
message: 'This icon has brands aliases?',
message: 'This icon has brand aliases?',
default: false,
});
@ -154,7 +168,7 @@ if (answers.hasAliases) {
answers.confirmToAdd = await confirm({
message: [
'About to write to simple-icons.json',
'About to write the following to simple-icons.json:',
chalk.reset(JSON.stringify(getIconDataFromAnswers(answers), null, 4)),
chalk.reset('Is this OK?'),
].join('\n\n'),
@ -166,7 +180,8 @@ if (answers.confirmToAdd) {
iconsData.icons.push(icon);
iconsData.icons.sort((a, b) => collator.compare(a.title, b.title));
await writeIconsData(iconsData);
console.log(chalk.green('\nData written successfully.'));
} else {
console.log('Aborted.');
console.log(chalk.red('\nAborted.'));
process.exit(1);
}