UNPKG

3.44 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var fs = require("fs");
4var path = require("path");
5var commander = require("commander");
6var akashic_cli_commons_1 = require("@akashic/akashic-cli-commons");
7var exportZip_1 = require("./exportZip");
8var ver = JSON.parse(fs.readFileSync(path.resolve(__dirname, "..", "package.json"), "utf8")).version;
9function cli(param) {
10 var logger = new akashic_cli_commons_1.ConsoleLogger({ quiet: param.quiet });
11 Promise.resolve()
12 .then(function () { return exportZip_1.promiseExportZip({
13 bundle: param.bundle,
14 babel: (param.babel != null) ? param.babel : true,
15 minify: param.minify,
16 strip: (param.strip != null) ? param.strip : true,
17 source: param.cwd,
18 dest: param.output,
19 force: param.force,
20 hashLength: !param.hashFilename ? 0 : (param.hashFilename === true) ? 20 : Number(param.hashFilename),
21 omitEmptyJs: param.omitEmptyJs,
22 logger: logger,
23 exportInfo: {
24 version: ver,
25 option: {
26 quiet: param.quiet,
27 force: param.force,
28 strip: param.strip,
29 minify: param.minify,
30 bundle: param.bundle,
31 babel: param.babel,
32 hashFilename: param.hashFilename,
33 omitEmptyJs: param.omitEmptyJs
34 }
35 }
36 }); })
37 .then(function () { return logger.info("Done!"); })
38 .catch(function (err) {
39 logger.error(err);
40 process.exit(1);
41 });
42}
43exports.cli = cli;
44commander
45 .version(ver);
46commander
47 .description("Export an Akashic game to a zip file")
48 .option("-C, --cwd <dir>", "A directory containing a game.json (default: .)")
49 .option("-q, --quiet", "Suppress output")
50 .option("-o, --output <fileName>", "Name of output file (default: game.zip)")
51 .option("-f, --force", "Overwrites existing files")
52 .option("-S, --no-strip", "output fileset without strip")
53 .option("-M, --minify", "Minify JavaScript files")
54 .option("-H, --hash-filename [length]", "Rename asset files with their hash values")
55 .option("-b, --bundle", "Bundle script assets into a single file")
56 .option("--no-es5-downpile", "No convert JavaScript into es5")
57 .option("--no-omit-empty-js", "Disable omitting empty js from global assets");
58function run(argv) {
59 // Commander の制約により --strip と --no-strip 引数を両立できないため、暫定対応として Commander 前に argv を処理する
60 var argvCopy = dropDeprecatedArgs(argv);
61 commander.parse(argvCopy);
62 cli({
63 cwd: commander["cwd"],
64 quiet: commander["quiet"],
65 output: commander["output"],
66 force: commander["force"],
67 strip: commander["strip"],
68 minify: commander["minify"],
69 hashFilename: commander["hashFilename"],
70 bundle: commander["bundle"],
71 babel: commander["es5Downpile"],
72 omitEmptyJs: commander["omitEmptyJs"]
73 });
74}
75exports.run = run;
76function dropDeprecatedArgs(argv) {
77 var filteredArgv = argv.filter(function (v) { return !/^(-s|--strip)$/.test(v); });
78 if (argv.length !== filteredArgv.length) {
79 console.log("WARN: --strip option is deprecated. strip is applied by default.");
80 console.log("WARN: If you do not need to apply it, use --no-strip option.");
81 }
82 return filteredArgv;
83}