@defer/redwood
Version:
Setup Defer in RedwoodJS
56 lines (55 loc) • 2.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.scriptName = void 0;
const tslib_1 = require("tslib");
/* eslint-disable prefer-const */
const fs_1 = tslib_1.__importDefault(require("fs"));
const path_1 = tslib_1.__importDefault(require("path"));
const findup_sync_1 = tslib_1.__importDefault(require("findup-sync"));
const yargs_1 = tslib_1.__importDefault(require("yargs"));
const yargs_parser_1 = tslib_1.__importDefault(require("yargs-parser"));
const helpers_1 = require("yargs/helpers");
const command_js_1 = require("./plugin/command.js");
exports.scriptName = "defer-setup-redwoodjs";
let { cwd, help } = (0, yargs_parser_1.default)((0, helpers_1.hideBin)(process.argv));
cwd ?? (cwd = process.env["RWJS_CWD"]);
try {
if (cwd) {
// `cwd` was set by the `--cwd` option or the `RWJS_CWD` env var. In this case,
// we don't want to find up for a `redwood.toml` file. The `redwood.toml` should just be in that directory.
if (!fs_1.default.existsSync(path_1.default.join(cwd, "redwood.toml")) && !help) {
throw new Error(`Couldn't find a "redwood.toml" file in ${cwd}`);
}
}
else {
// `cwd` wasn't set. Odds are they're in a Redwood project,
// but they could be in ./api or ./web, so we have to find up to be sure.
const redwoodTOMLPath = (0, findup_sync_1.default)("redwood.toml", { cwd: process.cwd() });
if (!redwoodTOMLPath && !help) {
throw new Error(`Couldn't find up a "redwood.toml" file from ${process.cwd()}`);
}
if (redwoodTOMLPath) {
cwd = path_1.default.dirname(redwoodTOMLPath);
}
}
}
catch (error) {
if (error instanceof Error) {
console.error(error.message);
}
process.exit(1);
}
process.env["RWJS_CWD"] = cwd;
// export const command = 'plugin <command>';
yargs_1.default
.demandCommand()
.scriptName(exports.scriptName)
.option("cwd", {
type: "string",
demandOption: false,
description: "Working directory to use (where `redwood.toml` is located)",
})
// default command
.command("$0", command_js_1.description, command_js_1.builder, command_js_1.handler)
.parse();