inngest-setup-redwoodjs
Version:
Setup Inngest in RedwoodJS
62 lines (61 loc) • 2.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.scriptName = void 0;
const tslib_1 = require("tslib");
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 cli_helpers_1 = require("@redwoodjs/cli-helpers");
const command_js_1 = require("./function/command.js");
const command_js_2 = require("./plugin/command.js");
exports.scriptName = 'inngest-setup-redwoodjs';
let { cwd, help } = (0, yargs_parser_1.default)((0, helpers_1.hideBin)(process.argv));
// eslint-disable-next-line dot-notation
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);
}
if (!(0, cli_helpers_1.isTypeScriptProject)()) {
throw new Error(`Inngest works best with TypeScript. Please run \`yarn rw setup typescript\` to convert your project to TypeScript first.`);
}
}
}
catch (error) {
if (error instanceof Error) {
// eslint-disable-next-line no-console
console.error(error.message);
}
process.exit(1);
}
// eslint-disable-next-line dot-notation
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)',
})
.command('plugin', command_js_2.description, command_js_2.builder, command_js_2.handler)
.command('function <name>', command_js_1.description, command_js_1.builder, command_js_1.handler)
.parse();