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