@onereach/orest-input-cli
Version:
The tool for creating, serving, and publishing OREST Inputs
54 lines (44 loc) • 1.2 kB
JavaScript
const axios = require('axios');
const inquirer = require('inquirer');
const questions = [
{
type: 'input',
name: 'stepBuilderUiUrl',
message: 'Step Builder URL',
default: 'https://stepbuilder.onereach.ai',
filter: function (userInput) {
let value = userInput;
if (!/https?:\/\//.test(value)) {
value = 'https://' + value;
}
value.replaceAll(/([^:]\/)\/+/g, '$1');
if (value.at(-1) === '/') {
value = value.slice(0, -1);
}
return value;
},
validate: function (value) {
try {
const { origin } = new URL(value);
const regex = /^(https?:\/\/)((?:[\w\d\-_]+)\.)+\w{2,6}$/i;
return regex.test(origin) || 'Wrong URL format';
} catch (err) {
return 'Invalid URL input';
}
},
},
{
type: 'input',
name: 'username',
message: 'Username',
validate: function (value) {
return Boolean(value);
},
},
];
async function getVars() {
const answers = await inquirer.prompt(questions);
const response = await axios.get(`${answers.stepBuilderUiUrl}/cli.json`);
return { ...response.data, ...answers };
}
module.exports = getVars;