@alori/cli 0.1.9 → 0.1.10
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 +3 -0
- package/bin/alori.mjs +21 -2
- package/lib/prospect.mjs +43 -0
- package/lib/sync.mjs +6 -0
- package/lib/upload.mjs +65 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,6 +17,9 @@ folder; only the same lines changed on both sides stop the push, with their copy
|
|
|
17
17
|
One sign-in works on every app you can change: `alori apps` lists them (yours, and your agency's clients), and
|
|
18
18
|
`alori dev --app "Client name"` downloads one into a new folder. Each folder keeps working on its own app.
|
|
19
19
|
|
|
20
|
+
`alori upload docs/*.pdf` puts files (PDFs, photos) in your app's own storage and prints each one's address, to link
|
|
21
|
+
from your site's code.
|
|
22
|
+
|
|
20
23
|
`alori dev` runs the app from your files against its real backend and data: screens and text change as you save,
|
|
21
24
|
backend changes (`convex/`) reach it with `alori push`.
|
|
22
25
|
|
package/bin/alori.mjs
CHANGED
|
@@ -7,6 +7,8 @@ import { resolve } from "node:path";
|
|
|
7
7
|
import { apiBase, call, forget, login, SignedOut, useApp } from "../lib/auth.mjs";
|
|
8
8
|
import { readState } from "../lib/folder.mjs";
|
|
9
9
|
import { appsList, dev, pull, push, status } from "../lib/sync.mjs";
|
|
10
|
+
import { upload } from "../lib/upload.mjs";
|
|
11
|
+
import { prospect } from "../lib/prospect.mjs";
|
|
10
12
|
|
|
11
13
|
const help = `alori: build your Alori app with Claude Code
|
|
12
14
|
|
|
@@ -17,6 +19,10 @@ const help = `alori: build your Alori app with Claude Code
|
|
|
17
19
|
alori apps The apps you can change: yours, your agency's clients, the ones support opened
|
|
18
20
|
alori status What changed since the last pull or push
|
|
19
21
|
alori push -m "message" Send your changes: Alori builds them and saves a new version
|
|
22
|
+
alori upload <files…> Put files (PDFs, photos) in your app's storage and print each one's address
|
|
23
|
+
--json Print the addresses as JSON
|
|
24
|
+
alori prospect <website> Alori team: a demo of a prospect's site at <name>.prospects.aloriapp.com
|
|
25
|
+
--name <company> The name on its "Made for" bar (else taken from the address)
|
|
20
26
|
alori whoami Which app you're connected to
|
|
21
27
|
alori logout Forget this computer's sign-in
|
|
22
28
|
|
|
@@ -54,7 +60,7 @@ async function main() {
|
|
|
54
60
|
await login();
|
|
55
61
|
const me = await call("/code/me");
|
|
56
62
|
if (!me.ok) {
|
|
57
|
-
console.log(me.body?.error === "cantBuild" ? "Connected, but your role doesn't build this app." : "Connected.");
|
|
63
|
+
console.log(me.body?.error === "superAdminsOnly" ? "The alori command is only for the Alori team for now." : me.body?.error === "cantBuild" ? "Connected, but your role doesn't build this app." : "Connected.");
|
|
58
64
|
return;
|
|
59
65
|
}
|
|
60
66
|
console.log(`Connected to ${me.body.app} as ${me.body.email ?? "you"}. Next: alori dev`);
|
|
@@ -68,7 +74,7 @@ async function main() {
|
|
|
68
74
|
// In a pulled folder, the folder's app.
|
|
69
75
|
useApp(readState(resolve("."))?.appId ?? null);
|
|
70
76
|
const me = await call("/code/me");
|
|
71
|
-
if (!me.ok) throw Object.assign(new Error(me.body?.error === "cantBuild" ? "Your role doesn't build this app." : "Run: alori login"), { plain: true });
|
|
77
|
+
if (!me.ok) throw Object.assign(new Error(me.body?.error === "superAdminsOnly" ? "The alori command is only for the Alori team for now." : me.body?.error === "cantBuild" ? "Your role doesn't build this app." : "Run: alori login"), { plain: true });
|
|
72
78
|
console.log(`${me.body.app} (version ${me.body.version ?? "none"}), signed in as ${me.body.email ?? "you"}.`);
|
|
73
79
|
return;
|
|
74
80
|
}
|
|
@@ -88,12 +94,25 @@ async function main() {
|
|
|
88
94
|
}
|
|
89
95
|
});
|
|
90
96
|
return;
|
|
97
|
+
case "upload":
|
|
98
|
+
// In a pulled folder, the folder's app; elsewhere, --app or the sign-in's own app.
|
|
99
|
+
useApp(readState(resolve("."))?.appId ?? appArgOf(args) ?? null);
|
|
100
|
+
await signedIn(async () => {
|
|
101
|
+
const files = args.filter((arg, index) => !arg.startsWith("-") && !["--app", "-a"].includes(args[index - 1] ?? ""));
|
|
102
|
+
const saved = await upload(files);
|
|
103
|
+
if (args.includes("--json")) console.log(JSON.stringify(saved, null, 2));
|
|
104
|
+
else for (const file of saved) console.log(`${file.url} ${file.name}`);
|
|
105
|
+
});
|
|
106
|
+
return;
|
|
91
107
|
case "status":
|
|
92
108
|
status(resolve("."));
|
|
93
109
|
return;
|
|
94
110
|
case "push":
|
|
95
111
|
await push(resolve("."), messageOf(args));
|
|
96
112
|
return;
|
|
113
|
+
case "prospect":
|
|
114
|
+
await signedIn(() => prospect(args.find((arg, index) => !arg.startsWith("-") && args[index - 1] !== "--name"), flagOf(args, ["--name"])));
|
|
115
|
+
return;
|
|
97
116
|
default:
|
|
98
117
|
console.log(help);
|
|
99
118
|
}
|
package/lib/prospect.mjs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { call } from "./auth.mjs";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `alori prospect <url>` (Alori team only): turns a prospect's website into a demo site on Alori, at
|
|
5
|
+
* `<name>.prospects.aloriapp.com`, then waits until it is live. The platform reads the site, copies its photos and
|
|
6
|
+
* builds it (`convex/prospects/demos.ts`); the demo hides from search, shows a Make it mine bar and ends after 30 days.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const errors = {
|
|
10
|
+
superAdminsOnly: "The alori command is only for the Alori team for now.",
|
|
11
|
+
noProspectsApp: "The Prospects app isn't set up on this Alori (ALORI_PROSPECTS_APP_ID).",
|
|
12
|
+
badUrl: "That isn't a website address. Try: alori prospect aspavocats.ca",
|
|
13
|
+
noAddress: "No address is free for this demo. Try again with --name.",
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const pollMs = 10_000;
|
|
17
|
+
const waitMs = 20 * 60 * 1000;
|
|
18
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
19
|
+
|
|
20
|
+
function fail(message) {
|
|
21
|
+
const error = new Error(message);
|
|
22
|
+
error.plain = true;
|
|
23
|
+
return error;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function prospect(url, company) {
|
|
27
|
+
if (!url) throw fail("Which website? Try: alori prospect aspavocats.ca");
|
|
28
|
+
const started = await call("/code/prospect", { method: "POST", body: { url, ...(company ? { company } : {}) } });
|
|
29
|
+
if (!started.ok) throw fail(errors[started.body?.error] ?? `The demo couldn't start (${started.body?.error ?? started.status}). Try again.`);
|
|
30
|
+
const address = `https://${started.body.host}`;
|
|
31
|
+
if (started.body.again) console.log(`This site already has a demo: ${address}`);
|
|
32
|
+
else console.log(`Building the demo at ${address} (a few minutes)…`);
|
|
33
|
+
const until = Date.now() + waitMs;
|
|
34
|
+
while (Date.now() < until) {
|
|
35
|
+
const demo = await call(`/code/prospect?id=${encodeURIComponent(started.body.projectId)}`);
|
|
36
|
+
if (demo.ok && demo.body.live) {
|
|
37
|
+
console.log(`Live: ${address} (for ${demo.body.company}, ends ${new Date(demo.body.expiresAt).toLocaleDateString()})`);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
await sleep(pollMs);
|
|
41
|
+
}
|
|
42
|
+
console.log(`Still building. It will be live at ${address}`);
|
|
43
|
+
}
|
package/lib/sync.mjs
CHANGED
|
@@ -20,6 +20,7 @@ const errors = {
|
|
|
20
20
|
notCodeClient: "This sign-in can't change code. Run: alori login",
|
|
21
21
|
cantBuild: "Your role in this app doesn't build it. Ask an admin to change your role.",
|
|
22
22
|
noApp: "Your Alori account has no app yet.",
|
|
23
|
+
superAdminsOnly: "The alori command is only for the Alori team for now.",
|
|
23
24
|
notYours: "You can't change this app with this sign-in. Run alori apps to see the ones you can. Alori support: click Work on its code on the account's page in /admin first.",
|
|
24
25
|
rateLimited: "Too many calls in a minute. Wait a moment and try again.",
|
|
25
26
|
noCode: "This app has no saved code yet.",
|
|
@@ -410,6 +411,11 @@ export async function push(dir, message) {
|
|
|
410
411
|
console.log("Someone else changed these files too. Their changes and yours were merged:");
|
|
411
412
|
for (const path of merged) console.log(` ${path}`);
|
|
412
413
|
}
|
|
414
|
+
if (pushed.copied > 0 && !pushed.behind) {
|
|
415
|
+
// The saved code points at the app's own copies of files it linked on other websites: bring those links here.
|
|
416
|
+
console.log(`\nCopied ${pushed.copied} file(s) linked from other websites into your app's storage. Bringing the new links here…`);
|
|
417
|
+
await pullOver(dir, readState(dir), me);
|
|
418
|
+
}
|
|
413
419
|
if (pushed.behind) {
|
|
414
420
|
// Bring the merged files and everyone else's changes here, so this folder holds what was just saved.
|
|
415
421
|
console.log("\nSomeone else saved changes since your pull. Bringing them here…");
|
package/lib/upload.mjs
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { openAsBlob, statSync } from "node:fs";
|
|
2
|
+
import { basename, extname } from "node:path";
|
|
3
|
+
import { call } from "./auth.mjs";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `alori upload <files…>`: puts files into the app's own storage (a product's PDFs, photos) and prints the lasting
|
|
7
|
+
* address of each, for the site's code to link. The bytes go straight to the app's backend through one-time links
|
|
8
|
+
* (`POST /code/upload`), never through Alori; each file is then recorded by the app (`POST /code/files`).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const perCall = 50;
|
|
12
|
+
|
|
13
|
+
const types = {
|
|
14
|
+
".pdf": "application/pdf",
|
|
15
|
+
".png": "image/png",
|
|
16
|
+
".jpg": "image/jpeg",
|
|
17
|
+
".jpeg": "image/jpeg",
|
|
18
|
+
".webp": "image/webp",
|
|
19
|
+
".gif": "image/gif",
|
|
20
|
+
".svg": "image/svg+xml",
|
|
21
|
+
".mp4": "video/mp4",
|
|
22
|
+
".webm": "video/webm",
|
|
23
|
+
".zip": "application/zip",
|
|
24
|
+
".dwg": "application/acad",
|
|
25
|
+
".ies": "text/plain",
|
|
26
|
+
".ldt": "text/plain",
|
|
27
|
+
".csv": "text/csv",
|
|
28
|
+
".txt": "text/plain",
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const typeOf = (path) => types[extname(path).toLowerCase()] ?? "application/octet-stream";
|
|
32
|
+
|
|
33
|
+
function fail(message) {
|
|
34
|
+
return Object.assign(new Error(message), { plain: true });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Sends one file's bytes to a one-time link; the app's storage id. */
|
|
38
|
+
async function send(url, path) {
|
|
39
|
+
const blob = await openAsBlob(path, { type: typeOf(path) });
|
|
40
|
+
const response = await fetch(url, { method: "POST", headers: { "Content-Type": typeOf(path) }, body: blob });
|
|
41
|
+
const answer = await response.json().catch(() => null);
|
|
42
|
+
if (!response.ok || typeof answer?.storageId !== "string") throw fail(`${basename(path)} wasn't uploaded (${response.status}). Try again.`);
|
|
43
|
+
return answer.storageId;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Uploads these files; each one's name, address and size, in the order given. */
|
|
47
|
+
export async function upload(paths) {
|
|
48
|
+
if (paths.length === 0) throw fail("Name the files to upload: alori upload docs/*.pdf");
|
|
49
|
+
for (const path of paths) if (!statSync(path, { throwIfNoEntry: false })?.isFile()) throw fail(`No file at ${path}.`);
|
|
50
|
+
const saved = [];
|
|
51
|
+
for (let start = 0; start < paths.length; start += perCall) {
|
|
52
|
+
const batch = paths.slice(start, start + perCall);
|
|
53
|
+
const links = await call("/code/upload", { method: "POST", body: { count: batch.length } });
|
|
54
|
+
if (!links.ok) throw fail(links.body?.error === "notYours" ? "This sign-in can't reach this app." : `The app couldn't take files (${links.body?.error ?? links.status}). Try again.`);
|
|
55
|
+
const urls = links.body.uploadUrls;
|
|
56
|
+
for (const [index, path] of batch.entries()) {
|
|
57
|
+
const storageId = await send(urls[index], path);
|
|
58
|
+
const kept = await call("/code/files", { method: "POST", body: { storageId, name: basename(path) } });
|
|
59
|
+
if (!kept.ok) throw fail(`${basename(path)} wasn't kept by the app (${kept.body?.error ?? kept.status}).`);
|
|
60
|
+
saved.push({ file: path, name: kept.body.name, url: kept.body.url, size: kept.body.size, mime: kept.body.mime });
|
|
61
|
+
process.stderr.write(` ${start + index + 1}/${paths.length} ${basename(path)}\n`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return saved;
|
|
65
|
+
}
|