1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var fs = require("fs");
|
4 | var path = require("path");
|
5 | var chalk_1 = require("chalk");
|
6 | var build_1 = require("./commands/build");
|
7 | var env_1 = require("./commands/env");
|
8 | var install_1 = require("./commands/install");
|
9 | var run_1 = require("./commands/run");
|
10 | var const_1 = require("./const");
|
11 | var help_1 = require("./commands/help");
|
12 | var instdir = path.resolve(path.dirname(process.argv[1]) + "/..");
|
13 | var instmod = instdir + (fs.existsSync(instdir + "/node_modules/webpack") ? "/node_modules" : "/..");
|
14 | var command = process.argv[2];
|
15 | if (command === "help") {
|
16 | help_1.help(instdir, const_1.EXIT_STATUS.OK);
|
17 | }
|
18 | else if (command === "version") {
|
19 | console.log(help_1.version(instdir));
|
20 | }
|
21 | else if (command === "env") {
|
22 | console.log(env_1.default());
|
23 | }
|
24 | else if (command === "install") {
|
25 | install_1.default(instdir);
|
26 | }
|
27 | else if (command === "build" && process.argv[3]) {
|
28 | var options = {
|
29 | input: [],
|
30 | output: [],
|
31 | watch: false,
|
32 | uglify: false,
|
33 | };
|
34 | var outDir = "";
|
35 | var _c = false;
|
36 | var _o = false;
|
37 | for (var i = 3; i < process.argv.length; i++) {
|
38 | var arg = process.argv[i];
|
39 | if (arg === "-w") {
|
40 | options.watch = true;
|
41 | }
|
42 | else if (arg === "-u") {
|
43 | options.uglify = true;
|
44 | }
|
45 | else if (arg === "--skipJDK") {
|
46 | options.skipJDK = true;
|
47 | }
|
48 | else if (arg === "-c") {
|
49 | _c = true;
|
50 | if (_c && _o) {
|
51 | console.error(chalk_1.default.red("Cannot use -c and -o together"));
|
52 | process.exit(const_1.EXIT_STATUS.CLI_INVALID_OPTION);
|
53 | }
|
54 | else if (process.argv[i + 1] === undefined) {
|
55 | console.error(chalk_1.default.red("Undefined -c argument"));
|
56 | process.exit(const_1.EXIT_STATUS.CLI_INVALID_OPTION);
|
57 | }
|
58 | else {
|
59 | outDir = process.argv[i + 1];
|
60 | i += 1;
|
61 | }
|
62 | }
|
63 | else if (arg === "-o") {
|
64 | _o = true;
|
65 | if (_c && _o) {
|
66 | console.error(chalk_1.default.red("Cannot use -c and -o together"));
|
67 | process.exit(const_1.EXIT_STATUS.CLI_INVALID_OPTION);
|
68 | }
|
69 | else if (process.argv[i + 1] === undefined) {
|
70 | console.error(chalk_1.default.red("Undefined -o argument"));
|
71 | process.exit(const_1.EXIT_STATUS.CLI_INVALID_OPTION);
|
72 | }
|
73 | else {
|
74 | options.output.push(process.argv[i + 1]);
|
75 | i += 1;
|
76 | }
|
77 | }
|
78 | else {
|
79 | options.input.push(arg);
|
80 | if (!_o) {
|
81 | if (arg.endsWith(".ts")) {
|
82 | options.output.push(path.join(outDir, path.basename(arg, ".ts") + ".js"));
|
83 | }
|
84 | else if (arg.endsWith(".tsx")) {
|
85 | options.output.push(path.join(outDir, path.basename(arg, ".tsx") + ".js"));
|
86 | }
|
87 | else {
|
88 | console.error(chalk_1.default.red("Entry suffix should be .ts or .tsx"));
|
89 | process.exit(const_1.EXIT_STATUS.CLI_INVALID_ENTRY);
|
90 | }
|
91 | }
|
92 | }
|
93 | }
|
94 | build_1.default(instdir, instmod, options);
|
95 | }
|
96 | else if (command === "run" && process.argv[3]) {
|
97 | var watch = false;
|
98 | var jjsOptions = [];
|
99 | for (var i = 3; i < process.argv.length; i++) {
|
100 | var arg = process.argv[i];
|
101 | if (i === 3 && arg === "-w") {
|
102 | watch = true;
|
103 | }
|
104 | else if (arg.charAt(0) === "-") {
|
105 | jjsOptions.push(arg);
|
106 | }
|
107 | else {
|
108 | run_1.default(jjsOptions, arg, process.argv.slice(i + 1), watch);
|
109 | break;
|
110 | }
|
111 | }
|
112 | }
|
113 | else {
|
114 | help_1.help(instdir, const_1.EXIT_STATUS.CLI_BAD_COMMAND);
|
115 | }
|