@cardstack/boxel-cli 0.1.4 → 0.2.0-unstable.294
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/dist/index.js +99 -93
- package/package.json +3 -3
- package/src/build-program.ts +4 -0
- package/src/commands/consolidate-workspaces.ts +104 -0
- package/src/commands/realm/index.ts +3 -1
- package/src/commands/realm/status.ts +668 -0
- package/src/commands/realm/sync.ts +3 -2
- package/src/lib/realm-local-paths.ts +243 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cardstack/boxel-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-unstable.294",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "CLI tools for Boxel workspace management",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"vite": "^6.3.2",
|
|
53
53
|
"vitest": "^2.1.9",
|
|
54
54
|
"@cardstack/local-types": "0.0.0",
|
|
55
|
-
"@cardstack/
|
|
56
|
-
"@cardstack/
|
|
55
|
+
"@cardstack/postgres": "0.0.0",
|
|
56
|
+
"@cardstack/runtime-common": "1.0.0"
|
|
57
57
|
},
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"access": "public",
|
package/src/build-program.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { Command } from 'commander';
|
|
2
2
|
import { profileCommand } from './commands/profile';
|
|
3
|
+
import { registerConsolidateWorkspacesCommand } from './commands/consolidate-workspaces';
|
|
3
4
|
import { registerReadTranspiledCommand } from './commands/read-transpiled';
|
|
4
5
|
import { registerRealmCommand } from './commands/realm/index';
|
|
5
6
|
import { registerFileCommand } from './commands/file/index';
|
|
6
7
|
import { registerRunCommand } from './commands/run-command';
|
|
7
8
|
import { registerSearchCommand } from './commands/search';
|
|
8
9
|
import { setQuiet } from './lib/cli-log';
|
|
10
|
+
import { warnIfMisplacedLocalRealmDirs } from './lib/realm-local-paths';
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* Construct the boxel CLI program with every command registered. Pure builder
|
|
@@ -30,6 +32,7 @@ export function buildBoxelProgram(version: string): Command {
|
|
|
30
32
|
if (opts.quiet) {
|
|
31
33
|
setQuiet(true);
|
|
32
34
|
}
|
|
35
|
+
warnIfMisplacedLocalRealmDirs(process.cwd());
|
|
33
36
|
});
|
|
34
37
|
|
|
35
38
|
program
|
|
@@ -86,6 +89,7 @@ Environment variables (for 'add'):
|
|
|
86
89
|
registerRunCommand(program);
|
|
87
90
|
registerSearchCommand(program);
|
|
88
91
|
registerReadTranspiledCommand(program);
|
|
92
|
+
registerConsolidateWorkspacesCommand(program);
|
|
89
93
|
|
|
90
94
|
return program;
|
|
91
95
|
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import type { Command } from 'commander';
|
|
4
|
+
import { findMisplacedLocalRealmDirs } from '../lib/realm-local-paths';
|
|
5
|
+
|
|
6
|
+
export interface ConsolidateWorkspacesOptions {
|
|
7
|
+
dryRun?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function ensureDir(dirPath: string): void {
|
|
11
|
+
if (!fs.existsSync(dirPath)) {
|
|
12
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function moveDir(from: string, to: string): void {
|
|
17
|
+
try {
|
|
18
|
+
fs.renameSync(from, to);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
const err = error as NodeJS.ErrnoException;
|
|
21
|
+
if (err.code !== 'EXDEV') {
|
|
22
|
+
throw err;
|
|
23
|
+
}
|
|
24
|
+
fs.cpSync(from, to, { recursive: true });
|
|
25
|
+
fs.rmSync(from, { recursive: true, force: true });
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function consolidateWorkspacesCommand(
|
|
30
|
+
rootDirInput: string | undefined,
|
|
31
|
+
options: ConsolidateWorkspacesOptions,
|
|
32
|
+
): Promise<void> {
|
|
33
|
+
const rootDir = path.resolve(rootDirInput || '.');
|
|
34
|
+
const entries = findMisplacedLocalRealmDirs(rootDir);
|
|
35
|
+
|
|
36
|
+
if (entries.length === 0) {
|
|
37
|
+
console.log(`No misplaced local realm paths found under ${rootDir}`);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
console.log(`Found ${entries.length} misplaced local realm path(s):\n`);
|
|
42
|
+
|
|
43
|
+
let moved = 0;
|
|
44
|
+
let skipped = 0;
|
|
45
|
+
|
|
46
|
+
for (const entry of entries) {
|
|
47
|
+
const from = path.relative(rootDir, entry.currentDir) || '.';
|
|
48
|
+
const to = path.relative(rootDir, entry.expectedDir) || '.';
|
|
49
|
+
console.log(`- ${from} -> ${to}`);
|
|
50
|
+
|
|
51
|
+
if (options.dryRun) {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (fs.existsSync(entry.expectedDir)) {
|
|
56
|
+
console.warn(' Skipping: target path already exists');
|
|
57
|
+
skipped += 1;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
ensureDir(path.dirname(entry.expectedDir));
|
|
62
|
+
try {
|
|
63
|
+
moveDir(entry.currentDir, entry.expectedDir);
|
|
64
|
+
moved += 1;
|
|
65
|
+
} catch (error) {
|
|
66
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
67
|
+
console.warn(` Skipping: failed to move (${message})`);
|
|
68
|
+
skipped += 1;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (options.dryRun) {
|
|
73
|
+
console.log('\n[DRY RUN] No directories moved.');
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
console.log(`\nMoved ${moved} director${moved === 1 ? 'y' : 'ies'}.`);
|
|
78
|
+
if (skipped > 0) {
|
|
79
|
+
console.log(
|
|
80
|
+
`Skipped ${skipped} due to existing target paths or move failures.`,
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function registerConsolidateWorkspacesCommand(program: Command): void {
|
|
86
|
+
program
|
|
87
|
+
.command('consolidate-workspaces')
|
|
88
|
+
.description(
|
|
89
|
+
'Move local realm mirror directories into the canonical <root>/<domain>/<owner>/<realm> layout',
|
|
90
|
+
)
|
|
91
|
+
.argument(
|
|
92
|
+
'[root-dir]',
|
|
93
|
+
'Root directory to scan (default: current directory)',
|
|
94
|
+
)
|
|
95
|
+
.option('--dry-run', 'Preview without moving anything')
|
|
96
|
+
.action(
|
|
97
|
+
async (
|
|
98
|
+
rootDir: string | undefined,
|
|
99
|
+
opts: ConsolidateWorkspacesOptions,
|
|
100
|
+
) => {
|
|
101
|
+
await consolidateWorkspacesCommand(rootDir, opts);
|
|
102
|
+
},
|
|
103
|
+
);
|
|
104
|
+
}
|
|
@@ -7,6 +7,7 @@ import { registerMilestoneCommand } from './milestone';
|
|
|
7
7
|
import { registerPullCommand } from './pull';
|
|
8
8
|
import { registerPushCommand } from './push';
|
|
9
9
|
import { registerRemoveCommand } from './remove';
|
|
10
|
+
import { registerStatusCommand } from './status';
|
|
10
11
|
import { registerSyncCommand } from './sync';
|
|
11
12
|
import { registerWaitForReadyCommand } from './wait-for-ready';
|
|
12
13
|
import { registerWatchCommand } from './watch';
|
|
@@ -24,7 +25,8 @@ export function registerRealmCommand(program: Command): void {
|
|
|
24
25
|
registerPullCommand(realm);
|
|
25
26
|
registerPushCommand(realm);
|
|
26
27
|
registerRemoveCommand(realm);
|
|
27
|
-
registerSyncCommand(realm);
|
|
28
|
+
const sync = registerSyncCommand(realm);
|
|
29
|
+
registerStatusCommand(sync);
|
|
28
30
|
registerWaitForReadyCommand(realm);
|
|
29
31
|
registerWatchCommand(realm);
|
|
30
32
|
}
|