UNPKG

alwaysai

Version:

The alwaysAI command-line interface (CLI)

76 lines 3.11 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AppJsonFile = void 0; const path_1 = require("path"); const chalk = require("chalk"); const config_nodejs_1 = require("@alwaysai/config-nodejs"); const alwayscli_1 = require("@alwaysai/alwayscli"); const constants_1 = require("../../constants"); const app_configuration_schemas_1 = require("@alwaysai/app-configuration-schemas"); const paths_1 = require("../../paths"); const ENOENT = { message: `${paths_1.APP_JSON_FILE_NAME} not found. Did you run "${constants_1.ALWAYSAI_CLI_EXECUTABLE_NAME} app configure"?`, code: alwayscli_1.CLI_TERSE_ERROR }; function AppJsonFile(dir = process.cwd()) { const configFile = (0, config_nodejs_1.ConfigFileSchema)({ path: (0, path_1.join)(dir, paths_1.APP_JSON_FILE_NAME), validateFunction: app_configuration_schemas_1.validateAppConfig, ENOENT, initialValue: { models: {}, scripts: { start: `python ${paths_1.APP_PY_FILE_NAME}` } } }); return Object.assign(Object.assign({}, configFile), { name: paths_1.APP_JSON_FILE_NAME, addModel(id, version) { return configFile.update((config) => { config.models = config.models || {}; config.models[id] = version; }); }, removeModel(id) { return configFile.update((config) => { if (config.models) { delete config.models[id]; } }); }, describeModels() { const config = configFile.readIfExists(); const MODELS_COLON = 'Models:'; if (!config) { return `${MODELS_COLON} "${paths_1.APP_JSON_FILE_NAME}" not found`; } let description = `${MODELS_COLON} ${chalk.bold('None')}`; if (config.models) { const entries = Object.entries(config.models); if (entries.length > 0) { description = `${MODELS_COLON}\n${entries .map(([modelId, modelVersion]) => ` ${modelId}@${modelVersion}`) .join('\n')}`; } } return description; }, describeScripts() { const config = configFile.readIfExists(); const SCRIPTS_COLON = 'Scripts:'; if (!config) { return `${SCRIPTS_COLON} "${paths_1.APP_JSON_FILE_NAME}" not found`; } let description = `${SCRIPTS_COLON} ${chalk.bold('None')}`; if (config.scripts) { const entries = Object.entries(config.scripts); if (entries.length > 0) { description = `${SCRIPTS_COLON}\n${entries .map(([scriptName, scriptValue]) => ` ${scriptName} => "${scriptValue}"`) .join('\n')}`; } } return description; } }); } exports.AppJsonFile = AppJsonFile; //# sourceMappingURL=app-json-file.js.map