alwaysai
Version:
The alwaysAI command-line interface (CLI)
60 lines • 2.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.targetPathPromptComponent = void 0;
const alwayscli_1 = require("@alwaysai/alwayscli");
const general_1 = require("../../general");
const util_1 = require("../../../util");
const create_target_directory_component_1 = require("./create-target-directory-component");
const app_1 = require("../../../core/app");
async function targetPathPromptComponent(props) {
let writable = false;
let targetPath;
let skipPromptForTargetPath;
const targetPathDefaultValue = (0, app_1.TargetPathDefaultValue)();
if (props.targetPath) {
// Existing value or command-line input
targetPath = props.targetPath;
skipPromptForTargetPath = false;
}
else {
targetPath = targetPathDefaultValue;
skipPromptForTargetPath = await (0, general_1.confirmPromptComponent)({
message: `Would you like to use the default installation directory "${targetPathDefaultValue}"?`
});
}
while (!writable) {
if (!skipPromptForTargetPath) {
({ targetPath } = await (0, util_1.promptForInput)({
purpose: 'for a target path',
questions: [
{
type: 'text',
name: 'targetPath',
message: 'Where do you want to run the app? Enter a filesystem path:',
initial: targetPath || targetPathDefaultValue,
validate: (value) => (!value ? 'Value is required' : true)
}
]
}));
}
try {
await (0, create_target_directory_component_1.createTargetDirectoryComponent)({
targetHostname: props.targetHostname,
targetPath
});
writable = true;
}
catch (exception) {
if (exception.code === alwayscli_1.CLI_TERSE_ERROR) {
skipPromptForTargetPath = false;
(0, util_1.echo)(exception.message);
}
else {
throw exception;
}
}
}
return targetPath;
}
exports.targetPathPromptComponent = targetPathPromptComponent;
//# sourceMappingURL=target-path-prompt-component.js.map