UNPKG

@tobiastengler/create-relay-app

Version:

Easy configuration of Relay for existing projects

42 lines (41 loc) 1.56 kB
import { NEXT_APP_ROOT, APP_ROOT } from "../consts.js"; import { bold } from "../utils/index.js"; import { ArgumentBase } from "./ArgumentBase.js"; export class SrcArgument extends ArgumentBase { constructor(fs, env) { super(); this.fs = fs; this.env = env; this.name = "src"; this.promptMessage = "Where's the root directory of your application code"; } registerCliOption(command) { const flags = this.getCliFlags("-s", "<path>"); command.option(flags, "root directory of your application code", (value) => { var _a; return (_a = this.env.rel(value)) === null || _a === void 0 ? void 0 : _a.rel; }); } promptForValue(existingArgs) { return this.showInquirerPrompt({ type: "input", validate: (input) => this.isValid(input, existingArgs), filter: (input) => { var _a; return ((_a = this.env.rel(input)) === null || _a === void 0 ? void 0 : _a.rel) || ""; }, }, existingArgs); } isValid(value, existingArgs) { if (!value) { return `Required`; } if (!this.fs.isDirectory(value)) { return `Must be a directory`; } if (!this.fs.isSubDirectory(this.env.cwd, value)) { return `Must be directory below ${bold(this.env.cwd)}`; } return true; } getDefaultValue(existingArgs) { if (existingArgs.toolchain === "next") { return Promise.resolve(NEXT_APP_ROOT); } return Promise.resolve(APP_ROOT); } }