UNPKG

alwaysai

Version:

The alwaysAI command-line interface (CLI)

108 lines 4.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.appStartComponent = void 0; const alwayscli_1 = require("@alwaysai/alwayscli"); const fs_1 = require("fs"); const constants_1 = require("../../constants"); const user_1 = require("../user"); const util_1 = require("../../util"); const app_check_component_1 = require("./app-check-component"); const app_1 = require("../../core/app"); const environment_1 = require("../../environment"); const paths_1 = require("../../paths"); const BASH_INITIAL_ARGS = ['-o', 'onecmd', '-O', 'huponexit', '-c']; async function appStartComponent(props = {}) { var _a; const { noSuperuser, volumes, env_vars, args = [] } = props; await (0, user_1.checkUserIsLoggedInComponent)({ yes: true }); await (0, app_check_component_1.appCheckComponent)(); const appJson = (0, app_1.AppJsonFile)().read(); const startScript = (_a = appJson.scripts) === null || _a === void 0 ? void 0 : _a.start; if (!startScript) { throw new alwayscli_1.CliTerseError(`This application does not define a "start" script in its application configuration file "${paths_1.APP_JSON_FILE_NAME}"`); } const targetJsonFile = (0, app_1.TargetJsonFile)(); const targetJson = targetJsonFile.read(); let exitCode; const quotedArgsString = args.map((arg) => `'${arg}'`).join(' '); const tty = process.stdin.isTTY; switch (targetJson.targetProtocol) { case 'docker:': { const spawner = targetJsonFile.readContainerSpawner({ volumes, env_vars }); exitCode = await spawner.runForeground({ exe: '/bin/bash', args: [ ...BASH_INITIAL_ARGS, `. ${paths_1.VENV_BIN_ACTIVATE} && ${startScript} ${quotedArgsString}` ], cwd: '.', tty, expose5000: true, superuser: !noSuperuser }); break; } // This case differs from "docker:"" only in the extra single quotes around the command case 'ssh+docker:': { const spawner = targetJsonFile.readContainerSpawner({ volumes, env_vars }); exitCode = await spawner.runForeground({ exe: '/bin/bash', args: [ ...BASH_INITIAL_ARGS, `'. ${paths_1.VENV_BIN_ACTIVATE} && ${startScript} ${quotedArgsString}'` ], cwd: '.', tty, expose5000: true, superuser: !noSuperuser }); break; } case 'native:': { switch (environment_1.ALWAYSAI_OS_PLATFORM) { case 'win32': { if (!(0, fs_1.existsSync)(paths_1.VENV_SCRIPTS_ACTIVATE)) { throw new alwayscli_1.CliTerseError(`File not found "${paths_1.VENV_SCRIPTS_ACTIVATE}". Did you run "${constants_1.ALWAYSAI_CLI_EXECUTABLE_NAME} app install"?`); } exitCode = await (0, util_1.JsSpawner)().runForeground({ exe: 'cmd.exe', args: [ '/c', `${paths_1.VENV_SCRIPTS_ACTIVATE} && ${startScript} ${args.join(' ')}` ] }); break; } case 'darwin': { if (!(0, fs_1.existsSync)(paths_1.VENV_BIN_ACTIVATE)) { throw new alwayscli_1.CliTerseError(`File not found "${paths_1.VENV_BIN_ACTIVATE}". Did you run "${constants_1.ALWAYSAI_CLI_EXECUTABLE_NAME} app install"?`); } exitCode = await (0, util_1.JsSpawner)().runForeground({ exe: '/bin/sh', args: [ `-c`, `. ${paths_1.VENV_BIN_ACTIVATE} && ${startScript} ${quotedArgsString}` ] }); break; } default: { throw new alwayscli_1.CliTerseError(`OS ${environment_1.ALWAYSAI_OS_PLATFORM} not supported for native start`); } } break; } default: { throw new Error('Unsupported protocol'); } } return exitCode || 0; } exports.appStartComponent = appStartComponent; //# sourceMappingURL=app-start-component.js.map