flypod 0.1.1 → 0.4.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 +151 -10
- package/dist/bin/deploy.js +1171 -25
- package/dist/{cli-w8brx6zh.js → cli-ynzcc4xy.js} +5 -2
- package/dist/src/cli.js +1 -1
- package/package.json +5 -3
package/dist/bin/deploy.js
CHANGED
|
@@ -2,16 +2,925 @@
|
|
|
2
2
|
import {
|
|
3
3
|
collectDist,
|
|
4
4
|
deploySite,
|
|
5
|
-
resolveDeployDir
|
|
6
|
-
|
|
5
|
+
resolveDeployDir,
|
|
6
|
+
zipSync
|
|
7
|
+
} from "../cli-ynzcc4xy.js";
|
|
7
8
|
|
|
8
9
|
// bin/deploy.ts
|
|
9
|
-
import { readFile } from "node:fs/promises";
|
|
10
|
+
import { readFile as readFile4 } from "node:fs/promises";
|
|
11
|
+
import { homedir as homedir3 } from "node:os";
|
|
10
12
|
import { relative } from "node:path";
|
|
11
13
|
import { fileURLToPath } from "node:url";
|
|
12
14
|
|
|
13
|
-
// src/
|
|
15
|
+
// src/cli/projects.ts
|
|
16
|
+
import { readFile } from "node:fs/promises";
|
|
17
|
+
|
|
18
|
+
// src/cli/paths.ts
|
|
19
|
+
import { mkdir, rename, writeFile } from "node:fs/promises";
|
|
20
|
+
import { homedir, platform } from "node:os";
|
|
21
|
+
import { dirname, join } from "node:path";
|
|
22
|
+
function configDir(env = process.env) {
|
|
23
|
+
if (env.FLYPOD_CONFIG_DIR)
|
|
24
|
+
return env.FLYPOD_CONFIG_DIR;
|
|
25
|
+
const os = platform();
|
|
26
|
+
if (os === "darwin") {
|
|
27
|
+
return join(homedir(), "Library", "Application Support", "flypod");
|
|
28
|
+
}
|
|
29
|
+
if (os === "win32") {
|
|
30
|
+
const appData = env.APPDATA ?? join(homedir(), "AppData", "Roaming");
|
|
31
|
+
return join(appData, "flypod");
|
|
32
|
+
}
|
|
33
|
+
const xdg = env.XDG_CONFIG_HOME ?? join(homedir(), ".config");
|
|
34
|
+
return join(xdg, "flypod");
|
|
35
|
+
}
|
|
36
|
+
function sessionFilePath(env = process.env) {
|
|
37
|
+
return join(configDir(env), "session.json");
|
|
38
|
+
}
|
|
39
|
+
function projectsFilePath(env = process.env) {
|
|
40
|
+
return join(configDir(env), "projects.json");
|
|
41
|
+
}
|
|
42
|
+
async function atomicWriteFile(path, content) {
|
|
43
|
+
await mkdir(dirname(path), { recursive: true });
|
|
44
|
+
const tmp = `${path}.tmp`;
|
|
45
|
+
await writeFile(tmp, content, { mode: 384 });
|
|
46
|
+
await rename(tmp, path);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/cli/projects.ts
|
|
50
|
+
var MAX_PROJECTS = 64;
|
|
51
|
+
function prune(projects, now) {
|
|
52
|
+
const out = {};
|
|
53
|
+
for (const [dir, rec] of Object.entries(projects)) {
|
|
54
|
+
if (rec.expires_at !== null && rec.expires_at <= now)
|
|
55
|
+
continue;
|
|
56
|
+
out[dir] = rec;
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
function cap(projects) {
|
|
61
|
+
const entries = Object.entries(projects);
|
|
62
|
+
if (entries.length <= MAX_PROJECTS)
|
|
63
|
+
return projects;
|
|
64
|
+
entries.sort(([, a], [, b]) => b.last_used - a.last_used);
|
|
65
|
+
return Object.fromEntries(entries.slice(0, MAX_PROJECTS));
|
|
66
|
+
}
|
|
67
|
+
async function loadProjects(env) {
|
|
68
|
+
try {
|
|
69
|
+
const text = await readFile(projectsFilePath(env), "utf8");
|
|
70
|
+
const parsed = JSON.parse(text);
|
|
71
|
+
if (!parsed || typeof parsed !== "object" || typeof parsed.projects !== "object")
|
|
72
|
+
return {};
|
|
73
|
+
return prune(parsed.projects, Date.now());
|
|
74
|
+
} catch {
|
|
75
|
+
return {};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async function saveProjects(projects, env) {
|
|
79
|
+
const cleaned = cap(prune(projects, Date.now()));
|
|
80
|
+
const file = { v: 1, projects: cleaned };
|
|
81
|
+
const path = projectsFilePath(env);
|
|
82
|
+
await atomicWriteFile(path, `${JSON.stringify(file, null, 2)}
|
|
83
|
+
`);
|
|
84
|
+
return path;
|
|
85
|
+
}
|
|
86
|
+
async function linkProject(dir, rec, env) {
|
|
87
|
+
const projects = await loadProjects(env);
|
|
88
|
+
projects[dir] = rec;
|
|
89
|
+
await saveProjects(projects, env);
|
|
90
|
+
}
|
|
91
|
+
async function projectForDir(dir, env) {
|
|
92
|
+
const projects = await loadProjects(env);
|
|
93
|
+
return projects[dir] ?? null;
|
|
94
|
+
}
|
|
95
|
+
async function forgetDir(dir, env) {
|
|
96
|
+
const projects = await loadProjects(env);
|
|
97
|
+
if (!(dir in projects))
|
|
98
|
+
return false;
|
|
99
|
+
delete projects[dir];
|
|
100
|
+
await saveProjects(projects, env);
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
async function forgetSite(site_id, env) {
|
|
104
|
+
const projects = await loadProjects(env);
|
|
105
|
+
let removed = 0;
|
|
106
|
+
for (const [dir, rec] of Object.entries(projects)) {
|
|
107
|
+
if (rec.site_id === site_id) {
|
|
108
|
+
delete projects[dir];
|
|
109
|
+
removed++;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (removed)
|
|
113
|
+
await saveProjects(projects, env);
|
|
114
|
+
return removed;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/cli/session.ts
|
|
118
|
+
import { readFile as readFile2, unlink } from "node:fs/promises";
|
|
119
|
+
async function resolveAuth(env = process.env) {
|
|
120
|
+
const session = await loadSession(env);
|
|
121
|
+
const apiKey = session?.api_key ?? env.FLYPOD_API_KEY;
|
|
122
|
+
const baseUrl = session?.base_url ?? env.DEPLOY_URL ?? "https://flypod.dev";
|
|
123
|
+
return { apiKey, baseUrl };
|
|
124
|
+
}
|
|
125
|
+
async function loadSession(env) {
|
|
126
|
+
try {
|
|
127
|
+
const path = sessionFilePath(env);
|
|
128
|
+
const text = await readFile2(path, "utf8");
|
|
129
|
+
const parsed = JSON.parse(text);
|
|
130
|
+
if (typeof parsed?.api_key === "string" && typeof parsed?.base_url === "string" && typeof parsed?.created_at === "number") {
|
|
131
|
+
return parsed;
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
} catch {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
async function saveSession(session, env) {
|
|
139
|
+
const path = sessionFilePath(env);
|
|
140
|
+
await atomicWriteFile(path, `${JSON.stringify(session, null, 2)}
|
|
141
|
+
`);
|
|
142
|
+
return path;
|
|
143
|
+
}
|
|
144
|
+
async function clearSession(env) {
|
|
145
|
+
try {
|
|
146
|
+
await unlink(sessionFilePath(env));
|
|
147
|
+
return true;
|
|
148
|
+
} catch {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/cli/commands.ts
|
|
154
|
+
function baseUrlFrom(env = process.env) {
|
|
155
|
+
return env.DEPLOY_URL ?? "https://flypod.dev";
|
|
156
|
+
}
|
|
157
|
+
function looksLikeApiKey(key) {
|
|
158
|
+
return /^fk_[A-Za-z0-9_-]{16,}$/.test(key);
|
|
159
|
+
}
|
|
160
|
+
async function login(args, io) {
|
|
161
|
+
const env = io.env ?? process.env;
|
|
162
|
+
if (!args.key) {
|
|
163
|
+
io.err("flypod login: --key fk_... is required.");
|
|
164
|
+
io.err("");
|
|
165
|
+
io.err("Mint a key at https://flypod.dev/account (or wherever your");
|
|
166
|
+
io.err("flypod server lives) and run:");
|
|
167
|
+
io.err(" flypod login --key fk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
|
|
168
|
+
return 2;
|
|
169
|
+
}
|
|
170
|
+
if (!looksLikeApiKey(args.key)) {
|
|
171
|
+
io.err("flypod login: that doesn't look like a flypod key (expected fk_...).");
|
|
172
|
+
return 2;
|
|
173
|
+
}
|
|
174
|
+
const baseUrl = baseUrlFrom(env);
|
|
175
|
+
const path = await saveSession({ api_key: args.key, base_url: baseUrl, created_at: Date.now() }, env);
|
|
176
|
+
io.err(`Saved your key to ${path}`);
|
|
177
|
+
io.err(`Now using ${baseUrl} for every flypod command.`);
|
|
178
|
+
return 0;
|
|
179
|
+
}
|
|
180
|
+
async function logout(_args, io) {
|
|
181
|
+
const env = io.env ?? process.env;
|
|
182
|
+
const ok = await clearSession(env);
|
|
183
|
+
if (ok)
|
|
184
|
+
io.err("Signed out. Local session forgotten.");
|
|
185
|
+
else
|
|
186
|
+
io.err("Already signed out.");
|
|
187
|
+
return 0;
|
|
188
|
+
}
|
|
189
|
+
async function list(_args, io) {
|
|
190
|
+
const env = io.env ?? process.env;
|
|
191
|
+
const session = await loadSession(env);
|
|
192
|
+
if (!session) {
|
|
193
|
+
io.err("Not signed in. Run `flypod login --key fk_...` first.");
|
|
194
|
+
return 1;
|
|
195
|
+
}
|
|
196
|
+
const fetchImpl = io.fetch ?? fetch;
|
|
197
|
+
const res = await fetchImpl(`${session.base_url}/account/sites`, {
|
|
198
|
+
headers: { authorization: `Bearer ${session.api_key}` }
|
|
199
|
+
});
|
|
200
|
+
if (!res.ok) {
|
|
201
|
+
io.err(`flypod list: server returned ${res.status}.`);
|
|
202
|
+
return 1;
|
|
203
|
+
}
|
|
204
|
+
const body = await res.json();
|
|
205
|
+
const sites = body.sites ?? [];
|
|
206
|
+
if (sites.length === 0) {
|
|
207
|
+
io.err("No sites yet. Run `flypod` in a folder to deploy one.");
|
|
208
|
+
return 0;
|
|
209
|
+
}
|
|
210
|
+
for (const site of sites)
|
|
211
|
+
io.out(`${site.site_id} ${site.url}`);
|
|
212
|
+
return 0;
|
|
213
|
+
}
|
|
214
|
+
async function claim(args, io) {
|
|
215
|
+
const env = io.env ?? process.env;
|
|
216
|
+
const session = await loadSession(env);
|
|
217
|
+
if (!session) {
|
|
218
|
+
io.err("Not signed in. Run `flypod login --key fk_...` first.");
|
|
219
|
+
return 1;
|
|
220
|
+
}
|
|
221
|
+
if (!args.site_id || !args.token) {
|
|
222
|
+
io.err("Usage: flypod claim <site_id> <claim_token>");
|
|
223
|
+
return 2;
|
|
224
|
+
}
|
|
225
|
+
const fetchImpl = io.fetch ?? fetch;
|
|
226
|
+
const res = await fetchImpl(`${session.base_url}/sites/${args.site_id}/claim`, {
|
|
227
|
+
method: "POST",
|
|
228
|
+
headers: {
|
|
229
|
+
"content-type": "application/json",
|
|
230
|
+
authorization: `Bearer ${session.api_key}`
|
|
231
|
+
},
|
|
232
|
+
body: JSON.stringify({ claim_token: args.token })
|
|
233
|
+
});
|
|
234
|
+
if (!res.ok) {
|
|
235
|
+
io.err(`flypod claim: server returned ${res.status}.`);
|
|
236
|
+
return 1;
|
|
237
|
+
}
|
|
238
|
+
const body = await res.json();
|
|
239
|
+
io.out(body.site_id);
|
|
240
|
+
io.err(`Claimed. Owned by ${body.owner_account_id}.`);
|
|
241
|
+
return 0;
|
|
242
|
+
}
|
|
243
|
+
async function keysCreate(_args, io) {
|
|
244
|
+
const env = io.env ?? process.env;
|
|
245
|
+
const session = await loadSession(env);
|
|
246
|
+
if (!session) {
|
|
247
|
+
io.err("Not signed in. Run `flypod login --key fk_...` first.");
|
|
248
|
+
return 1;
|
|
249
|
+
}
|
|
250
|
+
const fetchImpl = io.fetch ?? fetch;
|
|
251
|
+
const res = await fetchImpl(`${session.base_url}/account/api-keys`, {
|
|
252
|
+
method: "POST",
|
|
253
|
+
headers: { authorization: `Bearer ${session.api_key}` }
|
|
254
|
+
});
|
|
255
|
+
if (!res.ok) {
|
|
256
|
+
io.err(`flypod keys create: server returned ${res.status}.`);
|
|
257
|
+
return 1;
|
|
258
|
+
}
|
|
259
|
+
const body = await res.json();
|
|
260
|
+
io.out(body.api_key);
|
|
261
|
+
io.err("Save this now. You will not see it again.");
|
|
262
|
+
return 0;
|
|
263
|
+
}
|
|
264
|
+
var NO_SITE = "No flypod site is linked to this folder. Run 'flypod' here to create one, or pass --site <id>.";
|
|
265
|
+
async function resolveTarget(args, io) {
|
|
266
|
+
const env = io.env ?? process.env;
|
|
267
|
+
if (args.site)
|
|
268
|
+
return { site_id: args.site, rec: null, dir: null };
|
|
269
|
+
const cwd = io.cwd ?? process.cwd();
|
|
270
|
+
const rec = await projectForDir(cwd, env);
|
|
271
|
+
return rec ? { site_id: rec.site_id, rec, dir: cwd } : null;
|
|
272
|
+
}
|
|
273
|
+
async function requestContext(target, args, env) {
|
|
274
|
+
const session = await loadSession(env);
|
|
275
|
+
const baseUrl = target.rec?.base_url ?? session?.base_url ?? baseUrlFrom(env);
|
|
276
|
+
const auth = args.token ?? target.rec?.manage_token ?? session?.api_key;
|
|
277
|
+
return { baseUrl, auth };
|
|
278
|
+
}
|
|
279
|
+
function authHeaders(auth, extra = {}) {
|
|
280
|
+
return auth ? { ...extra, authorization: `Bearer ${auth}` } : { ...extra };
|
|
281
|
+
}
|
|
282
|
+
async function healGone(target, io, env) {
|
|
283
|
+
if (target.dir)
|
|
284
|
+
await forgetDir(target.dir, env);
|
|
285
|
+
io.err(`Site ${target.site_id} is gone (expired or deleted). Run 'flypod' to create a new one.`);
|
|
286
|
+
}
|
|
287
|
+
function unauthorized(target, io) {
|
|
288
|
+
io.err(`Unauthorized for ${target.site_id}. Run 'flypod login' or pass --token <manage_token>.`);
|
|
289
|
+
}
|
|
290
|
+
async function fetchSite(target, args, io, env) {
|
|
291
|
+
const { baseUrl, auth } = await requestContext(target, args, env);
|
|
292
|
+
const fetchImpl = io.fetch ?? fetch;
|
|
293
|
+
const res = await fetchImpl(`${baseUrl}/sites/${target.site_id}`, { headers: authHeaders(auth) });
|
|
294
|
+
if (res.status === 401 || res.status === 403) {
|
|
295
|
+
unauthorized(target, io);
|
|
296
|
+
return { error: 1 };
|
|
297
|
+
}
|
|
298
|
+
if (res.status === 404) {
|
|
299
|
+
await healGone(target, io, env);
|
|
300
|
+
return { error: 1 };
|
|
301
|
+
}
|
|
302
|
+
if (!res.ok) {
|
|
303
|
+
io.err(`flypod: server returned ${res.status}.`);
|
|
304
|
+
return { error: 1 };
|
|
305
|
+
}
|
|
306
|
+
return { data: await res.json() };
|
|
307
|
+
}
|
|
308
|
+
async function touchLink(target, version_id, env) {
|
|
309
|
+
if (target.dir && target.rec) {
|
|
310
|
+
await linkProject(target.dir, { ...target.rec, version_id, last_used: Date.now() }, env);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
async function update(args, io) {
|
|
314
|
+
const env = io.env ?? process.env;
|
|
315
|
+
const cwd = io.cwd ?? process.cwd();
|
|
316
|
+
const target = await resolveTarget(args, io);
|
|
317
|
+
if (!target) {
|
|
318
|
+
io.err(NO_SITE);
|
|
319
|
+
return 1;
|
|
320
|
+
}
|
|
321
|
+
let dir;
|
|
322
|
+
try {
|
|
323
|
+
dir = await resolveDeployDir({ cwd, explicit: args.path });
|
|
324
|
+
} catch (e) {
|
|
325
|
+
io.err(e.message);
|
|
326
|
+
return 1;
|
|
327
|
+
}
|
|
328
|
+
let files;
|
|
329
|
+
try {
|
|
330
|
+
files = await collectDist(dir);
|
|
331
|
+
} catch (e) {
|
|
332
|
+
io.err(`Could not read ${dir}: ${e.message}`);
|
|
333
|
+
return 1;
|
|
334
|
+
}
|
|
335
|
+
const { baseUrl, auth } = await requestContext(target, args, env);
|
|
336
|
+
const fetchImpl = io.fetch ?? fetch;
|
|
337
|
+
const res = await fetchImpl(`${baseUrl}/sites/${target.site_id}/deploys`, {
|
|
338
|
+
method: "POST",
|
|
339
|
+
headers: authHeaders(auth, { "content-type": "application/zip" }),
|
|
340
|
+
body: zipSync(files)
|
|
341
|
+
});
|
|
342
|
+
if (res.status === 401 || res.status === 403) {
|
|
343
|
+
unauthorized(target, io);
|
|
344
|
+
return 1;
|
|
345
|
+
}
|
|
346
|
+
if (res.status === 404) {
|
|
347
|
+
await healGone(target, io, env);
|
|
348
|
+
return 1;
|
|
349
|
+
}
|
|
350
|
+
if (!res.ok) {
|
|
351
|
+
io.err(`flypod update: server returned ${res.status}.`);
|
|
352
|
+
return 1;
|
|
353
|
+
}
|
|
354
|
+
const body = await res.json();
|
|
355
|
+
const noop = target.rec?.version_id !== undefined && body.version_id === target.rec.version_id;
|
|
356
|
+
await touchLink(target, body.version_id, env);
|
|
357
|
+
if (args.json) {
|
|
358
|
+
io.out(JSON.stringify({
|
|
359
|
+
ok: true,
|
|
360
|
+
site_id: target.site_id,
|
|
361
|
+
version_id: body.version_id,
|
|
362
|
+
url: body.url
|
|
363
|
+
}));
|
|
364
|
+
return 0;
|
|
365
|
+
}
|
|
366
|
+
io.err(noop ? `No changes — already live as ${body.version_id}.` : `→ version ${body.version_id} is now live`);
|
|
367
|
+
io.out(body.url);
|
|
368
|
+
return 0;
|
|
369
|
+
}
|
|
370
|
+
async function versions(args, io) {
|
|
371
|
+
const env = io.env ?? process.env;
|
|
372
|
+
const target = await resolveTarget(args, io);
|
|
373
|
+
if (!target) {
|
|
374
|
+
io.err(NO_SITE);
|
|
375
|
+
return 1;
|
|
376
|
+
}
|
|
377
|
+
const site = await fetchSite(target, args, io, env);
|
|
378
|
+
if ("error" in site)
|
|
379
|
+
return site.error;
|
|
380
|
+
const { live_version_id, versions: vers } = site.data;
|
|
381
|
+
if (args.json) {
|
|
382
|
+
io.out(JSON.stringify({ ok: true, site_id: target.site_id, live_version_id, versions: vers }));
|
|
383
|
+
return 0;
|
|
384
|
+
}
|
|
385
|
+
for (const v of [...vers].reverse()) {
|
|
386
|
+
io.out(`${v.version_id} ${v.created_at} ${v.version_id === live_version_id ? "live" : ""}`);
|
|
387
|
+
}
|
|
388
|
+
return 0;
|
|
389
|
+
}
|
|
390
|
+
async function rollback(args, io) {
|
|
391
|
+
const env = io.env ?? process.env;
|
|
392
|
+
const target = await resolveTarget(args, io);
|
|
393
|
+
if (!target) {
|
|
394
|
+
io.err(NO_SITE);
|
|
395
|
+
return 1;
|
|
396
|
+
}
|
|
397
|
+
const site = await fetchSite(target, args, io, env);
|
|
398
|
+
if ("error" in site)
|
|
399
|
+
return site.error;
|
|
400
|
+
const { live_version_id, versions: vers } = site.data;
|
|
401
|
+
let chosen;
|
|
402
|
+
if (args.version) {
|
|
403
|
+
const exact = vers.find((v) => v.version_id === args.version);
|
|
404
|
+
const prefixed = vers.filter((v) => v.version_id.startsWith(args.version));
|
|
405
|
+
if (exact)
|
|
406
|
+
chosen = exact.version_id;
|
|
407
|
+
else if (prefixed.length === 1)
|
|
408
|
+
chosen = prefixed[0]?.version_id;
|
|
409
|
+
else if (prefixed.length === 0) {
|
|
410
|
+
io.err(`No version matches '${args.version}'.`);
|
|
411
|
+
return 1;
|
|
412
|
+
} else {
|
|
413
|
+
io.err(`'${args.version}' is ambiguous — it matches ${prefixed.length} versions.`);
|
|
414
|
+
return 1;
|
|
415
|
+
}
|
|
416
|
+
} else {
|
|
417
|
+
if (vers.length < 2) {
|
|
418
|
+
io.err("Only one version exists — nothing to roll back to.");
|
|
419
|
+
return 1;
|
|
420
|
+
}
|
|
421
|
+
const liveIdx = vers.findIndex((v) => v.version_id === live_version_id);
|
|
422
|
+
if (liveIdx <= 0) {
|
|
423
|
+
io.err("Already at the oldest version.");
|
|
424
|
+
return 1;
|
|
425
|
+
}
|
|
426
|
+
chosen = vers[liveIdx - 1]?.version_id;
|
|
427
|
+
}
|
|
428
|
+
const { baseUrl, auth } = await requestContext(target, args, env);
|
|
429
|
+
const fetchImpl = io.fetch ?? fetch;
|
|
430
|
+
const res = await fetchImpl(`${baseUrl}/sites/${target.site_id}/rollback`, {
|
|
431
|
+
method: "POST",
|
|
432
|
+
headers: authHeaders(auth, { "content-type": "application/json" }),
|
|
433
|
+
body: JSON.stringify({ version_id: chosen })
|
|
434
|
+
});
|
|
435
|
+
if (res.status === 404) {
|
|
436
|
+
await healGone(target, io, env);
|
|
437
|
+
return 1;
|
|
438
|
+
}
|
|
439
|
+
if (!res.ok) {
|
|
440
|
+
io.err(`flypod rollback: server returned ${res.status}.`);
|
|
441
|
+
return 1;
|
|
442
|
+
}
|
|
443
|
+
const body = await res.json();
|
|
444
|
+
await touchLink(target, body.live_version_id, env);
|
|
445
|
+
if (args.json) {
|
|
446
|
+
io.out(JSON.stringify({ ok: true, site_id: target.site_id, live_version_id: body.live_version_id }));
|
|
447
|
+
return 0;
|
|
448
|
+
}
|
|
449
|
+
io.err(`→ rolled back to ${body.live_version_id}`);
|
|
450
|
+
io.out(body.live_version_id);
|
|
451
|
+
return 0;
|
|
452
|
+
}
|
|
453
|
+
async function forget(args, io) {
|
|
454
|
+
const env = io.env ?? process.env;
|
|
455
|
+
if (args.site) {
|
|
456
|
+
const n = await forgetSite(args.site, env);
|
|
457
|
+
io.err(n ? `Forgot ${n} link${n === 1 ? "" : "s"} to ${args.site}.` : `No links to ${args.site}.`);
|
|
458
|
+
return 0;
|
|
459
|
+
}
|
|
460
|
+
const cwd = io.cwd ?? process.cwd();
|
|
461
|
+
const rec = await projectForDir(cwd, env);
|
|
462
|
+
const removed = await forgetDir(cwd, env);
|
|
463
|
+
io.err(removed && rec ? `Forgot ${rec.site_id} for this folder.` : "Nothing linked to this folder.");
|
|
464
|
+
return 0;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// src/cli/select.ts
|
|
14
468
|
var ESC = "\x1B[";
|
|
469
|
+
function canPrompt(input = process.stdin, output = process.stderr) {
|
|
470
|
+
return Boolean(input.isTTY && output.isTTY && typeof input.setRawMode === "function");
|
|
471
|
+
}
|
|
472
|
+
function multiselect(opts) {
|
|
473
|
+
const input = opts.input ?? process.stdin;
|
|
474
|
+
const output = opts.output ?? process.stderr;
|
|
475
|
+
const { style } = opts;
|
|
476
|
+
const choices = opts.choices.map((c) => ({ ...c }));
|
|
477
|
+
return new Promise((resolve) => {
|
|
478
|
+
let index = 0;
|
|
479
|
+
let printed = 0;
|
|
480
|
+
const footer = style.dim("↑/↓ move · space toggle · a all · enter confirm · esc cancel");
|
|
481
|
+
const render = () => {
|
|
482
|
+
const lines = [` ${style.bold(opts.title)}`, ""];
|
|
483
|
+
choices.forEach((c, i) => {
|
|
484
|
+
const active = i === index;
|
|
485
|
+
const pointer = active ? style.accent("›") : " ";
|
|
486
|
+
const box = c.checked ? style.ok("◉") : style.dim("◯");
|
|
487
|
+
const label = active ? style.bold(c.label) : c.label;
|
|
488
|
+
const hint = c.hint ? ` ${style.dim(c.hint)}` : "";
|
|
489
|
+
lines.push(` ${pointer} ${box} ${label}${hint}`);
|
|
490
|
+
});
|
|
491
|
+
lines.push("");
|
|
492
|
+
lines.push(` ${footer}`);
|
|
493
|
+
return lines;
|
|
494
|
+
};
|
|
495
|
+
const draw = () => {
|
|
496
|
+
if (printed > 0)
|
|
497
|
+
output.write(`${ESC}${printed}A`);
|
|
498
|
+
output.write(`${ESC}0J`);
|
|
499
|
+
const lines = render();
|
|
500
|
+
output.write(`${lines.join(`
|
|
501
|
+
`)}
|
|
502
|
+
`);
|
|
503
|
+
printed = lines.length;
|
|
504
|
+
};
|
|
505
|
+
const cleanup = () => {
|
|
506
|
+
if (printed > 0) {
|
|
507
|
+
output.write(`${ESC}${printed}A`);
|
|
508
|
+
output.write(`${ESC}0J`);
|
|
509
|
+
}
|
|
510
|
+
output.write(`${ESC}?25h`);
|
|
511
|
+
input.removeListener("data", onData);
|
|
512
|
+
if (typeof input.setRawMode === "function")
|
|
513
|
+
input.setRawMode(false);
|
|
514
|
+
input.pause();
|
|
515
|
+
};
|
|
516
|
+
const finish = (value) => {
|
|
517
|
+
cleanup();
|
|
518
|
+
resolve(value);
|
|
519
|
+
};
|
|
520
|
+
const onData = (buf) => {
|
|
521
|
+
const key = buf.toString("utf8");
|
|
522
|
+
switch (key) {
|
|
523
|
+
case "\x03":
|
|
524
|
+
case "\x1B":
|
|
525
|
+
case "q":
|
|
526
|
+
return finish(null);
|
|
527
|
+
case "\r":
|
|
528
|
+
case `
|
|
529
|
+
`:
|
|
530
|
+
return finish(choices.filter((c) => c.checked).map((c) => c.id));
|
|
531
|
+
case " ": {
|
|
532
|
+
const c = choices[index];
|
|
533
|
+
if (c)
|
|
534
|
+
c.checked = !c.checked;
|
|
535
|
+
return draw();
|
|
536
|
+
}
|
|
537
|
+
case "a": {
|
|
538
|
+
const allOn = choices.every((c) => c.checked);
|
|
539
|
+
for (const c of choices)
|
|
540
|
+
c.checked = !allOn;
|
|
541
|
+
return draw();
|
|
542
|
+
}
|
|
543
|
+
case "\x1B[A":
|
|
544
|
+
case "k":
|
|
545
|
+
index = (index - 1 + choices.length) % choices.length;
|
|
546
|
+
return draw();
|
|
547
|
+
case "\x1B[B":
|
|
548
|
+
case "j":
|
|
549
|
+
index = (index + 1) % choices.length;
|
|
550
|
+
return draw();
|
|
551
|
+
default:
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
output.write(`${ESC}?25l`);
|
|
556
|
+
if (typeof input.setRawMode === "function")
|
|
557
|
+
input.setRawMode(true);
|
|
558
|
+
input.resume();
|
|
559
|
+
input.on("data", onData);
|
|
560
|
+
draw();
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
// src/cli/skill.ts
|
|
565
|
+
import { mkdir as mkdir2, readFile as readFile3, stat, writeFile as writeFile2 } from "node:fs/promises";
|
|
566
|
+
import { homedir as homedir2 } from "node:os";
|
|
567
|
+
import { dirname as dirname2, join as join2 } from "node:path";
|
|
568
|
+
var SKILL_NAME = "flypod";
|
|
569
|
+
var SKILL_DESCRIPTION = "Deploy any folder of static files to a live public URL with flypod (flypod.dev) — no account, config, or build pipeline needed. " + "Use when the user wants to deploy, publish, ship, share, or host a static site, build output, preview, or demo, or asks to put a finished build online or get a URL for it.";
|
|
570
|
+
var MARK_BEGIN = `<!-- ${SKILL_NAME}:begin -->`;
|
|
571
|
+
var MARK_END = `<!-- ${SKILL_NAME}:end -->`;
|
|
572
|
+
function renderBody(sub) {
|
|
573
|
+
return `flypod turns any folder of static files into a live, public URL with a single
|
|
574
|
+
command. No account, no config, no build step of its own — you bring the built
|
|
575
|
+
files, flypod hosts them. Reach for it the moment a build exists and the user
|
|
576
|
+
wants it online: a site, a preview, a demo, a one-off share.
|
|
577
|
+
|
|
578
|
+
${sub} The happy path
|
|
579
|
+
|
|
580
|
+
1. Make sure the site is built — there is a folder of static files to ship
|
|
581
|
+
(e.g. \`dist/\`, \`build/\`, \`out/\`). flypod ships files; it does not build them.
|
|
582
|
+
2. Deploy that folder. Prefer \`--json\` so you can read the result:
|
|
583
|
+
|
|
584
|
+
\`\`\`sh
|
|
585
|
+
npx flypod ./dist --json
|
|
586
|
+
\`\`\`
|
|
587
|
+
|
|
588
|
+
If flypod is installed globally, drop the \`npx\`: \`flypod ./dist --json\`.
|
|
589
|
+
3. Read the \`url\` field from the JSON and give it to the user. That is the live
|
|
590
|
+
site. That's the whole loop.
|
|
591
|
+
|
|
592
|
+
If you omit the path, flypod auto-detects a build folder, trying \`dist\`,
|
|
593
|
+
\`build\`, \`out\`, \`.output/public\`, \`.vercel/output/static\`, \`public\`, \`_site\`
|
|
594
|
+
(each must contain an \`index.html\`). When in doubt, pass the path explicitly.
|
|
595
|
+
|
|
596
|
+
${sub} Is flypod installed?
|
|
597
|
+
|
|
598
|
+
Run \`flypod --version\`. If it is missing, **do not install anything** — just
|
|
599
|
+
prefix commands with \`npx\`: \`npx flypod ...\` downloads and runs it on the fly.
|
|
600
|
+
To install once: \`npm install -g flypod\`.
|
|
601
|
+
|
|
602
|
+
${sub} Reading the result
|
|
603
|
+
|
|
604
|
+
\`npx flypod ./dist --json\` prints a JSON object on stdout:
|
|
605
|
+
|
|
606
|
+
\`\`\`json
|
|
607
|
+
{
|
|
608
|
+
"ok": true,
|
|
609
|
+
"url": "https://ab12cd34.flypod.dev",
|
|
610
|
+
"site_id": "ab12cd34",
|
|
611
|
+
"manage_token": "…",
|
|
612
|
+
"claim_token": "…",
|
|
613
|
+
"expires_at": 1782929906088,
|
|
614
|
+
"files": 12,
|
|
615
|
+
"bytes": 1234567,
|
|
616
|
+
"elapsed_ms": 812
|
|
617
|
+
}
|
|
618
|
+
\`\`\`
|
|
619
|
+
|
|
620
|
+
- \`url\` — the live site. Always surface this to the user.
|
|
621
|
+
- \`manage_token\` — save it; it is needed to redeploy, roll back, or delete the site.
|
|
622
|
+
- \`claim_token\` — save it; it attaches an anonymous site to an account later.
|
|
623
|
+
- \`expires_at\` — anonymous deploys are ephemeral (~14 days); \`null\` once owned.
|
|
624
|
+
|
|
625
|
+
Treat \`manage_token\` and \`claim_token\` as secrets — don't paste them into chat
|
|
626
|
+
unless the user asks. Without \`--json\`, use quiet mode to capture the URL in a
|
|
627
|
+
shell variable: \`URL=$(npx flypod ./dist -q)\` (URL on stdout, token on stderr).
|
|
628
|
+
|
|
629
|
+
${sub} Anonymous vs. signed in
|
|
630
|
+
|
|
631
|
+
- **Anonymous (default):** zero auth. The first deploy just works and the site
|
|
632
|
+
expires in ~14 days. Best for previews and throwaways.
|
|
633
|
+
- **Signed in:** deploys are attributed to an account, never expire, and show up
|
|
634
|
+
in \`flypod list\`. Sign in once (no interactive prompt):
|
|
635
|
+
|
|
636
|
+
\`\`\`sh
|
|
637
|
+
flypod login --key fk_xxxxxxxxxxxxxxxxxxxx
|
|
638
|
+
\`\`\`
|
|
639
|
+
|
|
640
|
+
For agents and CI, skip the session file entirely — set the key in the
|
|
641
|
+
environment and every deploy is attributed to the account:
|
|
642
|
+
|
|
643
|
+
\`\`\`sh
|
|
644
|
+
FLYPOD_API_KEY=fk_xxxxxxxxxxxxxxxxxxxx npx flypod ./dist --json
|
|
645
|
+
\`\`\`
|
|
646
|
+
|
|
647
|
+
Mint a key at https://flypod.dev/account, or run \`flypod keys create\` when
|
|
648
|
+
already signed in.
|
|
649
|
+
|
|
650
|
+
${sub} Other commands
|
|
651
|
+
|
|
652
|
+
\`\`\`sh
|
|
653
|
+
flypod list # sites you own (requires sign in)
|
|
654
|
+
flypod claim <site_id> <token> # attach an anonymous deploy to your account
|
|
655
|
+
flypod keys create # mint an API key for agents / CI
|
|
656
|
+
flypod logout # forget the saved key
|
|
657
|
+
flypod --help # full usage
|
|
658
|
+
\`\`\`
|
|
659
|
+
|
|
660
|
+
${sub} Rules of thumb
|
|
661
|
+
|
|
662
|
+
- Build first. Point flypod at the **output** folder, never the project root or source.
|
|
663
|
+
- Prefer \`--json\` and read \`url\`. Use \`-q\`/\`--quiet\` when you only need the URL.
|
|
664
|
+
- flypod hosts **static files only** (HTML/CSS/JS/assets). It runs no server or backend.
|
|
665
|
+
- A missing \`flypod\` binary is fine — use \`npx flypod\`; never block on installing it.`;
|
|
666
|
+
}
|
|
667
|
+
function standaloneMarkdown() {
|
|
668
|
+
return `# Deploy with flypod
|
|
669
|
+
|
|
670
|
+
${renderBody("##")}
|
|
671
|
+
`;
|
|
672
|
+
}
|
|
673
|
+
function embedSection() {
|
|
674
|
+
return `${MARK_BEGIN}
|
|
675
|
+
## Deploying with flypod
|
|
676
|
+
|
|
677
|
+
${renderBody("###")}
|
|
678
|
+
${MARK_END}`;
|
|
679
|
+
}
|
|
680
|
+
function claudeSkillFile() {
|
|
681
|
+
return `---
|
|
682
|
+
name: ${SKILL_NAME}
|
|
683
|
+
description: ${SKILL_DESCRIPTION}
|
|
684
|
+
---
|
|
685
|
+
|
|
686
|
+
${standaloneMarkdown()}`;
|
|
687
|
+
}
|
|
688
|
+
function cursorRuleFile() {
|
|
689
|
+
return `---
|
|
690
|
+
description: ${SKILL_DESCRIPTION}
|
|
691
|
+
globs:
|
|
692
|
+
alwaysApply: false
|
|
693
|
+
---
|
|
694
|
+
|
|
695
|
+
${standaloneMarkdown()}`;
|
|
696
|
+
}
|
|
697
|
+
async function exists(path) {
|
|
698
|
+
try {
|
|
699
|
+
await stat(path);
|
|
700
|
+
return true;
|
|
701
|
+
} catch {
|
|
702
|
+
return false;
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
async function anyExists(root, rels) {
|
|
706
|
+
for (const rel of rels) {
|
|
707
|
+
if (await exists(join2(root, rel)))
|
|
708
|
+
return true;
|
|
709
|
+
}
|
|
710
|
+
return false;
|
|
711
|
+
}
|
|
712
|
+
var TARGETS = [
|
|
713
|
+
{
|
|
714
|
+
id: "agents",
|
|
715
|
+
label: "AGENTS.md",
|
|
716
|
+
detail: "universal — Codex, Cursor, Copilot, Gemini, Zed, Jules, +more",
|
|
717
|
+
kind: "embed",
|
|
718
|
+
alwaysDefault: true,
|
|
719
|
+
projectPath: (root) => join2(root, "AGENTS.md"),
|
|
720
|
+
globalPath: () => join2(homedir2(), ".codex", "AGENTS.md"),
|
|
721
|
+
detect: () => Promise.resolve(true),
|
|
722
|
+
render: embedSection
|
|
723
|
+
},
|
|
724
|
+
{
|
|
725
|
+
id: "claude",
|
|
726
|
+
label: "Claude Code",
|
|
727
|
+
detail: ".claude/skills/flypod/SKILL.md — loaded on demand",
|
|
728
|
+
kind: "skill",
|
|
729
|
+
alwaysDefault: true,
|
|
730
|
+
projectPath: (root) => join2(root, ".claude", "skills", SKILL_NAME, "SKILL.md"),
|
|
731
|
+
globalPath: () => join2(homedir2(), ".claude", "skills", SKILL_NAME, "SKILL.md"),
|
|
732
|
+
detect: (root) => anyExists(root, [".claude", "CLAUDE.md"]),
|
|
733
|
+
render: claudeSkillFile
|
|
734
|
+
},
|
|
735
|
+
{
|
|
736
|
+
id: "cursor",
|
|
737
|
+
label: "Cursor",
|
|
738
|
+
detail: ".cursor/rules/flypod.mdc",
|
|
739
|
+
kind: "rules",
|
|
740
|
+
alwaysDefault: false,
|
|
741
|
+
projectPath: (root) => join2(root, ".cursor", "rules", `${SKILL_NAME}.mdc`),
|
|
742
|
+
globalPath: () => null,
|
|
743
|
+
detect: (root) => anyExists(root, [".cursor", ".cursorrules"]),
|
|
744
|
+
render: cursorRuleFile
|
|
745
|
+
},
|
|
746
|
+
{
|
|
747
|
+
id: "copilot",
|
|
748
|
+
label: "GitHub Copilot",
|
|
749
|
+
detail: ".github/copilot-instructions.md",
|
|
750
|
+
kind: "embed",
|
|
751
|
+
alwaysDefault: false,
|
|
752
|
+
projectPath: (root) => join2(root, ".github", "copilot-instructions.md"),
|
|
753
|
+
globalPath: () => null,
|
|
754
|
+
detect: (root) => anyExists(root, [".github"]),
|
|
755
|
+
render: embedSection
|
|
756
|
+
},
|
|
757
|
+
{
|
|
758
|
+
id: "windsurf",
|
|
759
|
+
label: "Windsurf",
|
|
760
|
+
detail: ".windsurf/rules/flypod.md",
|
|
761
|
+
kind: "rules",
|
|
762
|
+
alwaysDefault: false,
|
|
763
|
+
projectPath: (root) => join2(root, ".windsurf", "rules", `${SKILL_NAME}.md`),
|
|
764
|
+
globalPath: () => null,
|
|
765
|
+
detect: (root) => anyExists(root, [".windsurf", ".windsurfrules"]),
|
|
766
|
+
render: standaloneMarkdown
|
|
767
|
+
},
|
|
768
|
+
{
|
|
769
|
+
id: "cline",
|
|
770
|
+
label: "Cline",
|
|
771
|
+
detail: ".clinerules/flypod.md",
|
|
772
|
+
kind: "rules",
|
|
773
|
+
alwaysDefault: false,
|
|
774
|
+
projectPath: (root) => join2(root, ".clinerules", `${SKILL_NAME}.md`),
|
|
775
|
+
globalPath: () => null,
|
|
776
|
+
detect: (root) => anyExists(root, [".clinerules"]),
|
|
777
|
+
render: standaloneMarkdown
|
|
778
|
+
},
|
|
779
|
+
{
|
|
780
|
+
id: "roo",
|
|
781
|
+
label: "Roo Code",
|
|
782
|
+
detail: ".roo/rules/flypod.md",
|
|
783
|
+
kind: "rules",
|
|
784
|
+
alwaysDefault: false,
|
|
785
|
+
projectPath: (root) => join2(root, ".roo", "rules", `${SKILL_NAME}.md`),
|
|
786
|
+
globalPath: () => null,
|
|
787
|
+
detect: (root) => anyExists(root, [".roo", ".roorules"]),
|
|
788
|
+
render: standaloneMarkdown
|
|
789
|
+
},
|
|
790
|
+
{
|
|
791
|
+
id: "gemini",
|
|
792
|
+
label: "Gemini CLI",
|
|
793
|
+
detail: "GEMINI.md",
|
|
794
|
+
kind: "embed",
|
|
795
|
+
alwaysDefault: false,
|
|
796
|
+
projectPath: (root) => join2(root, "GEMINI.md"),
|
|
797
|
+
globalPath: () => join2(homedir2(), ".gemini", "GEMINI.md"),
|
|
798
|
+
detect: (root) => anyExists(root, ["GEMINI.md", ".gemini"]),
|
|
799
|
+
render: embedSection
|
|
800
|
+
}
|
|
801
|
+
];
|
|
802
|
+
function spliceBlock(existing, section) {
|
|
803
|
+
const begin = existing.indexOf(MARK_BEGIN);
|
|
804
|
+
const end = existing.indexOf(MARK_END);
|
|
805
|
+
if (begin !== -1 && end !== -1 && end > begin) {
|
|
806
|
+
const before = existing.slice(0, begin);
|
|
807
|
+
const after = existing.slice(end + MARK_END.length);
|
|
808
|
+
return `${before}${section}${after}`;
|
|
809
|
+
}
|
|
810
|
+
const trimmed = existing.replace(/\s+$/, "");
|
|
811
|
+
return trimmed ? `${trimmed}
|
|
812
|
+
|
|
813
|
+
${section}
|
|
814
|
+
` : `${section}
|
|
815
|
+
`;
|
|
816
|
+
}
|
|
817
|
+
async function writeTarget(target, path) {
|
|
818
|
+
const had = await exists(path);
|
|
819
|
+
const current = had ? await readFile3(path, "utf8") : "";
|
|
820
|
+
let next;
|
|
821
|
+
if (target.kind === "embed") {
|
|
822
|
+
next = spliceBlock(current, target.render());
|
|
823
|
+
} else {
|
|
824
|
+
next = target.render();
|
|
825
|
+
}
|
|
826
|
+
if (had && current === next)
|
|
827
|
+
return { target, path, status: "unchanged" };
|
|
828
|
+
await mkdir2(dirname2(path), { recursive: true });
|
|
829
|
+
await writeFile2(path, next, "utf8");
|
|
830
|
+
return { target, path, status: had ? "updated" : "created" };
|
|
831
|
+
}
|
|
832
|
+
async function buildPlan(root, env, global) {
|
|
833
|
+
const entries = [];
|
|
834
|
+
for (const target of TARGETS) {
|
|
835
|
+
const path = global ? target.globalPath(env) : target.projectPath(root);
|
|
836
|
+
if (!path)
|
|
837
|
+
continue;
|
|
838
|
+
const detected = await target.detect(root, env);
|
|
839
|
+
entries.push({
|
|
840
|
+
target,
|
|
841
|
+
path,
|
|
842
|
+
detected,
|
|
843
|
+
defaultOn: target.alwaysDefault || detected
|
|
844
|
+
});
|
|
845
|
+
}
|
|
846
|
+
return entries;
|
|
847
|
+
}
|
|
848
|
+
async function installSkill(args, io) {
|
|
849
|
+
const env = io.env ?? process.env;
|
|
850
|
+
const root = args.cwd ?? process.cwd();
|
|
851
|
+
const global = Boolean(args.global);
|
|
852
|
+
const plan = await buildPlan(root, env, global);
|
|
853
|
+
if (args.list) {
|
|
854
|
+
io.err(global ? "flypod skill targets (global):" : "flypod skill targets (this project):");
|
|
855
|
+
io.err("");
|
|
856
|
+
for (const e of plan) {
|
|
857
|
+
const mark = e.defaultOn ? "●" : "○";
|
|
858
|
+
const tag = e.target.alwaysDefault ? "default" : e.detected ? "detected" : "available";
|
|
859
|
+
io.out(`${mark} ${e.target.id} ${tag} ${e.path}`);
|
|
860
|
+
}
|
|
861
|
+
io.err("");
|
|
862
|
+
io.err("● = installed by default. Run `flypod install skill` to write them.");
|
|
863
|
+
return 0;
|
|
864
|
+
}
|
|
865
|
+
let chosen;
|
|
866
|
+
if (args.all) {
|
|
867
|
+
chosen = plan.map((e) => e.target.id);
|
|
868
|
+
} else if (args.targets && args.targets.length > 0) {
|
|
869
|
+
const known = new Set(plan.map((e) => e.target.id));
|
|
870
|
+
const unknown = args.targets.filter((id) => !known.has(id));
|
|
871
|
+
if (unknown.length > 0) {
|
|
872
|
+
io.err(`flypod: unknown target(s): ${unknown.join(", ")}`);
|
|
873
|
+
io.err(`Known targets: ${TARGETS.map((t) => t.id).join(", ")}`);
|
|
874
|
+
return 2;
|
|
875
|
+
}
|
|
876
|
+
chosen = args.targets;
|
|
877
|
+
} else if (args.picker) {
|
|
878
|
+
const picked = await args.picker(plan);
|
|
879
|
+
if (picked === null) {
|
|
880
|
+
io.err("Cancelled. Nothing written.");
|
|
881
|
+
return 130;
|
|
882
|
+
}
|
|
883
|
+
chosen = picked;
|
|
884
|
+
} else {
|
|
885
|
+
chosen = plan.filter((e) => e.defaultOn).map((e) => e.target.id);
|
|
886
|
+
}
|
|
887
|
+
const selected = plan.filter((e) => chosen.includes(e.target.id));
|
|
888
|
+
if (selected.length === 0) {
|
|
889
|
+
io.err("No targets selected. Nothing written.");
|
|
890
|
+
return 0;
|
|
891
|
+
}
|
|
892
|
+
if (args.dryRun) {
|
|
893
|
+
io.err("Would write:");
|
|
894
|
+
for (const e of selected)
|
|
895
|
+
io.out(e.path);
|
|
896
|
+
return 0;
|
|
897
|
+
}
|
|
898
|
+
const results = [];
|
|
899
|
+
for (const e of selected) {
|
|
900
|
+
try {
|
|
901
|
+
results.push(await writeTarget(e.target, e.path));
|
|
902
|
+
} catch (error) {
|
|
903
|
+
io.err(`flypod: failed to write ${e.path}: ${error.message}`);
|
|
904
|
+
return 1;
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
const verb = {
|
|
908
|
+
created: "created",
|
|
909
|
+
updated: "updated",
|
|
910
|
+
unchanged: "up to date"
|
|
911
|
+
};
|
|
912
|
+
for (const r of results) {
|
|
913
|
+
io.err(` ${r.status === "unchanged" ? "·" : "✓"} ${verb[r.status]} ${r.path}`);
|
|
914
|
+
io.out(r.path);
|
|
915
|
+
}
|
|
916
|
+
const changed = results.filter((r) => r.status !== "unchanged").length;
|
|
917
|
+
io.err("");
|
|
918
|
+
io.err(changed > 0 ? `Your agents now know how to deploy with flypod. Try asking one to "deploy this with flypod".` : "Everything was already up to date.");
|
|
919
|
+
return 0;
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
// src/ui.ts
|
|
923
|
+
var ESC2 = "\x1B[";
|
|
15
924
|
function envBool(name) {
|
|
16
925
|
const v = process.env[name];
|
|
17
926
|
return v !== undefined && v !== "" && v !== "0" && v !== "false";
|
|
@@ -25,7 +934,7 @@ function colorsEnabled(stream = process.stderr) {
|
|
|
25
934
|
}
|
|
26
935
|
var FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
27
936
|
function paint(open, s) {
|
|
28
|
-
return `${
|
|
937
|
+
return `${ESC2}${open}m${s}${ESC2}0m`;
|
|
29
938
|
}
|
|
30
939
|
function makeStyle(enabled) {
|
|
31
940
|
if (!enabled) {
|
|
@@ -48,11 +957,11 @@ function makeSpinner(stream = process.stderr, style = makeStyle(false)) {
|
|
|
48
957
|
let label = "";
|
|
49
958
|
let started = false;
|
|
50
959
|
const writeFrame = () => {
|
|
51
|
-
stream.write(`\r${
|
|
960
|
+
stream.write(`\r${ESC2}2K ${style.accent(FRAMES[frame] ?? "·")} ${label}`);
|
|
52
961
|
};
|
|
53
962
|
const clearLine = () => {
|
|
54
963
|
if (tty)
|
|
55
|
-
stream.write(`\r${
|
|
964
|
+
stream.write(`\r${ESC2}2K`);
|
|
56
965
|
};
|
|
57
966
|
return {
|
|
58
967
|
start(text) {
|
|
@@ -114,6 +1023,30 @@ function fmtCount(n, singular) {
|
|
|
114
1023
|
}
|
|
115
1024
|
|
|
116
1025
|
// bin/deploy.ts
|
|
1026
|
+
var SUBCOMMANDS = new Set([
|
|
1027
|
+
"deploy",
|
|
1028
|
+
"update",
|
|
1029
|
+
"versions",
|
|
1030
|
+
"rollback",
|
|
1031
|
+
"forget",
|
|
1032
|
+
"login",
|
|
1033
|
+
"logout",
|
|
1034
|
+
"list",
|
|
1035
|
+
"claim",
|
|
1036
|
+
"keys",
|
|
1037
|
+
"install"
|
|
1038
|
+
]);
|
|
1039
|
+
var TARGET_FLAGS = {
|
|
1040
|
+
"--agents": "agents",
|
|
1041
|
+
"--agents-md": "agents",
|
|
1042
|
+
"--claude": "claude",
|
|
1043
|
+
"--cursor": "cursor",
|
|
1044
|
+
"--copilot": "copilot",
|
|
1045
|
+
"--windsurf": "windsurf",
|
|
1046
|
+
"--cline": "cline",
|
|
1047
|
+
"--roo": "roo",
|
|
1048
|
+
"--gemini": "gemini"
|
|
1049
|
+
};
|
|
117
1050
|
function parseArgs(argv) {
|
|
118
1051
|
const out = { json: false, quiet: false, help: false, version: false };
|
|
119
1052
|
for (const a of argv) {
|
|
@@ -135,12 +1068,159 @@ Run \`flypod --help\` for usage.
|
|
|
135
1068
|
}
|
|
136
1069
|
return out;
|
|
137
1070
|
}
|
|
1071
|
+
function flag(argv, name) {
|
|
1072
|
+
const long = `--${name}`;
|
|
1073
|
+
const equals = `${long}=`;
|
|
1074
|
+
for (let i = 0;i < argv.length; i++) {
|
|
1075
|
+
const a = argv[i];
|
|
1076
|
+
if (a === long)
|
|
1077
|
+
return argv[i + 1];
|
|
1078
|
+
if (a.startsWith(equals))
|
|
1079
|
+
return a.slice(equals.length);
|
|
1080
|
+
}
|
|
1081
|
+
return;
|
|
1082
|
+
}
|
|
1083
|
+
function parseSub(argv) {
|
|
1084
|
+
const positionals = [];
|
|
1085
|
+
let site;
|
|
1086
|
+
let token;
|
|
1087
|
+
let json = false;
|
|
1088
|
+
let quiet = false;
|
|
1089
|
+
for (let i = 0;i < argv.length; i++) {
|
|
1090
|
+
const a = argv[i];
|
|
1091
|
+
if (a === "--site")
|
|
1092
|
+
site = argv[++i];
|
|
1093
|
+
else if (a.startsWith("--site="))
|
|
1094
|
+
site = a.slice("--site=".length);
|
|
1095
|
+
else if (a === "--token")
|
|
1096
|
+
token = argv[++i];
|
|
1097
|
+
else if (a.startsWith("--token="))
|
|
1098
|
+
token = a.slice("--token=".length);
|
|
1099
|
+
else if (a === "--json")
|
|
1100
|
+
json = true;
|
|
1101
|
+
else if (a === "-q" || a === "--quiet")
|
|
1102
|
+
quiet = true;
|
|
1103
|
+
else if (!a.startsWith("-"))
|
|
1104
|
+
positionals.push(a);
|
|
1105
|
+
}
|
|
1106
|
+
return { positionals, site, token, json, quiet };
|
|
1107
|
+
}
|
|
1108
|
+
async function runSubcommand(name, argv) {
|
|
1109
|
+
const io = {
|
|
1110
|
+
out: (line) => process.stdout.write(`${line}
|
|
1111
|
+
`),
|
|
1112
|
+
err: (line) => process.stderr.write(`${line}
|
|
1113
|
+
`)
|
|
1114
|
+
};
|
|
1115
|
+
switch (name) {
|
|
1116
|
+
case "update": {
|
|
1117
|
+
const { positionals, site, token, json, quiet } = parseSub(argv);
|
|
1118
|
+
return update({ path: positionals[0], site, token, json, quiet }, io);
|
|
1119
|
+
}
|
|
1120
|
+
case "versions": {
|
|
1121
|
+
const { site, token, json } = parseSub(argv);
|
|
1122
|
+
return versions({ site, token, json }, io);
|
|
1123
|
+
}
|
|
1124
|
+
case "rollback": {
|
|
1125
|
+
const { positionals, site, token, json } = parseSub(argv);
|
|
1126
|
+
return rollback({ version: positionals[0], site, token, json }, io);
|
|
1127
|
+
}
|
|
1128
|
+
case "forget": {
|
|
1129
|
+
const { site } = parseSub(argv);
|
|
1130
|
+
return forget({ site }, io);
|
|
1131
|
+
}
|
|
1132
|
+
case "login":
|
|
1133
|
+
return login({ key: flag(argv, "key") }, io);
|
|
1134
|
+
case "logout":
|
|
1135
|
+
return logout({}, io);
|
|
1136
|
+
case "list":
|
|
1137
|
+
return list({}, io);
|
|
1138
|
+
case "claim": {
|
|
1139
|
+
const positional = argv.filter((a) => !a.startsWith("-"));
|
|
1140
|
+
return claim({ site_id: positional[0], token: positional[1] }, io);
|
|
1141
|
+
}
|
|
1142
|
+
case "keys": {
|
|
1143
|
+
const sub = argv.find((a) => !a.startsWith("-"));
|
|
1144
|
+
if (sub === "create")
|
|
1145
|
+
return keysCreate({}, io);
|
|
1146
|
+
io.err("Usage: flypod keys create");
|
|
1147
|
+
return 2;
|
|
1148
|
+
}
|
|
1149
|
+
case "install":
|
|
1150
|
+
return runInstall(argv, io);
|
|
1151
|
+
default:
|
|
1152
|
+
io.err(`flypod: unknown subcommand "${name}"`);
|
|
1153
|
+
return 2;
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
function shortHome(path) {
|
|
1157
|
+
const home = homedir3();
|
|
1158
|
+
return path.startsWith(home) ? `~${path.slice(home.length)}` : path;
|
|
1159
|
+
}
|
|
1160
|
+
async function runInstall(argv, io) {
|
|
1161
|
+
const noun = argv.find((a) => !a.startsWith("-"));
|
|
1162
|
+
if (noun !== "skill" && noun !== "skills") {
|
|
1163
|
+
io.err("Usage: flypod install skill [targets] [--all] [--global] [--list] [--dry-run]");
|
|
1164
|
+
io.err("");
|
|
1165
|
+
io.err("Teaches your coding agents (Claude Code, Codex, Cursor, …) how to deploy");
|
|
1166
|
+
io.err("with flypod by writing a small instruction file they read automatically.");
|
|
1167
|
+
return 2;
|
|
1168
|
+
}
|
|
1169
|
+
const KNOWN_FLAGS = new Set([
|
|
1170
|
+
"--all",
|
|
1171
|
+
"--global",
|
|
1172
|
+
"--list",
|
|
1173
|
+
"--dry-run",
|
|
1174
|
+
"--print",
|
|
1175
|
+
"--yes",
|
|
1176
|
+
"-y",
|
|
1177
|
+
...Object.keys(TARGET_FLAGS)
|
|
1178
|
+
]);
|
|
1179
|
+
const unknownFlag = argv.find((a) => a.startsWith("-") && !KNOWN_FLAGS.has(a));
|
|
1180
|
+
if (unknownFlag) {
|
|
1181
|
+
io.err(`flypod: unknown flag "${unknownFlag}"`);
|
|
1182
|
+
io.err("Run `flypod install skill --list` to see available targets and flags.");
|
|
1183
|
+
return 2;
|
|
1184
|
+
}
|
|
1185
|
+
const has = (flag2) => argv.includes(flag2);
|
|
1186
|
+
const targets = [];
|
|
1187
|
+
for (const [flag2, id] of Object.entries(TARGET_FLAGS)) {
|
|
1188
|
+
if (has(flag2) && !targets.includes(id))
|
|
1189
|
+
targets.push(id);
|
|
1190
|
+
}
|
|
1191
|
+
const all = has("--all");
|
|
1192
|
+
const global = has("--global");
|
|
1193
|
+
const list2 = has("--list");
|
|
1194
|
+
const dryRun = has("--dry-run") || has("--print");
|
|
1195
|
+
const yes = has("--yes") || has("-y");
|
|
1196
|
+
const interactive = !list2 && !dryRun && !all && !yes && targets.length === 0 && canPrompt(process.stdin);
|
|
1197
|
+
const picker = interactive ? async (plan) => {
|
|
1198
|
+
const style = makeStyle(colorsEnabled(process.stderr));
|
|
1199
|
+
process.stderr.write(`
|
|
1200
|
+
${style.bold(style.accent("flypod"))} ${style.dim("· teach your agents to deploy")}
|
|
1201
|
+
|
|
1202
|
+
`);
|
|
1203
|
+
const choices = plan.map((e) => ({
|
|
1204
|
+
id: e.target.id,
|
|
1205
|
+
label: e.target.label,
|
|
1206
|
+
hint: `${e.target.detail}${e.detected && !e.target.alwaysDefault ? " · detected" : ""}`,
|
|
1207
|
+
checked: e.defaultOn
|
|
1208
|
+
}));
|
|
1209
|
+
return multiselect({ title: "Install the flypod skill into:", choices, style });
|
|
1210
|
+
} : undefined;
|
|
1211
|
+
const io2 = {
|
|
1212
|
+
out: io.out,
|
|
1213
|
+
err: (line) => io.err(shortHome(line)),
|
|
1214
|
+
env: io.env
|
|
1215
|
+
};
|
|
1216
|
+
return installSkill({ targets, all, global, list: list2, dryRun, picker }, io2);
|
|
1217
|
+
}
|
|
138
1218
|
async function readVersion() {
|
|
139
1219
|
const here = fileURLToPath(import.meta.url);
|
|
140
1220
|
for (const rel of ["../../package.json", "../package.json"]) {
|
|
141
1221
|
try {
|
|
142
1222
|
const url = new URL(rel, `file://${here}`);
|
|
143
|
-
const text = await
|
|
1223
|
+
const text = await readFile4(url, "utf8");
|
|
144
1224
|
const version = JSON.parse(text).version;
|
|
145
1225
|
if (version)
|
|
146
1226
|
return version;
|
|
@@ -150,19 +1230,60 @@ async function readVersion() {
|
|
|
150
1230
|
}
|
|
151
1231
|
function showHelp(version) {
|
|
152
1232
|
const usage = `flypod v${version}
|
|
153
|
-
Drop files, get a live URL.
|
|
1233
|
+
Drop files, get a live URL. Every deploy is versioned, so you can roll back.
|
|
154
1234
|
|
|
155
|
-
|
|
156
|
-
flypod [path]
|
|
157
|
-
flypod
|
|
158
|
-
flypod
|
|
159
|
-
flypod
|
|
160
|
-
|
|
1235
|
+
THE LOOP (this is all most agents need):
|
|
1236
|
+
flypod [path] Deploy NEW content -> creates a new site, prints a URL.
|
|
1237
|
+
flypod update Ship CHANGES to that same site -> adds a new VERSION.
|
|
1238
|
+
flypod versions List every version, newest first (the live one is marked).
|
|
1239
|
+
flypod rollback Make the previous version live again.
|
|
1240
|
+
|
|
1241
|
+
A "version" is one deploy of a set of files. 'flypod' makes a brand-new site;
|
|
1242
|
+
'flypod update' adds a version to the site you already made. flypod remembers
|
|
1243
|
+
which site a folder belongs to (stored under your home config, never in your
|
|
1244
|
+
repo), so 'update'/'versions'/'rollback' just work from that folder. To target
|
|
1245
|
+
a site from anywhere, pass --site <id> (the id is printed on first deploy).
|
|
1246
|
+
|
|
1247
|
+
Examples:
|
|
1248
|
+
flypod ./dist Deploy a built site (folder).
|
|
1249
|
+
flypod index.html Deploy a single file. (For several files, put
|
|
1250
|
+
them in a folder and deploy the folder.)
|
|
1251
|
+
flypod Deploy the auto-detected build folder.
|
|
1252
|
+
flypod update Re-deploy this folder as a new version.
|
|
1253
|
+
flypod update ./dist Same, with an explicit path.
|
|
1254
|
+
flypod versions Show this folder's version history.
|
|
1255
|
+
flypod rollback Roll back to the previous version.
|
|
1256
|
+
flypod rollback <version> Roll back to a specific version (id or prefix).
|
|
1257
|
+
flypod update --site <id> Update any site by id (no folder memory needed).
|
|
1258
|
+
|
|
1259
|
+
Targeting (update / versions / rollback):
|
|
1260
|
+
--site <id> The site to act on. Omit to use the folder's remembered site.
|
|
1261
|
+
--token <tok> A site's manage token, for acting on an anonymous site from a
|
|
1262
|
+
machine that doesn't remember it. Owned sites use your login.
|
|
1263
|
+
|
|
1264
|
+
Account (optional — lets deploys live forever and be listed/owned):
|
|
1265
|
+
flypod login --key fk_... Save an API key; deploys are then yours forever.
|
|
1266
|
+
flypod logout Forget the saved API key.
|
|
1267
|
+
flypod list List sites you own.
|
|
1268
|
+
flypod claim <id> <token> Attach an earlier anonymous deploy to your account.
|
|
1269
|
+
flypod keys create Mint a new API key (for agents / CI).
|
|
1270
|
+
flypod forget [--site <id>] Drop this folder's remembered site link.
|
|
1271
|
+
|
|
1272
|
+
Agents:
|
|
1273
|
+
flypod install skill Teach your coding agents (Claude Code, Codex,
|
|
1274
|
+
Cursor, …) how to deploy with flypod.
|
|
1275
|
+
|
|
1276
|
+
Output:
|
|
1277
|
+
--json Emit a stable JSON result on stdout (for agents/scripts).
|
|
1278
|
+
-q, --quiet Print only the URL.
|
|
1279
|
+
-h, --help Show this help. -v, --version Show the flypod version.
|
|
161
1280
|
|
|
162
1281
|
Environment:
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
1282
|
+
FLYPOD_API_KEY Deploy as your account without logging in (agents / CI)
|
|
1283
|
+
DEPLOY_URL Override the deploy server (default: https://flypod.dev)
|
|
1284
|
+
FLYPOD_CONFIG_DIR Override where the CLI keeps its session + folder memory
|
|
1285
|
+
NO_COLOR Disable ANSI colors
|
|
1286
|
+
FORCE_COLOR Force ANSI colors even when stderr is not a TTY
|
|
166
1287
|
|
|
167
1288
|
When no path is given, flypod looks for a build folder in the current directory:
|
|
168
1289
|
dist, build, out, .output/public, .vercel/output/static, public, _site
|
|
@@ -178,8 +1299,15 @@ function shortDir(dir) {
|
|
|
178
1299
|
return rel === "" || rel.startsWith("..") ? dir : rel || ".";
|
|
179
1300
|
}
|
|
180
1301
|
async function main() {
|
|
181
|
-
const
|
|
1302
|
+
const rawArgv = process.argv.slice(2);
|
|
182
1303
|
const version = await readVersion();
|
|
1304
|
+
const firstPositional = rawArgv.find((a) => !a.startsWith("-"));
|
|
1305
|
+
if (firstPositional && SUBCOMMANDS.has(firstPositional) && firstPositional !== "deploy") {
|
|
1306
|
+
const rest = rawArgv.filter((a) => a !== firstPositional);
|
|
1307
|
+
const code = await runSubcommand(firstPositional, rest);
|
|
1308
|
+
process.exit(code);
|
|
1309
|
+
}
|
|
1310
|
+
const args = parseArgs(firstPositional === "deploy" ? rawArgv.filter((a) => a !== "deploy") : rawArgv);
|
|
183
1311
|
if (args.help) {
|
|
184
1312
|
showHelp(version);
|
|
185
1313
|
return;
|
|
@@ -189,7 +1317,7 @@ async function main() {
|
|
|
189
1317
|
`);
|
|
190
1318
|
return;
|
|
191
1319
|
}
|
|
192
|
-
const baseUrl =
|
|
1320
|
+
const { apiKey, baseUrl } = await resolveAuth();
|
|
193
1321
|
const useUI = !args.json && !args.quiet;
|
|
194
1322
|
const style = makeStyle(colorsEnabled(process.stderr) && useUI);
|
|
195
1323
|
if (useUI) {
|
|
@@ -251,7 +1379,7 @@ async function main() {
|
|
|
251
1379
|
const started = Date.now();
|
|
252
1380
|
let result;
|
|
253
1381
|
try {
|
|
254
|
-
result = await deploySite({ baseUrl, files });
|
|
1382
|
+
result = await deploySite({ baseUrl, files, apiKey });
|
|
255
1383
|
} catch (error) {
|
|
256
1384
|
spinner.fail("Deploy failed.");
|
|
257
1385
|
const msg = error.message;
|
|
@@ -267,6 +1395,18 @@ async function main() {
|
|
|
267
1395
|
}
|
|
268
1396
|
const elapsed = Date.now() - started;
|
|
269
1397
|
spinner.success(`Deployed in ${fmtSeconds(elapsed)}`);
|
|
1398
|
+
const owned = typeof result.owner_account_id === "string";
|
|
1399
|
+
try {
|
|
1400
|
+
await linkProject(process.cwd(), {
|
|
1401
|
+
site_id: result.site_id,
|
|
1402
|
+
url: result.url,
|
|
1403
|
+
base_url: baseUrl,
|
|
1404
|
+
...owned ? {} : { manage_token: result.manage_token },
|
|
1405
|
+
expires_at: result.expires_at,
|
|
1406
|
+
last_used: Date.now(),
|
|
1407
|
+
version_id: result.version_id
|
|
1408
|
+
});
|
|
1409
|
+
} catch {}
|
|
270
1410
|
if (args.json) {
|
|
271
1411
|
process.stdout.write(`${JSON.stringify({
|
|
272
1412
|
ok: true,
|
|
@@ -275,6 +1415,8 @@ async function main() {
|
|
|
275
1415
|
version_id: result.version_id,
|
|
276
1416
|
expires_at: result.expires_at,
|
|
277
1417
|
manage_token: result.manage_token,
|
|
1418
|
+
claim_token: result.claim_token,
|
|
1419
|
+
owner_account_id: result.owner_account_id,
|
|
278
1420
|
source: shortDir(dir),
|
|
279
1421
|
files: fileNames.length,
|
|
280
1422
|
bytes: totalBytes,
|
|
@@ -301,12 +1443,16 @@ async function main() {
|
|
|
301
1443
|
process.stderr.write(` ${rule}
|
|
302
1444
|
|
|
303
1445
|
`);
|
|
304
|
-
|
|
305
|
-
`
|
|
1446
|
+
const expiry = typeof result.expires_at === "number" ? `in ${Math.max(0, Math.round((result.expires_at - Date.now()) / 86400000))} days . ephemeral by default` : result.owner_account_id ? `never . owned by you (${result.owner_account_id})` : "never (claimed)";
|
|
1447
|
+
process.stderr.write(` ${style.muted("expires")} ${style.dim(expiry)}
|
|
1448
|
+
|
|
1449
|
+
`);
|
|
1450
|
+
process.stderr.write(` ${style.muted("ship a change")} ${style.bold("flypod update")} ${style.dim("(new version of this site)")}
|
|
1451
|
+
` + ` ${style.muted("roll back")} ${style.bold("flypod rollback")}
|
|
1452
|
+
` + ` ${style.muted("history")} ${style.bold("flypod versions")}
|
|
306
1453
|
|
|
307
1454
|
`);
|
|
308
|
-
|
|
309
|
-
process.stderr.write(` ${style.muted("expires ")} ${style.dim(expiry)}
|
|
1455
|
+
process.stderr.write(` ${style.dim(`manage token ${result.manage_token} — remembered for this folder; needed only with --site elsewhere`)}
|
|
310
1456
|
|
|
311
1457
|
`);
|
|
312
1458
|
process.stdout.write(`${result.url}
|