mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-12-14 05:45:20 +01:00
[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:
parent
6d1a69bfea
commit
b0a6b027fa
@ -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",
|
||||
|
||||
784
pnpm-lock.yaml
784
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
@ -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",
|
||||
const choice = await select({
|
||||
message: "What type of test would you like to create?",
|
||||
choices: [...validTestTypes, "EXIT"],
|
||||
},
|
||||
])
|
||||
).selectedOption;
|
||||
});
|
||||
|
||||
if (choice === "EXIT") {
|
||||
console.log("Exiting...");
|
||||
@ -44,11 +38,7 @@ export async function promptTestType() {
|
||||
*/
|
||||
export async function promptFileName(selectedType) {
|
||||
/** @type {string} */
|
||||
const fileNameAnswer = (
|
||||
await inquirer.prompt([
|
||||
{
|
||||
type: "input",
|
||||
name: "userInput",
|
||||
const fileNameAnswer = await input({
|
||||
message: `Please provide the name of the ${selectedType}.`,
|
||||
validate: name => {
|
||||
const nameProcessed = name.trim().replace(".test.ts", "");
|
||||
@ -57,9 +47,7 @@ export async function promptFileName(selectedType) {
|
||||
}
|
||||
return true;
|
||||
},
|
||||
},
|
||||
])
|
||||
).userInput;
|
||||
});
|
||||
|
||||
// Trim whitespace and any extension suffixes
|
||||
return fileNameAnswer.trim().replace(".test.ts", "");
|
||||
|
||||
@ -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",
|
||||
const answer = await select({
|
||||
message: "Select the method to obtain egg moves.",
|
||||
choices: ["Console", "File", "Help", "Exit"],
|
||||
},
|
||||
])
|
||||
.then(a => a.type);
|
||||
});
|
||||
|
||||
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",
|
||||
return await input({
|
||||
message: "Please enter the path to the egg move CSV file.",
|
||||
validate: input => {
|
||||
if (input.trim() === "") {
|
||||
validate: filePath => {
|
||||
if (filePath.trim() === "") {
|
||||
return "File path cannot be empty!";
|
||||
}
|
||||
if (!fs.existsSync(input)) {
|
||||
if (!fs.existsSync(filePath)) {
|
||||
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.
|
||||
*/
|
||||
async function doPromptConsole() {
|
||||
return await inquirer
|
||||
.prompt([
|
||||
{
|
||||
type: "input",
|
||||
name: "csv",
|
||||
return await input({
|
||||
message: "Please enter the egg move CSV text.",
|
||||
validate: input => {
|
||||
if (input.trim() === "") {
|
||||
validate: value => {
|
||||
if (value.trim() === "") {
|
||||
return "CSV text cannot be empty!";
|
||||
}
|
||||
if (!input.match(/^[^,]+(,[^,]+){4}$/gm)) {
|
||||
if (!value.match(/^[^,]+(,[^,]+){4}$/gm)) {
|
||||
return "CSV text malformed - should contain 5 consecutive comma-separated values per line!";
|
||||
}
|
||||
return true;
|
||||
},
|
||||
},
|
||||
])
|
||||
.then(answer => answer.csv);
|
||||
});
|
||||
}
|
||||
|
||||
@ -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");
|
||||
|
||||
|
||||
@ -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",
|
||||
return await confirm({
|
||||
message: `File ${chalk.blue(outFile)} already exists!\nDo you want to replace it?`,
|
||||
default: false,
|
||||
},
|
||||
])
|
||||
).continue;
|
||||
});
|
||||
}
|
||||
|
||||
await main();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user