@alori/cli 0.1.2 → 0.1.3
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/lib/git.mjs +89 -0
- package/lib/guide.mjs +6 -0
- package/lib/sync.mjs +8 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,4 +15,7 @@ looks right. How it works: `docs/CLAUDE_CODE.md` in Alori's repository.
|
|
|
15
15
|
`alori dev` runs the app from your files against its real backend and data: screens and text change as you save,
|
|
16
16
|
backend changes (`convex/`) reach it with `alori push`.
|
|
17
17
|
|
|
18
|
+
The folder is a git repository: each pull is a commit by Alori, so it opens in GitHub Desktop and can go to your own
|
|
19
|
+
GitHub. A push to GitHub deploys nothing; only `alori push` does.
|
|
20
|
+
|
|
18
21
|
No dependencies; Node 20 or newer, and `tar`. pnpm is used when installed, through npx otherwise.
|
package/lib/git.mjs
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Git in the pulled folder, so GitHub Desktop, GitHub and Claude Code work with it. Each pull is a commit by Alori
|
|
3
|
+
* ("Pulled version 12"), apart from the person's own commits. Git stays on this computer: Alori never pushes to a
|
|
4
|
+
* remote, and a push to GitHub deploys nothing (only `alori push` does). A folder inside another repository is left
|
|
5
|
+
* alone: that repository is the person's to manage.
|
|
6
|
+
*/
|
|
7
|
+
import { execFileSync } from "node:child_process";
|
|
8
|
+
import { existsSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
|
|
11
|
+
/** Pull commits are Alori's, which also works on a computer where git has no name or email set. */
|
|
12
|
+
const asAlori = {
|
|
13
|
+
...process.env,
|
|
14
|
+
GIT_AUTHOR_NAME: "Alori",
|
|
15
|
+
GIT_AUTHOR_EMAIL: "noreply@alori.dev",
|
|
16
|
+
GIT_COMMITTER_NAME: "Alori",
|
|
17
|
+
GIT_COMMITTER_EMAIL: "noreply@alori.dev",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function git(dir, args) {
|
|
21
|
+
return execFileSync("git", ["-C", dir, ...args], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"], env: asAlori });
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function hasGit() {
|
|
25
|
+
try {
|
|
26
|
+
execFileSync("git", ["--version"], { stdio: "ignore" });
|
|
27
|
+
return true;
|
|
28
|
+
} catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** "own": `dir` is the root of its own repository; "none": no repository; "parent": inside someone else's. */
|
|
34
|
+
function repoOf(dir) {
|
|
35
|
+
try {
|
|
36
|
+
const top = git(dir, ["rev-parse", "--show-toplevel"]).trim();
|
|
37
|
+
return realpathSync(top) === realpathSync(dir) ? "own" : "parent";
|
|
38
|
+
} catch {
|
|
39
|
+
return "none";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Lines every pulled folder's .gitignore needs: the template's own file comes fresh with each pull and lacks them. */
|
|
44
|
+
export function ensureIgnored(dir, lines) {
|
|
45
|
+
const file = join(dir, ".gitignore");
|
|
46
|
+
const current = existsSync(file) ? readFileSync(file, "utf8") : "";
|
|
47
|
+
const have = new Set(current.split("\n").map((line) => line.trim()));
|
|
48
|
+
const missing = lines.filter((line) => !have.has(line));
|
|
49
|
+
if (missing.length === 0) return;
|
|
50
|
+
writeFileSync(file, `${current}${current === "" || current.endsWith("\n") ? "" : "\n"}${missing.join("\n")}\n`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Before a pull lays Alori's files down: whether the person has changes not committed yet. A pull commits only into a
|
|
55
|
+
* clean folder, so their work never lands inside Alori's commit.
|
|
56
|
+
*/
|
|
57
|
+
export function hadChanges(dir) {
|
|
58
|
+
if (repoOf(dir) !== "own") return false;
|
|
59
|
+
try {
|
|
60
|
+
return git(dir, ["status", "--porcelain"]).trim() !== "";
|
|
61
|
+
} catch {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** After a pull: starts the repository when there is none, and commits what the pull brought. */
|
|
67
|
+
export function commitPull(dir, version, { hadChanges }) {
|
|
68
|
+
if (!hasGit()) return;
|
|
69
|
+
const repo = repoOf(dir);
|
|
70
|
+
if (repo === "parent") return;
|
|
71
|
+
try {
|
|
72
|
+
if (repo === "none") {
|
|
73
|
+
git(dir, ["init", "-b", "main"]);
|
|
74
|
+
git(dir, ["add", "-A"]);
|
|
75
|
+
git(dir, ["commit", "-q", "-m", `Pulled version ${version} from Alori`]);
|
|
76
|
+
console.log("Started git in this folder: open it in GitHub Desktop, or add your own GitHub remote.");
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (hadChanges) {
|
|
80
|
+
console.log("Your folder had changes not committed, so this pull isn't a commit of its own. Commit when ready.");
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
git(dir, ["add", "-A"]);
|
|
84
|
+
if (git(dir, ["status", "--porcelain"]).trim() === "") return;
|
|
85
|
+
git(dir, ["commit", "-q", "-m", `Pulled version ${version} from Alori`]);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.log(`Git couldn't commit this pull (${String(error.stderr ?? error.message).trim().split("\n")[0]}). Your files are pulled.`);
|
|
88
|
+
}
|
|
89
|
+
}
|
package/lib/guide.mjs
CHANGED
|
@@ -16,6 +16,12 @@ with \`alori push\`. Alori builds them, deploys them, and shows them in the work
|
|
|
16
16
|
even before Publish. Never drop a table or a field that holds data.
|
|
17
17
|
- \`convex/_generated/\` and \`src/routeTree.gen.ts\` are generated: never edit them.
|
|
18
18
|
|
|
19
|
+
## Git and GitHub
|
|
20
|
+
|
|
21
|
+
This folder is a git repository, and each \`alori pull\` is a commit by Alori ("Pulled version 12 from Alori"), so
|
|
22
|
+
\`git log\` shows Alori's changes apart from yours. Commit your own work as usual, and push it to your own GitHub if you
|
|
23
|
+
like. **GitHub is only a copy:** a push to GitHub deploys nothing. Only \`alori push\` sends changes to the app.
|
|
24
|
+
|
|
19
25
|
## Seeing changes
|
|
20
26
|
|
|
21
27
|
\`alori dev\` runs the app at http://localhost:5300 (or the next free port) from this folder's files, against the app's
|
package/lib/sync.mjs
CHANGED
|
@@ -10,6 +10,7 @@ import { basename, dirname, join, resolve } from "node:path";
|
|
|
10
10
|
import { apiBase, call } from "./auth.mjs";
|
|
11
11
|
import { changesOf, codeHashes, isAppCode, readState, stateDir, walk, writeState } from "./folder.mjs";
|
|
12
12
|
import { install, installed, runLocally } from "./dev.mjs";
|
|
13
|
+
import { commitPull, ensureIgnored, hadChanges } from "./git.mjs";
|
|
13
14
|
import { claudeGuide } from "./guide.mjs";
|
|
14
15
|
|
|
15
16
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -71,14 +72,8 @@ function copyInto(from, to, path) {
|
|
|
71
72
|
copyFileSync(join(from, path), join(to, path));
|
|
72
73
|
}
|
|
73
74
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
dist/
|
|
77
|
-
.output/
|
|
78
|
-
.tanstack/
|
|
79
|
-
.env*
|
|
80
|
-
*.alori-theirs
|
|
81
|
-
`;
|
|
75
|
+
/** Kept out of git: installed packages, builds, secrets, the pull snapshot and Alori's copies of overlapping files. */
|
|
76
|
+
const ignoreLines = ["node_modules/", `${stateDir}/`, "dist/", ".output/", ".tanstack/", ".vercel/", ".env*", "*.alori-theirs"];
|
|
82
77
|
|
|
83
78
|
/** pnpm 11 stops `pnpm install` until each package's build script is allowed or refused. */
|
|
84
79
|
const workspaceFile = `allowBuilds:
|
|
@@ -95,10 +90,11 @@ async function pullFresh(dir, me) {
|
|
|
95
90
|
for (const path of walk(folder).filter((path) => !templateNotes.has(path))) copyInto(folder, dir, path);
|
|
96
91
|
rmSync(temp, { recursive: true, force: true });
|
|
97
92
|
writeFileSync(join(dir, "CLAUDE.md"), claudeGuide(me.app));
|
|
98
|
-
|
|
93
|
+
ensureIgnored(dir, ignoreLines);
|
|
99
94
|
if (!existsSync(join(dir, "pnpm-workspace.yaml"))) writeFileSync(join(dir, "pnpm-workspace.yaml"), workspaceFile);
|
|
100
95
|
writeState(dir, { api: apiBase(), appId: me.appId, app: me.app, version, hashes: codeHashes(dir) });
|
|
101
96
|
console.log(`Pulled ${me.app}, version ${version}, into ${dir}`);
|
|
97
|
+
commitPull(dir, version, { hadChanges: false });
|
|
102
98
|
install(dir);
|
|
103
99
|
}
|
|
104
100
|
|
|
@@ -108,6 +104,7 @@ async function pullFresh(dir, me) {
|
|
|
108
104
|
*/
|
|
109
105
|
async function pullOver(dir, state, me) {
|
|
110
106
|
const { folder, temp, version } = await download();
|
|
107
|
+
const uncommitted = hadChanges(dir);
|
|
111
108
|
const remote = codeHashes(folder);
|
|
112
109
|
const local = codeHashes(dir);
|
|
113
110
|
const overlaps = [];
|
|
@@ -134,8 +131,10 @@ async function pullOver(dir, state, me) {
|
|
|
134
131
|
const packagesChanged = lockfile(folder) !== lockfile(dir);
|
|
135
132
|
for (const path of walk(folder).filter((path) => !isAppCode(path) && !templateNotes.has(path))) copyInto(folder, dir, path);
|
|
136
133
|
rmSync(temp, { recursive: true, force: true });
|
|
134
|
+
ensureIgnored(dir, ignoreLines);
|
|
137
135
|
writeState(dir, { api: apiBase(), appId: me.appId, app: me.app, version, hashes: remote });
|
|
138
136
|
console.log(`Pulled ${me.app}, version ${version}.`);
|
|
137
|
+
commitPull(dir, version, { hadChanges: uncommitted });
|
|
139
138
|
if (packagesChanged || !installed(dir)) install(dir);
|
|
140
139
|
if (overlaps.length > 0) {
|
|
141
140
|
console.log("\nThese files changed both here and in Alori. Yours are kept; Alori's are beside them as .alori-theirs:");
|