#!/usr/bin/env node
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
require("reflect-metadata");
const commander_1 = __importDefault(require("commander"));
const ip_1 = __importDefault(require("ip"));
const open_1 = __importDefault(require("open"));
const selfUpdate_1 = __importDefault(require("./selfUpdate"));
const start_1 = __importDefault(require("./start"));
const syncHost_1 = __importDefault(require("./syncHost"));
const syncRule_1 = __importDefault(require("./syncRule"));
const packageInfo = require('../../package');
commander_1.default
    .version(packageInfo.version)
    .description('start ZanProxy server')
    .option('-p, --proxy_port [value]', 'set the proxy port')
    .option('-m, --manager_port [value]', 'set the manager server port')
    .option('--no-update', 'do not check if update available')
    .option('--no-sync', 'do not sync remote rules')
    .parse(process.argv);
function run() {
    return __awaiter(this, void 0, void 0, function* () {
        if (commander_1.default.update) {
            yield selfUpdate_1.default();
        }
        if (commander_1.default.sync) {
            yield syncRule_1.default();
            yield syncHost_1.default();
        }
        const managerPort = commander_1.default.manager_port || 40001;
        const url = `http://${ip_1.default.address()}:${managerPort}`;
        yield start_1.default(commander_1.default.proxy_port, commander_1.default.manager_port);
        open_1.default(url);
    });
}
run();
//# sourceMappingURL=index.js.map