197 lines
6.6 KiB
TypeScript
197 lines
6.6 KiB
TypeScript
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
|
|
import chalk = require('chalk');
|
|
import { system } from 'gluegun';
|
|
import { defaultMenuSettings, getSettings } from '../../../globals';
|
|
const { Confirm, Input } = require('enquirer');
|
|
|
|
const checkCLIProgram = async (toolbox: GluegunMenuToolbox, cmd: string) => {
|
|
const { print, system, strings } = toolbox;
|
|
try {
|
|
const result = strings.trim(await system.run(`command -v ${cmd}`));
|
|
return true;
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
};
|
|
|
|
module.exports = {
|
|
name: 'settings',
|
|
alias: ['se'],
|
|
description: 'Setup settings for pwcli (se)',
|
|
hidden: false,
|
|
run: async (toolbox: GluegunMenuToolbox) => {
|
|
const { print, system, strings } = toolbox;
|
|
|
|
print.info(
|
|
chalk.yellow(`
|
|
|
|
This will help you setup everything needed to run pwcli on a mac (maby linux).
|
|
All settings will be saved to ${chalk.cyan('~/.pwcli_settings')}
|
|
|
|
First step is to install aws cli [https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html]
|
|
and configuring it. Install it either with brew or do as specified in the link.
|
|
|
|
`),
|
|
);
|
|
|
|
let config = await getSettings(toolbox);
|
|
|
|
// Check if brew is installed
|
|
// if (await checkCLIProgram(toolbox, 'brew')) {
|
|
// print.info(`\nDetected ${chalk.green('brew')}`);
|
|
// } else {
|
|
// print.info(`\nRequired program ${chalk.green('brew')} is not installed.`);
|
|
|
|
// if (await (new Confirm({
|
|
// name: 'confirm',
|
|
// message: `Do you want pwcli to install it?`
|
|
// })).run()) {
|
|
// print.info(`/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"`);
|
|
// // system.run('/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"');
|
|
// } else {
|
|
// if (await (new Confirm({
|
|
// name: 'confirm',
|
|
// message: `Do you want to install it your self?`
|
|
// })).run()) {
|
|
// system.run('open https://brew.sh');
|
|
// } else {
|
|
// print.info('😔 ok, your choice..');
|
|
// }
|
|
// }
|
|
|
|
// if (await (new Confirm({
|
|
// name: 'confirm',
|
|
// message: `Is ${chalk.green('brew')} installed?`
|
|
// })).run()) {
|
|
// print.info('Great, lets continue!');
|
|
// } else {
|
|
// print.info('😔 ok, your choice..');
|
|
// }
|
|
// }
|
|
|
|
// if (await checkCLIProgram(toolbox, 'asdf')) {
|
|
// print.info(`\nDetected ${chalk.green('aws cli')}`);
|
|
// } else {
|
|
// print.info(`\nRequired program ${chalk.green('aws cli')} is not installed.`);
|
|
// if (await (new Confirm({
|
|
// name: 'confirm',
|
|
// message: `Do you want pwcli to install it?`
|
|
// })).run()) {
|
|
// print.info(`brew install awscli`);
|
|
// // system.run('brew install awscli');
|
|
// } else {
|
|
// if (await (new Confirm({
|
|
// name: 'confirm',
|
|
// message: `Do you want to install it your self?`
|
|
// })).run()) {
|
|
// system.run('open https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html');
|
|
// } else {
|
|
// print.info('😔 ok, your choice..');
|
|
// }
|
|
// }
|
|
|
|
// if (await (new Confirm({
|
|
// name: 'confirm',
|
|
// message: `Is ${chalk.green('aws cli')} installed and configured?`
|
|
// })).run()) {
|
|
|
|
// } else {
|
|
// print.info('😔 ok, install it and run ..');
|
|
// await toolbox.menu.showMenu();
|
|
// }
|
|
// }
|
|
|
|
await system.run('touch ~/.pwcli_settings');
|
|
print.info(
|
|
`Created configuration file ${chalk.yellow(`~/.pwcli_settings`)}`,
|
|
);
|
|
|
|
if (!config) {
|
|
config = {
|
|
gh_token: '',
|
|
photowall_repo: '',
|
|
mandrill_api_key: '',
|
|
localhost_url: '',
|
|
localhost_username: '',
|
|
localhost_password: '',
|
|
llm_api_keys: {
|
|
gemini_api_key: '',
|
|
openai_api_key: '',
|
|
},
|
|
};
|
|
}
|
|
|
|
// Ensure llm_api_keys exists in existing configs
|
|
if (!config.llm_api_keys) {
|
|
config.llm_api_keys = {
|
|
gemini_api_key: '',
|
|
openai_api_key: '',
|
|
};
|
|
}
|
|
|
|
config.gh_token = await new Input({
|
|
message: `A github accesstoken is required with ${chalk.yellow(
|
|
'Full control of private repositories',
|
|
)}, please insert the key >`,
|
|
initial: config.gh_token,
|
|
}).run();
|
|
|
|
config.photowall_repo = await new Input({
|
|
message: `If you want to be able to use current branch in your photowall repository\nor the create and update commands for testservers, please insert\nthe absolute path to the project or leave blank >`,
|
|
initial: config.photowall_repo,
|
|
}).run();
|
|
|
|
config.mandrill_api_key = await new Input({
|
|
message: `If you want to be able to use the mailchimp commands, please insert\nyour mailchimp api key. Otherwise leave blank >`,
|
|
initial: config.mandrill_api_key,
|
|
}).run();
|
|
|
|
config.localhost_url = await new Input({
|
|
message: `If you want to be able to run route tests against localhost, please enter the base URL for localhost (e.g. https://www.photowall-local.se:8080) >`,
|
|
initial: config.localhost_url,
|
|
}).run();
|
|
|
|
config.localhost_username = await new Input({
|
|
message: `If you want to be able to run route tests against localhost, please enter the username for localhost >`,
|
|
initial: config.localhost_username,
|
|
}).run();
|
|
|
|
config.localhost_password = await new Input({
|
|
message: `If you want to be able to run route tests against localhost, please enter the password for localhost >`,
|
|
initial: config.localhost_password,
|
|
}).run();
|
|
|
|
config.llm_api_keys.gemini_api_key = await new Input({
|
|
message: `If you want to use Gemini AI features, please insert\nyour Gemini API key. Otherwise leave blank >`,
|
|
initial: config.llm_api_keys.gemini_api_key,
|
|
}).run();
|
|
|
|
config.llm_api_keys.openai_api_key = await new Input({
|
|
message: `If you want to use OpenAI features, please insert\nyour OpenAI API key. Otherwise leave blank >`,
|
|
initial: config.llm_api_keys.openai_api_key,
|
|
}).run();
|
|
|
|
print.info(`
|
|
|
|
${JSON.stringify(config)}
|
|
|
|
`);
|
|
if (
|
|
await new Confirm({
|
|
message: `Ok to save the these settings to ${chalk.yellow(
|
|
`~/.pwcli_settings`,
|
|
)}?`,
|
|
}).run()
|
|
) {
|
|
await system.run(`echo '${JSON.stringify(config)}' > ~/.pwcli_settings`);
|
|
} else {
|
|
print.info('Ok then.');
|
|
if (toolbox.fromMenu())
|
|
await toolbox.menu.showMenu(null, defaultMenuSettings);
|
|
}
|
|
|
|
if (toolbox.fromMenu())
|
|
await toolbox.menu.showMenu(null, defaultMenuSettings);
|
|
},
|
|
};
|