@alori/cli 0.1.0 → 0.1.2

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 CHANGED
@@ -4,14 +4,15 @@ Build your Alori app with your own Claude Code.
4
4
 
5
5
  ```bash
6
6
  npm install -g @alori/cli # once
7
- alori login # connect this computer to your Alori account
8
- alori pull my-app # download your app's code
9
- cd my-app && pnpm install
10
- claude # change it with Claude Code
7
+ alori dev # signs you in, downloads your app, installs it and opens it on this computer
8
+ claude # in the app's folder: change it with Claude Code, and watch it change
11
9
  alori push -m "New pricing page"
12
10
  ```
13
11
 
14
12
  Alori builds each push, shows it in your workspace preview and saves it as a version. Publish it from Alori when it
15
13
  looks right. How it works: `docs/CLAUDE_CODE.md` in Alori's repository.
16
14
 
17
- No dependencies; Node 20 or newer, and `tar`.
15
+ `alori dev` runs the app from your files against its real backend and data: screens and text change as you save,
16
+ backend changes (`convex/`) reach it with `alori push`.
17
+
18
+ No dependencies; Node 20 or newer, and `tar`. pnpm is used when installed, through npx otherwise.
package/bin/alori.mjs CHANGED
@@ -5,11 +5,12 @@
5
5
  */
6
6
  import { resolve } from "node:path";
7
7
  import { apiBase, call, forget, login, SignedOut } from "../lib/auth.mjs";
8
- import { pull, push, status } from "../lib/sync.mjs";
8
+ import { dev, pull, push, status } from "../lib/sync.mjs";
9
9
 
10
10
  const help = `alori: build your Alori app with Claude Code
11
11
 
12
12
  alori login Connect this computer to your Alori account
13
+ alori dev [folder] Download your app, install it and run it on this computer (opens your browser)
13
14
  alori pull [folder] Download your app's code (or bring the latest into a pulled folder)
14
15
  alori status What changed since the last pull or push
15
16
  alori push -m "message" Send your changes: Alori builds them and saves a new version
@@ -23,6 +24,17 @@ function messageOf(args) {
23
24
  return index >= 0 ? args[index + 1] : undefined;
24
25
  }
25
26
 
27
+ /** Runs a command that needs a sign-in, signing in first when this computer isn't connected yet. */
28
+ async function signedIn(run) {
29
+ try {
30
+ await run();
31
+ } catch (error) {
32
+ if (!(error instanceof SignedOut)) throw error;
33
+ await login();
34
+ await run();
35
+ }
36
+ }
37
+
26
38
  async function main() {
27
39
  const [command, ...args] = process.argv.slice(2);
28
40
  switch (command) {
@@ -33,7 +45,7 @@ async function main() {
33
45
  console.log(me.body?.error === "cantBuild" ? "Connected, but your role doesn't build this app." : "Connected.");
34
46
  return;
35
47
  }
36
- console.log(`Connected to ${me.body.app} as ${me.body.email ?? "you"}. Next: alori pull <folder>`);
48
+ console.log(`Connected to ${me.body.app} as ${me.body.email ?? "you"}. Next: alori dev`);
37
49
  return;
38
50
  }
39
51
  case "logout":
@@ -46,8 +58,11 @@ async function main() {
46
58
  console.log(`${me.body.app} (version ${me.body.version ?? "none"}), signed in as ${me.body.email ?? "you"}.`);
47
59
  return;
48
60
  }
61
+ case "dev":
62
+ await signedIn(() => dev(args.find((arg) => !arg.startsWith("-"))));
63
+ return;
49
64
  case "pull":
50
- await pull(resolve(args.find((arg) => !arg.startsWith("-")) ?? "."));
65
+ await signedIn(() => pull(args.find((arg) => !arg.startsWith("-"))));
51
66
  return;
52
67
  case "status":
53
68
  status(resolve("."));
package/lib/auth.mjs CHANGED
@@ -54,7 +54,7 @@ export function forget() {
54
54
 
55
55
  const base64Url = (buffer) => buffer.toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
56
56
 
57
- function openBrowser(url) {
57
+ export function openBrowser(url) {
58
58
  const command = process.platform === "darwin" ? "open" : process.platform === "win32" ? "cmd" : "xdg-open";
59
59
  const args = process.platform === "win32" ? ["/c", "start", "", url] : [url];
60
60
  try {
package/lib/dev.mjs ADDED
@@ -0,0 +1,71 @@
1
+ /**
2
+ * `alori dev`: the app running on this computer from the folder's files, against the app's own backend (its one
3
+ * Convex deployment, with real data). Screens and text change as files are saved; `convex/` changes reach the
4
+ * backend only with `alori push`.
5
+ */
6
+ import { spawn, spawnSync } from "node:child_process";
7
+ import { existsSync } from "node:fs";
8
+ import { createServer } from "node:net";
9
+ import { join } from "node:path";
10
+ import { openBrowser } from "./auth.mjs";
11
+
12
+ function fail(message) {
13
+ const error = new Error(message);
14
+ error.plain = true;
15
+ throw error;
16
+ }
17
+
18
+ const hasCommand = (name) => spawnSync(process.platform === "win32" ? "where" : "which", [name], { stdio: "ignore" }).status === 0;
19
+
20
+ /** Installs the app's packages with pnpm (the app's lockfile is pnpm's), through npx when pnpm isn't installed. */
21
+ export function install(dir) {
22
+ console.log("Installing packages (a minute the first time)...");
23
+ const [command, args] = hasCommand("pnpm") ? ["pnpm", ["install"]] : ["npx", ["--yes", "pnpm@11", "install"]];
24
+ const result = spawnSync(command, args, { cwd: dir, stdio: "inherit", shell: process.platform === "win32" });
25
+ if (result.status !== 0) fail("Installing packages failed. Fix what it says above, then run alori dev again.");
26
+ }
27
+
28
+ export const installed = (dir) => existsSync(join(dir, "node_modules", ".bin", "vite"));
29
+
30
+ /** The first free port from `from` on. */
31
+ function freePort(from) {
32
+ return new Promise((resolve) => {
33
+ const server = createServer();
34
+ server.once("error", () => resolve(freePort(from + 1)));
35
+ server.listen(from, "127.0.0.1", () => server.close(() => resolve(from)));
36
+ });
37
+ }
38
+
39
+ /** Runs the site until Ctrl-C, and opens it in the browser once it answers. */
40
+ export async function runLocally(dir, app, convexUrl) {
41
+ if (!convexUrl) fail("Alori didn't say where this app's backend is. Run alori pull, then try again.");
42
+ if (!installed(dir)) install(dir);
43
+ const port = await freePort(5300);
44
+ const url = `http://localhost:${port}`;
45
+ console.log(`\n${app} is starting at ${url} (Ctrl-C stops it).`);
46
+ console.log("Saved changes show at once. Send them to Alori with: alori push -m \"what changed\"\n");
47
+ const vite = join(dir, "node_modules", ".bin", process.platform === "win32" ? "vite.cmd" : "vite");
48
+ const child = spawn(vite, ["dev", "--port", String(port), "--strictPort"], {
49
+ cwd: dir,
50
+ stdio: "inherit",
51
+ shell: process.platform === "win32",
52
+ env: { ...process.env, VITE_CONVEX_URL: convexUrl },
53
+ });
54
+ let opened = false;
55
+ const opener = setInterval(async () => {
56
+ if (opened) return;
57
+ try {
58
+ await fetch(url, { signal: AbortSignal.timeout(1500) });
59
+ opened = true;
60
+ clearInterval(opener);
61
+ if (process.env.ALORI_NO_BROWSER !== "1") openBrowser(url);
62
+ } catch {
63
+ // Not answering yet.
64
+ }
65
+ }, 1000);
66
+ const stop = () => child.kill("SIGINT");
67
+ process.on("SIGINT", stop);
68
+ process.on("SIGTERM", stop);
69
+ await new Promise((resolve) => child.on("exit", resolve));
70
+ clearInterval(opener);
71
+ }
package/lib/guide.mjs CHANGED
@@ -16,10 +16,16 @@ 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
+ ## Seeing changes
20
+
21
+ \`alori dev\` runs the app at http://localhost:5300 (or the next free port) from this folder's files, against the app's
22
+ real backend and data. Screens, text and styles change as files are saved. A change under \`convex/\` reaches the backend
23
+ only with \`alori push\`. Keep \`alori dev\` running and check each change there before pushing.
24
+
19
25
  ## Commands
20
26
 
21
27
  \`\`\`bash
22
- pnpm install # once, after a pull
28
+ alori dev # runs the app on this computer and opens it; saved changes show at once
23
29
  pnpm typecheck # before each push
24
30
  pnpm lint
25
31
  alori status # what changed since the last pull or push
package/lib/sync.mjs CHANGED
@@ -6,9 +6,10 @@
6
6
  import { execFileSync } from "node:child_process";
7
7
  import { copyFileSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
8
8
  import { tmpdir } from "node:os";
9
- import { dirname, join } from "node:path";
9
+ 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
+ import { install, installed, runLocally } from "./dev.mjs";
12
13
  import { claudeGuide } from "./guide.mjs";
13
14
 
14
15
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
@@ -79,6 +80,14 @@ dist/
79
80
  *.alori-theirs
80
81
  `;
81
82
 
83
+ /** pnpm 11 stops `pnpm install` until each package's build script is allowed or refused. */
84
+ const workspaceFile = `allowBuilds:
85
+ esbuild: true
86
+ onnxruntime-node: true
87
+ protobufjs: true
88
+ sharp: true
89
+ `;
90
+
82
91
  /** A first pull into an empty folder. */
83
92
  async function pullFresh(dir, me) {
84
93
  const { folder, temp, version } = await download();
@@ -87,9 +96,10 @@ async function pullFresh(dir, me) {
87
96
  rmSync(temp, { recursive: true, force: true });
88
97
  writeFileSync(join(dir, "CLAUDE.md"), claudeGuide(me.app));
89
98
  if (!existsSync(join(dir, ".gitignore"))) writeFileSync(join(dir, ".gitignore"), ignoreFile);
99
+ if (!existsSync(join(dir, "pnpm-workspace.yaml"))) writeFileSync(join(dir, "pnpm-workspace.yaml"), workspaceFile);
90
100
  writeState(dir, { api: apiBase(), appId: me.appId, app: me.app, version, hashes: codeHashes(dir) });
91
101
  console.log(`Pulled ${me.app}, version ${version}, into ${dir}`);
92
- console.log("Next: pnpm install, then change it with Claude Code, then: alori push -m \"what changed\"");
102
+ install(dir);
93
103
  }
94
104
 
95
105
  /**
@@ -120,10 +130,13 @@ async function pullOver(dir, state, me) {
120
130
  }
121
131
  }
122
132
  // Alori's template files (package.json, vite.config.ts, public/…) always come fresh.
133
+ const lockfile = (root) => (existsSync(join(root, "pnpm-lock.yaml")) ? readFileSync(join(root, "pnpm-lock.yaml"), "utf8") : "");
134
+ const packagesChanged = lockfile(folder) !== lockfile(dir);
123
135
  for (const path of walk(folder).filter((path) => !isAppCode(path) && !templateNotes.has(path))) copyInto(folder, dir, path);
124
136
  rmSync(temp, { recursive: true, force: true });
125
137
  writeState(dir, { api: apiBase(), appId: me.appId, app: me.app, version, hashes: remote });
126
138
  console.log(`Pulled ${me.app}, version ${version}.`);
139
+ if (packagesChanged || !installed(dir)) install(dir);
127
140
  if (overlaps.length > 0) {
128
141
  console.log("\nThese files changed both here and in Alori. Yours are kept; Alori's are beside them as .alori-theirs:");
129
142
  for (const path of overlaps) console.log(` ${path}`);
@@ -141,8 +154,25 @@ function checkSameApp(state, me) {
141
154
  if (state.appId && state.appId !== me.appId) fail(`This folder holds ${state.app}, but you're signed in to ${me.app}. Run alori login with the right account.`);
142
155
  }
143
156
 
144
- export async function pull(dir) {
157
+ /** A folder name from the app's name: "Pro-Quai Inc" → pro-quai-inc. */
158
+ const folderNameOf = (app) =>
159
+ app
160
+ .normalize("NFD")
161
+ .replace(/[\u0300-\u036f]/g, "")
162
+ .toLowerCase()
163
+ .replace(/[^a-z0-9]+/g, "-")
164
+ .replace(/^-+|-+$/g, "") || "alori-app";
165
+
166
+ /** Where a command works: the folder named, else this one when it was pulled, else a new folder named after the app. */
167
+ function folderFor(named, me) {
168
+ if (named) return resolve(named);
169
+ if (readState(resolve("."))) return resolve(".");
170
+ return resolve(folderNameOf(me.app));
171
+ }
172
+
173
+ export async function pull(named) {
145
174
  const me = await whoAmI();
175
+ const dir = folderFor(named, me);
146
176
  const state = readState(dir);
147
177
  if (state) {
148
178
  checkSameApp(state, me);
@@ -151,6 +181,21 @@ export async function pull(dir) {
151
181
  }
152
182
  if (existsSync(dir) && readdirSync(dir).some((name) => name !== ".DS_Store")) fail(`${dir} isn't empty. Pull into a new folder: alori pull <folder>`);
153
183
  await pullFresh(dir, me);
184
+ const move = dir === resolve(".") ? "" : `cd ${basename(dir)} && `;
185
+ console.log(`\nReady. Run it on this computer: ${move}alori dev`);
186
+ }
187
+
188
+ /** `alori dev`: pulls the app first when there is no pulled folder, installs what's missing, and runs it here. */
189
+ export async function dev(named) {
190
+ const me = await whoAmI();
191
+ const dir = folderFor(named, me);
192
+ const state = readState(dir);
193
+ if (state) checkSameApp(state, me);
194
+ else {
195
+ if (existsSync(dir) && readdirSync(dir).some((name) => name !== ".DS_Store")) fail(`${dir} isn't empty and wasn't pulled from Alori. Run alori dev <new folder>.`);
196
+ await pullFresh(dir, me);
197
+ }
198
+ await runLocally(dir, me.app, me.convexUrl);
154
199
  }
155
200
 
156
201
  export function status(dir) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alori/cli",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Build your Alori app with your own Claude Code: pull its code, change it, push it back.",
5
5
  "type": "module",
6
6
  "bin": {