diff --git a/dist/windows.zip b/dist/windows.zip index 6d6292c..23be231 100644 Binary files a/dist/windows.zip and b/dist/windows.zip differ diff --git a/executors.js b/executors.js index f860548..1240773 100644 --- a/executors.js +++ b/executors.js @@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.do_queue_time = exports.printTableHeader = exports.alignLeft = exports.alignRight = exports.do_cron = exports.do_event = exports.do_envvar = exports.do_key = exports.do_inspect = exports.do_build = exports.do_redeploy = exports.do_deploy = exports.generateNewKey = exports.useExistingKey = exports.do_register = exports.do_duplicate = exports.fetch_template = exports.createService = exports.createServiceGroup = exports.createOrganization = exports.do_clone = exports.do_fetch = void 0; +exports.do_help = exports.do_queue_time = exports.printTableHeader = exports.alignLeft = exports.alignRight = exports.do_cron = exports.do_event = exports.do_envvar = exports.do_key = exports.do_inspect = exports.do_build = exports.do_redeploy = exports.do_deploy = exports.generateNewKey = exports.useExistingKey = exports.do_register = exports.do_duplicate = exports.fetch_template = exports.createService = exports.createServiceGroup = exports.createOrganization = exports.do_clone = exports.do_fetch = void 0; const fs_1 = __importDefault(require("fs")); const os_1 = __importDefault(require("os")); const utils_1 = require("./utils"); @@ -168,10 +168,10 @@ function createService(pth, group, name) { else throw e; } - (0, utils_1.addExitMessage)(`Use '${prompt_1.COLOR3}cd ${pth + (0, utils_1.addExitMessage)(`Use '${prompt_1.YELLOW}cd ${pth .with(name) .toString() - .replace(/\\/g, "\\\\")}${prompt_1.NORMAL_COLOR}' to go to the new service. \nThen use '${prompt_1.COLOR3}${process.env["COMMAND"]} deploy${prompt_1.NORMAL_COLOR}' to deploy it.`); + .replace(/\\/g, "\\\\")}${prompt_1.NORMAL_COLOR}' to go to the new service. \nThen use '${prompt_1.YELLOW}${process.env["COMMAND"]} deploy${prompt_1.NORMAL_COLOR}' to deploy it.`); process.chdir(before); } catch (e) { @@ -360,7 +360,7 @@ function do_key(org, key, name, duration) { if (key === null) { let { key, expiry } = JSON.parse(yield (0, utils_1.sshReq)(...cmd)); (0, utils_1.output2)(`${key} expires on ${new Date(expiry).toLocaleString()}.`); - (0, utils_1.addExitMessage)(`Key: ${prompt_1.COLOR3}${key}${prompt_1.NORMAL_COLOR}`); + (0, utils_1.addExitMessage)(`Key: ${prompt_1.YELLOW}${key}${prompt_1.NORMAL_COLOR}`); } else { cmd.push(`--update`, key); @@ -461,3 +461,38 @@ function do_queue_time(org, time) { }); } exports.do_queue_time = do_queue_time; +function do_help() { + return __awaiter(this, void 0, void 0, function* () { + let whoami = JSON.parse(yield (0, utils_1.sshReq)("whoami")); + if (whoami === undefined || whoami.length === 0) { + let cache = (0, utils_1.getCache)(); + if (!cache.registered) { + (0, utils_1.output2)(`${prompt_1.YELLOW}No key registered with ${process.env["COMMAND"]}.${prompt_1.NORMAL_COLOR}`); + } + (0, utils_1.output2)(`${prompt_1.RED}No verified email.${prompt_1.NORMAL_COLOR}`); + } + else { + (0, utils_1.output2)(`${prompt_1.GREEN}Logged in as: ${whoami.join(", ")}.${prompt_1.NORMAL_COLOR}`); + } + let rawStruct = (0, utils_1.fetchOrgRaw)(); + if (rawStruct.org === null) { + (0, utils_1.output2)(`${prompt_1.YELLOW}Not inside organization.${prompt_1.NORMAL_COLOR}`); + } + else { + (0, utils_1.output2)(`${prompt_1.GREEN}Inside organization: ${rawStruct.org.name}${prompt_1.NORMAL_COLOR}`); + } + if (rawStruct.serviceGroup === null) { + (0, utils_1.output2)(`${prompt_1.YELLOW}Not inside service group.${prompt_1.NORMAL_COLOR}`); + } + else { + (0, utils_1.output2)(`${prompt_1.GREEN}Inside service group: ${rawStruct.serviceGroup}${prompt_1.NORMAL_COLOR}`); + } + if (!fs_1.default.existsSync("mist.json") && !fs_1.default.existsSync("merrymake.json")) { + (0, utils_1.output2)(`${prompt_1.YELLOW}Not inside service repo.${prompt_1.NORMAL_COLOR}`); + } + else { + (0, utils_1.output2)(`${prompt_1.GREEN}Inside service repo.${prompt_1.NORMAL_COLOR}`); + } + }); +} +exports.do_help = do_help; diff --git a/executors.ts b/executors.ts index 0dd88c4..e1c0f8b 100644 --- a/executors.ts +++ b/executors.ts @@ -11,6 +11,8 @@ import { addExitMessage, sshReq, urlReq, + getCache, + fetchOrgRaw, } from "./utils"; import { API_URL, GIT_HOST, HTTP_HOST } from "./config"; import { @@ -18,7 +20,7 @@ import { BUILD_SCRIPT_MAKERS, } from "@merrymake/detect-project-type"; import { ExecOptions, spawn } from "child_process"; -import { COLOR3, NORMAL_COLOR } from "./prompt"; +import { RED, BLUE, YELLOW, NORMAL_COLOR, GREEN } from "./prompt"; import path from "path"; import { getArgs } from "./args"; @@ -174,13 +176,13 @@ export async function createService(pth: Path, group: string, name: string) { } else throw e; } addExitMessage( - `Use '${COLOR3}cd ${pth + `Use '${YELLOW}cd ${pth .with(name) .toString() .replace( /\\/g, "\\\\" - )}${NORMAL_COLOR}' to go to the new service. \nThen use '${COLOR3}${ + )}${NORMAL_COLOR}' to go to the new service. \nThen use '${YELLOW}${ process.env["COMMAND"] } deploy${NORMAL_COLOR}' to deploy it.` ); @@ -385,7 +387,7 @@ export async function do_key( await sshReq(...cmd) ); output2(`${key} expires on ${new Date(expiry).toLocaleString()}.`); - addExitMessage(`Key: ${COLOR3}${key}${NORMAL_COLOR}`); + addExitMessage(`Key: ${YELLOW}${key}${NORMAL_COLOR}`); } else { cmd.push(`--update`, key); let { count, expiry }: { count: number; expiry: string } = JSON.parse( @@ -544,3 +546,38 @@ export async function do_queue_time(org: string, time: number) { throw e; } } + +export async function do_help() { + let whoami = JSON.parse(await sshReq("whoami")); + if (whoami === undefined || whoami.length === 0) { + let cache = getCache(); + if (!cache.registered) { + output2( + `${YELLOW}No key registered with ${process.env["COMMAND"]}.${NORMAL_COLOR}` + ); + } + output2(`${RED}No verified email.${NORMAL_COLOR}`); + } else { + output2(`${GREEN}Logged in as: ${whoami.join(", ")}.${NORMAL_COLOR}`); + } + let rawStruct = fetchOrgRaw(); + if (rawStruct.org === null) { + output2(`${YELLOW}Not inside organization.${NORMAL_COLOR}`); + } else { + output2( + `${GREEN}Inside organization: ${rawStruct.org.name}${NORMAL_COLOR}` + ); + } + if (rawStruct.serviceGroup === null) { + output2(`${YELLOW}Not inside service group.${NORMAL_COLOR}`); + } else { + output2( + `${GREEN}Inside service group: ${rawStruct.serviceGroup}${NORMAL_COLOR}` + ); + } + if (!fs.existsSync("mist.json") && !fs.existsSync("merrymake.json")) { + output2(`${YELLOW}Not inside service repo.${NORMAL_COLOR}`); + } else { + output2(`${GREEN}Inside service repo.${NORMAL_COLOR}`); + } +} diff --git a/mm.js b/mm.js index 9f412e0..abea122 100644 --- a/mm.js +++ b/mm.js @@ -9,5 +9,5 @@ if (!node_process_1.stdin.isTTY || node_process_1.stdin.setRawMode === undefined } const prompt_1 = require("./prompt"); process.env["UPDATE_MESSAGE"] = `to update run the command: -${prompt_1.COLOR3}npm update -g @merrymake/cli${prompt_1.NORMAL_COLOR}`; +${prompt_1.YELLOW}npm update -g @merrymake/cli${prompt_1.NORMAL_COLOR}`; require("./index"); diff --git a/mm.ts b/mm.ts index b8aa2f6..855bc0b 100644 --- a/mm.ts +++ b/mm.ts @@ -7,7 +7,7 @@ if (!stdin.isTTY || stdin.setRawMode === undefined) { ); process.exit(1); } -import { COLOR3, NORMAL_COLOR } from "./prompt"; +import { YELLOW, NORMAL_COLOR } from "./prompt"; process.env["UPDATE_MESSAGE"] = `to update run the command: -${COLOR3}npm update -g @merrymake/cli${NORMAL_COLOR}`; +${YELLOW}npm update -g @merrymake/cli${NORMAL_COLOR}`; import "./index"; diff --git a/mmk.js b/mmk.js index 45722ee..c627c49 100644 --- a/mmk.js +++ b/mmk.js @@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", { value: true }); process.env["COMMAND"] = "mmk"; const prompt_1 = require("./prompt"); process.env["UPDATE_MESSAGE"] = `to update run the command: -${prompt_1.COLOR3}npm update -g @merrymake/cli${prompt_1.NORMAL_COLOR}`; +${prompt_1.YELLOW}npm update -g @merrymake/cli${prompt_1.NORMAL_COLOR}`; require("./index"); diff --git a/mmk.ts b/mmk.ts index 5fd83b5..8842c23 100644 --- a/mmk.ts +++ b/mmk.ts @@ -1,6 +1,6 @@ #!/usr/bin/env winpty node process.env["COMMAND"] = "mmk"; -import { COLOR3, NORMAL_COLOR } from "./prompt"; +import { YELLOW, NORMAL_COLOR } from "./prompt"; process.env["UPDATE_MESSAGE"] = `to update run the command: -${COLOR3}npm update -g @merrymake/cli${NORMAL_COLOR}`; +${YELLOW}npm update -g @merrymake/cli${NORMAL_COLOR}`; import "./index"; diff --git a/package.json b/package.json index d2e8e1e..71f8f1b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@merrymake/cli", - "version": "1.6.2", + "version": "1.6.3", "description": "", "main": "index.js", "scripts": { diff --git a/pkg.js b/pkg.js index ac84e48..b1a5848 100644 --- a/pkg.js +++ b/pkg.js @@ -9,5 +9,5 @@ if (!node_process_1.stdin.isTTY || node_process_1.stdin.setRawMode === undefined } const prompt_1 = require("./prompt"); process.env["UPDATE_MESSAGE"] = `get the latest version from: -${prompt_1.COLOR3}https://github.com/merrymake/cli/releases${prompt_1.NORMAL_COLOR}`; +${prompt_1.YELLOW}https://github.com/merrymake/cli/releases${prompt_1.NORMAL_COLOR}`; require("./index"); diff --git a/pkg.ts b/pkg.ts index f68ddf0..55ed8a2 100644 --- a/pkg.ts +++ b/pkg.ts @@ -7,7 +7,7 @@ if (!stdin.isTTY || stdin.setRawMode === undefined) { ); process.exit(1); } -import { COLOR3, NORMAL_COLOR } from "./prompt"; +import { YELLOW, NORMAL_COLOR } from "./prompt"; process.env["UPDATE_MESSAGE"] = `get the latest version from: -${COLOR3}https://github.com/merrymake/cli/releases${NORMAL_COLOR}`; +${YELLOW}https://github.com/merrymake/cli/releases${NORMAL_COLOR}`; import "./index"; diff --git a/prompt.js b/prompt.js index a12164c..bc66870 100644 --- a/prompt.js +++ b/prompt.js @@ -1,6 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.exit = exports.shortText = exports.spinner_stop = exports.spinner_start = exports.choice = exports.INVISIBLE = exports.COLOR3 = exports.COLOR2 = exports.COLOR1 = exports.NORMAL_COLOR = exports.SHOW_CURSOR = exports.HIDE_CURSOR = exports.RIGHT = exports.LEFT = exports.DOWN = exports.UP = exports.ENTER = exports.DELETE = exports.ESCAPE = exports.BACKSPACE = exports.CTRL_C = void 0; +exports.exit = exports.shortText = exports.spinner_stop = exports.spinner_start = exports.choice = exports.INVISIBLE = exports.YELLOW = exports.GREEN = exports.BLUE = exports.RED = exports.NORMAL_COLOR = exports.SHOW_CURSOR = exports.HIDE_CURSOR = exports.RIGHT = exports.LEFT = exports.DOWN = exports.UP = exports.ENTER = exports.DELETE = exports.ESCAPE = exports.BACKSPACE = exports.CTRL_C = void 0; const node_process_1 = require("node:process"); const args_1 = require("./args"); const utils_1 = require("./utils"); @@ -17,16 +17,17 @@ exports.RIGHT = "\u001b[C"; exports.HIDE_CURSOR = "\u001B[?25l"; exports.SHOW_CURSOR = "\u001B[?25h"; exports.NORMAL_COLOR = "\u001B[0m"; -exports.COLOR1 = "\u001B[0;31m"; -exports.COLOR2 = "\u001B[0;34m"; -exports.COLOR3 = "\u001B[0;93m"; +exports.RED = "\u001B[0;31m"; +exports.BLUE = "\u001B[0;34m"; +exports.GREEN = "\u001B[0;32m"; +exports.YELLOW = "\u001B[0;93m"; exports.INVISIBLE = [ exports.HIDE_CURSOR, exports.SHOW_CURSOR, exports.NORMAL_COLOR, - exports.COLOR1, - exports.COLOR2, - exports.COLOR3, + exports.RED, + exports.BLUE, + exports.YELLOW, ]; let xOffset = 0; let yOffset = 0; @@ -130,7 +131,7 @@ function choice(options, invertedQuiet = { cmd: false, select: true }, def = 0) const before = o.text.substring(0, index); const after = o.text.substring(index + o.long.length); str.push(before); - str.push(exports.COLOR3); + str.push(exports.YELLOW); str.push(o.long); str.push(exports.NORMAL_COLOR); str.push(after); @@ -143,7 +144,7 @@ function choice(options, invertedQuiet = { cmd: false, select: true }, def = 0) output(exports.HIDE_CURSOR); output(str.join("")); let pos = def; - output(exports.COLOR3); + output(exports.YELLOW); moveCursor(0, -options.length + pos); output(`>`); moveCursor(-1, 0); diff --git a/prompt.ts b/prompt.ts index d219f2c..32c099a 100644 --- a/prompt.ts +++ b/prompt.ts @@ -15,16 +15,17 @@ export const RIGHT = "\u001b[C"; export const HIDE_CURSOR = "\u001B[?25l"; export const SHOW_CURSOR = "\u001B[?25h"; export const NORMAL_COLOR = "\u001B[0m"; -export const COLOR1 = "\u001B[0;31m"; -export const COLOR2 = "\u001B[0;34m"; -export const COLOR3 = "\u001B[0;93m"; +export const RED = "\u001B[0;31m"; +export const BLUE = "\u001B[0;34m"; +export const GREEN = "\u001B[0;32m"; +export const YELLOW = "\u001B[0;93m"; export const INVISIBLE = [ HIDE_CURSOR, SHOW_CURSOR, NORMAL_COLOR, - COLOR1, - COLOR2, - COLOR3, + RED, + BLUE, + YELLOW, ]; let xOffset = 0; @@ -152,7 +153,7 @@ export function choice( const before = o.text.substring(0, index); const after = o.text.substring(index + o.long.length); str.push(before); - str.push(COLOR3); + str.push(YELLOW); str.push(o.long); str.push(NORMAL_COLOR); str.push(after); @@ -167,7 +168,7 @@ export function choice( output(str.join("")); let pos = def; - output(COLOR3); + output(YELLOW); moveCursor(0, -options.length + pos); output(`>`); moveCursor(-1, 0); diff --git a/questions.js b/questions.js index 993bb41..ca1a674 100644 --- a/questions.js +++ b/questions.js @@ -40,6 +40,10 @@ function redeploy() { (0, utils_1.addToExecuteQueue)(() => (0, executors_1.do_redeploy)()); return (0, utils_1.finish)(); } +function help() { + (0, utils_1.addToExecuteQueue)(() => (0, executors_1.do_help)()); + return (0, utils_1.finish)(); +} function build() { (0, utils_1.addToExecuteQueue)(() => (0, executors_1.do_build)()); return (0, utils_1.finish)(); @@ -203,9 +207,8 @@ function register_manual() { function register() { return __awaiter(this, void 0, void 0, function* () { try { - let keys = (0, utils_1.getFiles)(new utils_2.Path(`${os_1.default.homedir()}/.ssh`), "") - .filter((x) => x.endsWith(".pub")) - .map((x) => { + let keyfiles = (0, utils_1.getFiles)(new utils_2.Path(`${os_1.default.homedir()}/.ssh`), "").filter((x) => x.endsWith(".pub")); + let keys = keyfiles.map((x) => { let f = x.substring(0, x.length - ".pub".length); return { long: f, @@ -219,12 +222,14 @@ function register() { text: "Manually add key", action: () => register_manual(), }); - keys.push({ - long: "new", - short: "n", - text: "Setup new key specifically for Merrymake", - action: () => register_key(executors_1.generateNewKey), - }); + if (keyfiles.includes("merrymake")) { + keys.push({ + long: "new", + short: "n", + text: "Setup new key specifically for Merrymake", + action: () => register_key(executors_1.generateNewKey), + }); + } return yield (0, prompt_1.choice)(keys, { cmd: false, select: true }, keys.length - 1).then((x) => x); } catch (e) { @@ -428,7 +433,7 @@ function keys(org) { let options = keys.map((x) => { let d = new Date(x.expiry); let ds = d.getTime() < Date.now() - ? `${prompt_1.COLOR1}${d.toLocaleString()}${prompt_1.NORMAL_COLOR}` + ? `${prompt_1.RED}${d.toLocaleString()}${prompt_1.NORMAL_COLOR}` : d.toLocaleString(); let n = x.name || ""; return { @@ -782,6 +787,11 @@ function start() { text: "allow or disallow events through api-keys for the organization", action: () => event(orgName), }); + options.push({ + long: "help", + text: "help diagnose potential issues", + action: () => help(), + }); return yield (0, prompt_1.choice)(options).then((x) => x); } else { @@ -814,6 +824,12 @@ function start() { action: () => checkout(), weight: cache.hasOrgs ? 10 : 3, }); + options.push({ + long: "help", + text: "help diagnose potential issues", + action: () => help(), + weight: 0, + }); options.sort((a, b) => b.weight - a.weight); return yield (0, prompt_1.choice)(options).then((x) => x); } diff --git a/questions.ts b/questions.ts index d4aeefd..f8c06de 100644 --- a/questions.ts +++ b/questions.ts @@ -2,7 +2,7 @@ import path from "path"; import os from "os"; import fs from "fs"; import { - COLOR1, + RED, NORMAL_COLOR, choice, shortText, @@ -44,6 +44,7 @@ import { alignRight, alignLeft, do_event, + do_help, } from "./executors"; import { VERSION_CMD, type ProjectType } from "@merrymake/detect-project-type"; import { execSync } from "child_process"; @@ -76,6 +77,11 @@ function redeploy() { return finish(); } +function help() { + addToExecuteQueue(() => do_help()); + return finish(); +} + function build() { addToExecuteQueue(() => do_build()); return finish(); @@ -271,28 +277,31 @@ async function register_manual() { async function register() { try { - let keys = getFiles(new Path(`${os.homedir()}/.ssh`), "") - .filter((x) => x.endsWith(".pub")) - .map