@alori/cli 0.1.5 → 0.1.7
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 -1
- package/lib/sync.mjs +56 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -10,7 +10,9 @@ alori push -m "New pricing page"
|
|
|
10
10
|
```
|
|
11
11
|
|
|
12
12
|
Alori builds each push, shows it in your workspace preview and saves it as a version. Publish it from Alori when it
|
|
13
|
-
looks right.
|
|
13
|
+
looks right. If someone else saved changes since your pull, Alori merges them with yours and pulls the result into your
|
|
14
|
+
folder; only the same lines changed on both sides stop the push, with their copy beside yours as
|
|
15
|
+
`<file>.alori-theirs` to merge. How it works: `docs/CLAUDE_CODE.md` in Alori's repository.
|
|
14
16
|
|
|
15
17
|
`alori dev` runs the app from your files against its real backend and data: screens and text change as you save,
|
|
16
18
|
backend changes (`convex/`) reach it with `alori push`.
|
package/lib/sync.mjs
CHANGED
|
@@ -276,6 +276,20 @@ const stageWords = {
|
|
|
276
276
|
preview: "Updating the preview",
|
|
277
277
|
};
|
|
278
278
|
|
|
279
|
+
/** How often a long stage says it's still going. */
|
|
280
|
+
const stillEveryMs = 15_000;
|
|
281
|
+
|
|
282
|
+
function secondsSince(start) {
|
|
283
|
+
const seconds = Math.round((Date.now() - start) / 1000);
|
|
284
|
+
return seconds < 60 ? `${seconds}s` : `${Math.floor(seconds / 60)}m ${String(seconds % 60).padStart(2, "0")}s`;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function sizeOf(bytes) {
|
|
288
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
289
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
290
|
+
return `${(bytes / 1024 / 1024).toFixed(1)} MB`;
|
|
291
|
+
}
|
|
292
|
+
|
|
279
293
|
export async function push(dir, message) {
|
|
280
294
|
const state = readState(dir);
|
|
281
295
|
if (!state) fail("This folder wasn't pulled from Alori. Run: alori pull <folder>");
|
|
@@ -290,11 +304,15 @@ export async function push(dir, message) {
|
|
|
290
304
|
return;
|
|
291
305
|
}
|
|
292
306
|
const files = changed.map((path) => ({ path, content: readFileSync(join(dir, path), "utf8") }));
|
|
293
|
-
|
|
294
|
-
const
|
|
307
|
+
const started = Date.now();
|
|
308
|
+
const body = { baseVersion: state.version, message: message ?? "", files, deletedPaths: deleted };
|
|
309
|
+
console.log(`${me.app}: pushing on top of version ${state.version}${message ? ` — "${message}"` : ""}`);
|
|
310
|
+
for (const file of files) console.log(` ${state.hashes[file.path] ? "changed" : "new "} ${file.path} (${sizeOf(Buffer.byteLength(file.content))})`);
|
|
311
|
+
for (const path of deleted) console.log(` removed ${path}`);
|
|
312
|
+
console.log(`Sending ${changed.length} changed and ${deleted.length} removed file${changed.length + deleted.length === 1 ? "" : "s"} (${sizeOf(Buffer.byteLength(JSON.stringify(body)))})…`);
|
|
313
|
+
const sent = await call("/code/push", { method: "POST", body });
|
|
295
314
|
if (!sent.ok) {
|
|
296
315
|
const error = sent.body?.error;
|
|
297
|
-
if (error === "conflicts") fail(`Someone saved changes to these files since your pull:\n${sent.body.paths.map((path) => ` ${path}`).join("\n")}\nRun alori pull, merge, then push again.`);
|
|
298
316
|
if (error === "notEditable") fail(`These files are Alori's and change for every app, so they can't be pushed:\n${sent.body.paths.map((path) => ` ${path}`).join("\n")}\nPut the change in the app's own files instead.`);
|
|
299
317
|
if (error === "busy") fail("Alori is already building this app (the builder or another push). Try again in a minute.");
|
|
300
318
|
if (error === "noCredits") fail("You're out of credits. Add credits in Alori, then push again.");
|
|
@@ -303,18 +321,33 @@ export async function push(dir, message) {
|
|
|
303
321
|
failOn(sent);
|
|
304
322
|
}
|
|
305
323
|
const pushId = sent.body.pushId;
|
|
324
|
+
console.log(`Sent in ${secondsSince(started)}. Alori is building it (push ${pushId}).`);
|
|
306
325
|
let shown = "";
|
|
326
|
+
let shownAt = Date.now();
|
|
327
|
+
let nudgedAt = Date.now();
|
|
328
|
+
/** Closes the stage on screen with how long it took. */
|
|
329
|
+
const endStage = () => {
|
|
330
|
+
if (shown) console.log(` ✓ ${shown} (${secondsSince(shownAt)})`);
|
|
331
|
+
};
|
|
307
332
|
for (;;) {
|
|
308
333
|
await sleep(2000);
|
|
309
334
|
const answer = await call(`/code/push?id=${encodeURIComponent(pushId)}`);
|
|
310
335
|
if (!answer.ok) failOn(answer);
|
|
311
336
|
const pushed = answer.body;
|
|
312
337
|
// A push deploys from its first moment; the build machine names a stage once it takes the job.
|
|
313
|
-
const line = pushed.stage ? (stageWords[pushed.stage] ??
|
|
314
|
-
|
|
338
|
+
const line = pushed.stage ? (stageWords[pushed.stage] ?? `Building (${pushed.stage})`) : "Waiting for a build machine";
|
|
339
|
+
const building = pushed.status === "queued" || pushed.status === "deploying";
|
|
340
|
+
if (building && line !== shown) {
|
|
341
|
+
endStage();
|
|
315
342
|
console.log(`${line}…`);
|
|
316
343
|
shown = line;
|
|
344
|
+
shownAt = nudgedAt = Date.now();
|
|
345
|
+
} else if (building && Date.now() - nudgedAt >= stillEveryMs) {
|
|
346
|
+
// Some stages take minutes: say it's still going, so a quiet terminal never looks stuck.
|
|
347
|
+
console.log(` …still ${line.charAt(0).toLowerCase()}${line.slice(1)} (${secondsSince(shownAt)}, ${secondsSince(started)} in all)`);
|
|
348
|
+
nudgedAt = Date.now();
|
|
317
349
|
}
|
|
350
|
+
if (!building) endStage();
|
|
318
351
|
if (pushed.status === "saved") {
|
|
319
352
|
// The snapshot moves to what was just saved: only what was sent counts as Alori's now.
|
|
320
353
|
const hashes = { ...state.hashes };
|
|
@@ -322,11 +355,26 @@ export async function push(dir, message) {
|
|
|
322
355
|
for (const path of deleted) delete hashes[path];
|
|
323
356
|
// Others saved too between the pull and this save: this folder lacks their changes, so the next push pulls first.
|
|
324
357
|
writeState(dir, { ...state, version: pushed.version, hashes, ...(pushed.behind ? { needsPull: true } : {}) });
|
|
325
|
-
console.log(`Saved as version ${pushed.version}. It's in the preview: publish it in Alori when you're ready.`);
|
|
326
|
-
|
|
358
|
+
console.log(`Saved as version ${pushed.version} in ${secondsSince(started)}. It's in the preview: publish it in Alori when you're ready.`);
|
|
359
|
+
const merged = pushed.merged ?? [];
|
|
360
|
+
if (merged.length > 0) {
|
|
361
|
+
console.log("Someone else changed these files too. Their changes and yours were merged:");
|
|
362
|
+
for (const path of merged) console.log(` ${path}`);
|
|
363
|
+
}
|
|
364
|
+
if (pushed.behind) {
|
|
365
|
+
// Bring the merged files and everyone else's changes here, so this folder holds what was just saved.
|
|
366
|
+
console.log("\nSomeone else saved changes since your pull. Bringing them here…");
|
|
367
|
+
await pullOver(dir, readState(dir), me);
|
|
368
|
+
}
|
|
327
369
|
return;
|
|
328
370
|
}
|
|
329
|
-
if (pushed.status === "refused"
|
|
371
|
+
if (pushed.status === "refused" || pushed.status === "failed") console.log(`Stopped after ${secondsSince(started)}.`);
|
|
372
|
+
if (pushed.status === "refused" && !pushed.conflicts?.length) fail(`${pushed.error ?? "Nothing was saved."}`);
|
|
373
|
+
if (pushed.status === "refused") {
|
|
374
|
+
console.log(`Someone else changed the same lines in these files, so nothing was saved:\n${pushed.conflicts.map((path) => ` ${path}`).join("\n")}\n\nPulling their changes so you can merge them…`);
|
|
375
|
+
await pullOver(dir, state, me);
|
|
376
|
+
fail("Merge the files above, delete the .alori-theirs files, then push again.");
|
|
377
|
+
}
|
|
330
378
|
if (pushed.status === "failed") fail(`The build failed, so nothing was saved:\n${pushed.error ?? ""}`);
|
|
331
379
|
}
|
|
332
380
|
}
|