mirror of
https://github.com/Mibew/simple-icons.git
synced 2025-02-21 16:34:33 +03:00
Migrate inquirer
to @inquirer/prompts
(#8592)
This commit is contained in:
parent
747901a4d7
commit
a9a226c58a
@ -60,13 +60,13 @@
|
|||||||
"url": "https://opencollective.com/simple-icons"
|
"url": "https://opencollective.com/simple-icons"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@inquirer/prompts": "^1.0.0",
|
||||||
"chalk": "5.2.0",
|
"chalk": "5.2.0",
|
||||||
"editorconfig-checker": "5.0.1",
|
"editorconfig-checker": "5.0.1",
|
||||||
"esbuild": "0.17.18",
|
"esbuild": "0.17.18",
|
||||||
"fake-diff": "1.0.0",
|
"fake-diff": "1.0.0",
|
||||||
"get-relative-luminance": "1.0.0",
|
"get-relative-luminance": "1.0.0",
|
||||||
"husky": "8.0.3",
|
"husky": "8.0.3",
|
||||||
"inquirer": "9.2.0",
|
|
||||||
"is-ci": "3.0.1",
|
"is-ci": "3.0.1",
|
||||||
"jsonschema": "1.4.1",
|
"jsonschema": "1.4.1",
|
||||||
"mocha": "10.2.0",
|
"mocha": "10.2.0",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import inquirer from 'inquirer';
|
|
||||||
import chalk from 'chalk';
|
import chalk from 'chalk';
|
||||||
|
import { input, confirm, checkbox } from '@inquirer/prompts';
|
||||||
import getRelativeLuminance from 'get-relative-luminance';
|
import getRelativeLuminance from 'get-relative-luminance';
|
||||||
import {
|
import {
|
||||||
URL_REGEX,
|
URL_REGEX,
|
||||||
@ -83,96 +83,81 @@ const getIconDataFromAnswers = (answers) => ({
|
|||||||
: {}),
|
: {}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const dataPrompt = [
|
const answers = {};
|
||||||
{
|
|
||||||
type: 'input',
|
answers.title = await input({
|
||||||
name: 'title',
|
message: 'Title',
|
||||||
message: 'Title',
|
validate: titleValidator,
|
||||||
validate: titleValidator,
|
});
|
||||||
},
|
|
||||||
{
|
answers.hex = await input({
|
||||||
type: 'input',
|
message: 'Hex',
|
||||||
name: 'hex',
|
validate: hexValidator,
|
||||||
message: 'Hex',
|
filter: (text) => normalizeColor(text),
|
||||||
validate: hexValidator,
|
transformer: hexTransformer,
|
||||||
filter: (text) => normalizeColor(text),
|
});
|
||||||
transformer: hexTransformer,
|
|
||||||
},
|
answers.source = await input({
|
||||||
{
|
message: 'Source',
|
||||||
type: 'input',
|
validate: sourceValidator,
|
||||||
name: 'source',
|
});
|
||||||
message: 'Source',
|
|
||||||
validate: sourceValidator,
|
answers.hasGuidelines = await confirm({
|
||||||
},
|
message: 'The icon has brand guidelines?',
|
||||||
{
|
});
|
||||||
type: 'confirm',
|
|
||||||
name: 'hasGuidelines',
|
if (answers.hasGuidelines) {
|
||||||
message: 'The icon has brand guidelines?',
|
answers.guidelines = await input({
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'input',
|
|
||||||
name: 'guidelines',
|
|
||||||
message: 'Guidelines',
|
message: 'Guidelines',
|
||||||
validate: sourceValidator,
|
validate: sourceValidator,
|
||||||
when: ({ hasGuidelines }) => hasGuidelines,
|
});
|
||||||
},
|
}
|
||||||
{
|
|
||||||
type: 'confirm',
|
answers.hasLicense = await confirm({
|
||||||
name: 'hasLicense',
|
message: 'The icon has brand license?',
|
||||||
message: 'The icon has brand license?',
|
});
|
||||||
},
|
|
||||||
{
|
if (answers.hasLicense) {
|
||||||
type: 'input',
|
answers.licenseType = await input({
|
||||||
name: 'licenseType',
|
|
||||||
message: 'License type',
|
message: 'License type',
|
||||||
validate: (text) => Boolean(text),
|
validate: (text) => Boolean(text),
|
||||||
when: ({ hasLicense }) => hasLicense,
|
});
|
||||||
},
|
|
||||||
{
|
answers.licenseUrl = await input({
|
||||||
type: 'input',
|
message: 'License URL' + chalk.reset(' (optional)'),
|
||||||
name: 'licenseUrl',
|
|
||||||
message: 'License URL',
|
|
||||||
suffix: ' (optional)',
|
|
||||||
validate: (text) => !Boolean(text) || sourceValidator(text),
|
validate: (text) => !Boolean(text) || sourceValidator(text),
|
||||||
when: ({ hasLicense }) => hasLicense,
|
});
|
||||||
},
|
}
|
||||||
{
|
|
||||||
type: 'confirm',
|
answers.hasAliases = await confirm({
|
||||||
name: 'hasAliases',
|
message: 'This icon has brands aliases?',
|
||||||
message: 'The icon has brand aliases?',
|
default: false,
|
||||||
default: false,
|
});
|
||||||
},
|
|
||||||
{
|
if (answers.hasAliases) {
|
||||||
type: 'checkbox',
|
answers.aliasesTypes = await checkbox({
|
||||||
name: 'aliasesTypes',
|
|
||||||
message: 'What types of aliases do you want to add?',
|
message: 'What types of aliases do you want to add?',
|
||||||
choices: aliasesChoices,
|
choices: aliasesChoices,
|
||||||
when: ({ hasAliases }) => hasAliases,
|
});
|
||||||
},
|
|
||||||
...aliasesChoices.map((x) => ({
|
for (const x of aliasesChoices) {
|
||||||
type: 'input',
|
if (!answers?.aliasesTypes?.includes(x.value)) continue;
|
||||||
name: `${x.value}AliasesList`,
|
answers[`${x.value}AliasesList`] = await input({
|
||||||
message: x.value,
|
message: x.value + chalk.reset(' (separate with commas)'),
|
||||||
suffix: ' (separate with commas)',
|
validate: (text) => Boolean(text),
|
||||||
validate: (text) => Boolean(text),
|
transformer: aliasesTransformer,
|
||||||
transformer: aliasesTransformer,
|
});
|
||||||
when: (answers) => answers?.aliasesTypes?.includes(x.value),
|
}
|
||||||
})),
|
}
|
||||||
{
|
|
||||||
type: 'confirm',
|
answers.confirmToAdd = await confirm({
|
||||||
name: 'confirmToAdd',
|
message: [
|
||||||
message: (answers) => {
|
'About to write to simple-icons.json',
|
||||||
const icon = getIconDataFromAnswers(answers);
|
chalk.reset(JSON.stringify(getIconDataFromAnswers(answers), null, 4)),
|
||||||
return [
|
chalk.reset('Is this OK?'),
|
||||||
'About to write to simple-icons.json',
|
].join('\n\n'),
|
||||||
chalk.reset(JSON.stringify(icon, null, 4)),
|
});
|
||||||
chalk.reset('Is this OK?'),
|
|
||||||
].join('\n\n');
|
|
||||||
},
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const answers = await inquirer.prompt(dataPrompt);
|
|
||||||
const icon = getIconDataFromAnswers(answers);
|
const icon = getIconDataFromAnswers(answers);
|
||||||
|
|
||||||
if (answers.confirmToAdd) {
|
if (answers.confirmToAdd) {
|
||||||
|
Loading…
Reference in New Issue
Block a user