pokerogue/scripts/create-test/interactive.js
Bertie690 3478e09923
[Dev] Break up test:create script; add help message, file name CLI argument support (#6793)
* [Dev] Broke up `test:create` script, added CLI args file name suppoert

* Moved `HELP_FLAGS` constant; fixed help msg indentation

* ran biome

* Fix floting promise err

* Added REUSE info

* Typo fix

* comment out reward boilerplate

* Removed redundant comments

---------

Co-authored-by: fabske0 <192151969+fabske0@users.noreply.github.com>
2025-11-28 21:26:49 +00:00

67 lines
1.7 KiB
JavaScript

/*
* SPDX-FileCopyrightText: 2024-2025 Pagefault Games
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import chalk from "chalk";
import inquirer from "inquirer";
import { validTestTypes } from "./constants.js";
/**
* @import {testType} from "./constants.js"
*/
/**
* Prompt the user to select a test type via list.
* @returns {Promise<testType | undefined>} The selected type, or `undefined` if "Exit" was pressed.
*/
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;
if (choice === "EXIT") {
console.log("Exiting...");
process.exitCode = 0;
return;
}
return choice;
}
/**
* Prompt the user to provide a file name.
* @param {testType} selectedType - The chosen string (used for logging & validation)
* @returns {Promise<string>} The selected file name
*/
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;
// Trim whitespace and any extension suffixes
return fileNameAnswer.trim().replace(".test.ts", "");
}