mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-12-14 22:05:34 +01:00
* Add license information * Add reuse lint workflow * Add snippets for spdx * fix: minor wording adjustments and typo fixes Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> * chore: add FileContributor attributions for Bertie Co-authored-by: Bertie690 <136088738+Bertie690@users.noreply.github.com> * begin licensing some audio assets * Add pokemon reborn sound affect attribution * Annotate Leavannite's section * Add more licensing info * Add license info to license files ._. * Move ps1 files out of public * Add license for animation jsons * Add license for bat scripts in public * Update licensing in scripts * Fix typo in license ref * Fix AGPL-3.0-or-later * Add license info to typedoc.config.js * Add MIT license for snippets * chore: update license info for files in scripts * chore: update license info * chore: update license info * chore: update license info * Remove licenses used only by public before linting with reuse * Add license info to new files added by docker PR * chore: apply biome * fix: add back linting workflow lost during merge * Add attribution based on Hanniel's information * Add attribution based on Officer Porkchop and Green Ninja's information * add attribution to unicorn_power for reshiram/zekrom/kyurem epic variant * Fixup minor typo * Adjust sprite test to not think REUSE.toml is a sprite json * Add missing continue-on-error to workflow * fix: address kev's comments from code review * docs: minor touchups --------- Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> Co-authored-by: Bertie690 <136088738+Bertie690@users.noreply.github.com>
115 lines
2.9 KiB
JavaScript
115 lines
2.9 KiB
JavaScript
/*
|
|
* SPDX-FileCopyrightText: 2025 Pagefault Games
|
|
* SPDX-FileContributor: Bertie690
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
import fs from "fs";
|
|
import chalk from "chalk";
|
|
import inquirer from "inquirer";
|
|
import { showHelpText } from "./help-message.js";
|
|
|
|
/**
|
|
* @import { Option } from "./main.js"
|
|
*/
|
|
|
|
/**
|
|
* Prompt the user to interactively select an option (console/file) to retrieve the egg move CSV.
|
|
* @returns {Promise<Option>} The selected option with value
|
|
*/
|
|
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);
|
|
|
|
if (answer === "Exit") {
|
|
console.log("Exiting...");
|
|
process.exitCode = 1;
|
|
return { type: "Exit" };
|
|
}
|
|
|
|
if (answer === "Help") {
|
|
showHelpText();
|
|
return { type: "Exit" };
|
|
}
|
|
|
|
if (!["Console", "File"].includes(answer)) {
|
|
console.error(chalk.red("Please provide a valid type!"));
|
|
return await runInteractive();
|
|
}
|
|
|
|
return { type: answer, value: await promptForValue(answer) };
|
|
}
|
|
|
|
/**
|
|
* Prompt the user to give a value (either the direct CSV or the file path).
|
|
* @param {"Console" | "File"} type - The input method
|
|
* @returns {Promise<string>} A Promise resolving with the CSV/file path.
|
|
*/
|
|
function promptForValue(type) {
|
|
switch (type) {
|
|
case "Console":
|
|
return doPromptConsole();
|
|
case "File":
|
|
return getFilePath();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Prompt the user to enter a file path from the console.
|
|
* @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);
|
|
}
|
|
|
|
/**
|
|
* Prompt the user for CSV input from the console.
|
|
* @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);
|
|
}
|