ezhst 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/apps.js +2 -2
- package/dist/commands/auth.js +46 -15
- package/dist/commands/build.js +57 -0
- package/dist/commands/db.js +76 -0
- package/dist/commands/deploy.js +77 -28
- package/dist/commands/domains.js +47 -0
- package/dist/commands/email.js +75 -0
- package/dist/commands/env.js +69 -0
- package/dist/commands/keys.js +30 -0
- package/dist/commands/projects.js +65 -0
- package/dist/commands/skill.js +20 -0
- package/dist/commands/storage.js +105 -0
- package/dist/index.js +123 -31
- package/dist/lib/api.js +10 -4
- package/dist/lib/config.js +10 -6
- package/dist/lib/project.js +66 -0
- package/dist/lib/ui.js +61 -6
- package/package.json +4 -3
- package/skill/SKILL.md +100 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import pc from "picocolors";
|
|
2
|
+
import { json, request } from "../lib/api.js";
|
|
3
|
+
import { linkProject, resolveProject, resolveProjectDetail } from "../lib/project.js";
|
|
4
|
+
import { confirmed, log, output } from "../lib/ui.js";
|
|
5
|
+
export const listProjects = async () => {
|
|
6
|
+
const { apps } = await request("/apps");
|
|
7
|
+
output({ projects: apps }, () => {
|
|
8
|
+
if (!apps.length) {
|
|
9
|
+
log.info("No projects yet. Create one with `ezhst projects create <name>`.");
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
for (const project of apps) {
|
|
13
|
+
log.info(`${pc.bold(project.slug.padEnd(28))} ${project.status.padEnd(10)} ${pc.dim(project.url)}`);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
export const createProject = async (name, options) => {
|
|
18
|
+
const { app } = await request("/apps", json("POST", { name }));
|
|
19
|
+
if (options.link) {
|
|
20
|
+
await linkProject(app.slug);
|
|
21
|
+
}
|
|
22
|
+
output({ project: app }, () => log.success(`Created ${app.name}: ${app.slug} (${app.url})`));
|
|
23
|
+
};
|
|
24
|
+
export const projectInfo = async (options) => {
|
|
25
|
+
const detail = await resolveProjectDetail(options);
|
|
26
|
+
const { app, deployments, domains } = detail;
|
|
27
|
+
output(detail, () => {
|
|
28
|
+
log.info(`${pc.bold(app.name)} ${pc.dim(`(${app.slug})`)}`);
|
|
29
|
+
log.info(`Status: ${app.status}`);
|
|
30
|
+
log.info(`URL: ${app.url}`);
|
|
31
|
+
log.info(`Env: ${Object.keys(app.env).length} variables`);
|
|
32
|
+
log.info(`Domains: ${domains.map((domain) => `${domain.hostname} (${domain.status})`).join(", ") || "none"}`);
|
|
33
|
+
const latest = deployments[0];
|
|
34
|
+
if (latest) {
|
|
35
|
+
log.info(`Latest deployment: ${latest.id} ${latest.status} ${latest.createdAt}`);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
export const renameProject = async (name, options) => {
|
|
40
|
+
const project = await resolveProject(options);
|
|
41
|
+
const { app } = await request(`/apps/${project.id}`, json("PUT", { name }));
|
|
42
|
+
output({ project: app }, () => log.success(`Renamed to ${app.name}. The URL stays ${app.url}`));
|
|
43
|
+
};
|
|
44
|
+
export const deleteProject = async (options) => {
|
|
45
|
+
const project = await resolveProject(options);
|
|
46
|
+
confirmed(options.yes, `Deleting ${project.slug} removes its app, deployments, storage, database, email and API keys.`);
|
|
47
|
+
const result = await request(`/apps/${project.id}`, { method: "DELETE" });
|
|
48
|
+
output(result, () => log.success(`Deleted ${project.slug}`));
|
|
49
|
+
};
|
|
50
|
+
export const link = async (options) => {
|
|
51
|
+
const project = await linkProject(options.project);
|
|
52
|
+
output({ project }, () => log.success(`Linked to ${project.name} (${project.url})`));
|
|
53
|
+
};
|
|
54
|
+
export const logs = async (options) => {
|
|
55
|
+
const project = await resolveProject(options);
|
|
56
|
+
const { logs: text } = await request(`/apps/${project.id}/logs?tail=${options.tail ?? "200"}`);
|
|
57
|
+
output({ logs: text }, () => process.stdout.write(text || "No logs yet.\n"));
|
|
58
|
+
};
|
|
59
|
+
const setRunning = async (options, action) => {
|
|
60
|
+
const project = await resolveProject(options);
|
|
61
|
+
const { app } = await request(`/apps/${project.id}/${action}`, { method: "POST" });
|
|
62
|
+
output({ project: app }, () => log.success(`${app.slug} is ${app.status.toLowerCase()}`));
|
|
63
|
+
};
|
|
64
|
+
export const start = (options) => setRunning(options, "start");
|
|
65
|
+
export const stop = (options) => setRunning(options, "stop");
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { copyFileSync, mkdirSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { log, output } from "../lib/ui.js";
|
|
6
|
+
const SKILL_SOURCE = fileURLToPath(new URL("../../skill/SKILL.md", import.meta.url));
|
|
7
|
+
export const installSkill = (options) => {
|
|
8
|
+
let base = process.cwd();
|
|
9
|
+
if (options.global) {
|
|
10
|
+
base = homedir();
|
|
11
|
+
}
|
|
12
|
+
const directory = path.join(base, ".claude", "skills", "easyhost");
|
|
13
|
+
const target = path.join(directory, "SKILL.md");
|
|
14
|
+
mkdirSync(directory, { recursive: true });
|
|
15
|
+
copyFileSync(SKILL_SOURCE, target);
|
|
16
|
+
output({ path: target }, () => {
|
|
17
|
+
log.success(`Installed the EasyHost skill at ${target}`);
|
|
18
|
+
log.info('Ask your agent: "Deploy this app to EasyHost."');
|
|
19
|
+
});
|
|
20
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { openAsBlob, writeFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import pc from "picocolors";
|
|
4
|
+
import { json, request } from "../lib/api.js";
|
|
5
|
+
import { resolveProject } from "../lib/project.js";
|
|
6
|
+
import { confirmed, fail, formatBytes, log, output } from "../lib/ui.js";
|
|
7
|
+
const findBucket = async (options) => {
|
|
8
|
+
const project = await resolveProject(options);
|
|
9
|
+
const { buckets } = await request("/storage/buckets", {}, project.id);
|
|
10
|
+
const bucket = buckets[0];
|
|
11
|
+
if (!bucket) {
|
|
12
|
+
return fail("This project has no storage yet. Create it with `ezhst storage create <name>`.");
|
|
13
|
+
}
|
|
14
|
+
return { project, bucket };
|
|
15
|
+
};
|
|
16
|
+
const listObjects = async (projectId, bucketId, prefix = "") => {
|
|
17
|
+
const query = new URLSearchParams({ prefix });
|
|
18
|
+
return request(`/storage/buckets/${bucketId}/objects?${query}`, {}, projectId);
|
|
19
|
+
};
|
|
20
|
+
const printCredentials = (bucket) => {
|
|
21
|
+
log.info(`${pc.bold(bucket.name)} ${pc.dim(`(${bucket.minioName})`)}`);
|
|
22
|
+
log.info(`Public URL: ${bucket.baseUrl}/<key>`);
|
|
23
|
+
log.info(`S3 endpoint: ${bucket.s3.endpoint}`);
|
|
24
|
+
log.info(`Region: ${bucket.s3.region}`);
|
|
25
|
+
log.info(`Bucket: ${bucket.s3.bucket}`);
|
|
26
|
+
log.info(`Access key ID: ${bucket.s3.accessKeyId}`);
|
|
27
|
+
log.info(`Secret access key: ${bucket.s3.secretAccessKey}`);
|
|
28
|
+
log.dim("Use path-style addressing (forcePathStyle: true).");
|
|
29
|
+
};
|
|
30
|
+
export const storageInfo = async (options) => {
|
|
31
|
+
const { project, bucket } = await findBucket(options);
|
|
32
|
+
const { bucket: detail } = await listObjects(project.id, bucket.id);
|
|
33
|
+
output({ bucket: detail }, () => printCredentials(detail));
|
|
34
|
+
};
|
|
35
|
+
export const createStorage = async (name, options) => {
|
|
36
|
+
const project = await resolveProject(options);
|
|
37
|
+
const { bucket } = await request("/storage/buckets", json("POST", { name }), project.id);
|
|
38
|
+
output({ bucket }, () => {
|
|
39
|
+
log.success("Storage created");
|
|
40
|
+
printCredentials(bucket);
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
export const rotateStorageKeys = async (options) => {
|
|
44
|
+
const { project, bucket } = await findBucket(options);
|
|
45
|
+
const result = await request(`/storage/buckets/${bucket.id}/rotate-keys`, { method: "POST" }, project.id);
|
|
46
|
+
output(result, () => {
|
|
47
|
+
log.success("Keys rotated. The old keys no longer work.");
|
|
48
|
+
printCredentials(result.bucket);
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
export const listStorage = async (prefix, options) => {
|
|
52
|
+
const { project, bucket } = await findBucket(options);
|
|
53
|
+
const { objects } = await listObjects(project.id, bucket.id, prefix);
|
|
54
|
+
output({ objects }, () => {
|
|
55
|
+
if (!objects.length) {
|
|
56
|
+
log.info("No files.");
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
for (const object of objects) {
|
|
60
|
+
if (object.isFolder) {
|
|
61
|
+
log.info(pc.bold(object.key));
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
log.info(`${object.key.padEnd(48)} ${formatBytes(object.size).padStart(10)} ${pc.dim(object.url ?? "")}`);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
export const uploadStorage = async (files, options) => {
|
|
69
|
+
const { project, bucket } = await findBucket(options);
|
|
70
|
+
const uploaded = [];
|
|
71
|
+
for (const file of files) {
|
|
72
|
+
const form = new FormData();
|
|
73
|
+
form.append("file", await openAsBlob(file), path.basename(file));
|
|
74
|
+
if (options.prefix) {
|
|
75
|
+
form.append("prefix", options.prefix);
|
|
76
|
+
}
|
|
77
|
+
const result = await request(`/storage/buckets/${bucket.id}/objects`, { method: "POST", body: form }, project.id);
|
|
78
|
+
uploaded.push(result);
|
|
79
|
+
log.success(`Uploaded ${result.key}: ${result.url}`);
|
|
80
|
+
}
|
|
81
|
+
output({ uploaded }, () => undefined);
|
|
82
|
+
};
|
|
83
|
+
export const downloadStorage = async (key, destination, options) => {
|
|
84
|
+
const { bucket } = await findBucket(options);
|
|
85
|
+
const url = `${bucket.baseUrl}/${encodeURI(key)}`;
|
|
86
|
+
const res = await fetch(url);
|
|
87
|
+
if (!res.ok) {
|
|
88
|
+
fail(`Could not download ${key} (status ${res.status}).`);
|
|
89
|
+
}
|
|
90
|
+
const target = destination ?? path.basename(key);
|
|
91
|
+
writeFileSync(target, Buffer.from(await res.arrayBuffer()));
|
|
92
|
+
output({ key, path: target }, () => log.success(`Saved ${key} to ${target}`));
|
|
93
|
+
};
|
|
94
|
+
export const removeStorageObject = async (key, options) => {
|
|
95
|
+
const { project, bucket } = await findBucket(options);
|
|
96
|
+
const query = new URLSearchParams({ key });
|
|
97
|
+
const result = await request(`/storage/buckets/${bucket.id}/objects?${query}`, { method: "DELETE" }, project.id);
|
|
98
|
+
output(result, () => log.success(`Deleted ${key}`));
|
|
99
|
+
};
|
|
100
|
+
export const deleteStorage = async (options) => {
|
|
101
|
+
const { project, bucket } = await findBucket(options);
|
|
102
|
+
confirmed(options.yes, `Deleting storage ${bucket.name} removes every file in it.`);
|
|
103
|
+
const result = await request(`/storage/buckets/${bucket.id}`, { method: "DELETE" }, project.id);
|
|
104
|
+
output(result, () => log.success("Storage deleted"));
|
|
105
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -1,42 +1,134 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from "commander";
|
|
3
|
-
import { login, logout, whoami } from "./commands/auth.js";
|
|
4
|
-
import {
|
|
5
|
-
import { deploy, redeploy } from "./commands/deploy.js";
|
|
6
|
-
import {
|
|
3
|
+
import { forgotPassword, login, logout, register, resendVerification, whoami } from "./commands/auth.js";
|
|
4
|
+
import { createProject, deleteProject, link, listProjects, logs, projectInfo, renameProject, start, stop } from "./commands/projects.js";
|
|
5
|
+
import { deploy, deploymentLog, listDeployments, redeploy } from "./commands/deploy.js";
|
|
6
|
+
import { importEnv, listEnv, setEnv, unsetEnv } from "./commands/env.js";
|
|
7
|
+
import { resetBuild, setBuild, showBuild } from "./commands/build.js";
|
|
8
|
+
import { addDomain, listDomains, removeDomain, verifyDomain } from "./commands/domains.js";
|
|
9
|
+
import { createStorage, deleteStorage, downloadStorage, listStorage, removeStorageObject, rotateStorageKeys, storageInfo, uploadStorage, } from "./commands/storage.js";
|
|
10
|
+
import { createDatabase, databaseInfo, deleteDatabase, queryDatabase, resetDatabasePassword, tableRows } from "./commands/db.js";
|
|
11
|
+
import { createSender, deleteSender, emailInfo, emailLogs, sendEmail } from "./commands/email.js";
|
|
12
|
+
import { createKey, listKeys, revokeKey } from "./commands/keys.js";
|
|
13
|
+
import { installSkill } from "./commands/skill.js";
|
|
14
|
+
import { fail, setJsonMode } from "./lib/ui.js";
|
|
7
15
|
const program = new Command();
|
|
8
|
-
program.name("easyhost").description("Deploy Next.js apps to EasyHost").version("0.1.0");
|
|
9
|
-
program.command("login").description("Log in to EasyHost").option("--api <url>", "API URL").action(login);
|
|
10
|
-
program.command("logout").description("Log out").action(logout);
|
|
11
|
-
program.command("whoami").description("Show the logged in user").action(whoami);
|
|
12
|
-
program.command("apps").description("List your apps").action(listApps);
|
|
13
|
-
program.command("init").description("Link this folder to an app").action(init);
|
|
14
16
|
program
|
|
15
|
-
.
|
|
16
|
-
.description("
|
|
17
|
-
.
|
|
18
|
-
.option("--
|
|
19
|
-
.action
|
|
17
|
+
.name("ezhst")
|
|
18
|
+
.description("EasyHost from the terminal: deploy apps and manage storage, databases, email and API keys")
|
|
19
|
+
.version("0.2.0")
|
|
20
|
+
.option("--json", "Print machine-readable JSON")
|
|
21
|
+
.hook("preAction", (_command, action) => {
|
|
22
|
+
setJsonMode(!!action.optsWithGlobals().json);
|
|
23
|
+
});
|
|
24
|
+
const scoped = (command) => command.option("-p, --project <slug>", "Project slug (defaults to the linked project)");
|
|
20
25
|
program
|
|
21
|
-
.command("
|
|
22
|
-
.description("
|
|
23
|
-
.option("--
|
|
24
|
-
.option("--
|
|
25
|
-
.
|
|
26
|
+
.command("register")
|
|
27
|
+
.description("Create an account")
|
|
28
|
+
.option("--name <name>")
|
|
29
|
+
.option("--email <email>")
|
|
30
|
+
.option("--password <password>")
|
|
31
|
+
.option("--api <url>", "API URL")
|
|
32
|
+
.action(register);
|
|
26
33
|
program
|
|
27
|
-
.command("
|
|
28
|
-
.description("
|
|
29
|
-
.option("--
|
|
30
|
-
.option("--
|
|
31
|
-
.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
.command("login")
|
|
35
|
+
.description("Log in")
|
|
36
|
+
.option("--email <email>")
|
|
37
|
+
.option("--password <password>")
|
|
38
|
+
.option("--api <url>", "API URL")
|
|
39
|
+
.action(login);
|
|
40
|
+
program.command("logout").description("Log out").action(logout);
|
|
41
|
+
program.command("whoami").description("Show the logged in user").action(whoami);
|
|
42
|
+
program.command("resend-verification").description("Send the verification email again").action(resendVerification);
|
|
43
|
+
program.command("forgot-password").description("Email a password reset link").option("--email <email>").action(forgotPassword);
|
|
44
|
+
const projects = program.command("projects").description("Manage projects");
|
|
45
|
+
projects.command("list").description("List projects").action(listProjects);
|
|
46
|
+
projects
|
|
47
|
+
.command("create")
|
|
48
|
+
.description("Create a project (the name becomes its subdomain)")
|
|
49
|
+
.argument("<name>")
|
|
50
|
+
.option("--link", "Link the current folder to it")
|
|
51
|
+
.action(createProject);
|
|
52
|
+
scoped(projects.command("info").description("Show status, URL, domains and the latest deployment")).action(projectInfo);
|
|
53
|
+
scoped(projects.command("rename").description("Rename a project (the URL stays)").argument("<name>")).action(renameProject);
|
|
54
|
+
scoped(projects.command("delete").description("Delete a project and everything in it").option("--yes", "Confirm")).action(deleteProject);
|
|
55
|
+
scoped(program.command("link").description("Link the current folder to a project")).action(link);
|
|
56
|
+
scoped(program.command("deploy").description("Upload and deploy the Next.js app in this folder").option("--verbose", "Stream the build log")).action(deploy);
|
|
57
|
+
scoped(program.command("redeploy").description("Rebuild the latest upload").option("--verbose", "Stream the build log")).action(redeploy);
|
|
58
|
+
scoped(program.command("start").description("Start a stopped app")).action(start);
|
|
59
|
+
scoped(program.command("stop").description("Stop the running app")).action(stop);
|
|
60
|
+
scoped(program.command("logs").description("Show runtime logs").option("--tail <lines>", "Number of lines", "200")).action(logs);
|
|
61
|
+
const deployments = program.command("deployments").description("Deployments and build logs");
|
|
62
|
+
scoped(deployments.command("list").description("List recent deployments")).action(listDeployments);
|
|
63
|
+
scoped(deployments.command("log").description("Show a build log (latest by default)").argument("[deploymentId]")).action(deploymentLog);
|
|
64
|
+
const env = program.command("env").description("Environment variables (applied on the next deploy)");
|
|
65
|
+
scoped(env.command("list").description("List variables")).action(listEnv);
|
|
66
|
+
scoped(env.command("set").description("Set variables").argument("<pairs...>", "KEY=VALUE pairs")).action(setEnv);
|
|
67
|
+
scoped(env.command("unset").description("Remove variables").argument("<keys...>")).action(unsetEnv);
|
|
68
|
+
scoped(env.command("import").description("Merge variables from a .env file").argument("<file>")).action(importEnv);
|
|
69
|
+
const build = program.command("build").description("Build settings (empty means auto-detect)");
|
|
70
|
+
scoped(build.command("show").description("Show build settings")).action(showBuild);
|
|
71
|
+
scoped(build
|
|
72
|
+
.command("set")
|
|
73
|
+
.description('Change build settings (pass "" to reset one to auto)')
|
|
74
|
+
.option("--node <version>", "Node.js version: 20, 22 or 24")
|
|
75
|
+
.option("--root-dir <dir>", "Folder with the app's package.json")
|
|
76
|
+
.option("--install <command>", "Install command")
|
|
77
|
+
.option("--build <command>", "Build command")
|
|
78
|
+
.option("--start <command>", "Start command, must listen on $PORT")).action(setBuild);
|
|
79
|
+
scoped(build.command("reset").description("Reset every build setting to auto")).action(resetBuild);
|
|
80
|
+
const domains = program.command("domains").description("Custom domains");
|
|
81
|
+
scoped(domains.command("list").description("List domains and the DNS target")).action(listDomains);
|
|
82
|
+
scoped(domains.command("add").description("Add a domain").argument("<hostname>")).action(addDomain);
|
|
83
|
+
scoped(domains.command("verify").description("Check DNS and issue HTTPS").argument("<hostname>")).action(verifyDomain);
|
|
84
|
+
scoped(domains.command("remove").description("Remove a domain").argument("<hostname>")).action(removeDomain);
|
|
85
|
+
const storage = program.command("storage").description("S3 compatible storage");
|
|
86
|
+
scoped(storage.command("info").description("Show the bucket and S3 credentials")).action(storageInfo);
|
|
87
|
+
scoped(storage.command("create").description("Create the project's bucket").argument("<name>")).action(createStorage);
|
|
88
|
+
scoped(storage.command("rotate-keys").description("Replace the S3 access keys")).action(rotateStorageKeys);
|
|
89
|
+
scoped(storage.command("ls").description("List files").argument("[prefix]")).action(listStorage);
|
|
90
|
+
scoped(storage.command("upload").description("Upload files").argument("<files...>").option("--prefix <path>", "Folder, e.g. images/")).action(uploadStorage);
|
|
91
|
+
scoped(storage.command("download").description("Download a file").argument("<key>").argument("[output]")).action(downloadStorage);
|
|
92
|
+
scoped(storage.command("rm").description("Delete a file").argument("<key>")).action(removeStorageObject);
|
|
93
|
+
scoped(storage.command("delete").description("Delete the bucket and all files").option("--yes", "Confirm")).action(deleteStorage);
|
|
94
|
+
const db = program.command("db").description("Postgres database");
|
|
95
|
+
scoped(db.command("info").description("Show connection strings and tables")).action(databaseInfo);
|
|
96
|
+
scoped(db.command("create").description("Create the project's database").argument("<name>")).action(createDatabase);
|
|
97
|
+
scoped(db.command("query").description("Run SQL").argument("[sql]").option("--file <file>", "Read SQL from a file")).action(queryDatabase);
|
|
98
|
+
scoped(db.command("rows").description("Browse a table").argument("<table>").option("--page <n>", "Page", "1")).action(tableRows);
|
|
99
|
+
scoped(db.command("reset-password").description("Rotate the database password")).action(resetDatabasePassword);
|
|
100
|
+
scoped(db.command("delete").description("Delete the database and its data").option("--yes", "Confirm")).action(deleteDatabase);
|
|
101
|
+
const email = program.command("email").description("Transactional email");
|
|
102
|
+
scoped(email.command("info").description("Show the sender address and usage")).action(emailInfo);
|
|
103
|
+
const sender = email.command("sender").description("Sender address");
|
|
104
|
+
scoped(sender.command("create").description("Create <username>@easyhost.fun").argument("<username>")).action(createSender);
|
|
105
|
+
scoped(sender.command("delete").description("Delete the sender address")).action(deleteSender);
|
|
106
|
+
scoped(email
|
|
107
|
+
.command("send")
|
|
108
|
+
.description("Send an email")
|
|
109
|
+
.option("--from <address>")
|
|
110
|
+
.option("--to <addresses...>")
|
|
111
|
+
.option("--subject <text>")
|
|
112
|
+
.option("--text <body>")
|
|
113
|
+
.option("--html <html>")).action(sendEmail);
|
|
114
|
+
scoped(email.command("logs").description("Show sent emails").option("--page <n>", "Page", "1")).action(emailLogs);
|
|
115
|
+
const keys = program.command("keys").description("API keys for the HTTP API");
|
|
116
|
+
scoped(keys.command("list").description("List API keys")).action(listKeys);
|
|
117
|
+
scoped(keys.command("create").description("Create an API key").argument("<name>")).action(createKey);
|
|
118
|
+
scoped(keys.command("revoke").description("Revoke an API key").argument("<id>")).action(revokeKey);
|
|
119
|
+
const skill = program.command("skill").description("Agent skill");
|
|
120
|
+
skill
|
|
121
|
+
.command("install")
|
|
122
|
+
.description("Install the EasyHost skill for Claude Code")
|
|
123
|
+
.option("--global", "Install to ~/.claude/skills instead of this project")
|
|
124
|
+
.action(installSkill);
|
|
36
125
|
program.parseAsync().catch((error) => {
|
|
37
126
|
if (error?.name === "ExitPromptError") {
|
|
38
127
|
process.exit(130);
|
|
39
128
|
}
|
|
40
|
-
|
|
41
|
-
|
|
129
|
+
let message = String(error);
|
|
130
|
+
if (error instanceof Error) {
|
|
131
|
+
message = error.message;
|
|
132
|
+
}
|
|
133
|
+
fail(message);
|
|
42
134
|
});
|
package/dist/lib/api.js
CHANGED
|
@@ -6,22 +6,28 @@ export class ApiError extends Error {
|
|
|
6
6
|
this.status = status;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
export const request = async (pathname, init = {}) => {
|
|
9
|
+
export const request = async (pathname, init = {}, projectId) => {
|
|
10
10
|
const { apiUrl, token } = readConfig();
|
|
11
11
|
const headers = new Headers(init.headers);
|
|
12
12
|
if (token) {
|
|
13
13
|
headers.set("Authorization", `Bearer ${token}`);
|
|
14
14
|
}
|
|
15
|
+
if (projectId) {
|
|
16
|
+
headers.set("X-Project-ID", projectId);
|
|
17
|
+
}
|
|
15
18
|
if (init.body && typeof init.body === "string") {
|
|
16
19
|
headers.set("Content-Type", "application/json");
|
|
17
20
|
}
|
|
18
|
-
const res = await fetch(`${apiUrl}/api${pathname}`, { ...init, headers })
|
|
21
|
+
const res = await fetch(`${apiUrl}/api${pathname}`, { ...init, headers }).catch(() => {
|
|
22
|
+
throw new ApiError(`Could not reach ${apiUrl}. Log in again with \`ezhst login --api <url>\` to change it.`, 0);
|
|
23
|
+
});
|
|
19
24
|
const data = await res.json().catch(() => ({}));
|
|
20
25
|
if (!res.ok) {
|
|
21
|
-
if (res.status === 401) {
|
|
22
|
-
throw new ApiError("Not logged in. Run `
|
|
26
|
+
if (res.status === 401 && !pathname.startsWith("/auth/")) {
|
|
27
|
+
throw new ApiError("Not logged in. Run `ezhst login` or set EZHST_TOKEN.", 401);
|
|
23
28
|
}
|
|
24
29
|
throw new ApiError(data.error ?? `Request failed with status ${res.status}`, res.status);
|
|
25
30
|
}
|
|
26
31
|
return data;
|
|
27
32
|
};
|
|
33
|
+
export const json = (method, body) => ({ method, body: JSON.stringify(body) });
|
package/dist/lib/config.js
CHANGED
|
@@ -4,12 +4,16 @@ import path from "node:path";
|
|
|
4
4
|
const CONFIG_DIR = path.join(homedir(), ".easyhost");
|
|
5
5
|
const CONFIG_FILE = path.join(CONFIG_DIR, "config.json");
|
|
6
6
|
const PROJECT_FILE = ".easyhost.json";
|
|
7
|
-
|
|
7
|
+
const PRODUCTION_API_URL = "https://api.easyhost.fun";
|
|
8
8
|
export const readConfig = () => {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
let config = { apiUrl: PRODUCTION_API_URL };
|
|
10
|
+
if (existsSync(CONFIG_FILE)) {
|
|
11
|
+
config = { ...config, ...JSON.parse(readFileSync(CONFIG_FILE, "utf8")) };
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
+
if (process.env.EZHST_TOKEN) {
|
|
14
|
+
config.token = process.env.EZHST_TOKEN;
|
|
15
|
+
}
|
|
16
|
+
return config;
|
|
13
17
|
};
|
|
14
18
|
export const writeConfig = (config) => {
|
|
15
19
|
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
@@ -18,13 +22,13 @@ export const writeConfig = (config) => {
|
|
|
18
22
|
export const clearConfig = () => {
|
|
19
23
|
rmSync(CONFIG_FILE, { force: true });
|
|
20
24
|
};
|
|
21
|
-
export const
|
|
25
|
+
export const readLinkedProject = (cwd = process.cwd()) => {
|
|
22
26
|
const file = path.join(cwd, PROJECT_FILE);
|
|
23
27
|
if (!existsSync(file)) {
|
|
24
28
|
return null;
|
|
25
29
|
}
|
|
26
30
|
return JSON.parse(readFileSync(file, "utf8"));
|
|
27
31
|
};
|
|
28
|
-
export const
|
|
32
|
+
export const writeLinkedProject = (project, cwd = process.cwd()) => {
|
|
29
33
|
writeFileSync(path.join(cwd, PROJECT_FILE), `${JSON.stringify(project, null, 2)}\n`);
|
|
30
34
|
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { input, select } from "@inquirer/prompts";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { request } from "./api.js";
|
|
4
|
+
import { readLinkedProject, writeLinkedProject } from "./config.js";
|
|
5
|
+
import { fail, isInteractive, log } from "./ui.js";
|
|
6
|
+
const slugify = (value) => {
|
|
7
|
+
return value
|
|
8
|
+
.toLowerCase()
|
|
9
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
10
|
+
.replace(/(^-|-$)/g, "");
|
|
11
|
+
};
|
|
12
|
+
export const fetchProject = (idOrSlug) => request(`/apps/${idOrSlug}`);
|
|
13
|
+
const chooseProject = async () => {
|
|
14
|
+
const { apps } = await request("/apps");
|
|
15
|
+
const NEW_PROJECT = "__new__";
|
|
16
|
+
let choice = NEW_PROJECT;
|
|
17
|
+
if (apps.length) {
|
|
18
|
+
choice = await select({
|
|
19
|
+
message: "Which project should this folder use?",
|
|
20
|
+
choices: [
|
|
21
|
+
{ name: "Create a new project", value: NEW_PROJECT },
|
|
22
|
+
...apps.map((project) => ({ name: `${project.name} (${project.url})`, value: project.id })),
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const existing = apps.find((project) => project.id === choice);
|
|
27
|
+
if (existing) {
|
|
28
|
+
return existing;
|
|
29
|
+
}
|
|
30
|
+
const name = await input({ message: "Project name (used as subdomain)", default: slugify(path.basename(process.cwd())) });
|
|
31
|
+
const { app } = await request("/apps", { method: "POST", body: JSON.stringify({ name }) });
|
|
32
|
+
log.success(`Created project ${app.name} (${app.url})`);
|
|
33
|
+
return app;
|
|
34
|
+
};
|
|
35
|
+
export const linkProject = async (slug) => {
|
|
36
|
+
let project;
|
|
37
|
+
if (slug) {
|
|
38
|
+
project = (await fetchProject(slug)).app;
|
|
39
|
+
}
|
|
40
|
+
else if (isInteractive()) {
|
|
41
|
+
project = await chooseProject();
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
return fail("Missing --project <slug>. List projects with `ezhst projects list`.");
|
|
45
|
+
}
|
|
46
|
+
writeLinkedProject({ projectId: project.id, slug: project.slug });
|
|
47
|
+
log.dim("Saved link in .easyhost.json");
|
|
48
|
+
return project;
|
|
49
|
+
};
|
|
50
|
+
export const resolveProjectDetail = async (options) => {
|
|
51
|
+
if (options.project) {
|
|
52
|
+
return fetchProject(options.project);
|
|
53
|
+
}
|
|
54
|
+
const linked = readLinkedProject();
|
|
55
|
+
if (linked) {
|
|
56
|
+
return fetchProject(linked.projectId);
|
|
57
|
+
}
|
|
58
|
+
if (!isInteractive()) {
|
|
59
|
+
return fail("No project linked. Pass --project <slug> or run `ezhst link --project <slug>`.");
|
|
60
|
+
}
|
|
61
|
+
const project = await linkProject();
|
|
62
|
+
return fetchProject(project.id);
|
|
63
|
+
};
|
|
64
|
+
export const resolveProject = async (options) => {
|
|
65
|
+
return (await resolveProjectDetail(options)).app;
|
|
66
|
+
};
|
package/dist/lib/ui.js
CHANGED
|
@@ -1,13 +1,68 @@
|
|
|
1
1
|
import pc from "picocolors";
|
|
2
|
+
let jsonMode = false;
|
|
3
|
+
export const setJsonMode = (enabled) => {
|
|
4
|
+
jsonMode = enabled;
|
|
5
|
+
};
|
|
6
|
+
export const isJsonMode = () => jsonMode;
|
|
7
|
+
const write = (message) => {
|
|
8
|
+
if (jsonMode) {
|
|
9
|
+
console.error(message);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
console.log(message);
|
|
13
|
+
};
|
|
2
14
|
export const log = {
|
|
3
|
-
info: (message) =>
|
|
4
|
-
step: (message) =>
|
|
5
|
-
success: (message) =>
|
|
6
|
-
warn: (message) =>
|
|
15
|
+
info: (message) => write(message),
|
|
16
|
+
step: (message) => write(pc.cyan(message)),
|
|
17
|
+
success: (message) => write(pc.green(message)),
|
|
18
|
+
warn: (message) => write(pc.yellow(message)),
|
|
7
19
|
error: (message) => console.error(pc.red(message)),
|
|
8
|
-
dim: (message) =>
|
|
20
|
+
dim: (message) => write(pc.dim(message)),
|
|
9
21
|
};
|
|
10
22
|
export const fail = (message) => {
|
|
11
|
-
|
|
23
|
+
if (jsonMode) {
|
|
24
|
+
console.log(JSON.stringify({ error: message }));
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
log.error(message);
|
|
28
|
+
}
|
|
12
29
|
process.exit(1);
|
|
13
30
|
};
|
|
31
|
+
export const output = (data, human) => {
|
|
32
|
+
if (jsonMode) {
|
|
33
|
+
console.log(JSON.stringify(data, null, 2));
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
human();
|
|
37
|
+
};
|
|
38
|
+
export const isInteractive = () => !!process.stdin.isTTY && !!process.stdout.isTTY && !jsonMode;
|
|
39
|
+
export const required = async (value, flag, ask) => {
|
|
40
|
+
if (value !== undefined) {
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
if (!isInteractive()) {
|
|
44
|
+
return fail(`Missing ${flag}.`);
|
|
45
|
+
}
|
|
46
|
+
return ask();
|
|
47
|
+
};
|
|
48
|
+
export const confirmed = (yes, warning) => {
|
|
49
|
+
if (!yes) {
|
|
50
|
+
fail(`${warning} This cannot be undone. Rerun with --yes to confirm.`);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
export const table = (rows) => {
|
|
54
|
+
if (!rows.length) {
|
|
55
|
+
log.dim("No rows.");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
console.table(rows);
|
|
59
|
+
};
|
|
60
|
+
export const formatBytes = (bytes) => {
|
|
61
|
+
if (bytes < 1024) {
|
|
62
|
+
return `${bytes} B`;
|
|
63
|
+
}
|
|
64
|
+
if (bytes < 1024 * 1024) {
|
|
65
|
+
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
66
|
+
}
|
|
67
|
+
return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
68
|
+
};
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ezhst",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "EasyHost CLI: agent-first hosting for Next.js apps with storage, databases and email",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"ezhst": "dist/index.js"
|
|
8
8
|
},
|
|
9
9
|
"files": [
|
|
10
|
-
"dist"
|
|
10
|
+
"dist",
|
|
11
|
+
"skill"
|
|
11
12
|
],
|
|
12
13
|
"scripts": {
|
|
13
14
|
"dev": "tsx src/index.ts",
|