UNPKG

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