-
Notifications
You must be signed in to change notification settings - Fork 6
/
cli.js
executable file
·63 lines (51 loc) · 1.82 KB
/
cli.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
#!/usr/bin/env node
"use strict";
const PixiPacker = require("./index");
const path = require("path");
const cliCursor = require("cli-cursor");
var yargs = require("yargs")
.usage(
"Usage: pixi-packer /path/to/resource-file.json /path/to/output"
)
.strict()
.boolean("clean-cache")
.boolean("clean-output")
.boolean("clean")
.boolean("quiet")
.boolean("debug")
.describe("cache", "path to cache folder. Will be created if necassary. Defaults to ~/.pixi-packer-tmp")
.describe("clean-cache", "empties cache folder before processing")
.describe("clean-output", "empties output folder before processing")
.describe("clean", "empties both cache and output folder before processing")
.describe("quiet", "Surpressses log output apart from errors")
.describe("debug", "Enable better stack traces at the cost of performance")
.alias("q", "quiet")
.demand(2);
var argv = yargs.argv;
var resourceFilePath = path.resolve(argv._[0]);
var outputPath = path.resolve(argv._[1]);
var config = require(resourceFilePath);
var inputPath = path.dirname(resourceFilePath);
var cachePath = argv.cache || path.join(process.env.HOME || process.env.USERPROFILE, ".pixi-packer-tmp");
var pixiPacker = new PixiPacker(config, inputPath, outputPath, cachePath);
if (argv.quiet) {
pixiPacker.log = {log: function() {}, error: console.error, info: function() {}, warn: function() {}};
}
if (argv.clean) {
config.cleanCache = true;
config.cleanOutput = true;
} else {
config.cleanCache = argv["clean-cache"];
config.cleanOutput = argv["clean-output"];
}
config.trim = true;
if (argv.debug) {
require("q").longStackSupport = true;
}
cliCursor.hide();
pixiPacker.process()
.catch(err => {
console.error("Error:", err.stack);
/* eslint no-process-exit:0 */
process.exit(1);
});