#!/usr/bin/env node
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
/* eslint-disable import/first -- 本文件禁用，要在入口最前面注册别名，后面的 import 才能使用别名；另外要先加载 dotenv，才能创建 redis 连接 */
const path_1 = tslib_1.__importDefault(require("path"));
const module_alias_1 = tslib_1.__importDefault(require("module-alias"));
module_alias_1.default.addAliases({
    '@': __dirname,
    'package.json': '../package.json',
});
const yargs_1 = tslib_1.__importDefault(require("yargs"));
// import detect from 'detect-port';
const dotenv_1 = tslib_1.__importDefault(require("dotenv"));
dotenv_1.default.config({ path: path_1.default.join(__dirname, './.env') });
const enum_1 = require("@/@types/enum");
const { argv } = yargs_1.default
    .alias('v', 'version')
    .alias('h', 'help')
    .help()
    .version()
    .option('entry', {
    type: 'string',
    default: 'dist/dev/index.bundle',
    describe: 'Path of the jsbundle for debugging',
})
    .option('static', {
    type: 'string',
    describe: 'Path of the static files such as images',
})
    .option('host', {
    type: 'string',
    default: '0.0.0.0',
    describe: 'The host the debug server will listen to',
})
    .option('port', {
    type: 'number',
    default: 38989,
    describe: 'The port the debug server will listen to',
})
    .option('open', {
    type: 'boolean',
    default: true,
    describe: 'Auto open chrome debug page',
})
    .option('log', {
    type: 'string',
    default: enum_1.LogLevel.Info,
    describe: 'Log level',
    choices: Object.values(enum_1.LogLevel),
})
    .option('iWDPPort', {
    type: 'number',
    default: 9000,
    describe: 'Device list port of ios_webkit_debug_proxy',
})
    .option('iWDPStartPort', {
    type: 'number',
    default: 9200,
    describe: 'Start port of ios_webkit_debug_proxy for iOS device',
})
    .option('iWDPEndPort', {
    type: 'number',
    default: 9300,
    describe: 'End port of ios_webkit_debug_proxy for iOS device',
})
    .option('env', {
    type: 'string',
    default: "hippy" /* Hippy */,
    describe: 'Debug framework',
    choices: ["hippy" /* Hippy */, "voltron" /* Voltron */, "TDF" /* TDF */, "TDFCore" /* TDFCore */],
})
    .epilog(`Copyright (C) 2017-${new Date().getFullYear()} THL A29 Limited, a Tencent company.`);
const fullArgv = argv;
if (fullArgv.help)
    yargs_1.default.showHelp().exit(0, null);
if (fullArgv.version)
    yargs_1.default.version().exit(0, null);
global.debugAppArgv = fullArgv;
/**
 * import after global.debugAppArgv is set
 */
require("@/utils/aegis");
const log_1 = require("@/utils/log");
const app_debug_1 = require("@/app-debug");
const package_json_1 = require("package.json");
require("./process-handler");
const log = new log_1.Logger('entry');
log.info('version: %s', package_json_1.version);
(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
    // const { iWDPPort } = global.debugAppArgv;
    // const port = await detect(iWDPPort);
    // if (port !== iWDPPort) {
    //   global.debugAppArgv.iWDPPort = port;
    //   log.warn('iWDPPort was changed to %d, because %d is occupied!', port, iWDPPort);
    // }
    app_debug_1.startDebugServer();
}))();
