-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlayaair-cmd-resourceVersion.js
75 lines (67 loc) · 1.52 KB
/
layaair-cmd-resourceVersion.js
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
const path = require("path");
const program = require("commander");
const spawn = require("child_process").spawn;
const os = require("os");
const
{
printOk,
printErr,
printQuotation,
tr
} = require("./print.js");
program
.version("0.1.1")
.option('-i --input <input>', tr("resource directory."))
.option('-o --output <output>', tr("output directory."))
.option('-n --versionName <version name>', tr("version name, default is numbers start from 1000."))
.parse(process.argv);
if (!program.input)
{
printErr("You must specify resource directory");
process.exit(1);
}
if (!program.output)
{
printErr("You must specify output directory");
process.exit(1);
}
//////////////////////////////////////////////////
// call external excutable web-resource-manager //
//////////////////////////////////////////////////
var args = [];
args.push(program.input);
args.push("-o");
args.push(program.output);
if (program.versionName)
args.push("-n", program.versionName);
let executable;
switch (os.platform())
{
case "win32":
executable = "web-resource-manager.exe";
break;
// case "linux":
// executable = "guetzli_linux_x86-64";
// break;
case "darwin":
executable = "web-resource-manager";
break;
default:
printErr("Platform does not support.");
exit(1);
}
var sp = spawn(
path.join(__dirname, "tools", "resource-manager", executable),
args);
sp.stdout.on("data", (data) =>
{
printQuotation(data.toString());
});
sp.stderr.on("data", (data) =>
{
printErr(data);
});
sp.on("close", (data) =>
{
printOk(tr("finish."));
});