Skip to content

Commit

Permalink
Publish
Browse files Browse the repository at this point in the history
  • Loading branch information
thedrlambda committed Jan 4, 2024
1 parent 489565c commit 2d132dd
Show file tree
Hide file tree
Showing 13 changed files with 373 additions and 92 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG → CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# NEXT:
## Breaking changes
-
## Added features
-
## Fixes and improvements
-

# 1.8.0

## Added features
- Add `post` command
## Fixes and improvements
- Don't print command when selecting default
- `public` excluded from service groups
- Fix bug where fetch would not initialize the git repos
- Make `clone` command slightly faster
- Add `.md` to `CHANGELOG` for better syntax highlighting

# 1.7.0

- Add $broadcast and $join
Expand Down
6 changes: 4 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GIT_HOST = exports.SSH_USER = exports.SSH_HOST = exports.HTTP_HOST = exports.API_URL = void 0;
exports.API_URL = `api.merrymake.io`;
exports.GIT_HOST = exports.SSH_USER = exports.SSH_HOST = exports.HTTP_HOST = exports.RAPIDS_HOST = exports.API_URL = exports.MERRYMAKE_IO = void 0;
exports.MERRYMAKE_IO = `merrymake.io`;
exports.API_URL = `api.${exports.MERRYMAKE_IO}`;
exports.RAPIDS_HOST = `https://rapids.${exports.MERRYMAKE_IO}`;
exports.HTTP_HOST = `https://${exports.API_URL}`;
exports.SSH_HOST = `${exports.API_URL}`;
exports.SSH_USER = `mist`;
Expand Down
4 changes: 3 additions & 1 deletion config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export const API_URL = `api.merrymake.io`;
export const MERRYMAKE_IO = `merrymake.io`;
export const API_URL = `api.${MERRYMAKE_IO}`;
export const RAPIDS_HOST = `https://rapids.${MERRYMAKE_IO}`;

export const HTTP_HOST = `https://${API_URL}`;
export const SSH_HOST = `${API_URL}`;
Expand Down
Binary file modified dist/windows.zip
Binary file not shown.
90 changes: 60 additions & 30 deletions executors.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
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.addKnownHost = exports.do_duplicate = exports.fetch_template = exports.createService = exports.createServiceGroup = exports.createOrganization = exports.do_clone = exports.do_fetch = void 0;
exports.do_post = 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.addKnownHost = 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");
const config_1 = require("./config");
const detect_project_type_1 = require("@merrymake/detect-project-type");
const child_process_1 = require("child_process");
const prompt_1 = require("./prompt");
const path_1 = __importDefault(require("path"));
const args_1 = require("./args");
function clone(struct, name) {
return __awaiter(this, void 0, void 0, function* () {
Expand All @@ -35,7 +34,7 @@ function clone(struct, name) {
yield (0, utils_1.execPromise)(`git init --initial-branch=main`, dir);
yield (0, utils_1.execPromise)(`git remote add origin "${config_1.GIT_HOST}/${name}/public"`, dir);
// await execPromise(`git fetch`, dir);
fetch(".", name, struct);
fetch(`./${name}`, name, struct);
}
catch (e) {
throw e;
Expand All @@ -45,10 +44,12 @@ function clone(struct, name) {
function fetch(prefix, org, struct) {
return __awaiter(this, void 0, void 0, function* () {
try {
Object.keys(struct).forEach((team) => {
fs_1.default.mkdirSync(`${prefix}/${org}/${team}`, { recursive: true });
createFolderStructure(struct[team], `${prefix}/${org}/${team}`, org, team);
});
let keys = Object.keys(struct);
for (let i = 0; i < keys.length; i++) {
let group = keys[i];
fs_1.default.mkdirSync(`${prefix}/${group}`, { recursive: true });
yield createFolderStructure(struct[group], `${prefix}/${group}`, org, group);
}
}
catch (e) {
throw e;
Expand All @@ -66,7 +67,7 @@ function do_fetch() {
}
(0, utils_1.output2)(`Fetching...`);
let structure = JSON.parse(reply);
yield fetch(path_1.default.join(org.pathToRoot, ".."), org.org.name, structure);
yield fetch(org.pathToRoot, org.org.name, structure);
}
catch (e) {
throw e;
Expand All @@ -75,34 +76,51 @@ function do_fetch() {
}
exports.do_fetch = do_fetch;
function createFolderStructure(struct, prefix, org, team) {
Object.keys(struct).forEach((k) => __awaiter(this, void 0, void 0, function* () {
if (struct[k] instanceof Object)
createFolderStructure(struct[k], prefix + "/" + k, org, team);
else {
// output(`git clone "${HOST}/${org}/${team}/${k}" "${prefix}/${k}"`);
let repo = `"${config_1.GIT_HOST}/${org}/${team}/${k}"`;
let dir = `${prefix}/${k}`;
try {
if (!fs_1.default.existsSync(dir)) {
fs_1.default.mkdirSync(dir, { recursive: true });
yield (0, utils_1.execPromise)(`git init --initial-branch=main`, dir);
yield (0, utils_1.execPromise)(`git remote add origin ${repo}`, dir);
yield fs_1.default.writeFile(dir + "/fetch.bat", `@echo off
return __awaiter(this, void 0, void 0, function* () {
try {
let keys = Object.keys(struct);
for (let i = 0; i < keys.length; i++) {
let k = keys[i];
if (struct[k] instanceof Object)
yield createFolderStructure(struct[k], prefix + "/" + k, org, team);
else {
// output(`git clone "${HOST}/${org}/${team}/${k}" "${prefix}/${k}"`);
let repo = `"${config_1.GIT_HOST}/${org}/${team}/${k}"`;
let dir = `${prefix}/${k}`;
try {
if (!fs_1.default.existsSync(dir)) {
fs_1.default.mkdirSync(dir, { recursive: true });
}
if (!fs_1.default.existsSync(dir + "/.git")) {
(0, utils_1.output2)("Here1 " + dir);
yield (0, utils_1.execPromise)(`git init --initial-branch=main`, dir);
(0, utils_1.output2)("Here2 " + dir);
yield (0, utils_1.execPromise)(`git remote add origin ${repo}`, dir);
(0, utils_1.output2)("Here3 " + dir);
fs_1.default.writeFileSync(dir + "/fetch.bat", `@echo off
git fetch
git reset --hard origin/main
del fetch.sh
(goto) 2>nul & del fetch.bat`, () => { });
yield fs_1.default.writeFile(dir + "/fetch.sh", `#!/bin/sh
(goto) 2>nul & del fetch.bat`);
fs_1.default.writeFileSync(dir + "/fetch.sh", `#!/bin/sh
git fetch
git reset --hard origin/main
rm fetch.bat fetch.sh`, () => { });
rm fetch.bat fetch.sh`);
}
else {
yield (0, utils_1.execPromise)(`git remote set-url origin ${repo}`, dir);
}
}
catch (e) {
console.log(e);
}
}
}
catch (e) {
console.log(e);
}
}
}));
catch (e) {
throw e;
}
});
}
function do_clone(name) {
return __awaiter(this, void 0, void 0, function* () {
Expand Down Expand Up @@ -227,10 +245,10 @@ function do_register(keyAction, email) {
let key = yield keyAction();
console.log("Registering...");
addKnownHost();
let result = yield (0, utils_1.urlReq)(`${config_1.HTTP_HOST}/admin/user`, "POST", {
let result = yield (0, utils_1.urlReq)(`${config_1.HTTP_HOST}/admin/user`, "POST", JSON.stringify({
email,
key,
});
}));
if (/^\d+$/.test(result.body)) {
(0, utils_1.saveCache)({ registered: true, hasOrgs: +result.body > 0 });
(0, utils_1.output2)("Registered user.");
Expand Down Expand Up @@ -549,3 +567,15 @@ function do_help() {
});
}
exports.do_help = do_help;
function do_post(eventType, key, contentType, payload) {
return __awaiter(this, void 0, void 0, function* () {
try {
let resp = yield (0, utils_1.urlReq)(`${config_1.RAPIDS_HOST}/${key}/${eventType}`, "POST", payload, contentType);
(0, utils_1.output2)(resp.body);
}
catch (e) {
throw e;
}
});
}
exports.do_post = do_post;
120 changes: 78 additions & 42 deletions executors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
getCache,
fetchOrgRaw,
} from "./utils";
import { API_URL, GIT_HOST, HTTP_HOST, SSH_USER } from "./config";
import { API_URL, GIT_HOST, HTTP_HOST, RAPIDS_HOST, SSH_USER } from "./config";
import {
detectProjectType,
BUILD_SCRIPT_MAKERS,
Expand Down Expand Up @@ -42,23 +42,25 @@ async function clone(struct: any, name: string) {
dir
);
// await execPromise(`git fetch`, dir);
fetch(".", name, struct);
fetch(`./${name}`, name, struct);
} catch (e) {
throw e;
}
}

async function fetch(prefix: string, org: string, struct: any) {
try {
Object.keys(struct).forEach((team) => {
fs.mkdirSync(`${prefix}/${org}/${team}`, { recursive: true });
createFolderStructure(
struct[team],
`${prefix}/${org}/${team}`,
let keys = Object.keys(struct);
for (let i = 0; i < keys.length; i++) {
let group = keys[i];
fs.mkdirSync(`${prefix}/${group}`, { recursive: true });
await createFolderStructure(
struct[group],
`${prefix}/${group}`,
org,
team
group
);
});
}
} catch (e) {
throw e;
}
Expand All @@ -74,53 +76,64 @@ export async function do_fetch() {
}
output2(`Fetching...`);
let structure = JSON.parse(reply);
await fetch(path.join(org.pathToRoot, ".."), org.org.name, structure);
await fetch(org.pathToRoot, org.org.name, structure);
} catch (e) {
throw e;
}
}

function createFolderStructure(
async function createFolderStructure(
struct: any,
prefix: string,
org: string,
team: string
) {
Object.keys(struct).forEach(async (k) => {
if (struct[k] instanceof Object)
createFolderStructure(struct[k], prefix + "/" + k, org, team);
else {
// output(`git clone "${HOST}/${org}/${team}/${k}" "${prefix}/${k}"`);
let repo = `"${GIT_HOST}/${org}/${team}/${k}"`;
let dir = `${prefix}/${k}`;
try {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
await execPromise(`git init --initial-branch=main`, dir);
await execPromise(`git remote add origin ${repo}`, dir);
await fs.writeFile(
dir + "/fetch.bat",
`@echo off
try {
let keys = Object.keys(struct);
for (let i = 0; i < keys.length; i++) {
let k = keys[i];
if (struct[k] instanceof Object)
await createFolderStructure(struct[k], prefix + "/" + k, org, team);
else {
// output(`git clone "${HOST}/${org}/${team}/${k}" "${prefix}/${k}"`);
let repo = `"${GIT_HOST}/${org}/${team}/${k}"`;
let dir = `${prefix}/${k}`;
try {
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
if (!fs.existsSync(dir + "/.git")) {
output2("Here1 " + dir);
await execPromise(`git init --initial-branch=main`, dir);
output2("Here2 " + dir);
await execPromise(`git remote add origin ${repo}`, dir);
output2("Here3 " + dir);
fs.writeFileSync(
dir + "/fetch.bat",
`@echo off
git fetch
git reset --hard origin/main
del fetch.sh
(goto) 2>nul & del fetch.bat`,
() => {}
);
await fs.writeFile(
dir + "/fetch.sh",
`#!/bin/sh
(goto) 2>nul & del fetch.bat`
);
fs.writeFileSync(
dir + "/fetch.sh",
`#!/bin/sh
git fetch
git reset --hard origin/main
rm fetch.bat fetch.sh`,
() => {}
);
rm fetch.bat fetch.sh`
);
} else {
await execPromise(`git remote set-url origin ${repo}`, dir);
}
} catch (e) {
console.log(e);
}
} catch (e) {
console.log(e);
}
}
});
} catch (e) {
throw e;
}
}

export async function do_clone(name: string) {
Expand Down Expand Up @@ -262,10 +275,14 @@ export async function do_register(
let key = await keyAction();
console.log("Registering...");
addKnownHost();
let result = await urlReq(`${HTTP_HOST}/admin/user`, "POST", {
email,
key,
});
let result = await urlReq(
`${HTTP_HOST}/admin/user`,
"POST",
JSON.stringify({
email,
key,
})
);
if (/^\d+$/.test(result.body)) {
saveCache({ registered: true, hasOrgs: +result.body > 0 });
output2("Registered user.");
Expand Down Expand Up @@ -637,3 +654,22 @@ export async function do_help() {
output2(`${GREEN}Inside service repo.${NORMAL_COLOR}`);
}
}

export async function do_post(
eventType: string,
key: string,
contentType: string,
payload: string
) {
try {
let resp = await urlReq(
`${RAPIDS_HOST}/${key}/${eventType}`,
"POST",
payload,
contentType
);
output2(resp.body);
} catch (e) {
throw e;
}
}
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.7.0",
"version": "1.8.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 3 additions & 1 deletion prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ function choice(options, invertedQuiet = { cmd: false, select: true }, def = 0)
if (options.length === 1) {
if ((0, args_1.getArgs)().length > 0)
(0, args_1.getArgs)().splice(0, 1);
resolve(makeSelection(options[0]));
resolve(invertedQuiet.cmd
? makeSelection(options[0])
: makeSelectionQuietly(options[0]));
return;
}
options.push({
Expand Down
Loading

0 comments on commit 2d132dd

Please sign in to comment.