[Misc] Migrate to @inquirer/prompts for CLI script input (#6789)

* update dependencies

* Update create-test

* use `validate` for filename check

* fix template path

* update parse-egg-moves

* update scrape-trainer-names

* replace use of `inquirer`

* Fix package ordering
This commit is contained in:
Fabi 2025-12-02 10:23:50 +01:00 committed by GitHub
parent 6d1a69bfea
commit b0a6b027fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 439 additions and 483 deletions

View File

@ -40,6 +40,7 @@
}, },
"devDependencies": { "devDependencies": {
"@biomejs/biome": "2.3.8", "@biomejs/biome": "2.3.8",
"@inquirer/prompts": "^8.0.1",
"@ls-lint/ls-lint": "2.3.1", "@ls-lint/ls-lint": "2.3.1",
"@types/crypto-js": "^4.2.2", "@types/crypto-js": "^4.2.2",
"@types/jsdom": "^27.0.0", "@types/jsdom": "^27.0.0",
@ -49,7 +50,6 @@
"@vitest/utils": "^4.0.14", "@vitest/utils": "^4.0.14",
"chalk": "^5.6.2", "chalk": "^5.6.2",
"dependency-cruiser": "^17.3.1", "dependency-cruiser": "^17.3.1",
"inquirer": "^13.0.1",
"jsdom": "^27.2.0", "jsdom": "^27.2.0",
"lefthook": "^2.0.4", "lefthook": "^2.0.4",
"msw": "^2.12.3", "msw": "^2.12.3",

File diff suppressed because it is too large Load Diff

View File

@ -4,8 +4,8 @@
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import { input, select } from "@inquirer/prompts";
import chalk from "chalk"; import chalk from "chalk";
import inquirer from "inquirer";
import { validTestTypes } from "./constants.js"; import { validTestTypes } from "./constants.js";
/** /**
@ -17,16 +17,10 @@ import { validTestTypes } from "./constants.js";
*/ */
export async function promptTestType() { export async function promptTestType() {
/** @type {testType | "EXIT"} */ /** @type {testType | "EXIT"} */
const choice = ( const choice = await select({
await inquirer.prompt([ message: "What type of test would you like to create?",
{ choices: [...validTestTypes, "EXIT"],
type: "list", });
name: "selectedOption",
message: "What type of test would you like to create?",
choices: [...validTestTypes, "EXIT"],
},
])
).selectedOption;
if (choice === "EXIT") { if (choice === "EXIT") {
console.log("Exiting..."); console.log("Exiting...");
@ -44,22 +38,16 @@ export async function promptTestType() {
*/ */
export async function promptFileName(selectedType) { export async function promptFileName(selectedType) {
/** @type {string} */ /** @type {string} */
const fileNameAnswer = ( const fileNameAnswer = await input({
await inquirer.prompt([ message: `Please provide the name of the ${selectedType}.`,
{ validate: name => {
type: "input", const nameProcessed = name.trim().replace(".test.ts", "");
name: "userInput", if (nameProcessed.length === 0) {
message: `Please provide the name of the ${selectedType}.`, return chalk.red.bold("✗ Cannot use an empty string as a file name!");
validate: name => { }
const nameProcessed = name.trim().replace(".test.ts", ""); return true;
if (nameProcessed.length === 0) { },
return chalk.red.bold("✗ Cannot use an empty string as a file name!"); });
}
return true;
},
},
])
).userInput;
// Trim whitespace and any extension suffixes // Trim whitespace and any extension suffixes
return fileNameAnswer.trim().replace(".test.ts", ""); return fileNameAnswer.trim().replace(".test.ts", "");

View File

@ -5,8 +5,8 @@
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
import fs from "fs"; import fs from "fs";
import { input, select } from "@inquirer/prompts";
import chalk from "chalk"; import chalk from "chalk";
import inquirer from "inquirer";
import { showHelpText } from "./help-message.js"; import { showHelpText } from "./help-message.js";
/** /**
@ -19,16 +19,10 @@ import { showHelpText } from "./help-message.js";
*/ */
export async function runInteractive() { export async function runInteractive() {
/** @type {"Console" | "File" | "Help" | "Exit"} */ /** @type {"Console" | "File" | "Help" | "Exit"} */
const answer = await inquirer const answer = await select({
.prompt([ message: "Select the method to obtain egg moves.",
{ choices: ["Console", "File", "Help", "Exit"],
type: "list", });
name: "type",
message: "Select the method to obtain egg moves.",
choices: ["Console", "File", "Help", "Exit"],
},
])
.then(a => a.type);
if (answer === "Exit") { if (answer === "Exit") {
console.log("Exiting..."); console.log("Exiting...");
@ -68,24 +62,18 @@ function promptForValue(type) {
* @returns {Promise<string>} The file path inputted by the user. * @returns {Promise<string>} The file path inputted by the user.
*/ */
async function getFilePath() { async function getFilePath() {
return await inquirer return await input({
.prompt([ message: "Please enter the path to the egg move CSV file.",
{ validate: filePath => {
type: "input", if (filePath.trim() === "") {
name: "path", return "File path cannot be empty!";
message: "Please enter the path to the egg move CSV file.", }
validate: input => { if (!fs.existsSync(filePath)) {
if (input.trim() === "") { return "File does not exist!";
return "File path cannot be empty!"; }
} return true;
if (!fs.existsSync(input)) { },
return "File does not exist!"; });
}
return true;
},
},
])
.then(answer => answer.path);
} }
/** /**
@ -93,22 +81,16 @@ async function getFilePath() {
* @returns {Promise<string>} The CSV input from the user. * @returns {Promise<string>} The CSV input from the user.
*/ */
async function doPromptConsole() { async function doPromptConsole() {
return await inquirer return await input({
.prompt([ message: "Please enter the egg move CSV text.",
{ validate: value => {
type: "input", if (value.trim() === "") {
name: "csv", return "CSV text cannot be empty!";
message: "Please enter the egg move CSV text.", }
validate: input => { if (!value.match(/^[^,]+(,[^,]+){4}$/gm)) {
if (input.trim() === "") { return "CSV text malformed - should contain 5 consecutive comma-separated values per line!";
return "CSV text cannot be empty!"; }
} return true;
if (!input.match(/^[^,]+(,[^,]+){4}$/gm)) { },
return "CSV text malformed - should contain 5 consecutive comma-separated values per line!"; });
}
return true;
},
},
])
.then(answer => answer.csv);
} }

View File

@ -24,7 +24,7 @@ const version = "1.0.1";
const __filename = fileURLToPath(import.meta.url); const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename); const __dirname = path.dirname(__filename);
const projectRoot = path.join(__dirname, "..", ".."); const projectRoot = path.join(__dirname, "..", "..");
const templatePath = path.join(__dirname, "egg-move-template.ts"); const templatePath = path.join(__dirname, "egg-move-template.boilerplate.ts");
// TODO: Do we want this to be configurable? // TODO: Do we want this to be configurable?
const eggMoveTargetPath = path.join(projectRoot, "src/data/balance/egg-moves.ts"); const eggMoveTargetPath = path.join(projectRoot, "src/data/balance/egg-moves.ts");

View File

@ -7,8 +7,8 @@
import { existsSync, writeFileSync } from "node:fs"; import { existsSync, writeFileSync } from "node:fs";
import { format, inspect } from "node:util"; import { format, inspect } from "node:util";
import { confirm } from "@inquirer/prompts";
import chalk from "chalk"; import chalk from "chalk";
import inquirer from "inquirer";
import { JSDOM } from "jsdom"; import { JSDOM } from "jsdom";
import { toCamelCase, toPascalSnakeCase, toTitleCase } from "../helpers/strings.js"; import { toCamelCase, toPascalSnakeCase, toTitleCase } from "../helpers/strings.js";
import { checkGenderAndType } from "./check-gender.js"; import { checkGenderAndType } from "./check-gender.js";
@ -285,16 +285,10 @@ async function tryWriteFile(outFile, output) {
* @returns {Promise<boolean>} Whether "Yes" or "No" was selected. * @returns {Promise<boolean>} Whether "Yes" or "No" was selected.
*/ */
async function promptExisting(outFile) { async function promptExisting(outFile) {
return ( return await confirm({
await inquirer.prompt([ message: `File ${chalk.blue(outFile)} already exists!\nDo you want to replace it?`,
{ default: false,
type: "confirm", });
name: "continue",
message: `File ${chalk.blue(outFile)} already exists!\nDo you want to replace it?`,
default: false,
},
])
).continue;
} }
await main(); await main();