@tobiastengler/create-relay-app
Version:
Easy configuration of Relay for existing projects
49 lines (48 loc) • 1.51 kB
JavaScript
import { ToolchainOptions } from "../types.js";
import { ArgumentBase, getNormalizedCliString } from "./ArgumentBase.js";
export class ToolchainArgument extends ArgumentBase {
constructor(env) {
super();
this.env = env;
this.name = "toolchain";
this.promptMessage = "What's the toolchain of your project";
}
registerCliOption(command) {
const flags = this.getCliFlags("-t", "<toolchain>");
command.option(flags, "the toolchain used to bundle / serve the project", (value) => this.parseToolChain(value));
}
promptForValue(existingArgs) {
return this.showInquirerPrompt({
type: "list",
choices: ToolchainOptions,
}, existingArgs);
}
isValid(value, existingArgs) {
return true;
}
async getDefaultValue(existingArgs) {
if (await this.env.packageJson.containsDependency("next")) {
return "next";
}
if (await this.env.packageJson.containsDependency("vite")) {
return "vite";
}
return "cra";
}
parseToolChain(rawInput) {
if (!rawInput) {
return null;
}
const input = getNormalizedCliString(rawInput);
if (input === "next") {
return "next";
}
if (input === "vite") {
return "vite";
}
if (input === "cra") {
return "cra";
}
throw this.getInvalidArgError(input, ToolchainOptions);
}
}