mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-09-22 06:00:56 +02:00
chore: Rename color-console.js to helper.js and add askQuestion as exported fn
This commit is contained in:
parent
c5325cee3a
commit
6c5bea0096
2 changed files with 36 additions and 22 deletions
|
@ -1,8 +1,24 @@
|
||||||
/**
|
/**
|
||||||
* Console changes
|
* Helper functions
|
||||||
* This allows us to give the console some colour when running in a terminal
|
* This allows us to give the console some colour when running in a terminal
|
||||||
*/
|
*/
|
||||||
|
const readline = require("readline");
|
||||||
|
|
||||||
|
const askQuestion = (query) => {
|
||||||
|
const rl = readline.createInterface({
|
||||||
|
input: process.stdin,
|
||||||
|
output: process.stdout,
|
||||||
|
});
|
||||||
|
|
||||||
|
return new Promise((resolve) =>
|
||||||
|
rl.question("\x1b[36m" + query + "\n> " + "\x1b[0m", (ans) => {
|
||||||
|
rl.close();
|
||||||
|
resolve(ans);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set the console colours
|
||||||
console.orange = (msg) => console.log('\x1b[33m%s\x1b[0m', msg);
|
console.orange = (msg) => console.log('\x1b[33m%s\x1b[0m', msg);
|
||||||
console.green = (msg) => console.log('\x1b[32m%s\x1b[0m', msg);
|
console.green = (msg) => console.log('\x1b[32m%s\x1b[0m', msg);
|
||||||
console.red = (msg) => console.log('\x1b[31m%s\x1b[0m', msg);
|
console.red = (msg) => console.log('\x1b[31m%s\x1b[0m', msg);
|
||||||
|
@ -11,4 +27,8 @@ console.purple = (msg) => console.log('\x1b[35m%s\x1b[0m', msg);
|
||||||
console.cyan = (msg) => console.log('\x1b[36m%s\x1b[0m', msg);
|
console.cyan = (msg) => console.log('\x1b[36m%s\x1b[0m', msg);
|
||||||
console.yellow = (msg) => console.log('\x1b[33m%s\x1b[0m', msg);
|
console.yellow = (msg) => console.log('\x1b[33m%s\x1b[0m', msg);
|
||||||
console.white = (msg) => console.log('\x1b[37m%s\x1b[0m', msg);
|
console.white = (msg) => console.log('\x1b[37m%s\x1b[0m', msg);
|
||||||
console.gray = (msg) => console.log('\x1b[90m%s\x1b[0m', msg);
|
console.gray = (msg) => console.log('\x1b[90m%s\x1b[0m', msg);
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
askQuestion,
|
||||||
|
}
|
|
@ -2,9 +2,8 @@
|
||||||
* Install script: WIP
|
* Install script: WIP
|
||||||
*/
|
*/
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const readline = require('readline');
|
|
||||||
const { exit } = require('process');
|
const { exit } = require('process');
|
||||||
require('./color-console');
|
const { askQuestion } = require('./helpers');
|
||||||
|
|
||||||
// Save the original console.log function
|
// Save the original console.log function
|
||||||
const originalConsoleWarn = console.warn;
|
const originalConsoleWarn = console.warn;
|
||||||
|
@ -38,22 +37,6 @@ loader.addSecureEnvVar(rootEnvPath, 'MEILI_MASTER_KEY', 32);
|
||||||
// Init env
|
// Init env
|
||||||
let env = {};
|
let env = {};
|
||||||
|
|
||||||
// Function to ask for user input
|
|
||||||
const askQuestion = (query) => {
|
|
||||||
const rl = readline.createInterface({
|
|
||||||
input: process.stdin,
|
|
||||||
output: process.stdout,
|
|
||||||
});
|
|
||||||
|
|
||||||
return new Promise((resolve) =>
|
|
||||||
rl.question("\x1b[34m" + query + "\n> " + "\x1b[0m", (ans) => {
|
|
||||||
rl.close();
|
|
||||||
resolve(ans);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
// If the terminal accepts questions, lets ask for the env vars
|
// If the terminal accepts questions, lets ask for the env vars
|
||||||
if (!process.stdin.isTTY) {
|
if (!process.stdin.isTTY) {
|
||||||
|
@ -76,7 +59,7 @@ const askQuestion = (query) => {
|
||||||
|
|
||||||
// Lets colour the console
|
// Lets colour the console
|
||||||
console.purple('=== LibreChat First Install ===');
|
console.purple('=== LibreChat First Install ===');
|
||||||
console.cyan('Note: Leave blank to use the default value.');
|
console.blue('Note: Leave blank to use the default value.');
|
||||||
console.log(''); // New line
|
console.log(''); // New line
|
||||||
|
|
||||||
// Ask for the app title
|
// Ask for the app title
|
||||||
|
@ -111,6 +94,18 @@ const askQuestion = (query) => {
|
||||||
console.orange('Warning: Your mongodb url looks incorrect, please double check it in the `.env` file.');
|
console.orange('Warning: Your mongodb url looks incorrect, please double check it in the `.env` file.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Lets ask about open registration
|
||||||
|
const openReg = await askQuestion(
|
||||||
|
'Do you want to allow user registration (y/n)? Default: y'
|
||||||
|
);
|
||||||
|
if (openReg === 'n' || openReg === 'no') {
|
||||||
|
env['ALLOW_REGISTRATION'] = 'false';
|
||||||
|
// Lets tell them about how to create an account:
|
||||||
|
console.red('Note: You can create an account by running: `npm run create-user <email> <name> <username>`');
|
||||||
|
// sleep for 1 second so they can read this
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||||
|
}
|
||||||
|
|
||||||
// Update the env file
|
// Update the env file
|
||||||
loader.writeEnvFile(rootEnvPath, env);
|
loader.writeEnvFile(rootEnvPath, env);
|
||||||
|
|
||||||
|
@ -119,4 +114,3 @@ const askQuestion = (query) => {
|
||||||
console.green('Success! Please read our docs if you need help setting up the rest of the app.');
|
console.green('Success! Please read our docs if you need help setting up the rest of the app.');
|
||||||
console.log(''); // New line
|
console.log(''); // New line
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue