@blitzjs/cli
Version:
Blitz.js CLI
41 lines (40 loc) • 1.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.run = void 0;
const tslib_1 = require("tslib");
require("v8-compile-cache");
const cacheFile = require("path").join(__dirname, ".blitzjs-cli-cache");
const lazyLoad = require("@salesforce/lazy-require").default.create(cacheFile);
lazyLoad.start();
const env_1 = require("@blitzjs/env");
const command_1 = require("@oclif/command");
const config_shared_1 = require("next/dist/server/config-shared");
const utils_1 = require("next/dist/server/lib/utils");
const options = require("minimist")(process.argv.slice(2));
if (options.e || options.env) {
process.env.APP_ENV = options.e || options.env;
}
// Have to copy this here from nextjs/packages/next/bin/next.ts before loadEnvConfig()
const defaultEnv = process.argv[2] === "build" || process.argv[2] === "start" ? "production" : "development";
process.env.NODE_ENV = process.env.NODE_ENV || defaultEnv;
// Load the .env environment variable so it's available for all commands
(0, env_1.loadEnvConfig)();
function buildConfigIfNeeded() {
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
if (["help", "-h", "autocomplete", "new", "s", "start"].includes(process.argv[2])) {
return Promise.resolve();
}
return (0, config_shared_1.compileConfig)(yield (0, utils_1.getProjectRoot)(process.cwd()));
});
}
function runOclif() {
return ((0, command_1.run)()
.then(require("@oclif/command/flush"))
// @ts-ignore (TS complains about using `catch`)
.catch(require("@oclif/errors/handle")));
}
function run() {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
buildConfigIfNeeded().then(runOclif);
}
exports.run = run;