UNPKG

2.03 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 modify_1 = require("./modify");
8function cliBasicParameter(target, value, opts) {
9 var logger = new akashic_cli_commons_1.ConsoleLogger({ quiet: opts.quiet });
10 modify_1.promiseModifyBasicParameter({ target: target, value: Number(value), cwd: opts.cwd, logger: logger })
11 .catch(function (err) {
12 logger.error(err);
13 process.exit(1);
14 });
15}
16function defineCommand(commandName) {
17 commander
18 .command(commandName + " <value>")
19 .description("Update '" + commandName + "' property of game.json")
20 .option("-C, --cwd <dir>", "The directory incluedes game.json")
21 .option("-q, --quiet", "Suppress output")
22 .action(function (value, opts) {
23 if (opts === void 0) { opts = {}; }
24 akashic_cli_commons_1.CliConfigurationFile.read(path.join(commander["cwd"] || process.cwd(), "akashic.config.js"), function (error, configuration) {
25 var _a, _b;
26 if (error) {
27 console.error(error);
28 process.exit(1);
29 }
30 var conf = configuration.commandOptions.modify || {};
31 cliBasicParameter(commandName, value, {
32 cwd: (_a = opts.cwd) !== null && _a !== void 0 ? _a : conf.cwd,
33 quiet: (_b = opts.quiet) !== null && _b !== void 0 ? _b : conf.quiet
34 });
35 });
36 });
37}
38["fps", "width", "height"].forEach(function (commandName) {
39 defineCommand(commandName);
40});
41commander
42 .version(JSON.parse(fs.readFileSync(path.resolve(__dirname, "..", "package.json"), "utf8")).version);
43commander
44 .command("*", "", { noHelp: true })
45 .action(function (value) {
46 console.error("Unknown target " + value);
47 process.exit(1);
48});
49function run(argv) {
50 commander.parse(argv);
51}
52exports.run = run;