UNPKG

gitsu-cli

Version:

Interactive command line util for quickly & easily switching git users

48 lines (47 loc) 2.41 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const node_fs_1 = __importDefault(require("node:fs")); const node_os_1 = __importDefault(require("node:os")); const node_path_1 = __importDefault(require("node:path")); const chalk_1 = __importDefault(require("chalk")); const log_symbols_1 = __importDefault(require("log-symbols")); const choice_1 = require("../utils/choice"); const get_config_1 = __importDefault(require("../utils/get-config")); const get_current_choice_1 = __importDefault(require("./get-current-choice")); exports.default = () => __awaiter(void 0, void 0, void 0, function* () { try { yield (0, get_config_1.default)(); return true; } catch (e) { try { const currentChoice = yield (0, get_current_choice_1.default)(); const user = (0, choice_1.parseChoice)(currentChoice); const configPath = node_path_1.default.join(node_os_1.default.homedir(), '/', '.gitsurc'); node_fs_1.default.writeFileSync(configPath, JSON.stringify([ { name: user.name, email: user.email, }, ])); console.info(`${log_symbols_1.default.info} Created initial ${chalk_1.default.cyan('~/.gitsurc')} with user ${chalk_1.default.cyan(currentChoice)}`); return true; } catch (error) { console.error(`${log_symbols_1.default.error} ${chalk_1.default.red('Failed to create ~/.gitsurc config file')}`, error); return false; } } });