alwaysai
Version:
The alwaysAI command-line interface (CLI)
43 lines • 1.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const prompt_1 = require("../util/prompt");
const required_with_yes_message_1 = require("../util/required-with-yes-message");
const alwayscli_1 = require("@alwaysai/alwayscli");
const path_1 = require("path");
const create_target_directory_component_1 = require("./create-target-directory-component");
async function targetPathInputComponent(props) {
if (props.yes) {
if (!props.targetPath) {
throw new alwayscli_1.UsageError(required_with_yes_message_1.RequiredWithYesMessage('path'));
}
const writable = await create_target_directory_component_1.createTargetDirectoryComponent({
targetHostname: props.targetHostname,
targetPath: props.targetPath,
});
if (!writable) {
throw new alwayscli_1.TerseError(`Target path "${props.targetPath}" is not writable`);
}
return props.targetPath;
}
let writable = false;
let targetPath = props.targetPath || '';
while (!writable) {
const answer = await prompt_1.prompt([
{
type: 'text',
name: 'targetPath',
message: 'Where do you want to run the app? Enter a filesystem path:',
initial: targetPath || path_1.posix.join('alwaysai', path_1.basename(process.cwd())),
validate: value => (!value ? 'Value is required' : true),
},
]);
targetPath = answer.targetPath;
writable = await create_target_directory_component_1.createTargetDirectoryComponent({
targetHostname: props.targetHostname,
targetPath,
});
}
return targetPath;
}
exports.targetPathInputComponent = targetPathInputComponent;
//# sourceMappingURL=target-path-input-component.js.map