first commit

This commit is contained in:
Arwid Thornström
2022-01-19 07:28:09 +01:00
commit f55052d5b3
40 changed files with 6193 additions and 0 deletions
+131
View File
@@ -0,0 +1,131 @@
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
import chalk = require('chalk');
import { system } from 'gluegun';
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: true,
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.
`));
// 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();
// }
// }
system.run('touch ~/.pwcli_settings');
print.info(`Created configuration file ${chalk.yellow(`~/.pwcli_settings`)}`);
const config = {
gh_token: '',
photowall_repo: '',
};
config.gh_token = await (new Input({
message: `A github accesstoken is required with ${chalk.yellow('Full control of private repositories')}, please insert the key >`
})).run();
config.photowall_repo = await (new Input({
message: `If you want to be able to push active branch in your photowall repository, please insert the absolute path to the project >`
})).run();
print.info(`
${JSON.stringify(config)}
`);
if (await (new Confirm({
message: `Ok to save the these settings to ${chalk.yellow(`~/.pwcli_settings`)}?`
})).run()) {
system.run(`echo '${JSON.stringify(config)}' > ~/.pwcli_settings`);
} else {
print.info('Ok then.');
if (toolbox.fromMenu()) await toolbox.menu.showMenu();
}
if (toolbox.fromMenu()) await toolbox.menu.showMenu();
}
};