@cardstack/boxel-cli 0.0.1 → 0.1.0

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.
Files changed (41) hide show
  1. package/README.md +124 -0
  2. package/api.ts +3 -0
  3. package/bin/boxel.js +15 -0
  4. package/dist/index.js +107 -66
  5. package/package.json +31 -24
  6. package/src/commands/file/delete.ts +110 -0
  7. package/src/commands/file/index.ts +20 -0
  8. package/src/commands/file/lint.ts +235 -0
  9. package/src/commands/file/list.ts +121 -0
  10. package/src/commands/file/read.ts +113 -0
  11. package/src/commands/file/touch.ts +222 -0
  12. package/src/commands/file/write.ts +152 -0
  13. package/src/commands/profile.ts +199 -106
  14. package/src/commands/read-transpiled.ts +120 -0
  15. package/src/commands/realm/cancel-indexing.ts +113 -0
  16. package/src/commands/realm/create.ts +1 -4
  17. package/src/commands/realm/history.ts +388 -0
  18. package/src/commands/realm/index.ts +12 -0
  19. package/src/commands/realm/list.ts +156 -0
  20. package/src/commands/realm/pull.ts +51 -17
  21. package/src/commands/realm/push.ts +52 -16
  22. package/src/commands/realm/remove.ts +281 -0
  23. package/src/commands/realm/sync.ts +153 -60
  24. package/src/commands/realm/wait-for-ready.ts +120 -0
  25. package/src/commands/realm/watch.ts +626 -0
  26. package/src/commands/run-command.ts +4 -3
  27. package/src/commands/search.ts +160 -0
  28. package/src/index.ts +60 -2
  29. package/src/lib/auth-resolver.ts +58 -0
  30. package/src/lib/auth.ts +56 -12
  31. package/src/lib/boxel-cli-client.ts +135 -279
  32. package/src/lib/cli-log.ts +132 -0
  33. package/src/lib/colors.ts +14 -9
  34. package/src/lib/find-checkpoint.ts +65 -0
  35. package/src/lib/profile-manager.ts +49 -4
  36. package/src/lib/prompt.ts +133 -0
  37. package/src/lib/realm-authenticator.ts +12 -0
  38. package/src/lib/realm-sync-base.ts +47 -10
  39. package/src/lib/seed-auth.ts +214 -0
  40. package/src/lib/watch-lock.ts +81 -0
  41. package/LICENSE +0 -21
@@ -0,0 +1,81 @@
1
+ import * as fs from 'fs/promises';
2
+ import * as path from 'path';
3
+
4
+ const LOCK_FILE = '.boxel-watch.lock';
5
+
6
+ export interface WatchLockInfo {
7
+ pid: number;
8
+ startedAt: string;
9
+ realmUrl: string;
10
+ }
11
+
12
+ export type WatchLockResult =
13
+ | { ok: true; staleOverwrote: boolean }
14
+ | { ok: false; existing: WatchLockInfo };
15
+
16
+ function lockPath(localDir: string): string {
17
+ return path.join(localDir, LOCK_FILE);
18
+ }
19
+
20
+ function isProcessAlive(pid: number): boolean {
21
+ try {
22
+ process.kill(pid, 0);
23
+ return true;
24
+ } catch (err: any) {
25
+ // EPERM means the process exists but we can't signal it — still alive.
26
+ return err?.code === 'EPERM';
27
+ }
28
+ }
29
+
30
+ async function readLock(localDir: string): Promise<WatchLockInfo | null> {
31
+ try {
32
+ const raw = await fs.readFile(lockPath(localDir), 'utf8');
33
+ const parsed = JSON.parse(raw) as Partial<WatchLockInfo>;
34
+ if (
35
+ typeof parsed.pid !== 'number' ||
36
+ typeof parsed.startedAt !== 'string' ||
37
+ typeof parsed.realmUrl !== 'string'
38
+ ) {
39
+ return null;
40
+ }
41
+ return parsed as WatchLockInfo;
42
+ } catch {
43
+ return null;
44
+ }
45
+ }
46
+
47
+ export async function acquireWatchLock(
48
+ localDir: string,
49
+ realmUrl: string,
50
+ ): Promise<WatchLockResult> {
51
+ await fs.mkdir(localDir, { recursive: true });
52
+ const existing = await readLock(localDir);
53
+ let staleOverwrote = false;
54
+ if (existing && isProcessAlive(existing.pid)) {
55
+ return { ok: false, existing };
56
+ }
57
+ if (existing) {
58
+ staleOverwrote = true;
59
+ }
60
+ const info: WatchLockInfo = {
61
+ pid: process.pid,
62
+ startedAt: new Date().toISOString(),
63
+ realmUrl,
64
+ };
65
+ await fs.writeFile(lockPath(localDir), JSON.stringify(info, null, 2) + '\n');
66
+ return { ok: true, staleOverwrote };
67
+ }
68
+
69
+ export async function releaseWatchLock(localDir: string): Promise<void> {
70
+ try {
71
+ await fs.unlink(lockPath(localDir));
72
+ } catch (err: any) {
73
+ if (err?.code !== 'ENOENT') throw err;
74
+ }
75
+ }
76
+
77
+ export async function readWatchLock(
78
+ localDir: string,
79
+ ): Promise<WatchLockInfo | null> {
80
+ return readLock(localDir);
81
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 Cardstack
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.