-
Notifications
You must be signed in to change notification settings - Fork 3
/
builder_launcher.ts
116 lines (95 loc) · 3.42 KB
/
builder_launcher.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
"use strict";
import * as program from "commander";
import * as log4js from "log4js";
import * as os from "os";
import { Builder } from "./builder";
import { AndroidBuilder } from "./builder_android";
import { BuilderError } from "./builder_error";
import { IOSBuilder } from "./builder_ios";
import { OSXBuilder } from "./builder_osx";
import { UbuntuBuilder } from "./builder_ubuntu";
import { WindowsBuilder } from "./builder_windows";
import { ICompilation } from "./compilation";
import * as globals from "./globals";
program
.version(globals.getVersion())
.option("-e, --env <env>", "Environment", /^(develop|testing|production)$/i, "develop")
.option("-j, --json <json>", "Compilation data json")
.option("-l, --logLevel <level>", "Log level", /^(all|trace|debug|info|warn|error|fatal|mark|off)$/i, "info")
.option("-p, --path <path>", "Config path (where config.json is)")
.parse(process.argv);
if (!program.env) {
if (process.send) {
process.send({ error: new Error("Parameter env not available"), data: null });
} else {
console.error("Parameter env not available");
}
process.exit(-1);
}
if (!program.json) {
if (process.send) {
process.send({ error: new Error("Parameter json not available"), data: null });
} else {
console.error("Parameter json not available");
}
process.exit(-1);
}
const env: globals.CocoonEnvironment = globals.stringToEnv(program.env);
const data: ICompilation = JSON.parse(program.json);
const configPath: string = program.path;
const logLevel: string = program.logLevel;
log4js.configure({
appenders: {
out: {
layout: {
pattern: "%[%d{yyyyMMddThhmmss} [%p] %c -%] %m",
type: "pattern",
},
type: "stdout",
},
},
categories: {default: {appenders: ["out"], level: logLevel}},
});
const logger: log4js.Logger = log4js.getLogger("Launcher");
logger.debug("Host: ", os.hostname());
logger.debug("Env: ", globals.envToString(env));
logger.debug("Config path:", configPath);
logger.debug("LogLevel: ", logLevel);
logger.debug("Json:", data);
let builder: Builder;
if (data.platform.name === "android") {
builder = new AndroidBuilder(env, data, configPath, logLevel);
} else if (data.platform.name === "ios") {
builder = new IOSBuilder(env, data, configPath, logLevel);
} else if (data.platform.name === "osx") {
builder = new OSXBuilder(env, data, configPath, logLevel);
} else if (data.platform.name === "windows") {
builder = new WindowsBuilder(env, data, configPath, logLevel);
} else if (data.platform.name === "ubuntu") {
builder = new UbuntuBuilder(env, data, configPath, logLevel);
}
if (!builder) {
if (process.send) { // If it's invoked by another process
process.send({ error: new Error("Builder not available"), data: null });
process.exit(0);
} else { // If it's invoked from the console
logger.error("Builder not available");
process.exit(-1);
}
}
builder.start((err: BuilderError) => {
if (err) {
if (process.send) { // If it's invoked by another process
process.send(err);
process.exit(0);
} else { // If it's invoked from the console
logger.error(JSON.stringify(err));
process.exit(-1);
}
} else {
if (process.send) {
process.send(null);
}
process.exit(0);
}
});