deployboat 0.0.0-stage → 0.1.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/README.md +11 -2
- package/index.js +76 -0
- package/package.json +12 -4
package/README.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# deployboat
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The command line for [Deploy Boat](https://github.com/osbulbul/deploy-boat):
|
|
4
|
+
publish any project to your own server.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
npx deployboat login <dashboard-url> <token> # once
|
|
8
|
+
npx deployboat deploy # in any project folder
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
You get a live HTTPS link, plus a database and file storage your app can use right away.
|
|
12
|
+
Don't have a server yet? See the [install guide](https://github.com/osbulbul/deploy-boat#install).
|
package/index.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Deploy Boat CLI. Plain JavaScript, no dependencies, so `npx deployboat` is instant.
|
|
3
|
+
//
|
|
4
|
+
// deployboat login <server-url> <token>
|
|
5
|
+
// deployboat deploy [--name my-app]
|
|
6
|
+
//
|
|
7
|
+
// Server and token can also come from DEPLOYBOAT_URL / DEPLOYBOAT_TOKEN or --server / --token.
|
|
8
|
+
|
|
9
|
+
import { spawn } from "node:child_process";
|
|
10
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
11
|
+
import { homedir } from "node:os";
|
|
12
|
+
import { basename, join } from "node:path";
|
|
13
|
+
import { Readable } from "node:stream";
|
|
14
|
+
|
|
15
|
+
const globalFile = join(homedir(), ".deployboat", "config.json");
|
|
16
|
+
const projectFile = ".deployboat.json"; // remembers the app name per project
|
|
17
|
+
|
|
18
|
+
const readJson = (f) => (existsSync(f) ? JSON.parse(readFileSync(f, "utf8")) : {});
|
|
19
|
+
const flag = (n) => { const i = process.argv.indexOf(`--${n}`); return i > -1 ? process.argv[i + 1] : undefined; };
|
|
20
|
+
const die = (msg) => { console.error(`✗ ${msg}`); process.exit(1); };
|
|
21
|
+
|
|
22
|
+
const [cmd, ...args] = process.argv.slice(2);
|
|
23
|
+
|
|
24
|
+
if (cmd === "login") {
|
|
25
|
+
const [server, token] = args;
|
|
26
|
+
if (!server || !token) die("Usage: deployboat login <server-url> <token>");
|
|
27
|
+
mkdirSync(join(homedir(), ".deployboat"), { recursive: true });
|
|
28
|
+
writeFileSync(globalFile, JSON.stringify({ server: server.replace(/\/$/, ""), token }, null, 2), { mode: 0o600 });
|
|
29
|
+
console.log("✓ Logged in. Now run: deployboat deploy");
|
|
30
|
+
} else if (cmd === "deploy") {
|
|
31
|
+
await deploy();
|
|
32
|
+
} else {
|
|
33
|
+
console.log("Usage:\n deployboat login <server-url> <token>\n deployboat deploy [--name my-app]");
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function deploy() {
|
|
37
|
+
const saved = readJson(globalFile);
|
|
38
|
+
const server = flag("server") ?? process.env.DEPLOYBOAT_URL ?? saved.server;
|
|
39
|
+
const token = flag("token") ?? process.env.DEPLOYBOAT_TOKEN ?? saved.token;
|
|
40
|
+
if (!server || !token) die("Not logged in. Run: deployboat login <server-url> <token>");
|
|
41
|
+
|
|
42
|
+
const project = readJson(projectFile);
|
|
43
|
+
const name = flag("name") ?? project.name ??
|
|
44
|
+
basename(process.cwd()).toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/^-+|-+$/g, "").slice(0, 40);
|
|
45
|
+
writeFileSync(projectFile, JSON.stringify({ name }, null, 2));
|
|
46
|
+
|
|
47
|
+
console.log(`→ Uploading ${name}…`);
|
|
48
|
+
const tar = spawn("tar", ["-cz", "--exclude=node_modules", "--exclude=.git", "--exclude=.env", "-f", "-", "."]);
|
|
49
|
+
|
|
50
|
+
const res = await fetch(`${server}/api/deploy/${name}`, {
|
|
51
|
+
method: "POST",
|
|
52
|
+
headers: { authorization: `Bearer ${token}`, "content-type": "application/gzip" },
|
|
53
|
+
body: Readable.toWeb(tar.stdout),
|
|
54
|
+
duplex: "half",
|
|
55
|
+
}).catch((e) => die(`Can't reach ${server} (${e.cause?.code ?? e.message})`));
|
|
56
|
+
|
|
57
|
+
if (!res.ok) die((await res.json().catch(() => ({}))).error ?? `Server error ${res.status}`);
|
|
58
|
+
|
|
59
|
+
// The app may have been renamed in the dashboard. Remember the new name.
|
|
60
|
+
const current = res.headers.get("x-app-name");
|
|
61
|
+
if (current && current !== name) writeFileSync(projectFile, JSON.stringify({ name: current }, null, 2));
|
|
62
|
+
|
|
63
|
+
// Stream the build log. Last line is "LIVE <url>" or "FAILED <reason>".
|
|
64
|
+
let ok = false, buf = "";
|
|
65
|
+
const decoder = new TextDecoder();
|
|
66
|
+
for await (const chunk of res.body) {
|
|
67
|
+
buf += decoder.decode(chunk, { stream: true });
|
|
68
|
+
const lines = buf.split("\n"); buf = lines.pop();
|
|
69
|
+
for (const line of lines) {
|
|
70
|
+
if (line.startsWith("LIVE ")) { ok = true; console.log(`\n✓ Live: ${line.slice(5)}`); }
|
|
71
|
+
else if (line.startsWith("FAILED ")) console.error(`\n✗ Deploy failed: ${line.slice(7)}`);
|
|
72
|
+
else console.log(` ${line}`);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
process.exit(ok ? 0 : 1);
|
|
76
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deployboat",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
}
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Publish any project to your own Deploy Boat server with one command.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": { "deployboat": "index.js" },
|
|
7
|
+
"files": ["index.js", "README.md"],
|
|
8
|
+
"engines": { "node": ">=20" },
|
|
9
|
+
"keywords": ["deploy", "self-hosted", "paas", "hosting", "cli", "ai"],
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"repository": { "type": "git", "url": "git+https://github.com/osbulbul/deploy-boat.git", "directory": "cli" },
|
|
12
|
+
"homepage": "https://github.com/osbulbul/deploy-boat#readme",
|
|
13
|
+
"bugs": "https://github.com/osbulbul/deploy-boat/issues"
|
|
14
|
+
}
|