Skip to content

Commit

Permalink
Publish
Browse files Browse the repository at this point in the history
  • Loading branch information
thedrlambda committed Nov 22, 2023
1 parent ac3c5f9 commit 057cf1e
Show file tree
Hide file tree
Showing 18 changed files with 180 additions and 67 deletions.
Binary file modified dist/windows.zip
Binary file not shown.
43 changes: 39 additions & 4 deletions executors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
45 changes: 41 additions & 4 deletions executors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ import {
addExitMessage,
sshReq,
urlReq,
getCache,
fetchOrgRaw,
} from "./utils";
import { API_URL, GIT_HOST, HTTP_HOST } from "./config";
import {
detectProjectType,
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";

Expand Down Expand Up @@ -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.`
);
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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}`);
}
}
2 changes: 1 addition & 1 deletion mm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
4 changes: 2 additions & 2 deletions mm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
2 changes: 1 addition & 1 deletion mmk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
4 changes: 2 additions & 2 deletions mmk.ts
Original file line number Diff line number Diff line change
@@ -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";
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@merrymake/cli",
"version": "1.6.2",
"version": "1.6.3",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion pkg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
4 changes: 2 additions & 2 deletions pkg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
19 changes: 10 additions & 9 deletions prompt.js
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
17 changes: 9 additions & 8 deletions prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
36 changes: 26 additions & 10 deletions questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)();
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit 057cf1e

Please sign in to comment.