1 | #!/usr/bin/env node
|
2 | "use strict";
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | const parseArgs = require("minimist");
|
5 | const buildscript_1 = require("./buildscript");
|
6 | const path = require("path");
|
7 | const args = parseArgs(process.argv);
|
8 | const shell = require("shelljs");
|
9 | if (args.scaffold) {
|
10 | const root = process.cwd();
|
11 | const tools = buildscript_1.buildscript(root);
|
12 | console.log("Scaffolding...");
|
13 | tools.tasks.scaffold();
|
14 | }
|
15 | if (args.prebuild) {
|
16 | prebuild();
|
17 | }
|
18 | if (args.prodRun || args.run) {
|
19 | prodRun();
|
20 | }
|
21 | async 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 | }
|
48 | async 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 |
|
\ | No newline at end of file |