import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
import { getChildProcess } from '../nodejs/child_process.mjs';
import { isWindows } from '../validate/validate.mjs';

/**
 * 启动 uni-app 项目
 * @param options 参数
 *
 * @example
 * ```ts
 * startUniProject();
 *
 * startUniProject({
 *   debug: false, // 默认为 true，会打印参数
 * })
 * ```
 */
function startUniProject(options) {
  var _a;
  var _getChildProcess = getChildProcess(),
    spawnSync = _getChildProcess.spawnSync;
  var command = isWindows() ? 'npm.cmd' : 'npm';
  var realArgv = process.argv.slice(2);
  var debug = (_a = options === null || options === void 0 ? void 0 : options.debug) !== null && _a !== void 0 ? _a : true;
  if (debug) {
    console.log('>>> startUniProject realArgv: ', realArgv);
  }
  var otherArgv = ['run'].concat(_toConsumableArray(realArgv));
  if (realArgv[0] === 'uni') {
    command = isWindows() ? 'npx.cmd' : 'npx';
    otherArgv = realArgv;
  }
  spawnSync(command, otherArgv, {
    stdio: 'inherit',
    shell: true
  });
}

export { startUniProject };
