[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": {
"@biomejs/biome": "2.3.8",
"@inquirer/prompts": "^8.0.1",
"@ls-lint/ls-lint": "2.3.1",
"@types/crypto-js": "^4.2.2",
"@types/jsdom": "^27.0.0",
@ -49,7 +50,6 @@
"@vitest/utils": "^4.0.14",
"chalk": "^5.6.2",
"dependency-cruiser": "^17.3.1",
"inquirer": "^13.0.1",
"jsdom": "^27.2.0",
"lefthook": "^2.0.4",
"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
*/
import { input, select } from "@inquirer/prompts";
import chalk from "chalk";
import inquirer from "inquirer";
import { validTestTypes } from "./constants.js";
/**
@ -17,16 +17,10 @@ import { validTestTypes } from "./constants.js";
*/
export async function promptTestType() {
/** @type {testType | "EXIT"} */
const choice = (
await inquirer.prompt([
{
type: "list",
name: "selectedOption",
message: "What type of test would you like to create?",
choices: [...validTestTypes, "EXIT"],
},
])
).selectedOption;
const choice = await select({
message: "What type of test would you like to create?",
choices: [...validTestTypes, "EXIT"],
});
if (choice === "EXIT") {
console.log("Exiting...");
@ -44,22 +38,16 @@ export async function promptTestType() {
*/
export async function promptFileName(selectedType) {
/** @type {string} */
const fileNameAnswer = (
await inquirer.prompt([
{
type: "input",
name: "userInput",
message: `Please provide the name of the ${selectedType}.`,
validate: name => {
const nameProcessed = name.trim().replace(".test.ts", "");
if (nameProcessed.length === 0) {
return chalk.red.bold("✗ Cannot use an empty string as a file name!");
}
return true;
},
},
])
).userInput;
const fileNameAnswer = await input({
message: `Please provide the name of the ${selectedType}.`,
validate: name => {
const nameProcessed = name.trim().replace(".test.ts", "");
if (nameProcessed.length === 0) {
return chalk.red.bold("✗ Cannot use an empty string as a file name!");
}
return true;
},
});
// Trim whitespace and any extension suffixes
return fileNameAnswer.trim().replace(".test.ts", "");

View File

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

View File

@ -24,7 +24,7 @@ const version = "1.0.1";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
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?
const eggMoveTargetPath = path.join(projectRoot, "src/data/balance/egg-moves.ts");

View File

@ -7,8 +7,8 @@
import { existsSync, writeFileSync } from "node:fs";
import { format, inspect } from "node:util";
import { confirm } from "@inquirer/prompts";
import chalk from "chalk";
import inquirer from "inquirer";
import { JSDOM } from "jsdom";
import { toCamelCase, toPascalSnakeCase, toTitleCase } from "../helpers/strings.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.
*/
async function promptExisting(outFile) {
return (
await inquirer.prompt([
{
type: "confirm",
name: "continue",
message: `File ${chalk.blue(outFile)} already exists!\nDo you want to replace it?`,
default: false,
},
])
).continue;
return await confirm({
message: `File ${chalk.blue(outFile)} already exists!\nDo you want to replace it?`,
default: false,
});
}
await main();