@getmagical/cli 0.1.8 → 0.1.11

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
@@ -10,6 +10,7 @@ Magical CLI for the shared MCP operation surface.
10
10
  ## Usage
11
11
 
12
12
  ```bash
13
+ mgcl --version
13
14
  mgcl update
14
15
  mgcl auth login
15
16
  mgcl settings env base-url http://main.localhost:1355
package/bin/mgcl.mjs ADDED
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { spawnSync } from 'node:child_process';
4
+ import { existsSync } from 'node:fs';
5
+ import path from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+
8
+ const packageDir = path.resolve(
9
+ path.dirname(fileURLToPath(import.meta.url)),
10
+ '..',
11
+ );
12
+ const repoRoot = path.resolve(packageDir, '..', '..');
13
+ const distEntrypoint = path.join(packageDir, 'dist', 'index.js');
14
+ const repoPackageJson = path.join(repoRoot, 'package.json');
15
+
16
+ const runNode = (args) => {
17
+ const result = spawnSync(process.execPath, args, {
18
+ env: process.env,
19
+ stdio: 'inherit',
20
+ });
21
+
22
+ if (result.error) {
23
+ throw result.error;
24
+ }
25
+
26
+ process.exit(result.status ?? 1);
27
+ };
28
+
29
+ const ensureBuiltEntrypoint = () => {
30
+ if (existsSync(distEntrypoint)) {
31
+ return;
32
+ }
33
+
34
+ const shouldUseWorkspaceBuild = existsSync(repoPackageJson);
35
+ const buildCommand = shouldUseWorkspaceBuild
36
+ ? ['run', 'build', '--', '--filter=@getmagical/cli...']
37
+ : ['run', 'build'];
38
+ const buildCwd = shouldUseWorkspaceBuild ? repoRoot : packageDir;
39
+ const manualBuildCommand = shouldUseWorkspaceBuild
40
+ ? 'npm run build -- --filter=@getmagical/cli...'
41
+ : 'npm run build --workspace=@getmagical/cli';
42
+
43
+ const result = spawnSync('npm', buildCommand, {
44
+ cwd: buildCwd,
45
+ env: process.env,
46
+ stdio: 'inherit',
47
+ });
48
+
49
+ if (result.error) {
50
+ throw result.error;
51
+ }
52
+
53
+ if (!existsSync(distEntrypoint)) {
54
+ process.stderr.write(
55
+ `mgcl is unavailable because dist/index.js is missing after the local build. Run \`${manualBuildCommand}\` and try again.\n`,
56
+ );
57
+ process.exit(result.status ?? 1);
58
+ }
59
+ };
60
+
61
+ ensureBuiltEntrypoint();
62
+ runNode([distEntrypoint, ...process.argv.slice(2)]);