#!/usr/bin/env node
'use strict';

var fs2 = require('fs');
var url = require('url');
var path2 = require('path');
var child_process = require('child_process');
var dotenv = require('dotenv');
var commander = require('commander');

var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var fs2__default = /*#__PURE__*/_interopDefault(fs2);
var path2__default = /*#__PURE__*/_interopDefault(path2);
var dotenv__default = /*#__PURE__*/_interopDefault(dotenv);

var execSync = (cmd, options = {}) => {
  try {
    const result = child_process.execSync(cmd, options);
    return { status: true, error: null, stdout: result.toString(), stderr: "" };
  } catch (error) {
    return { status: false, error, stdout: "", stderr: "" };
  }
};
var exec = (cmd, options = {}) => {
  return new Promise((resolve) => {
    child_process.exec(cmd, options, (error, stdout, stderr) => {
      const status = !error;
      resolve({ status, error, stdout, stderr });
    });
  });
};
var pm2Dir = path2__default.default.join(process.cwd(), "./@karinjs/config/pm2.json");
var start = () => {
  if (!fs2__default.default.existsSync(pm2Dir)) {
    console.log(`[pm2] \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728 \u8BF7\u68C0\u67E5 ${pm2Dir} \u662F\u5426\u5B58\u5728`);
    console.log("[pm2] \u5982\u679C\u662F\u65B0\u9879\u76EE\uFF0C\u8BF7\u5148\u524D\u53F0\u542F\u52A8\u751F\u6210\u914D\u7F6E\u6587\u4EF6: pnpm app");
    process.exit(1);
  }
  console.log("[pm2] \u542F\u52A8\u4E2D...");
  const data = JSON.parse(fs2__default.default.readFileSync(pm2Dir, "utf-8"));
  const script = "./node_modules/node-karin/dist/cli/pm2.js";
  if (data.apps[0].script !== script) {
    data.apps[0].script = script;
    fs2__default.default.writeFileSync(pm2Dir, JSON.stringify(data, null, 2));
  }
  const { error } = execSync(`pm2 start ${pm2Dir}`, { cwd: process.cwd() });
  if (error) {
    console.log("[pm2] \u542F\u52A8\u5931\u8D25");
    console.log(error);
    process.exit(1);
  }
  console.log("[pm2] \u542F\u52A8\u6210\u529F");
  console.log("[pm2] \u91CD\u542F\u670D\u52A1: pnpm rs");
  console.log("[pm2] \u67E5\u770B\u65E5\u5FD7: pnpm log");
  console.log("[pm2] \u505C\u6B62\u670D\u52A1: pnpm stop");
  console.log("[pm2] \u67E5\u770B\u76D1\u63A7: pm2 monit");
  console.log("[pm2] \u67E5\u770B\u5217\u8868: pm2 list");
  process.exit(0);
};
var log = () => {
  if (!fs2__default.default.existsSync(pm2Dir)) {
    console.log(`[pm2] \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728 \u8BF7\u68C0\u67E5 ${pm2Dir} \u662F\u5426\u5B58\u5728`);
    console.log("[pm2] \u5982\u679C\u662F\u65B0\u9879\u76EE\uFF0C\u8BF7\u5148\u524D\u53F0\u542F\u52A8\u751F\u6210\u914D\u7F6E\u6587\u4EF6: pnpm app");
    process.exit(1);
  }
  const data = JSON.parse(fs2__default.default.readFileSync(pm2Dir, "utf-8"));
  try {
    const prefix = process.platform === "win32" ? "pm2.cmd" : "pm2";
    child_process.spawn(prefix, ["logs", data.apps[0].name, "--lines", data.lines || 1e3], { stdio: "inherit", shell: true });
  } catch (error) {
    console.error("[pm2] \u53D1\u751F\u672A\u77E5\u9519\u8BEF: \u8BF7\u68C0\u67E5pm2\u662F\u5426\u5B89\u88C5 \u3010npm install -g pm2\u3011");
    console.error(error);
    process.exit(1);
  }
};
var stop = () => {
  if (!fs2__default.default.existsSync(pm2Dir)) {
    console.log(`[pm2] \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728 \u8BF7\u68C0\u67E5 ${pm2Dir} \u662F\u5426\u5B58\u5728`);
    console.log("[pm2] \u5982\u679C\u662F\u65B0\u9879\u76EE\uFF0C\u8BF7\u5148\u524D\u53F0\u542F\u52A8\u751F\u6210\u914D\u7F6E\u6587\u4EF6: pnpm app");
    process.exit(1);
  }
  const data = JSON.parse(fs2__default.default.readFileSync(pm2Dir, "utf-8"));
  execSync(`pm2 stop ${data.apps[0].name}`, { cwd: process.cwd() });
  console.log("[pm2] \u505C\u6B62\u6210\u529F");
  process.exit(0);
};
var restart = () => {
  console.log("[pm2] \u91CD\u542F\u4E2D...");
  if (!fs2__default.default.existsSync(pm2Dir)) {
    console.log(`[pm2] \u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728 \u8BF7\u68C0\u67E5 ${pm2Dir} \u662F\u5426\u5B58\u5728`);
    console.log("[pm2] \u5982\u679C\u662F\u65B0\u9879\u76EE\uFF0C\u8BF7\u5148\u524D\u53F0\u542F\u52A8\u751F\u6210\u914D\u7F6E\u6587\u4EF6: pnpm app");
    process.exit(1);
  }
  execSync(`pm2 restart ${pm2Dir}`, { cwd: process.cwd() });
  console.log("[pm2] \u91CD\u542F\u6210\u529F");
  process.exit(0);
};
var pm2 = {
  start,
  log,
  stop,
  restart
};
var isDev = false;
var dir = process.env.INIT_CWD || process.cwd();
var pkgDir = url.fileURLToPath(new url.URL("../..", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
var isPluginDev = () => {
  const pkg = fs2__default.default.readFileSync(path2__default.default.join(dir, "package.json"), "utf-8");
  const data = JSON.parse(pkg);
  if (data == null ? void 0 : data.karin) return true;
  if (fs2__default.default.existsSync(path2__default.default.join(dir, "src"))) return true;
  if (fs2__default.default.existsSync(path2__default.default.join(dir, "tsconfig.json"))) return true;
  if (fs2__default.default.existsSync(path2__default.default.join(dir, ".prettierrc"))) return true;
  if (fs2__default.default.existsSync(path2__default.default.join(dir, "eslint.config.mjs"))) return true;
  return false;
};
var createDir = () => {
  const list = [
    path2__default.default.join(dir, "@karinjs", "logs"),
    path2__default.default.join(dir, "@karinjs", "config"),
    path2__default.default.join(dir, "@karinjs", "data"),
    path2__default.default.join(dir, "@karinjs", "resource"),
    path2__default.default.join(dir, "@karinjs", "temp", "console"),
    path2__default.default.join(dir, "@karinjs", "temp", "html")
  ];
  !isDev && list.push(path2__default.default.join(dir, "plugins", "karin-plugin-example"));
  list.forEach((item) => {
    if (!fs2__default.default.existsSync(item)) fs2__default.default.mkdirSync(item, { recursive: true });
  });
};
var createPnpmFile = (dir2) => {
  const pnpmfile = path2__default.default.join(dir2, ".pnpmfile.cjs");
  if (fs2__default.default.existsSync(pnpmfile)) return;
  const content = [
    "// \u6E05\u7A7A\u5BF9\u7B49\u4F9D\u8D56\u4E2D\u7684node-karin",
    "function readPackage (pkg, context) {",
    "  if (pkg?.['peerDependencies']?.['node-karin'] && pkg['peerDependencies']['node-karin'] !== 'file:./lib') {",
    "    delete pkg['peerDependencies']['node-karin']",
    "  }",
    "  return pkg",
    "}",
    "module.exports = {",
    "  hooks: {",
    "    readPackage",
    "  },",
    "}"
  ].join("\n");
  fs2__default.default.writeFileSync(pnpmfile, content);
};
var shouldSkipNpmrc = () => {
  const { stdout } = execSync("npm config get registry");
  if (stdout.includes("registry.npmjs.org")) return true;
  const { stdout: proxy } = execSync("npm config get proxy");
  return !!proxy;
};
var createOrUpdateNpmrc = (dir2) => {
  const list = [
    "node_sqlite3_binary_host_mirror=https://registry.npmmirror.com/-/binary/sqlite3",
    "better_sqlite3_binary_host_mirror=https://registry.npmmirror.com/-/binary/better-sqlite3",
    "sass_binary_site=https://registry.npmmirror.com/-/binary/node-sass",
    "sharp_binary_host=https://registry.npmmirror.com/-/binary/sharp",
    "sharp_libvips_binary_host=https://registry.npmmirror.com/-/binary/sharp-libvips",
    "canvas_binary_host_mirror=https://registry.npmmirror.com/-/binary/canvas",
    "# 19\u4EE5\u4E0B\u7248\u672C",
    "puppeteer_download_host=https://registry.npmmirror.com/mirrors",
    "# 20\u4EE5\u4E0A\u7248\u672C",
    "PUPPETEER_DOWNLOAD_BASE_URL = https://registry.npmmirror.com/binaries/chrome-for-testing"
  ];
  const npmrc = path2__default.default.join(dir2, ".npmrc");
  if (!fs2__default.default.existsSync(npmrc)) {
    fs2__default.default.writeFileSync(npmrc, list.join("\n"));
    return;
  }
  const data = fs2__default.default.readFileSync(npmrc, "utf-8");
  const newEntries = list.filter((item) => {
    const key = item.split("=")[0];
    return !data.includes(key);
  });
  if (newEntries.length > 0) {
    fs2__default.default.appendFileSync(npmrc, "\n" + newEntries.join("\n"));
  }
};
var createOrUpdateEnv = (dir2) => {
  const generateRandomKey = () => {
    const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    return Array.from(
      { length: 6 },
      () => chars.charAt(Math.floor(Math.random() * chars.length))
    ).join("");
  };
  const envData = [
    "# \u662F\u5426\u542F\u7528HTTP",
    "HTTP_ENABLE=true",
    "# HTTP\u76D1\u542C\u7AEF\u53E3",
    "HTTP_PORT=7777",
    "# HTTP\u76D1\u542C\u5730\u5740",
    "HTTP_HOST=0.0.0.0",
    "# HTTP\u9274\u6743\u79D8\u94A5 \u4EC5\u7528\u4E8Ekarin\u81EA\u8EABApi",
    `HTTP_AUTH_KEY=${generateRandomKey()}`,
    "# ws_server\u9274\u6743\u79D8\u94A5",
    `WS_SERVER_AUTH_KEY=${generateRandomKey()}`,
    "\n",
    "# \u662F\u5426\u542F\u7528Redis \u5173\u95ED\u540E\u5C06\u4F7F\u7528\u5185\u90E8\u865A\u62DFRedis",
    "REDIS_ENABLE=true",
    "# \u91CD\u542F\u662F\u5426\u8C03\u7528pm2 \u5982\u679C\u4E0D\u8C03\u7528\u5219\u4F1A\u76F4\u63A5\u5173\u673A \u6B64\u914D\u7F6E\u9002\u5408\u6709\u8FDB\u7A0B\u5B88\u62A4\u7684\u7A0B\u5E8F",
    "PM2_RESTART=true",
    "\n",
    "# \u65E5\u5FD7\u7B49\u7EA7",
    "LOG_LEVEL=info",
    "# \u65E5\u5FD7\u4FDD\u7559\u5929\u6570",
    "LOG_DAYS_TO_KEEP=7",
    "# \u65E5\u5FD7\u6587\u4EF6\u6700\u5927\u5927\u5C0F \u5982\u679C\u6B64\u9879\u5927\u4E8E0\u5219\u542F\u7528\u65E5\u5FD7\u5206\u5272",
    "LOG_MAX_LOG_SIZE=0",
    "# logger.fnc\u989C\u8272",
    'LOG_FNC_COLOR="#E1D919"',
    "# \u65E5\u5FD7\u5B9E\u65F6Api\u6700\u591A\u652F\u6301\u540C\u65F6\u8FDE\u63A5\u6570",
    "LOG_API_MAX_CONNECTIONS=5",
    "\n",
    "# ffmpeg",
    "FFMPEG_PATH=",
    "# ffprobe",
    "FFPROBE_PATH=",
    "# ffplay",
    "FFPLAY_PATH=",
    "\n",
    "# \u8FD9\u91CC\u8BF7\u52FF\u4FEE\u6539",
    "RUNTIME=node"
  ];
  const env = path2__default.default.join(dir2, ".env");
  if (!fs2__default.default.existsSync(env)) {
    fs2__default.default.writeFileSync(env, envData.join("\n"));
    return;
  }
  const value = fs2__default.default.readFileSync(env, "utf-8");
  const newEntries = envData.filter((item) => {
    if (item.includes("#")) return false;
    const key = item.split("=")[0];
    return !value.includes(key);
  });
  if (newEntries.length > 0) {
    fs2__default.default.appendFileSync(env, "\n" + newEntries.join("\n"));
  }
};
var createWorkspace = (dir2) => {
  const workspace = path2__default.default.join(dir2, "pnpm-workspace.yaml");
  if (fs2__default.default.existsSync(workspace)) return;
  const content = "packages:\n  - 'plugins/**'\n";
  fs2__default.default.writeFileSync(workspace, content);
};
var createOtherFile = async () => {
  !isDev && createPnpmFile(dir);
  !isDev && createWorkspace(dir);
  if (!shouldSkipNpmrc()) {
    createOrUpdateNpmrc(dir);
  }
  createOrUpdateEnv(dir);
};
var createConfig = () => {
  const defCfg = path2__default.default.join(pkgDir, "default", "config");
  const files = fs2__default.default.readdirSync(defCfg);
  files.forEach((file) => {
    if (!file.endsWith(".json")) return;
    const filePath = path2__default.default.join(defCfg, file);
    const targetPath = path2__default.default.join(dir, "@karinjs", "config");
    const targetFile = path2__default.default.join(targetPath, file);
    if (!fs2__default.default.existsSync(targetFile)) {
      fs2__default.default.copyFileSync(filePath, targetFile);
      return;
    }
    const defData = fs2__default.default.readFileSync(filePath, "utf-8");
    const targetData = fs2__default.default.readFileSync(targetFile, "utf-8");
    const mergedData = { ...JSON.parse(defData), ...JSON.parse(targetData) };
    fs2__default.default.writeFileSync(targetFile, JSON.stringify(mergedData, null, 2));
  });
};
var modifyPackageJson = async () => {
  const pkg = fs2__default.default.readFileSync(path2__default.default.join(dir, "package.json"), "utf-8");
  const data = JSON.parse(pkg);
  data.type = "module";
  if (!data.scripts) data.scripts = {};
  data.scripts.karin = "karin";
  const { stdout: pnpmVersion } = execSync("pnpm -v");
  const majorVersion = parseInt(pnpmVersion.split(".")[0]);
  if (majorVersion < 10 && data.pnpm) {
    delete data.pnpm;
  } else if (majorVersion >= 10) {
    if (typeof data.pnpm !== "object") data.pnpm = {};
    data.pnpm.onlyBuiltDependenciesFile = [
      "sqlite3",
      "classic-level"
    ];
  }
  const list = ["app", "start", "pm2", "stop", "rs", "log"];
  if (!isDev) {
    list.forEach((v) => {
      data.scripts[v] = `karin ${v}`;
    });
  }
  fs2__default.default.writeFileSync(path2__default.default.join(dir, "package.json"), JSON.stringify(data, null, 2));
  return data;
};
var init = async () => {
  isDev = isPluginDev();
  createDir();
  await createOtherFile();
  createConfig();
  await modifyPackageJson();
  process.exit(0);
};
var parseEnvFiles = (env) => {
  if (!env) return [".env"];
  return env.split(",").map((file) => file.trim());
};
var loadEnv = (env) => {
  const dir2 = process.cwd();
  const files = parseEnvFiles(env);
  if (!files.includes(".env")) {
    files.unshift(".env");
  }
  files.forEach((file) => {
    if (!fs2__default.default.existsSync(`${dir2}/${file}`)) {
      if (file === ".env") {
        console.error(`\u672A\u627E\u5230${file}\u6587\u4EF6\uFF0C\u8BF7\u4F7F\u7528 npx karin init \u8FDB\u884C\u521D\u59CB\u5316\u9879\u76EE`);
      } else {
        console.error(`\u672A\u627E\u5230${file}\u6587\u4EF6\uFF0C\u8BF7\u5C06\u5176\u653E\u7F6E\u5728\u9879\u76EE\u6839\u76EE\u5F55`);
      }
      process.exit(1);
    }
  });
  const paths = files.map((file) => `${dir2}/${file}`);
  dotenv__default.default.config({ path: paths, override: true });
};
var start2 = async (env) => {
  loadEnv(env);
  const index = "../root.js";
  const { karinMain } = await import(index);
  const child = child_process.fork(karinMain);
  child.on("message", (message) => {
    if (message === "restart") {
      child.kill();
      child.removeAllListeners();
      start2(env);
    }
  });
  child.on("exit", (code) => process.exit(code));
};
var checkGitInstalled = async () => {
  try {
    const { status } = await exec("git --version");
    return status;
  } catch {
    return false;
  }
};
var updateDependencies = async (packagePath) => {
  try {
    const packageJson = JSON.parse(fs2__default.default.readFileSync(packagePath, "utf-8"));
    const dependencies = packageJson.dependencies || {};
    const packagesToUpdate = [];
    const checkVersionTasks = Object.entries(dependencies).map(async ([pkg, version]) => {
      if (pkg.startsWith("@types/")) {
        return;
      }
      try {
        const { stdout: pkgInfoStr } = await exec(`pnpm view ${pkg} --json`);
        const pkgInfo = JSON.parse(pkgInfoStr.trim());
        if (!pkgInfo.karin && pkg !== "node-karin") return;
        const currentVersion = version.replace(/[\^~]/g, "");
        const { stdout: distTagsStr } = await exec(`pnpm view ${pkg} dist-tags --json`);
        const distTags = JSON.parse(distTagsStr.trim());
        const isPreRelease = /[-+]/.test(currentVersion);
        const latestVersion = distTags.latest;
        console.log(`[npm] ${pkg}:`);
        console.log(`  \u5F53\u524D\u7248\u672C: ${currentVersion}${isPreRelease ? " (\u9884\u53D1\u5E03\u7248\u672C)" : ""}`);
        console.log(`  \u6700\u65B0\u7248\u672C: ${latestVersion}`);
        if (isPreRelease || currentVersion !== latestVersion) {
          console.log(`[npm] \u53D1\u73B0\u65B0\u7248\u672C ${pkg}: ${currentVersion} -> ${latestVersion}`);
          packagesToUpdate.push(`${pkg}@latest`);
        } else {
          console.log(`[npm] ${pkg} \u5DF2\u7ECF\u662F\u6700\u65B0\u7248\u672C`);
        }
      } catch (error) {
        console.error(`[npm] \u68C0\u67E5 ${pkg} \u7248\u672C\u5931\u8D25:`, error);
      }
    });
    await Promise.all(checkVersionTasks);
    if (packagesToUpdate.length > 0) {
      console.log("[npm] \u5F00\u59CB\u66F4\u65B0\u4EE5\u4E0B\u5305:\n", packagesToUpdate.join("\n"));
      try {
        const { status, error } = await exec(`pnpm update ${packagesToUpdate.join(" ")}`);
        if (status) {
          console.log("[npm] \u6240\u6709\u63D2\u4EF6\u66F4\u65B0\u5B8C\u6210");
        } else {
          console.error("[npm] \u6279\u91CF\u66F4\u65B0\u5931\u8D25:", error);
        }
      } catch (error) {
        console.error("[npm] \u6279\u91CF\u66F4\u65B0\u5931\u8D25:", error);
      }
    } else {
      console.log("[npm] \u6240\u6709\u63D2\u4EF6\u90FD\u5DF2\u7ECF\u662F\u6700\u65B0\u7248\u672C");
    }
  } catch (error) {
    console.error("[npm] \u66F4\u65B0\u4F9D\u8D56\u5931\u8D25:", error);
  }
};
var updatePlugins = async (pluginsPath) => {
  if (!await checkGitInstalled()) {
    console.error("[git] \u8BF7\u5148\u5B89\u88C5git");
    return;
  }
  if (!fs2__default.default.existsSync(pluginsPath)) {
    console.error("[git] plugins\u76EE\u5F55\u4E0D\u5B58\u5728");
    return;
  }
  const isDirectory = (await fs2__default.default.promises.stat(pluginsPath)).isDirectory();
  if (!isDirectory) {
    console.error("[git] plugins\u8DEF\u5F84\u4E0D\u662F\u4E00\u4E2A\u76EE\u5F55");
    return;
  }
  const dirs = await fs2__default.default.promises.readdir(pluginsPath);
  const updateTasks = dirs.map(async (dir2) => {
    const pluginPath = path2.join(pluginsPath, dir2);
    const gitPath = path2.join(pluginPath, ".git");
    const packageJsonPath = path2.join(pluginPath, "package.json");
    if (!dir2.startsWith("karin-plugin-") || !(await fs2__default.default.promises.stat(pluginPath)).isDirectory()) {
      return;
    }
    if (!fs2__default.default.existsSync(gitPath)) {
      console.log(`[git] ${dir2} \u4E0D\u662Fgit\u4ED3\u5E93\uFF0C\u8DF3\u8FC7`);
      return;
    }
    try {
      const packageJson = JSON.parse(fs2__default.default.readFileSync(packageJsonPath, "utf-8"));
      if (!packageJson.karin) {
        console.log(`[git] ${dir2} \u7684package.json\u4E2D\u6CA1\u6709karin\u5B57\u6BB5\uFF0C\u8DF3\u8FC7`);
        return;
      }
      console.log(`[git] \u6B63\u5728\u66F4\u65B0 ${dir2}...`);
      const { status, error } = await exec("git pull", { cwd: pluginPath });
      if (!status) {
        console.error(`[git] \u66F4\u65B0 ${dir2} \u5931\u8D25:`, error);
      }
    } catch (error) {
      console.error(`[git] \u66F4\u65B0 ${dir2} \u5931\u8D25:`, error);
    }
  });
  await Promise.all(updateTasks);
};
var updateAll = async () => {
  try {
    console.log("[all] \u5F00\u59CB\u6267\u884C\u66F4\u65B0\u4EFB\u52A1\n");
    await Promise.all([updateDependencies("./package.json"), updatePlugins("./plugins")]);
    console.log("\n[all] \u66F4\u65B0\u4EFB\u52A1\u6267\u884C\u5B8C\u6210");
  } finally {
    process.exit(0);
  }
};
var _a;
if (!((_a = process.argv) == null ? void 0 : _a[2])) process.argv.push("-h");
var addEnvOption = (command) => {
  return command.option("-e, --env <files>", "\u6307\u5B9A\u73AF\u5883\u53D8\u91CF\u6587\u4EF6\uFF0C\u591A\u4E2A\u6587\u4EF6\u7528\u9017\u53F7\u5206\u9694");
};
var getVersion = () => {
  try {
    const file = url.fileURLToPath(new URL("../../package.json", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href))));
    const packageJson = JSON.parse(fs2__default.default.readFileSync(file, "utf-8"));
    return packageJson.version;
  } catch {
    return "unknown";
  }
};
commander.program.version(getVersion(), "-v, --version", "\u663E\u793A\u7248\u672C\u53F7");
commander.program.command("pm2").description("\u540E\u53F0\u8FD0\u884C").action(pm2.start);
commander.program.command("stop").description("\u505C\u6B62\u540E\u53F0\u8FD0\u884C").action(pm2.stop);
commander.program.command("rs").description("\u91CD\u542Fpm2\u670D\u52A1").action(pm2.restart);
commander.program.command("log").description("\u67E5\u770B\u65E5\u5FD7").action(pm2.log);
commander.program.command("up").description("\u66F4\u65B0\u63D2\u4EF6").action(updateAll);
commander.program.command("init").description("\u521D\u59CB\u5316\u9879\u76EE").action(init);
addEnvOption(commander.program.command(".").description("\u524D\u53F0\u542F\u52A8")).action(
  (options) => start2(options.env)
);
addEnvOption(commander.program.command("app").description("\u524D\u53F0\u542F\u52A8")).action(
  (options) => start2(options.env)
);
addEnvOption(commander.program.command("start").description("\u524D\u53F0\u542F\u52A8"));
commander.program.parse(process.argv);
