-
-
Notifications
You must be signed in to change notification settings - Fork 802
/
Copy pathindex.ts
43 lines (36 loc) · 1.43 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
require("v8-compile-cache")
const cacheFile = require("path").join(__dirname, ".blitzjs-cli-cache")
const lazyLoad = require("@salesforce/lazy-require").default.create(cacheFile)
lazyLoad.start()
import {loadEnvConfig} from "@blitzjs/env"
import {run as oclifRun} from "@oclif/command"
import {compileConfig} from "next/dist/server/config-shared"
import {getProjectRoot} from "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 as any).NODE_ENV = process.env.NODE_ENV || defaultEnv
// Load the .env environment variable so it's available for all commands
loadEnvConfig()
async function buildConfigIfNeeded() {
if (["help", "-h", "autocomplete", "new", "s", "start"].includes(process.argv[2])) {
return Promise.resolve()
}
return compileConfig(await getProjectRoot(process.cwd()))
}
function runOclif() {
return (
oclifRun()
.then(require("@oclif/command/flush"))
// @ts-ignore (TS complains about using `catch`)
.catch(require("@oclif/errors/handle"))
)
}
export function run() {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
buildConfigIfNeeded().then(runOclif)
}