Skip to content

Commit e731274

Browse files
committed
Lots of little improvements
1 parent 7cf2924 commit e731274

47 files changed

Lines changed: 2523 additions & 1984 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

contexts.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ const NOT_ORGANIZATION_CONTEXT = async (cmd) => {
102102
}
103103
};
104104
export const CONTEXTS = {
105-
clone: NOT_ORGANIZATION_CONTEXT,
106105
clean: SERVICE_CONTEXT,
107106
build: SERVICE_CONTEXT,
108107
update: SERVICE_CONTEXT,

contexts.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ const NOT_ORGANIZATION_CONTEXT = async (cmd: string) => {
105105
};
106106

107107
export const CONTEXTS: { [cmd: string]: (cmd: string) => Promise<string> } = {
108-
clone: NOT_ORGANIZATION_CONTEXT,
109108
clean: SERVICE_CONTEXT,
110109
build: SERVICE_CONTEXT,
111110
update: SERVICE_CONTEXT,

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ if (stdin.isTTY) {
4444
const token = await index();
4545
})().catch((e) => {
4646
moveToBottom();
47-
const eStr = "" + e;
47+
const eStr1 = "" + e;
48+
const eStr = eStr1 === "[object Object]" ? JSON.stringify(e) : eStr1;
4849
if (eStr.includes("Permission denied (publickey)")) {
4950
addKnownHost();
5051
outputGit(`A permission error occurred. Please try these solutions:

index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ if (stdin.isTTY) {
5757
const token: never = await index();
5858
})().catch((e) => {
5959
moveToBottom();
60-
const eStr = "" + e;
60+
const eStr1 = "" + e;
61+
const eStr = eStr1 === "[object Object]" ? JSON.stringify(e) : eStr1;
6162
if (eStr.includes("Permission denied (publickey)")) {
6263
addKnownHost();
6364
outputGit(

newCommands/apikey.js

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Str } from "@merrymake/utils";
22
import { finish } from "../exitMessages.js";
33
import { outputGit } from "../printUtils.js";
4-
import { NORMAL_COLOR, RED, YELLOW, choice, output, shortText, } from "../prompt.js";
4+
import { NORMAL_COLOR, RED, YELLOW, choice, output, resetCommand, shortText, } from "../prompt.js";
55
import { sshReq } from "../utils.js";
66
export async function do_key_create(organizationId, description, duration) {
77
try {
@@ -16,7 +16,7 @@ export async function do_key_create(organizationId, description, duration) {
1616
const reply = await sshReq(...cmd);
1717
if (reply.length !== 8)
1818
throw reply;
19-
output(`Created apikey ${description !== "" ? `'${description}'` : ""}: ${YELLOW}${reply}${NORMAL_COLOR}\n`);
19+
output(`Created apikey${description !== "" ? ` '${description}'` : ""}: ${YELLOW}${reply}${NORMAL_COLOR}\n`);
2020
const apikeyId = reply;
2121
return apikeyId;
2222
}
@@ -65,6 +65,7 @@ async function composeAwait(f, g) {
6565
}
6666
export async function key_create(organizationId, continuation) {
6767
try {
68+
resetCommand("key");
6869
const description = await shortText("Apikey display name", "Used to identify this key", "");
6970
return key_key_name(description, (description, duration) => composeAwait(continuation, do_key_create(organizationId, description, duration)));
7071
}
@@ -74,34 +75,40 @@ export async function key_create(organizationId, continuation) {
7475
}
7576
export async function key(organizationId) {
7677
try {
77-
const resp = await sshReq(`apikey-list`, organizationId.toString());
78-
const keys = JSON.parse(resp);
79-
const options = [];
80-
const tableHeader = Str.AsciiTable.advanced({
81-
Key: 8,
82-
"Display name>": -12,
83-
"<Expiry time": 23,
84-
}, keys, (x) => {
85-
const d = new Date(x.expiresOn);
86-
const ds = d.getTime() < Date.now()
87-
? `${RED}${d.toLocaleString()}${NORMAL_COLOR}`
88-
: d.toLocaleString();
89-
const n = x.name || "";
90-
return [x.id, n, ds];
91-
}, (text, x) => {
92-
options.push({
93-
long: x.id,
94-
text,
95-
action: () => key_key(x.name, (description, duration) => composeAwait(finish, do_key_modify(x.id, description, duration))),
96-
});
97-
}, " ");
98-
options.push({
99-
long: `new`,
100-
short: `n`,
101-
text: `add a new apikey`,
102-
action: () => key_create(organizationId, finish),
103-
});
104-
return await choice("Which apikey would you like to edit?\n" + tableHeader, options).then();
78+
return await choice([
79+
{
80+
long: `new`,
81+
short: `n`,
82+
text: `add a new apikey`,
83+
action: () => key_create(organizationId, finish),
84+
},
85+
], async () => {
86+
const resp = await sshReq(`apikey-list`, organizationId.toString());
87+
const keys = JSON.parse(resp);
88+
const options = [];
89+
const tableHeader = Str.AsciiTable.advanced({
90+
Key: 8,
91+
"Display name>": -12,
92+
"<Expiry time": 23,
93+
}, keys, (x) => {
94+
const d = new Date(x.expiresOn);
95+
const ds = d.getTime() < Date.now()
96+
? `${RED}${d.toLocaleString()}${NORMAL_COLOR}`
97+
: d.toLocaleString();
98+
const n = x.name || "";
99+
return [x.id, n, ds];
100+
}, (text, x) => {
101+
options.push({
102+
long: x.id,
103+
text,
104+
action: () => key_key(x.name, (description, duration) => composeAwait(finish, do_key_modify(x.id, description, duration))),
105+
});
106+
}, " ");
107+
return {
108+
options,
109+
header: "Which apikey would you like to edit?\n" + tableHeader,
110+
};
111+
}).then();
105112
}
106113
catch (e) {
107114
throw e;

newCommands/apikey.ts

Lines changed: 53 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
YELLOW,
99
choice,
1010
output,
11+
resetCommand,
1112
shortText,
1213
} from "../prompt.js";
1314
import { OrganizationId } from "../types.js";
@@ -29,8 +30,8 @@ export async function do_key_create(
2930
const reply = await sshReq(...cmd);
3031
if (reply.length !== 8) throw reply;
3132
output(
32-
`Created apikey ${
33-
description !== "" ? `'${description}'` : ""
33+
`Created apikey${
34+
description !== "" ? ` '${description}'` : ""
3435
}: ${YELLOW}${reply}${NORMAL_COLOR}\n`
3536
);
3637
const apikeyId = reply;
@@ -101,6 +102,7 @@ export async function key_create(
101102
continuation: (apikeyId: string) => Promise<never>
102103
) {
103104
try {
105+
resetCommand("key");
104106
const description = await shortText(
105107
"Apikey display name",
106108
"Used to identify this key",
@@ -119,48 +121,56 @@ export async function key_create(
119121

120122
export async function key(organizationId: OrganizationId) {
121123
try {
122-
const resp = await sshReq(`apikey-list`, organizationId.toString());
123-
const keys: { name: string; id: string; expiresOn: Date }[] =
124-
JSON.parse(resp);
125-
const options: Option[] = [];
126-
const tableHeader = Str.AsciiTable.advanced(
127-
{
128-
Key: 8,
129-
"Display name>": -12,
130-
"<Expiry time": 23,
131-
},
132-
keys,
133-
(x) => {
134-
const d = new Date(x.expiresOn);
135-
const ds =
136-
d.getTime() < Date.now()
137-
? `${RED}${d.toLocaleString()}${NORMAL_COLOR}`
138-
: d.toLocaleString();
139-
const n = x.name || "";
140-
return [x.id, n, ds];
141-
},
142-
(text, x) => {
143-
options.push({
144-
long: x.id,
145-
text,
146-
action: () =>
147-
key_key(x.name, (description, duration) =>
148-
composeAwait(finish, do_key_modify(x.id, description, duration))
149-
),
150-
});
151-
},
152-
" "
153-
);
154-
155-
options.push({
156-
long: `new`,
157-
short: `n`,
158-
text: `add a new apikey`,
159-
action: () => key_create(organizationId, finish),
160-
});
161124
return await choice(
162-
"Which apikey would you like to edit?\n" + tableHeader,
163-
options
125+
[
126+
{
127+
long: `new`,
128+
short: `n`,
129+
text: `add a new apikey`,
130+
action: () => key_create(organizationId, finish),
131+
},
132+
],
133+
async () => {
134+
const resp = await sshReq(`apikey-list`, organizationId.toString());
135+
const keys: { name: string; id: string; expiresOn: Date }[] =
136+
JSON.parse(resp);
137+
const options: Option[] = [];
138+
const tableHeader = Str.AsciiTable.advanced(
139+
{
140+
Key: 8,
141+
"Display name>": -12,
142+
"<Expiry time": 23,
143+
},
144+
keys,
145+
(x) => {
146+
const d = new Date(x.expiresOn);
147+
const ds =
148+
d.getTime() < Date.now()
149+
? `${RED}${d.toLocaleString()}${NORMAL_COLOR}`
150+
: d.toLocaleString();
151+
const n = x.name || "";
152+
return [x.id, n, ds];
153+
},
154+
(text, x) => {
155+
options.push({
156+
long: x.id,
157+
text,
158+
action: () =>
159+
key_key(x.name, (description, duration) =>
160+
composeAwait(
161+
finish,
162+
do_key_modify(x.id, description, duration)
163+
)
164+
),
165+
});
166+
},
167+
" "
168+
);
169+
return {
170+
options,
171+
header: "Which apikey would you like to edit?\n" + tableHeader,
172+
};
173+
}
164174
).then();
165175
} catch (e) {
166176
throw e;

newCommands/clone.js

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,46 @@
1+
import { Str } from "@merrymake/utils";
12
import { existsSync } from "fs";
3+
import { mkdir, writeFile } from "fs/promises";
24
import { GIT_HOST } from "../config.js";
5+
import { addToExecuteQueue, finish } from "../exitMessages.js";
6+
import { outputGit } from "../printUtils.js";
37
import { choice } from "../prompt.js";
48
import { OrganizationId, PathToOrganization } from "../types.js";
59
import { execPromise, sshReq, toSubdomain } from "../utils.js";
6-
import { outputGit } from "../printUtils.js";
710
import { ensureGroupStructure } from "./fetch.js";
811
import { listOrgs } from "./org.js";
9-
import { addToExecuteQueue, finish } from "../exitMessages.js";
10-
import { mkdir, writeFile } from "fs/promises";
11-
import { Str } from "@merrymake/utils";
1212
export async function do_clone(struct, folderName, displayName, organizationId) {
1313
try {
1414
outputGit(`Cloning ${displayName}...`);
1515
await mkdir(`${folderName}/.merrymake`, { recursive: true });
1616
const orgFile = { organizationId: organizationId.toString() };
1717
await writeFile(`${folderName}/.merrymake/conf.json`, JSON.stringify(orgFile));
18-
const eventsDir = `${folderName}/event-catalogue`;
18+
const eventsDir = `${folderName}/event-configuration`;
1919
await mkdir(eventsDir, { recursive: true });
2020
await execPromise(`git init --initial-branch=main`, eventsDir);
2121
await execPromise(`git remote add origin "${GIT_HOST}/o${organizationId}/event-catalogue"`, eventsDir);
22-
await writeFile(eventsDir + "/api.json", "{}");
23-
await writeFile(eventsDir + "/cron.json", "{}");
24-
const publicDir = `${folderName}/public`;
22+
try {
23+
await execPromise(`git pull origin main`, eventsDir);
24+
await execPromise(`git branch --set-upstream-to=origin/main`, eventsDir);
25+
}
26+
catch (e) {
27+
if (!existsSync(eventsDir + "/api.json"))
28+
await writeFile(eventsDir + "/api.json", "{}");
29+
if (!existsSync(eventsDir + "/cron.json"))
30+
await writeFile(eventsDir + "/cron.json", "{}");
31+
}
32+
const publicDir = `${folderName}/front-end`;
2533
await mkdir(publicDir, { recursive: true });
2634
await execPromise(`git init --initial-branch=main`, publicDir);
2735
await execPromise(`git remote add origin "${GIT_HOST}/o${organizationId}/public"`, publicDir);
28-
await writeFile(publicDir + "/index.html", "<html><body>Hello, World!</body></html>");
36+
try {
37+
await execPromise(`git pull origin main`, publicDir);
38+
await execPromise(`git branch --set-upstream-to=origin/main`, publicDir);
39+
}
40+
catch (e) {
41+
if (!existsSync(publicDir + "/index.html"))
42+
await writeFile(publicDir + "/index.html", "<html><body>Hello, World!</body></html>");
43+
}
2944
await ensureGroupStructure({ pathTo: new PathToOrganization(folderName), id: organizationId }, struct);
3045
}
3146
catch (e) {
@@ -54,12 +69,17 @@ export async function checkout_org(displayName, organizationId) {
5469
}
5570
export async function checkout() {
5671
try {
57-
const orgs = await listOrgs();
58-
return choice("Which organization would you like to clone?", orgs.map((org) => ({
59-
long: org.id,
60-
text: `${org.name}`,
61-
action: () => checkout_org(org.name, new OrganizationId(org.id)),
62-
})));
72+
return choice([], async () => {
73+
const orgs = await listOrgs();
74+
return {
75+
options: orgs.map((org) => ({
76+
long: org.id,
77+
text: `${org.name}`,
78+
action: () => checkout_org(org.name, new OrganizationId(org.id)),
79+
})),
80+
header: "Which organization would you like to clone?",
81+
};
82+
});
6383
}
6484
catch (e) {
6585
throw e;

0 commit comments

Comments
 (0)