UNPKG

1.69 kBJavaScriptView Raw
1#!/usr/bin/env node
2"use strict";
3Object.defineProperty(exports, "__esModule", { value: true });
4const parseArgs = require("minimist");
5const buildscript_1 = require("./buildscript");
6const path = require("path");
7const args = parseArgs(process.argv);
8const shell = require("shelljs");
9if (args.scaffold) {
10 const root = process.cwd();
11 const tools = buildscript_1.buildscript(root);
12 console.log("Scaffolding...");
13 tools.tasks.scaffold();
14}
15if (args.prebuild) {
16 prebuild();
17}
18if (args.prodRun || args.run) {
19 prodRun();
20}
21async function prebuild() {
22 try {
23 const root = process.cwd();
24 if (shell.exec("yarn run compileProd").code !== 0) {
25 shell.echo("compileProd failed");
26 shell.exit(1);
27 return;
28 }
29 const serverModule = require(path.resolve(root, ".nextpress"));
30 const serverClass = serverModule.default;
31 if (serverClass.__tag__ !== "SERVER") {
32 shell.echo("invalid server class");
33 shell.exit(1);
34 return;
35 }
36 let context = serverClass.getDefaultContext();
37 let server = new serverClass(context);
38 server.isProduction = true;
39 await server.buildForProduction();
40 process.exit(0);
41 }
42 catch (err) {
43 shell.echo(err.message);
44 shell.exit(1);
45 return;
46 }
47}
48async function prodRun() {
49 const root = process.cwd();
50 if (shell.exec("yarn run compileProd").code !== 0) {
51 shell.echo("compileProd failed");
52 shell.exit(1);
53 return;
54 }
55 const serverModule = require(path.resolve(root, ".nextpress"));
56 serverModule.run();
57}
58//# sourceMappingURL=cli.js.map
\No newline at end of file