ezhst 0.3.0 → 0.4.1

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.
@@ -1,59 +1,24 @@
1
- import pc from "picocolors";
2
- import { request } from "../lib/api.js";
3
- import { linkApp, resolveApp } from "../lib/resolve-app.js";
4
- import { log } from "../lib/ui.js";
5
- export const listApps = async () => {
6
- const { apps } = await request("/apps");
7
- if (!apps.length) {
8
- log.info("No apps yet. Run `ezhst deploy` inside a Next.js project.");
9
- return;
10
- }
11
- for (const app of apps) {
12
- log.info(`${pc.bold(app.name.padEnd(24))} ${app.status.padEnd(10)} ${pc.dim(app.url)}`);
13
- }
14
- };
15
- export const init = async () => {
16
- const app = await linkApp();
17
- log.success(`Linked to ${app.name}`);
18
- };
19
- export const logs = async (options) => {
20
- const app = await resolveApp(options.app);
21
- const { logs: output } = await request(`/apps/${app.id}/logs?tail=${options.tail ?? "200"}`);
22
- process.stdout.write(output || "No logs yet.\n");
23
- };
24
- export const listEnv = async (options) => {
25
- const app = await resolveApp(options.app);
26
- const entries = Object.entries(app.env ?? {});
27
- if (!entries.length) {
28
- log.info("No environment variables set.");
29
- return;
30
- }
31
- for (const [key, value] of entries) {
32
- log.info(`${key}=${value}`);
33
- }
34
- };
35
- const saveEnv = async (app, env) => {
36
- await request(`/apps/${app.id}/env`, { method: "PUT", body: JSON.stringify({ env }) });
37
- log.success("Environment saved. Run `ezhst redeploy` to apply it.");
38
- };
39
- export const setEnv = async (pairs, options) => {
40
- const app = await resolveApp(options.app);
41
- const env = { ...(app.env ?? {}) };
42
- for (const pair of pairs) {
43
- const index = pair.indexOf("=");
44
- if (index < 1) {
45
- log.error(`Invalid pair "${pair}". Use KEY=VALUE.`);
46
- process.exit(1);
1
+ import { json, request } from "../lib/api.js";
2
+ import { resolveApp, resolveProject } from "../lib/project.js";
3
+ import { confirmed, log, output } from "../lib/ui.js";
4
+ export const listApps = async (options) => {
5
+ await resolveProject(options);
6
+ const result = await request("/apps");
7
+ output(result, () => {
8
+ log.info(`${result.apps.length}/${result.limit} apps`);
9
+ for (const app of result.apps) {
10
+ log.info(`${app.slug.padEnd(40)} ${app.status.padEnd(10)} ${app.url}`);
47
11
  }
48
- env[pair.slice(0, index)] = pair.slice(index + 1);
49
- }
50
- await saveEnv(app, env);
12
+ });
13
+ };
14
+ export const createApp = async (name, options) => {
15
+ await resolveProject(options);
16
+ const { app } = await request("/apps", json("POST", { name }));
17
+ output({ app }, () => log.success(`Created ${app.name}: ${app.slug} (${app.url})`));
51
18
  };
52
- export const unsetEnv = async (keys, options) => {
53
- const app = await resolveApp(options.app);
54
- const env = { ...(app.env ?? {}) };
55
- for (const key of keys) {
56
- delete env[key];
57
- }
58
- await saveEnv(app, env);
19
+ export const deleteApp = async (options) => {
20
+ const app = await resolveApp(options);
21
+ confirmed(options.yes, `Deleting ${app.slug} removes this app, its deployments and domains.`);
22
+ const result = await request(`/apps/${app.id}`, { method: "DELETE" });
23
+ output(result, () => log.success(`Deleted ${app.slug}`));
59
24
  };
@@ -1,5 +1,5 @@
1
1
  import { json, request } from "../lib/api.js";
2
- import { resolveProject } from "../lib/project.js";
2
+ import { resolveApp } from "../lib/project.js";
3
3
  import { log, output } from "../lib/ui.js";
4
4
  const settingsOf = (project) => ({
5
5
  nodeVersion: project.nodeVersion,
@@ -34,11 +34,11 @@ const saveSettings = async (project, settings) => {
34
34
  });
35
35
  };
36
36
  export const showBuild = async (options) => {
37
- const project = await resolveProject(options);
37
+ const project = await resolveApp(options);
38
38
  output({ build: settingsOf(project) }, () => printSettings(project));
39
39
  };
40
40
  export const setBuild = async (options) => {
41
- const project = await resolveProject(options);
41
+ const project = await resolveApp(options);
42
42
  let nodeVersion = pick(options.node, project.nodeVersion);
43
43
  if (!nodeVersion) {
44
44
  nodeVersion = null;
@@ -52,6 +52,6 @@ export const setBuild = async (options) => {
52
52
  });
53
53
  };
54
54
  export const resetBuild = async (options) => {
55
- const project = await resolveProject(options);
55
+ const project = await resolveApp(options);
56
56
  await saveSettings(project, { nodeVersion: null, rootDir: "", installCommand: "", buildCommand: "", startCommand: "" });
57
57
  };
@@ -5,7 +5,7 @@ import * as tar from "tar";
5
5
  import pc from "picocolors";
6
6
  import ora from "ora";
7
7
  import { request } from "../lib/api.js";
8
- import { resolveProject, resolveProjectDetail } from "../lib/project.js";
8
+ import { resolveApp, resolveAppDetail } from "../lib/project.js";
9
9
  import { fail, isJsonMode, log, output } from "../lib/ui.js";
10
10
  const IGNORED_DIRS = new Set(["node_modules", ".next", ".git", ".vercel", ".turbo", ".swc"]);
11
11
  const IGNORED_FILES = new Set([".DS_Store", ".easyhost.json"]);
@@ -20,17 +20,14 @@ const isIgnored = (entry) => {
20
20
  }
21
21
  return name.startsWith(".env") && name !== ".env.example";
22
22
  };
23
- const assertNextProject = (cwd) => {
23
+ const assertNodeProject = (cwd) => {
24
24
  const pkgFile = path.join(cwd, "package.json");
25
25
  if (!existsSync(pkgFile)) {
26
- fail("No package.json found. Run this inside your Next.js project.");
26
+ fail("No package.json found. Run this inside your Node.js app.");
27
27
  }
28
28
  const pkg = JSON.parse(readFileSync(pkgFile, "utf8"));
29
- if (!pkg.dependencies?.next && !pkg.devDependencies?.next) {
30
- fail("This does not look like a Next.js project. Only Next.js apps are supported right now.");
31
- }
32
- if (!pkg.scripts?.build) {
33
- fail("No build script found in package.json.");
29
+ if (!pkg || typeof pkg !== "object" || Array.isArray(pkg)) {
30
+ fail("package.json must contain a JSON object.");
34
31
  }
35
32
  };
36
33
  const packSource = async (cwd) => {
@@ -160,8 +157,8 @@ const finish = (project, deploymentId, url, result, cwd) => {
160
157
  };
161
158
  export const deploy = async (options) => {
162
159
  const cwd = process.cwd();
163
- assertNextProject(cwd);
164
- const project = await resolveProject(options);
160
+ assertNodeProject(cwd);
161
+ const project = await resolveApp(options, true);
165
162
  log.info(`\nDeploying ${pc.bold(project.name)}\n`);
166
163
  const { stage, archive } = await withSpinner("Packaging source", () => "Packaged source", () => packSource(cwd));
167
164
  try {
@@ -183,14 +180,14 @@ export const deploy = async (options) => {
183
180
  }
184
181
  };
185
182
  export const redeploy = async (options) => {
186
- const project = await resolveProject(options);
183
+ const project = await resolveApp(options);
187
184
  log.info(`\nRedeploying ${pc.bold(project.name)}\n`);
188
185
  const { deployment, url } = await withSpinner("Queueing redeploy", () => "Queued redeploy", () => request(`/apps/${project.id}/redeploy`, { method: "POST" }));
189
186
  const result = await followDeployment(project, deployment.id, !!options.verbose);
190
187
  finish(project, deployment.id, url, result);
191
188
  };
192
189
  export const listDeployments = async (options) => {
193
- const { deployments } = await resolveProjectDetail(options);
190
+ const { deployments } = await resolveAppDetail(options);
194
191
  output({ deployments }, () => {
195
192
  if (!deployments.length) {
196
193
  log.info("No deployments yet. Run `ezhst deploy`.");
@@ -202,7 +199,7 @@ export const listDeployments = async (options) => {
202
199
  });
203
200
  };
204
201
  export const deploymentLog = async (deploymentId, options) => {
205
- const { app, deployments } = await resolveProjectDetail(options);
202
+ const { app, deployments } = await resolveAppDetail(options);
206
203
  const id = deploymentId ?? deployments[0]?.id;
207
204
  if (!id) {
208
205
  fail("No deployments yet. Run `ezhst deploy`.");
@@ -1,6 +1,6 @@
1
1
  import pc from "picocolors";
2
2
  import { json, request } from "../lib/api.js";
3
- import { resolveProjectDetail } from "../lib/project.js";
3
+ import { resolveAppDetail } from "../lib/project.js";
4
4
  import { fail, log, output } from "../lib/ui.js";
5
5
  const findDomain = (domains, hostname) => {
6
6
  const domain = domains.find((item) => item.hostname === hostname.toLowerCase());
@@ -10,7 +10,7 @@ const findDomain = (domains, hostname) => {
10
10
  return domain;
11
11
  };
12
12
  export const listDomains = async (options) => {
13
- const { domains, dnsTarget } = await resolveProjectDetail(options);
13
+ const { domains, dnsTarget } = await resolveAppDetail(options);
14
14
  output({ domains, dnsTarget }, () => {
15
15
  if (!domains.length) {
16
16
  log.info("No custom domains yet. Add one with `ezhst domains add <hostname>`.");
@@ -25,7 +25,7 @@ export const listDomains = async (options) => {
25
25
  });
26
26
  };
27
27
  export const addDomain = async (hostname, options) => {
28
- const { app, dnsTarget } = await resolveProjectDetail(options);
28
+ const { app, dnsTarget } = await resolveAppDetail(options);
29
29
  const { domain } = await request(`/apps/${app.id}/domains`, json("POST", { hostname }));
30
30
  output({ domain, dnsTarget }, () => {
31
31
  log.success(`Added ${domain.hostname}.`);
@@ -34,13 +34,13 @@ export const addDomain = async (hostname, options) => {
34
34
  });
35
35
  };
36
36
  export const verifyDomain = async (hostname, options) => {
37
- const { app, domains } = await resolveProjectDetail(options);
37
+ const { app, domains } = await resolveAppDetail(options);
38
38
  const domain = findDomain(domains, hostname);
39
39
  const result = await request(`/apps/${app.id}/domains/${domain.id}/verify`, { method: "POST" });
40
40
  output(result, () => log.success(`${result.domain.hostname} is ${result.domain.status.toLowerCase()}`));
41
41
  };
42
42
  export const removeDomain = async (hostname, options) => {
43
- const { app, domains } = await resolveProjectDetail(options);
43
+ const { app, domains } = await resolveAppDetail(options);
44
44
  const domain = findDomain(domains, hostname);
45
45
  const result = await request(`/apps/${app.id}/domains/${domain.id}`, { method: "DELETE" });
46
46
  output(result, () => log.success(`Removed ${domain.hostname}`));
@@ -1,6 +1,6 @@
1
1
  import { readFileSync } from "node:fs";
2
2
  import { json, request } from "../lib/api.js";
3
- import { resolveProject } from "../lib/project.js";
3
+ import { resolveApp } from "../lib/project.js";
4
4
  import { fail, log, output } from "../lib/ui.js";
5
5
  const saveEnv = async (project, env) => {
6
6
  await request(`/apps/${project.id}/env`, json("PUT", { env }));
@@ -27,7 +27,7 @@ const parseDotenv = (text) => {
27
27
  return entries;
28
28
  };
29
29
  export const listEnv = async (options) => {
30
- const project = await resolveProject(options);
30
+ const project = await resolveApp(options);
31
31
  output({ env: project.env }, () => {
32
32
  const entries = Object.entries(project.env);
33
33
  if (!entries.length) {
@@ -40,7 +40,7 @@ export const listEnv = async (options) => {
40
40
  });
41
41
  };
42
42
  export const setEnv = async (pairs, options) => {
43
- const project = await resolveProject(options);
43
+ const project = await resolveApp(options);
44
44
  const env = { ...project.env };
45
45
  for (const pair of pairs) {
46
46
  const index = pair.indexOf("=");
@@ -52,7 +52,7 @@ export const setEnv = async (pairs, options) => {
52
52
  await saveEnv(project, env);
53
53
  };
54
54
  export const unsetEnv = async (keys, options) => {
55
- const project = await resolveProject(options);
55
+ const project = await resolveApp(options);
56
56
  const env = { ...project.env };
57
57
  for (const key of keys) {
58
58
  delete env[key];
@@ -60,7 +60,7 @@ export const unsetEnv = async (keys, options) => {
60
60
  await saveEnv(project, env);
61
61
  };
62
62
  export const importEnv = async (file, options) => {
63
- const project = await resolveProject(options);
63
+ const project = await resolveApp(options);
64
64
  const imported = parseDotenv(readFileSync(file, "utf8"));
65
65
  if (!Object.keys(imported).length) {
66
66
  fail(`No variables found in ${file}.`);
@@ -1,65 +1,67 @@
1
1
  import pc from "picocolors";
2
2
  import { json, request } from "../lib/api.js";
3
- import { linkProject, resolveProject, resolveProjectDetail } from "../lib/project.js";
3
+ import { linkProject, resolveApp, resolveProject } from "../lib/project.js";
4
+ import { writeLinkedProject } from "../lib/config.js";
4
5
  import { confirmed, log, output } from "../lib/ui.js";
5
6
  export const listProjects = async () => {
6
- const { apps } = await request("/apps");
7
- output({ projects: apps }, () => {
8
- if (!apps.length) {
7
+ const { projects } = await request("/projects");
8
+ output({ projects }, () => {
9
+ if (!projects.length) {
9
10
  log.info("No projects yet. Create one with `ezhst projects create <name>`.");
10
- return;
11
11
  }
12
- for (const project of apps) {
13
- log.info(`${pc.bold(project.slug.padEnd(28))} ${project.status.padEnd(10)} ${pc.dim(project.url)}`);
12
+ for (const project of projects) {
13
+ log.info(`${pc.bold(project.slug.padEnd(40))} ${project.name}`);
14
14
  }
15
15
  });
16
16
  };
17
17
  export const createProject = async (name, options) => {
18
- const { app } = await request("/apps", json("POST", { name }));
18
+ const { project } = await request("/projects", json("POST", { name }));
19
19
  if (options.link) {
20
- await linkProject(app.slug);
20
+ await linkProject(project.slug);
21
21
  }
22
- output({ project: app }, () => log.success(`Created ${app.name}: ${app.slug} (${app.url})`));
22
+ output({ project }, () => log.success(`Created ${project.name}: ${project.slug}`));
23
23
  };
24
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}`);
25
+ const project = await resolveProject(options);
26
+ const { apps } = await request("/apps");
27
+ output({ project, apps }, () => {
28
+ log.info(`${pc.bold(project.name)} (${project.slug})`);
29
+ for (const app of apps) {
30
+ log.info(`${app.slug} ${app.status} ${app.url}`);
36
31
  }
37
32
  });
38
33
  };
39
34
  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}`));
35
+ const current = await resolveProject(options);
36
+ const { project } = await request(`/projects/${current.id}`, json("PUT", { name }));
37
+ output({ project }, () => log.success(`Renamed to ${project.name}`));
43
38
  };
44
39
  export const deleteProject = async (options) => {
45
40
  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" });
41
+ confirmed(options.yes, `Deleting ${project.slug} removes all apps, deployments, schedules, storage, database, email and API keys.`);
42
+ const result = await request(`/projects/${project.id}`, { method: "DELETE" });
48
43
  output(result, () => log.success(`Deleted ${project.slug}`));
49
44
  };
50
45
  export const link = async (options) => {
51
46
  const project = await linkProject(options.project);
52
- output({ project }, () => log.success(`Linked to ${project.name} (${project.url})`));
47
+ if (options.app) {
48
+ const app = await resolveApp({ project: project.id, app: options.app });
49
+ writeLinkedProject({ projectId: project.id, slug: project.slug, appId: app.id });
50
+ output({ project, app }, () => log.success(`Linked to ${project.name} / ${app.name}`));
51
+ }
52
+ else {
53
+ output({ project }, () => log.success(`Linked to ${project.name}`));
54
+ }
53
55
  };
54
56
  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
+ const app = await resolveApp(options);
58
+ const { logs: text } = await request(`/apps/${app.id}/logs?tail=${options.tail ?? "200"}`);
57
59
  output({ logs: text }, () => process.stdout.write(text || "No logs yet.\n"));
58
60
  };
59
61
  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()}`));
62
+ const current = await resolveApp(options);
63
+ const { app } = await request(`/apps/${current.id}/${action}`, { method: "POST" });
64
+ output({ app }, () => log.success(`${app.slug} is ${app.status.toLowerCase()}`));
63
65
  };
64
66
  export const start = (options) => setRunning(options, "start");
65
67
  export const stop = (options) => setRunning(options, "stop");
@@ -0,0 +1,74 @@
1
+ import { json, request } from "../lib/api.js";
2
+ import { resolveProject } from "../lib/project.js";
3
+ import { confirmed, fail, log, output } from "../lib/ui.js";
4
+ const overview = async (options) => {
5
+ await resolveProject(options);
6
+ return request("/schedules");
7
+ };
8
+ const findSchedule = async (id, options) => {
9
+ const { schedules } = await overview(options);
10
+ const schedule = schedules.find((item) => item.id === id);
11
+ return schedule ?? fail("Schedule not found in this project");
12
+ };
13
+ const payload = (name, options, current) => {
14
+ const url = options.url ?? current?.url;
15
+ const intervalMinutes = options.every === undefined ? current?.intervalMinutes : Number(options.every);
16
+ if (!url || intervalMinutes === undefined) {
17
+ return fail("Pass --url <url> and --every <minutes>.");
18
+ }
19
+ let headers = current?.headers ?? {};
20
+ if (options.headers !== undefined) {
21
+ try {
22
+ headers = JSON.parse(options.headers);
23
+ }
24
+ catch {
25
+ return fail("--headers must be a JSON object with string values");
26
+ }
27
+ }
28
+ if (!headers || typeof headers !== "object" || Array.isArray(headers) || Object.values(headers).some((value) => typeof value !== "string")) {
29
+ return fail("--headers must be a JSON object with string values");
30
+ }
31
+ const method = (options.method ?? current?.method ?? "GET").toUpperCase();
32
+ return { name, url, intervalMinutes, method, headers, body: options.body ?? current?.body ?? null, enabled: options.paused ? false : current?.enabled ?? true };
33
+ };
34
+ export const listSchedules = async (options) => {
35
+ const data = await overview(options);
36
+ output(data, () => {
37
+ log.info(`${data.schedules.length}/${data.limit} schedules`);
38
+ for (const schedule of data.schedules) {
39
+ log.info(`${schedule.id} ${schedule.enabled ? "ACTIVE" : "PAUSED"} every ${schedule.intervalMinutes}m ${schedule.name}: ${schedule.method} ${schedule.url}`);
40
+ }
41
+ });
42
+ };
43
+ export const createSchedule = async (name, options) => {
44
+ await resolveProject(options);
45
+ const result = await request("/schedules", json("POST", payload(name, options)));
46
+ output(result, () => log.success(`Created schedule ${result.schedule.name} (${result.schedule.id})`));
47
+ };
48
+ export const updateSchedule = async (id, options) => {
49
+ const current = await findSchedule(id, options);
50
+ const result = await request(`/schedules/${id}`, json("PUT", payload(options.name ?? current.name, options, current)));
51
+ output(result, () => log.success(result.message));
52
+ };
53
+ export const setScheduleState = async (id, enabled, options) => {
54
+ await resolveProject(options);
55
+ const result = await request(`/schedules/${id}`, json("PATCH", { enabled }));
56
+ output(result, () => log.success(result.message));
57
+ };
58
+ export const scheduleLogs = async (id, options) => {
59
+ const schedule = await findSchedule(id, options);
60
+ output({ runs: schedule.runs }, () => {
61
+ for (const run of schedule.runs) {
62
+ log.info(`${run.startedAt} ${run.error ?? `HTTP ${run.statusCode}`} ${run.durationMs}ms`);
63
+ }
64
+ if (!schedule.runs.length) {
65
+ log.info("No runs yet.");
66
+ }
67
+ });
68
+ };
69
+ export const deleteSchedule = async (id, options) => {
70
+ await resolveProject(options);
71
+ confirmed(options.yes, "Deleting this schedule stops future calls and removes its run history.");
72
+ const result = await request(`/schedules/${id}`, { method: "DELETE" });
73
+ output(result, () => log.success(result.message));
74
+ };
package/dist/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command } from "commander";
3
3
  import { forgotPassword, login, logout, register, resendVerification, whoami } from "./commands/auth.js";
4
+ import { createApp, deleteApp, listApps } from "./commands/apps.js";
5
+ import { createSchedule, deleteSchedule, listSchedules, scheduleLogs, setScheduleState, updateSchedule } from "./commands/schedules.js";
4
6
  import { createProject, deleteProject, link, listProjects, logs, projectInfo, renameProject, start, stop } from "./commands/projects.js";
5
7
  import { deploy, deploymentLog, listDeployments, redeploy } from "./commands/deploy.js";
6
8
  import { importEnv, listEnv, setEnv, unsetEnv } from "./commands/env.js";
@@ -22,6 +24,7 @@ program
22
24
  setJsonMode(!!action.optsWithGlobals().json);
23
25
  });
24
26
  const scoped = (command) => command.option("-p, --project <slug>", "Project slug (defaults to the linked project)");
27
+ const appScoped = (command) => scoped(command).option("-a, --app <slug>", "App slug or ID (defaults to the linked or only app)");
25
28
  program
26
29
  .command("register")
27
30
  .description("Create an account")
@@ -45,30 +48,30 @@ const projects = program.command("projects").description("Manage projects");
45
48
  projects.command("list").description("List projects").action(listProjects);
46
49
  projects
47
50
  .command("create")
48
- .description("Create a project (the name becomes its subdomain)")
51
+ .description("Create a project for apps and shared services")
49
52
  .argument("<name>")
50
53
  .option("--link", "Link the current folder to it")
51
54
  .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);
55
+ scoped(projects.command("info").description("Show project details")).action(projectInfo);
56
+ scoped(projects.command("rename").description("Rename a project").argument("<name>")).action(renameProject);
54
57
  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);
58
+ appScoped(program.command("link").description("Link the current folder to a project")).action(link);
59
+ appScoped(program.command("deploy").description("Upload and deploy the Node.js app in this folder").option("--verbose", "Stream the build log")).action(deploy);
60
+ appScoped(program.command("redeploy").description("Rebuild the latest upload").option("--verbose", "Stream the build log")).action(redeploy);
61
+ appScoped(program.command("start").description("Start a stopped app")).action(start);
62
+ appScoped(program.command("stop").description("Stop the running app")).action(stop);
63
+ appScoped(program.command("logs").description("Show runtime logs").option("--tail <lines>", "Number of lines", "200")).action(logs);
61
64
  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);
65
+ appScoped(deployments.command("list").description("List recent deployments")).action(listDeployments);
66
+ appScoped(deployments.command("log").description("Show a build log (latest by default)").argument("[deploymentId]")).action(deploymentLog);
64
67
  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);
68
+ appScoped(env.command("list").description("List variables")).action(listEnv);
69
+ appScoped(env.command("set").description("Set variables").argument("<pairs...>", "KEY=VALUE pairs")).action(setEnv);
70
+ appScoped(env.command("unset").description("Remove variables").argument("<keys...>")).action(unsetEnv);
71
+ appScoped(env.command("import").description("Merge variables from a .env file").argument("<file>")).action(importEnv);
69
72
  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
73
+ appScoped(build.command("show").description("Show build settings")).action(showBuild);
74
+ appScoped(build
72
75
  .command("set")
73
76
  .description('Change build settings (pass "" to reset one to auto)')
74
77
  .option("--node <version>", "Node.js version: 20, 22 or 24")
@@ -76,12 +79,31 @@ scoped(build
76
79
  .option("--install <command>", "Install command")
77
80
  .option("--build <command>", "Build command")
78
81
  .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);
82
+ appScoped(build.command("reset").description("Reset every build setting to auto")).action(resetBuild);
80
83
  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);
84
+ appScoped(domains.command("list").description("List domains and the DNS target")).action(listDomains);
85
+ appScoped(domains.command("add").description("Add a domain").argument("<hostname>")).action(addDomain);
86
+ appScoped(domains.command("verify").description("Check DNS and issue HTTPS").argument("<hostname>")).action(verifyDomain);
87
+ appScoped(domains.command("remove").description("Remove a domain").argument("<hostname>")).action(removeDomain);
88
+ const apps = program.command("apps").description("Manage up to five Node.js apps per project");
89
+ scoped(apps.command("list").description("List apps in a project")).action(listApps);
90
+ scoped(apps.command("create").description("Create an app").argument("<name>")).action(createApp);
91
+ appScoped(apps.command("delete").description("Delete one app and its deployments").option("--yes", "Confirm")).action(deleteApp);
92
+ const schedules = program.command("schedules").description("Scheduled API calls, up to five per project");
93
+ scoped(schedules.command("list").description("List schedules and recent results")).action(listSchedules);
94
+ const scheduleOptions = (command) => scoped(command)
95
+ .option("--url <url>", "Public API URL")
96
+ .option("--every <minutes>", "Interval in minutes, 1 to 43200")
97
+ .option("--method <method>", "HTTP method")
98
+ .option("--headers <json>", "Headers as a JSON object")
99
+ .option("--body <text>", "Request body")
100
+ .option("--paused", "Save the schedule paused");
101
+ scheduleOptions(schedules.command("create").description("Create a schedule").argument("<name>")).action(createSchedule);
102
+ scheduleOptions(schedules.command("update").description("Edit a schedule").argument("<id>").option("--name <name>")).action(updateSchedule);
103
+ scoped(schedules.command("pause").description("Pause a schedule").argument("<id>")).action((id, options) => setScheduleState(id, false, options));
104
+ scoped(schedules.command("resume").description("Resume a schedule").argument("<id>")).action((id, options) => setScheduleState(id, true, options));
105
+ scoped(schedules.command("logs").description("Show recent runs").argument("<id>")).action(scheduleLogs);
106
+ scoped(schedules.command("delete").description("Delete a schedule").argument("<id>").option("--yes", "Confirm")).action(deleteSchedule);
85
107
  const storage = program.command("storage").description("S3 compatible storage");
86
108
  scoped(storage.command("info").description("Show the bucket and S3 credentials")).action(storageInfo);
87
109
  scoped(storage.command("create").description("Create the project's bucket").argument("<name>")).action(createStorage);
package/dist/lib/api.js CHANGED
@@ -1,4 +1,6 @@
1
1
  import { readConfig } from "./config.js";
2
+ let activeProjectId;
3
+ export const setProjectScope = (projectId) => { activeProjectId = projectId; };
2
4
  export class ApiError extends Error {
3
5
  status;
4
6
  constructor(message, status) {
@@ -12,8 +14,9 @@ export const request = async (pathname, init = {}, projectId) => {
12
14
  if (token) {
13
15
  headers.set("Authorization", `Bearer ${token}`);
14
16
  }
15
- if (projectId) {
16
- headers.set("X-Project-ID", projectId);
17
+ const scope = projectId ?? activeProjectId;
18
+ if (scope) {
19
+ headers.set("X-Project-ID", scope);
17
20
  }
18
21
  if (init.body && typeof init.body === "string") {
19
22
  headers.set("Content-Type", "application/json");
@@ -1,41 +1,34 @@
1
1
  import { input, select } from "@inquirer/prompts";
2
2
  import path from "node:path";
3
- import { request } from "./api.js";
3
+ import { json, request, setProjectScope } from "./api.js";
4
4
  import { readLinkedProject, writeLinkedProject } from "./config.js";
5
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, "");
6
+ const fetchProject = async (idOrSlug) => {
7
+ const { project } = await request(`/projects/${encodeURIComponent(idOrSlug)}`);
8
+ setProjectScope(project.id);
9
+ return project;
11
10
  };
12
- export const fetchProject = (idOrSlug) => request(`/apps/${idOrSlug}`);
13
11
  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
- });
12
+ const { projects } = await request("/projects");
13
+ let choice = "__new__";
14
+ if (projects.length) {
15
+ choice = await select({ message: "Which project should this folder use?", choices: [{ name: "Create a new project", value: "__new__" }, ...projects.map((project) => ({ name: `${project.name} (${project.slug})`, value: project.id }))] });
25
16
  }
26
- const existing = apps.find((project) => project.id === choice);
17
+ const existing = projects.find((project) => project.id === choice);
27
18
  if (existing) {
19
+ setProjectScope(existing.id);
28
20
  return existing;
29
21
  }
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;
22
+ const name = await input({ message: "Project name", default: path.basename(process.cwd()) });
23
+ const { project } = await request("/projects", json("POST", { name }));
24
+ setProjectScope(project.id);
25
+ log.success(`Created project ${project.name}`);
26
+ return project;
34
27
  };
35
28
  export const linkProject = async (slug) => {
36
29
  let project;
37
30
  if (slug) {
38
- project = (await fetchProject(slug)).app;
31
+ project = await fetchProject(slug);
39
32
  }
40
33
  else if (isInteractive()) {
41
34
  project = await chooseProject();
@@ -44,10 +37,10 @@ export const linkProject = async (slug) => {
44
37
  return fail("Missing --project <slug>. List projects with `ezhst projects list`.");
45
38
  }
46
39
  writeLinkedProject({ projectId: project.id, slug: project.slug });
47
- log.dim("Saved link in .easyhost.json");
40
+ log.dim("Saved project link in .easyhost.json");
48
41
  return project;
49
42
  };
50
- export const resolveProjectDetail = async (options) => {
43
+ export const resolveProject = async (options) => {
51
44
  if (options.project) {
52
45
  return fetchProject(options.project);
53
46
  }
@@ -58,9 +51,40 @@ export const resolveProjectDetail = async (options) => {
58
51
  if (!isInteractive()) {
59
52
  return fail("No project linked. Pass --project <slug> or run `ezhst link --project <slug>`.");
60
53
  }
61
- const project = await linkProject();
62
- return fetchProject(project.id);
54
+ return linkProject();
63
55
  };
64
- export const resolveProject = async (options) => {
65
- return (await resolveProjectDetail(options)).app;
56
+ export const resolveApp = async (options, create = false) => {
57
+ const project = await resolveProject(options);
58
+ const { apps } = await request("/apps");
59
+ const linked = readLinkedProject();
60
+ let selected = options.app;
61
+ if (!selected && linked?.projectId === project.id) {
62
+ selected = linked.appId;
63
+ }
64
+ let app = apps.find((item) => item.id === selected || item.slug === selected || item.name === selected);
65
+ if (!app && selected) {
66
+ return fail(`App "${selected}" not found in this project. List apps with \`ezhst apps list\`.`);
67
+ }
68
+ if (!app && !selected && apps.length === 1) {
69
+ app = apps[0];
70
+ }
71
+ if (!app && !selected && apps.length > 1) {
72
+ if (!isInteractive()) {
73
+ return fail("This project has multiple apps. Pass --app <slug>.");
74
+ }
75
+ const id = await select({ message: "Which app?", choices: apps.map((item) => ({ name: `${item.name} (${item.slug})`, value: item.id })) });
76
+ app = apps.find((item) => item.id === id);
77
+ }
78
+ if (!app && create && apps.length === 0) {
79
+ const name = path.basename(process.cwd());
80
+ app = (await request("/apps", json("POST", { name }))).app;
81
+ }
82
+ if (!app) {
83
+ return fail("This project has no apps. Create one with `ezhst apps create <name>`.");
84
+ }
85
+ return app;
86
+ };
87
+ export const resolveAppDetail = async (options) => {
88
+ const app = await resolveApp(options);
89
+ return request(`/apps/${app.id}`);
66
90
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ezhst",
3
- "version": "0.3.0",
4
- "description": "EasyHost CLI: agent-first hosting for Next.js apps with storage, databases and email",
3
+ "version": "0.4.1",
4
+ "description": "EasyHost CLI: agent-first hosting for Node.js apps with storage, databases and email",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "ezhst": "dist/index.js"
package/skill/SKILL.md CHANGED
@@ -1,18 +1,18 @@
1
1
  ---
2
2
  name: easyhost
3
- description: Deploy and manage apps on EasyHost (free hosting) with the ezhst CLI. Use when the user asks to deploy, host, publish or ship a Next.js app to EasyHost, or to manage its environment variables, build settings, logs, custom domains, S3 storage, Postgres database, transactional email or API keys.
3
+ description: Deploy and manage apps on EasyHost (free hosting) with the ezhst CLI. Use when the user asks to deploy, host, publish or ship a Node.js app to EasyHost, or to manage its environment variables, build settings, logs, custom domains, S3 storage, Postgres database, transactional email or API keys.
4
4
  ---
5
5
 
6
6
  # EasyHost
7
7
 
8
- EasyHost is free hosting for Next.js apps with built-in S3 storage, Postgres and email. Everything is done through the `ezhst` CLI. Run it with `npx ezhst <command>` (or `ezhst` if installed globally with `npm i -g ezhst`).
8
+ EasyHost is free hosting for Node.js apps with built-in S3 storage, Postgres and email. Everything is done through the `ezhst` CLI. Run it with `npx ezhst <command>` (or `ezhst` if installed globally with `npm i -g ezhst`).
9
9
 
10
10
  ## Rules for agents
11
11
 
12
12
  - Always pass `--json` and parse stdout. Progress and hints go to stderr. On failure the process exits with code 1 and prints `{"error": "..."}`.
13
13
  - The CLI never prompts without a TTY. Pass every value as a flag.
14
- - Commands that act on a project use the project linked in `.easyhost.json`, or `--project <slug>`.
15
- - Destructive commands (`projects delete`, `storage delete`, `db delete`) need `--yes`. Only run them when the user explicitly asks.
14
+ - Commands that act on a project use the project linked in `.easyhost.json`, or `--project <slug>`. App commands also use `--app <slug-or-id>` or the linked app. With multiple apps, select one explicitly.
15
+ - Destructive commands (`projects delete`, `apps delete`, `schedules delete`, `storage delete`, `db delete`) need `--yes`. Only run them when the user explicitly asks.
16
16
  - Never print secrets (passwords, S3 secret keys, API keys, connection strings) back to the user unless they ask. Put them in env vars with `ezhst env set` instead.
17
17
  - `.env` files are never uploaded. Environment variables must be set with `ezhst env set` or `ezhst env import .env`.
18
18
 
@@ -26,7 +26,7 @@ Check first: `npx ezhst whoami --json`. If it fails with "Not logged in":
26
26
 
27
27
  ## 2. Pick or create a project
28
28
 
29
- A project is one app plus its storage, database, email sender and API keys. Its slug is the subdomain: `https://<slug>.easyhost.fun`.
29
+ A project contains up to five Node.js apps, five schedules, and shared storage, database, email sender and API keys. Each app has its own slug and URL: `https://<app-slug>.easyhost.fun`. Existing project apps retain their URLs.
30
30
 
31
31
  ```
32
32
  npx ezhst projects list --json
@@ -36,9 +36,11 @@ npx ezhst link --project <slug> --json
36
36
 
37
37
  ## 3. Deploy
38
38
 
39
- Run inside the Next.js project folder (it needs `package.json` with `next` and a `build` script):
39
+ Run inside the Node.js app folder with a `package.json`. First create an app and link it (app slugs are returned by the create command). Build scripts are optional:
40
40
 
41
41
  ```
42
+ npx ezhst apps create <name> --project <project-slug> --json
43
+ npx ezhst link --project <project-slug> --app <app-slug> --json
42
44
  npx ezhst env import .env --json
43
45
  npx ezhst deploy --json
44
46
  ```
@@ -61,14 +63,15 @@ After changing env vars or build settings, run `npx ezhst redeploy --json` (rebu
61
63
 
62
64
  Projects and runtime:
63
65
  - `projects list | info | rename <name> | delete --yes`, `projects create <name> [--link]`, `link --project <slug>`
64
- - `deploy [--verbose]`, `redeploy`, `start`, `stop`
66
+ - `apps list | create <name> | delete --yes`
67
+ - `deploy [--verbose] [--app <slug>]`, `redeploy`, `start`, `stop`
65
68
  - `logs [--tail 200]` runtime logs
66
69
  - `deployments list`, `deployments log [deploymentId]` build logs
67
70
 
68
71
  Environment and build:
69
72
  - `env list | set KEY=VALUE... | unset KEY... | import <file>`
70
73
  - `build show`, `build set [--node <v>] [--root-dir <dir>] [--install <cmd>] [--build <cmd>] [--start <cmd>]` (`""` resets a field to auto), `build reset`
71
- - The start command must listen on `0.0.0.0` and `$PORT`. Default: `next start -H 0.0.0.0 -p $PORT`.
74
+ - The start command must listen on `0.0.0.0` and `$PORT`. Auto-detects `scripts.start`, Next.js, Nuxt, or a Node.js entry file. Runs the build script if present; skips building otherwise.
72
75
 
73
76
  Custom domains:
74
77
  - `domains list | add <hostname> | verify <hostname> | remove <hostname>`
@@ -83,10 +86,16 @@ Database (Postgres, one per project):
83
86
  - `db create <name> | info | query "<sql>" | query --file <file.sql> | rows <table> [--page n] | reset-password | delete --yes`
84
87
  - `db info --json` returns `connectionString` and `shadowConnectionString` (for `prisma migrate dev`). Set `DATABASE_URL` with `env set`, and run migrations from the local machine against it (for Prisma: `prisma migrate deploy`).
85
88
 
86
- Email (from `<username>@easyhost.fun`, 100 emails a day):
89
+ Email (from `<username>@easyhost.fun`, 20 emails a day):
87
90
  - `email sender create <username>`, `email info`, `email send --from <address> --to <address> --subject <text> --text <body>` (or `--html`), `email logs`, `email sender delete`
88
91
  - From app code: `POST https://api.easyhost.fun/api/v1/email/send` with header `Authorization: Bearer <api key>` and JSON `{ "from", "to", "subject", "text" | "html" }`. Create the key with `keys create <name>` and store it with `env set EASYHOST_API_KEY=...`.
89
92
 
93
+ Schedules (up to five per project, intervals in minutes):
94
+ - `schedules list`, `schedules create <name> --url <url> --every <minutes> [--method POST] [--headers '<json>'] [--body '<text>'] [--paused]`
95
+ - `schedules update <id> [--name <name>] [--url <url>] [--every <minutes>] [--method <method>] [--headers '<json>'] [--body '<text>']`
96
+ - `schedules pause <id>`, `schedules resume <id>`, `schedules logs <id>`, `schedules delete <id> --yes`
97
+ - Public HTTP/HTTPS URLs only, intervals 1 to 43200 minutes, 30-second timeout, no redirects. First call follows one interval; saving/resuming restarts it. Latest 100 runs retained, latest 10 shown. Missed intervals are skipped; execution has up to 10 seconds of polling delay. Requests in progress may finish after pausing/deleting.
98
+
90
99
  API keys:
91
100
  - `keys list | create <name> | revoke <id>` (a key is shown only once)
92
101
 
@@ -95,6 +104,6 @@ Account:
95
104
 
96
105
  ## Limits
97
106
 
98
- Free: 10 projects, one bucket, one database and one email sender per project, 100 emails a day, one build at a time, 512 MB RAM and 1 CPU per app. Only Next.js apps are supported right now.
107
+ Free: 10 projects. Per project: five Node.js apps, five schedules, one bucket, one database, one email sender and 20 emails a day. One build at a time; 512 MB RAM and 1 CPU per app.
99
108
 
100
109
  Docs: https://easyhost.fun/docs