mirror of
https://github.com/Mibew/simple-icons.git
synced 2025-02-08 02:04:42 +03:00
Handle cleanly interruption signals on add-icon-data script (#10620)
This commit is contained in:
parent
8aab5ab4e5
commit
1401fb2a05
@ -84,7 +84,7 @@
|
|||||||
"url": "https://opencollective.com/simple-icons"
|
"url": "https://opencollective.com/simple-icons"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@inquirer/prompts": "3.2.0",
|
"@inquirer/prompts": "4.3.0",
|
||||||
"chalk": "5.3.0",
|
"chalk": "5.3.0",
|
||||||
"del-cli": "5.1.0",
|
"del-cli": "5.1.0",
|
||||||
"editorconfig-checker": "5.1.1",
|
"editorconfig-checker": "5.1.1",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import process from 'node:process';
|
import process from 'node:process';
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
import { input, confirm, checkbox } from '@inquirer/prompts';
|
import { input, confirm, checkbox, ExitPromptError } from '@inquirer/prompts';
|
||||||
import autocomplete from 'inquirer-autocomplete-standalone';
|
import autocomplete from 'inquirer-autocomplete-standalone';
|
||||||
import getRelativeLuminance from 'get-relative-luminance';
|
import getRelativeLuminance from 'get-relative-luminance';
|
||||||
import { search } from 'fast-fuzzy';
|
import { search } from 'fast-fuzzy';
|
||||||
@ -88,40 +88,41 @@ const getIconDataFromAnswers = (answers) => ({
|
|||||||
: {}),
|
: {}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const answers = {};
|
const run = async () => {
|
||||||
|
const answers = {};
|
||||||
|
|
||||||
answers.title = await input({
|
answers.title = await input({
|
||||||
message: 'Title:',
|
message: 'Title:',
|
||||||
validate: titleValidator,
|
validate: titleValidator,
|
||||||
});
|
});
|
||||||
|
|
||||||
answers.hex = await input({
|
answers.hex = await input({
|
||||||
message: 'Hex:',
|
message: 'Hex:',
|
||||||
validate: hexValidator,
|
validate: hexValidator,
|
||||||
transformer: hexTransformer,
|
transformer: hexTransformer,
|
||||||
});
|
});
|
||||||
|
|
||||||
answers.source = await input({
|
answers.source = await input({
|
||||||
message: 'Source URL:',
|
message: 'Source URL:',
|
||||||
validate: sourceValidator,
|
validate: sourceValidator,
|
||||||
});
|
});
|
||||||
|
|
||||||
answers.hasGuidelines = await confirm({
|
answers.hasGuidelines = await confirm({
|
||||||
message: 'The icon has brand guidelines?',
|
message: 'The icon has brand guidelines?',
|
||||||
});
|
});
|
||||||
|
|
||||||
if (answers.hasGuidelines) {
|
if (answers.hasGuidelines) {
|
||||||
answers.guidelines = await input({
|
answers.guidelines = await input({
|
||||||
message: 'Guidelines URL:',
|
message: 'Guidelines URL:',
|
||||||
validate: sourceValidator,
|
validate: sourceValidator,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
answers.hasLicense = await confirm({
|
answers.hasLicense = await confirm({
|
||||||
message: 'The icon has brand license?',
|
message: 'The icon has brand license?',
|
||||||
});
|
});
|
||||||
|
|
||||||
if (answers.hasLicense) {
|
if (answers.hasLicense) {
|
||||||
const licenseTypes =
|
const licenseTypes =
|
||||||
jsonSchema.definitions.brand.properties.license.oneOf[0].properties.type.enum.map(
|
jsonSchema.definitions.brand.properties.license.oneOf[0].properties.type.enum.map(
|
||||||
(license) => {
|
(license) => {
|
||||||
@ -142,14 +143,14 @@ if (answers.hasLicense) {
|
|||||||
message: `License URL ${chalk.reset('(optional)')}:`,
|
message: `License URL ${chalk.reset('(optional)')}:`,
|
||||||
validate: (text) => text.length === 0 || sourceValidator(text),
|
validate: (text) => text.length === 0 || sourceValidator(text),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
answers.hasAliases = await confirm({
|
answers.hasAliases = await confirm({
|
||||||
message: 'This icon has brand aliases?',
|
message: 'This icon has brand aliases?',
|
||||||
default: false,
|
default: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (answers.hasAliases) {
|
if (answers.hasAliases) {
|
||||||
answers.aliasesTypes = await checkbox({
|
answers.aliasesTypes = await checkbox({
|
||||||
message: 'What types of aliases do you want to add?',
|
message: 'What types of aliases do you want to add?',
|
||||||
choices: aliasesChoices,
|
choices: aliasesChoices,
|
||||||
@ -163,24 +164,40 @@ if (answers.hasAliases) {
|
|||||||
transformer: aliasesTransformer,
|
transformer: aliasesTransformer,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
answers.confirmToAdd = await confirm({
|
answers.confirmToAdd = await confirm({
|
||||||
message: [
|
message: [
|
||||||
'About to write the following to simple-icons.json:',
|
'About to write the following to simple-icons.json:',
|
||||||
chalk.reset(JSON.stringify(getIconDataFromAnswers(answers), null, 4)),
|
chalk.reset(JSON.stringify(getIconDataFromAnswers(answers), null, 4)),
|
||||||
chalk.reset('Is this OK?'),
|
chalk.reset('Is this OK?'),
|
||||||
].join('\n\n'),
|
].join('\n\n'),
|
||||||
});
|
});
|
||||||
|
|
||||||
const icon = getIconDataFromAnswers(answers);
|
const icon = getIconDataFromAnswers(answers);
|
||||||
|
|
||||||
if (answers.confirmToAdd) {
|
if (answers.confirmToAdd) {
|
||||||
iconsData.icons.push(icon);
|
iconsData.icons.push(icon);
|
||||||
iconsData.icons.sort((a, b) => collator.compare(a.title, b.title));
|
iconsData.icons.sort((a, b) => collator.compare(a.title, b.title));
|
||||||
await writeIconsData(iconsData);
|
await writeIconsData(iconsData);
|
||||||
console.log(chalk.green('\nData written successfully.'));
|
console.log(chalk.green('\nData written successfully.'));
|
||||||
} else {
|
} else {
|
||||||
console.log(chalk.red('\nAborted.'));
|
console.log(chalk.red('\nAborted.'));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const main = async () => {
|
||||||
|
try {
|
||||||
|
await run();
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof ExitPromptError) {
|
||||||
|
console.log(chalk.red('\nAborted.'));
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
await main();
|
||||||
|
Loading…
Reference in New Issue
Block a user