@alori/cli 0.1.4 → 0.1.6
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/lib/git.mjs +16 -1
- package/lib/sync.mjs +61 -7
- package/package.json +1 -1
package/lib/git.mjs
CHANGED
|
@@ -57,12 +57,25 @@ export function ensureIgnored(dir, lines) {
|
|
|
57
57
|
export function hadChanges(dir) {
|
|
58
58
|
if (repoOf(dir) !== "own") return false;
|
|
59
59
|
try {
|
|
60
|
-
|
|
60
|
+
// The .gitignore comes fresh with every pull, and a file it now leaves out stops being tracked in the pull's commit.
|
|
61
|
+
const alorisOwn = new Set([".gitignore", ...trackedIgnored(dir)]);
|
|
62
|
+
return git(dir, ["status", "--porcelain", "-z"])
|
|
63
|
+
.split("\0")
|
|
64
|
+
.filter(Boolean)
|
|
65
|
+
.some((entry) => !alorisOwn.has(entry.slice(3)));
|
|
61
66
|
} catch {
|
|
62
67
|
return false;
|
|
63
68
|
}
|
|
64
69
|
}
|
|
65
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Tracked files the .gitignore now leaves out, such as the route tree an older pull committed. The pull's commit stops
|
|
73
|
+
* tracking them; they stay on disk.
|
|
74
|
+
*/
|
|
75
|
+
function trackedIgnored(dir) {
|
|
76
|
+
return git(dir, ["ls-files", "-ci", "--exclude-standard", "-z"]).split("\0").filter(Boolean);
|
|
77
|
+
}
|
|
78
|
+
|
|
66
79
|
/**
|
|
67
80
|
* A pull into a folder pulled before it had git: starts the repository with Alori's version alone as its first commit,
|
|
68
81
|
* built from the folder `snapshot()` makes (the downloaded code), so the person's own edits in `dir` show as changes on top of it, never
|
|
@@ -101,6 +114,8 @@ export function commitPull(dir, version, { hadChanges }) {
|
|
|
101
114
|
console.log("Your folder had changes not committed, so this pull isn't a commit of its own. Commit when ready.");
|
|
102
115
|
return;
|
|
103
116
|
}
|
|
117
|
+
const stale = trackedIgnored(dir);
|
|
118
|
+
if (stale.length > 0) git(dir, ["rm", "--cached", "-q", "--", ...stale]);
|
|
104
119
|
git(dir, ["add", "-A"]);
|
|
105
120
|
if (git(dir, ["status", "--porcelain"]).trim() === "") return;
|
|
106
121
|
git(dir, ["commit", "-q", "-m", `Pulled version ${version} from Alori`]);
|
package/lib/sync.mjs
CHANGED
|
@@ -72,8 +72,25 @@ function copyInto(from, to, path) {
|
|
|
72
72
|
copyFileSync(join(from, path), join(to, path));
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
/**
|
|
76
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Kept out of git: installed packages, builds, secrets, the pull snapshot and the copies a pull puts beside files, plus
|
|
77
|
+
* what this computer makes on its own: the lockfile the install writes, the route tree the dev server regenerates for
|
|
78
|
+
* the app's own pages, and macOS's folder files. Left tracked, a fresh pull shows changes nobody made.
|
|
79
|
+
*/
|
|
80
|
+
const ignoreLines = [
|
|
81
|
+
"node_modules/",
|
|
82
|
+
`${stateDir}/`,
|
|
83
|
+
"dist/",
|
|
84
|
+
".output/",
|
|
85
|
+
".tanstack/",
|
|
86
|
+
".vercel/",
|
|
87
|
+
".env*",
|
|
88
|
+
"*.alori-theirs",
|
|
89
|
+
"*.alori-mine",
|
|
90
|
+
"pnpm-lock.yaml",
|
|
91
|
+
"src/routeTree.gen.ts",
|
|
92
|
+
".DS_Store",
|
|
93
|
+
];
|
|
77
94
|
|
|
78
95
|
/** pnpm 11 stops `pnpm install` until each package's build script is allowed or refused. */
|
|
79
96
|
const workspaceFile = `allowBuilds:
|
|
@@ -153,6 +170,8 @@ function snapshotOf(dir, folder, temp) {
|
|
|
153
170
|
async function pullOver(dir, state, me) {
|
|
154
171
|
const { folder, temp, version } = await download();
|
|
155
172
|
const repo = startRepoFrom(dir, () => snapshotOf(dir, folder, temp), version);
|
|
173
|
+
// The ignore list first, so what this computer generated (the lockfile, .DS_Store) doesn't count as the person's changes.
|
|
174
|
+
ensureIgnored(dir, ignoreLines);
|
|
156
175
|
const uncommitted = hadChanges(dir);
|
|
157
176
|
const lockBefore = fileHash(dir, "pnpm-lock.yaml");
|
|
158
177
|
const code = mergeInto(dir, folder, new Set([...Object.keys(codeHashes(folder)), ...Object.keys(codeHashes(dir)), ...Object.keys(state.hashes)]), state.hashes);
|
|
@@ -257,6 +276,20 @@ const stageWords = {
|
|
|
257
276
|
preview: "Updating the preview",
|
|
258
277
|
};
|
|
259
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
|
+
|
|
260
293
|
export async function push(dir, message) {
|
|
261
294
|
const state = readState(dir);
|
|
262
295
|
if (!state) fail("This folder wasn't pulled from Alori. Run: alori pull <folder>");
|
|
@@ -271,8 +304,13 @@ export async function push(dir, message) {
|
|
|
271
304
|
return;
|
|
272
305
|
}
|
|
273
306
|
const files = changed.map((path) => ({ path, content: readFileSync(join(dir, path), "utf8") }));
|
|
274
|
-
|
|
275
|
-
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 });
|
|
276
314
|
if (!sent.ok) {
|
|
277
315
|
const error = sent.body?.error;
|
|
278
316
|
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.`);
|
|
@@ -284,18 +322,33 @@ export async function push(dir, message) {
|
|
|
284
322
|
failOn(sent);
|
|
285
323
|
}
|
|
286
324
|
const pushId = sent.body.pushId;
|
|
325
|
+
console.log(`Sent in ${secondsSince(started)}. Alori is building it (push ${pushId}).`);
|
|
287
326
|
let shown = "";
|
|
327
|
+
let shownAt = Date.now();
|
|
328
|
+
let nudgedAt = Date.now();
|
|
329
|
+
/** Closes the stage on screen with how long it took. */
|
|
330
|
+
const endStage = () => {
|
|
331
|
+
if (shown) console.log(` ✓ ${shown} (${secondsSince(shownAt)})`);
|
|
332
|
+
};
|
|
288
333
|
for (;;) {
|
|
289
334
|
await sleep(2000);
|
|
290
335
|
const answer = await call(`/code/push?id=${encodeURIComponent(pushId)}`);
|
|
291
336
|
if (!answer.ok) failOn(answer);
|
|
292
337
|
const pushed = answer.body;
|
|
293
338
|
// A push deploys from its first moment; the build machine names a stage once it takes the job.
|
|
294
|
-
const line = pushed.stage ? (stageWords[pushed.stage] ??
|
|
295
|
-
|
|
339
|
+
const line = pushed.stage ? (stageWords[pushed.stage] ?? `Building (${pushed.stage})`) : "Waiting for a build machine";
|
|
340
|
+
const building = pushed.status === "queued" || pushed.status === "deploying";
|
|
341
|
+
if (building && line !== shown) {
|
|
342
|
+
endStage();
|
|
296
343
|
console.log(`${line}…`);
|
|
297
344
|
shown = line;
|
|
345
|
+
shownAt = nudgedAt = Date.now();
|
|
346
|
+
} else if (building && Date.now() - nudgedAt >= stillEveryMs) {
|
|
347
|
+
// Some stages take minutes: say it's still going, so a quiet terminal never looks stuck.
|
|
348
|
+
console.log(` …still ${line.charAt(0).toLowerCase()}${line.slice(1)} (${secondsSince(shownAt)}, ${secondsSince(started)} in all)`);
|
|
349
|
+
nudgedAt = Date.now();
|
|
298
350
|
}
|
|
351
|
+
if (!building) endStage();
|
|
299
352
|
if (pushed.status === "saved") {
|
|
300
353
|
// The snapshot moves to what was just saved: only what was sent counts as Alori's now.
|
|
301
354
|
const hashes = { ...state.hashes };
|
|
@@ -303,10 +356,11 @@ export async function push(dir, message) {
|
|
|
303
356
|
for (const path of deleted) delete hashes[path];
|
|
304
357
|
// Others saved too between the pull and this save: this folder lacks their changes, so the next push pulls first.
|
|
305
358
|
writeState(dir, { ...state, version: pushed.version, hashes, ...(pushed.behind ? { needsPull: true } : {}) });
|
|
306
|
-
console.log(`Saved as version ${pushed.version}. It's in the preview: publish it in Alori when you're ready.`);
|
|
359
|
+
console.log(`Saved as version ${pushed.version} in ${secondsSince(started)}. It's in the preview: publish it in Alori when you're ready.`);
|
|
307
360
|
if (pushed.behind) console.log("Someone else saved changes since your pull too. Run alori pull to bring them here.");
|
|
308
361
|
return;
|
|
309
362
|
}
|
|
363
|
+
if (pushed.status === "refused" || pushed.status === "failed") console.log(`Stopped after ${secondsSince(started)}.`);
|
|
310
364
|
if (pushed.status === "refused") fail(`Someone saved changes to the same files while this built: ${pushed.conflicts.join(", ")}\nNothing was saved. Run alori pull, merge, then push again.`);
|
|
311
365
|
if (pushed.status === "failed") fail(`The build failed, so nothing was saved:\n${pushed.error ?? ""}`);
|
|
312
366
|
}
|