@yabasha/gex 1.3.4 → 1.3.6

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/cli.cjs CHANGED
@@ -31,721 +31,60 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  // src/cli.ts
32
32
  var cli_exports = {};
33
33
  __export(cli_exports, {
34
- run: () => run2
34
+ run: () => run
35
35
  });
36
36
  module.exports = __toCommonJS(cli_exports);
37
-
38
- // src/runtimes/node/commands.ts
39
- var import_node_path6 = __toESM(require("path"), 1);
40
- var import_commander = require("commander");
41
-
42
- // src/shared/cli/install.ts
43
- var INSTALL_COMMANDS = {
44
- npm: {
45
- global: ["i", "-g"],
46
- local: ["i"],
47
- dev: ["i", "-D"]
48
- },
49
- bun: {
50
- global: ["add", "-g"],
51
- local: ["add"],
52
- dev: ["add", "-d"]
53
- }
54
- };
55
- var MAX_BUFFER = 10 * 1024 * 1024;
56
- function formatSpec(pkg) {
57
- return pkg.version ? `${pkg.name}@${pkg.version}` : pkg.name;
58
- }
59
- async function getExecFileAsync() {
60
- const { execFile } = await import("child_process");
61
- const { promisify: promisify2 } = await import("util");
62
- return promisify2(execFile);
63
- }
64
- async function installFromReport(report, options) {
65
- const opts = typeof options === "string" ? { cwd: options } : options;
66
- const { cwd, packageManager = "npm" } = opts;
67
- const globalPkgs = report.global_packages.map(formatSpec).filter(Boolean);
68
- const localPkgs = report.local_dependencies.map(formatSpec).filter(Boolean);
69
- const devPkgs = report.local_dev_dependencies.map(formatSpec).filter(Boolean);
70
- if (globalPkgs.length === 0 && localPkgs.length === 0 && devPkgs.length === 0) {
71
- console.log("No packages to install from report.");
72
- return;
73
- }
74
- const execFileAsync = await getExecFileAsync();
75
- const cmd = INSTALL_COMMANDS[packageManager];
76
- const binary = packageManager === "bun" ? "bun" : "npm";
77
- if (globalPkgs.length > 0) {
78
- console.log(`Installing global: ${globalPkgs.join(" ")}`);
79
- await execFileAsync(binary, [...cmd.global, ...globalPkgs], { cwd, maxBuffer: MAX_BUFFER });
80
- }
81
- if (localPkgs.length > 0) {
82
- console.log(`Installing local deps: ${localPkgs.join(" ")}`);
83
- await execFileAsync(binary, [...cmd.local, ...localPkgs], { cwd, maxBuffer: MAX_BUFFER });
84
- }
85
- if (devPkgs.length > 0) {
86
- console.log(`Installing local devDeps: ${devPkgs.join(" ")}`);
87
- await execFileAsync(binary, [...cmd.dev, ...devPkgs], { cwd, maxBuffer: MAX_BUFFER });
88
- }
89
- }
90
- function printFromReport(report) {
91
- const lines = [];
92
- if (report.global_packages.length > 0) {
93
- lines.push("Global Packages:");
94
- for (const p of report.global_packages) {
95
- lines.push(`- ${p.name}@${p.version}`);
96
- }
97
- }
98
- if (report.local_dependencies.length > 0) {
99
- if (lines.length) lines.push("");
100
- lines.push("Local Dependencies:");
101
- for (const p of report.local_dependencies) {
102
- lines.push(`- ${p.name}@${p.version}`);
103
- }
104
- }
105
- if (report.local_dev_dependencies.length > 0) {
106
- if (lines.length) lines.push("");
107
- lines.push("Local Dev Dependencies:");
108
- for (const p of report.local_dev_dependencies) {
109
- lines.push(`- ${p.name}@${p.version}`);
110
- }
111
- }
112
- if (lines.length === 0) {
113
- lines.push("(no packages found in report)");
114
- }
115
- console.log(lines.join("\n"));
116
- }
117
-
118
- // src/shared/cli/output.ts
119
- var import_node_path = __toESM(require("path"), 1);
120
-
121
- // src/shared/report/json.ts
122
- function renderJson(report) {
123
- const r = {
124
- ...report,
125
- global_packages: [...report.global_packages].sort((a, b) => a.name.localeCompare(b.name)),
126
- local_dependencies: [...report.local_dependencies].sort((a, b) => a.name.localeCompare(b.name)),
127
- local_dev_dependencies: [...report.local_dev_dependencies].sort(
128
- (a, b) => a.name.localeCompare(b.name)
129
- )
130
- };
131
- return JSON.stringify(r, null, 2);
132
- }
133
-
134
- // src/shared/report/md.ts
135
- function table(headers, rows) {
136
- const header = `| ${headers.join(" | ")} |`;
137
- const sep = `| ${headers.map(() => "---").join(" | ")} |`;
138
- const body = rows.map((r) => `| ${r.join(" | ")} |`).join("\n");
139
- return [header, sep, body].filter(Boolean).join("\n");
140
- }
141
- function renderMarkdown(report) {
142
- const lines = [];
143
- lines.push("# GEX Report");
144
- lines.push("");
145
- if (report.project_name || report.project_version || report.project_description || report.project_homepage || report.project_bugs) {
146
- lines.push("## Project Metadata");
147
- if (report.project_name) lines.push(`- Name: ${report.project_name}`);
148
- if (report.project_version) lines.push(`- Version: ${report.project_version}`);
149
- if (report.project_description)
150
- lines.push(`- Description: ${report.project_description}`);
151
- if (report.project_homepage)
152
- lines.push(`- Homepage: ${report.project_homepage}`);
153
- if (report.project_bugs) lines.push(`- Bugs: ${report.project_bugs}`);
154
- lines.push("");
155
- }
156
- if (report.global_packages.length > 0) {
157
- lines.push("## Global Packages");
158
- const rows = report.global_packages.map((p) => [p.name, p.version || "", p.resolved_path || ""]);
159
- lines.push(table(["Name", "Version", "Path"], rows));
160
- lines.push("");
161
- }
162
- if (report.local_dependencies.length > 0) {
163
- lines.push("## Local Dependencies");
164
- const rows = report.local_dependencies.map((p) => [
165
- p.name,
166
- p.version || "",
167
- p.resolved_path || ""
168
- ]);
169
- lines.push(table(["Name", "Version", "Path"], rows));
170
- lines.push("");
171
- }
172
- if (report.local_dev_dependencies.length > 0) {
173
- lines.push("## Local Dev Dependencies");
174
- const rows = report.local_dev_dependencies.map((p) => [
175
- p.name,
176
- p.version || "",
177
- p.resolved_path || ""
178
- ]);
179
- lines.push(table(["Name", "Version", "Path"], rows));
180
- lines.push("");
181
- }
182
- lines.push("---");
183
- lines.push("_Generated by GEX_");
184
- return lines.join("\n");
185
- }
186
-
187
- // src/shared/cli/output.ts
188
- async function outputReport(report, format, outFile, markdownExtras) {
189
- const content = format === "json" ? renderJson(report) : renderMarkdown({ ...report, ...markdownExtras || {} });
190
- if (outFile) {
191
- const outDir = import_node_path.default.dirname(outFile);
192
- const { mkdir, writeFile } = await import("fs/promises");
193
- await mkdir(outDir, { recursive: true });
194
- await writeFile(outFile, content, "utf8");
195
- console.log(`Wrote report to ${outFile}`);
196
- } else {
197
- console.log(content);
198
- }
199
- }
200
-
201
- // src/shared/cli/parser.ts
202
- var import_promises = require("fs/promises");
203
- var import_node_path2 = __toESM(require("path"), 1);
204
- function isMarkdownReportFile(filePath) {
205
- const ext = import_node_path2.default.extname(filePath).toLowerCase();
206
- return ext === ".md" || ext === ".markdown";
207
- }
208
- function parseMarkdownPackagesTable(lines, startIndex) {
209
- const rows = [];
210
- if (!lines[startIndex] || !lines[startIndex].trim().startsWith("|")) return rows;
211
- let i = startIndex + 2;
212
- while (i < lines.length && lines[i].trim().startsWith("|")) {
213
- const cols = lines[i].split("|").map((c) => c.trim()).filter((_, idx, arr) => !(idx === 0 || idx === arr.length - 1));
214
- const [name = "", version = "", resolved_path = ""] = cols;
215
- if (name) rows.push({ name, version, resolved_path });
216
- i++;
217
- }
218
- return rows;
219
- }
220
- function parseMarkdownReport(md) {
221
- const lines = md.split(/\r?\n/);
222
- const findSection = (title) => lines.findIndex((l) => l.trim().toLowerCase() === `## ${title}`.toLowerCase());
223
- const parseSection = (idx) => {
224
- if (idx < 0) return [];
225
- let i = idx + 1;
226
- while (i < lines.length && !lines[i].trim().startsWith("|")) i++;
227
- return parseMarkdownPackagesTable(lines, i);
228
- };
229
- const global_packages = parseSection(findSection("Global Packages"));
230
- const local_dependencies = parseSection(findSection("Local Dependencies"));
231
- const local_dev_dependencies = parseSection(findSection("Local Dev Dependencies"));
232
- const report = {
233
- report_version: "1.0",
234
- timestamp: (/* @__PURE__ */ new Date()).toISOString(),
235
- tool_version: "unknown",
236
- global_packages,
237
- local_dependencies,
238
- local_dev_dependencies
239
- };
240
- return report;
241
- }
242
- async function loadReportFromFile(reportPath) {
243
- const raw = await (0, import_promises.readFile)(reportPath, "utf8");
244
- if (isMarkdownReportFile(reportPath) || raw.startsWith("# GEX Report")) {
245
- return parseMarkdownReport(raw);
246
- }
247
- return JSON.parse(raw);
248
- }
249
-
250
- // src/shared/npm-cli.ts
251
- var import_node_util = require("util");
252
- async function getExecFileAsync2() {
253
- const { execFile } = await import("child_process");
254
- return (0, import_node_util.promisify)(execFile);
255
- }
256
- async function npmOutdated(options = {}) {
257
- const args = ["outdated", "--json"];
258
- if (options.global) args.push("--global");
259
- try {
260
- const execFileAsync = await getExecFileAsync2();
261
- const { stdout } = await execFileAsync("npm", args, {
262
- cwd: options.cwd,
263
- maxBuffer: 10 * 1024 * 1024
264
- });
265
- return normalizeOutdated(stdout);
266
- } catch (error) {
267
- const stdout = typeof error?.stdout === "string" ? error.stdout : "";
268
- if (stdout.trim()) {
269
- return normalizeOutdated(stdout);
270
- }
271
- throw formatNpmError(error, "npm outdated");
272
- }
273
- }
274
- async function npmUpdate(options) {
275
- const args = ["update"];
276
- if (options.global) args.push("-g");
277
- if (options.packages && options.packages.length > 0) args.push(...options.packages);
278
- try {
279
- const execFileAsync = await getExecFileAsync2();
280
- await execFileAsync("npm", args, {
281
- cwd: options.cwd,
282
- maxBuffer: 10 * 1024 * 1024
283
- });
284
- } catch (error) {
285
- throw formatNpmError(error, "npm update");
286
- }
287
- }
288
- function normalizeOutdated(stdout) {
289
- if (!stdout.trim()) return [];
290
- let data;
291
- try {
292
- data = JSON.parse(stdout);
293
- } catch {
294
- return [];
295
- }
296
- if (!data) return [];
297
- return Object.entries(data).map(([name, info]) => ({
298
- name,
299
- current: info?.current ? String(info.current) : "",
300
- wanted: info?.wanted ? String(info.wanted) : "",
301
- latest: info?.latest ? String(info.latest) : "",
302
- type: info?.type ? String(info.type) : void 0
303
- }));
304
- }
305
- function formatNpmError(error, commandLabel) {
306
- const stderr = typeof error?.stderr === "string" ? error.stderr.trim() : "";
307
- const message = stderr || error?.message || `${commandLabel} failed`;
308
- return new Error(`${commandLabel} failed: ${message}`);
309
- }
310
-
311
- // src/shared/cli/loader.ts
312
- var frames = ["-", "\\", "|", "/"];
313
- function createLoader(message) {
314
- if (!process.stdout.isTTY) {
315
- console.log(`${message}...`);
316
- return {
317
- stop(finalMessage) {
318
- if (finalMessage) console.log(finalMessage);
319
- }
320
- };
321
- }
322
- let index = 0;
323
- const interval = globalThis.setInterval(() => {
324
- const frame = frames[index % frames.length];
325
- index += 1;
326
- process.stdout.write(`\r${message} ${frame}`);
327
- }, 80);
328
- return {
329
- stop(finalMessage) {
330
- globalThis.clearInterval(interval);
331
- process.stdout.write("\r");
332
- if (finalMessage) {
333
- console.log(finalMessage);
334
- } else {
335
- process.stdout.write("\x1B[2K");
336
- }
337
- }
338
- };
339
- }
340
-
341
- // src/shared/cli/outdated.ts
342
- function normalizeUpdateSelection(value) {
343
- if (value === void 0) {
344
- return { shouldUpdate: false, updateAll: false, packages: [] };
345
- }
346
- if (value === true) {
347
- return { shouldUpdate: true, updateAll: true, packages: [] };
348
- }
349
- const packages = Array.isArray(value) ? value : typeof value === "string" ? [value] : [];
350
- const normalized = packages.flatMap(
351
- (entry) => String(entry).split(",").map((part) => part.trim())
352
- ).filter(Boolean);
353
- return {
354
- shouldUpdate: true,
355
- updateAll: false,
356
- packages: normalized
357
- };
358
- }
359
- function formatOutdatedTable(entries) {
360
- const headers = ["Name", "Current", "Wanted", "Latest", "Type"];
361
- const rows = entries.map((entry) => [
362
- entry.name,
363
- entry.current || "-",
364
- entry.wanted || "-",
365
- entry.latest || "-",
366
- entry.type || "-"
367
- ]);
368
- const widths = headers.map(
369
- (header, index) => Math.max(header.length, ...rows.map((row) => row[index].length))
370
- );
371
- const formatRow = (columns) => columns.map((col, idx) => col.padEnd(widths[idx], " ")).join(" ");
372
- const lines = [formatRow(headers), formatRow(widths.map((w) => "-".repeat(w)))];
373
- for (const row of rows) {
374
- lines.push(formatRow(row));
375
- }
376
- return lines.join("\n");
377
- }
378
- async function handleOutdatedWorkflow(opts) {
379
- if (!opts.checkOutdated && !opts.selection.shouldUpdate) {
380
- return { proceed: true, outdated: [] };
381
- }
382
- let fetchLoader;
383
- if (opts.checkOutdated || opts.selection.shouldUpdate) {
384
- fetchLoader = createLoader("Checking for outdated packages");
385
- }
386
- const outdated = await opts.fetchOutdated();
387
- fetchLoader?.stop("Finished checking outdated packages.");
388
- if (opts.selection.shouldUpdate && opts.updateRunner) {
389
- const packagesToUpdate = opts.selection.updateAll ? outdated.map((entry) => entry.name) : opts.selection.packages;
390
- if (!packagesToUpdate || packagesToUpdate.length === 0) {
391
- if (opts.selection.updateAll) {
392
- console.log("No outdated packages to update.");
393
- } else {
394
- console.log("No packages were specified for updating.");
395
- }
396
- } else {
397
- const updateLoader = createLoader("Updating packages");
398
- await opts.updateRunner(packagesToUpdate);
399
- updateLoader.stop("Finished updating packages.");
400
- }
401
- }
402
- const proceed = !((opts.checkOutdated || opts.selection.shouldUpdate) && !opts.outFile);
403
- return { proceed, outdated };
404
- }
405
-
406
- // src/shared/cli/utils.ts
407
- var import_node_fs = require("fs");
408
- var import_promises2 = require("fs/promises");
409
- var import_node_path3 = __toESM(require("path"), 1);
410
- var import_node_url = require("url");
37
+ var import_node_readline = __toESM(require("readline"), 1);
411
38
  var import_meta = {};
412
- function getPkgJsonPath() {
413
- let startDir;
414
- try {
415
- const __filename = (0, import_node_url.fileURLToPath)(import_meta.url);
416
- startDir = import_node_path3.default.dirname(__filename);
417
- } catch {
418
- startDir = typeof __dirname !== "undefined" ? __dirname : process.cwd();
419
- }
420
- return findPackageJson(startDir);
421
- }
422
- function findPackageJson(startDir) {
423
- let current = startDir;
424
- const maxDepth = 6;
425
- for (let i = 0; i < maxDepth; i++) {
426
- const candidate = import_node_path3.default.resolve(current, "package.json");
427
- if ((0, import_node_fs.existsSync)(candidate)) {
428
- return candidate;
429
- }
430
- const parent = import_node_path3.default.dirname(current);
431
- if (parent === current) break;
432
- current = parent;
433
- }
434
- return import_node_path3.default.resolve(process.cwd(), "package.json");
435
- }
436
- async function getToolVersion() {
437
- try {
438
- const pkgPath = getPkgJsonPath();
439
- const raw = await (0, import_promises2.readFile)(pkgPath, "utf8");
440
- const pkg = JSON.parse(raw);
441
- return pkg.version || "0.0.0";
442
- } catch {
443
- return "0.0.0";
444
- }
445
- }
446
- var ASCII_BANNER = String.raw`
447
- ________ __
448
- / _____/ ____ _____/ |_ ____ ____
449
- / \ ___ / _ \ / _ \ __\/ __ \ / \
450
- \ \_\ ( <_> | <_> ) | \ ___/| | \
451
- \______ /\____/ \____/|__| \___ >___| /
452
- \/ \/ \/
453
- GEX
454
- `;
455
-
456
- // src/runtimes/node/report.ts
457
- var import_promises4 = require("fs/promises");
458
- var import_node_path5 = __toESM(require("path"), 1);
459
-
460
- // src/shared/transform.ts
461
- var import_node_path4 = __toESM(require("path"), 1);
462
- var import_promises3 = require("fs/promises");
463
- function toPkgArray(obj) {
464
- if (!obj) return [];
465
- return Object.keys(obj).map((name) => ({ name, node: obj[name] })).filter((p) => p && p.node);
466
- }
467
- async function buildReportFromNpmTree(tree, opts) {
468
- const timestamp = (/* @__PURE__ */ new Date()).toISOString();
469
- const report = {
470
- report_version: "1.0",
471
- timestamp,
472
- tool_version: opts.toolVersion,
473
- global_packages: [],
474
- local_dependencies: [],
475
- local_dev_dependencies: []
476
- };
477
- if (opts.context === "local") {
478
- let pkgMeta = null;
479
- try {
480
- const pkgJsonPath = import_node_path4.default.join(opts.cwd || process.cwd(), "package.json");
481
- const raw = await (0, import_promises3.readFile)(pkgJsonPath, "utf8");
482
- pkgMeta = JSON.parse(raw);
483
- } catch {
484
- }
485
- if (pkgMeta?.name) report.project_name = pkgMeta.name;
486
- if (pkgMeta?.version) report.project_version = pkgMeta.version;
487
- const depsObj = tree?.dependencies;
488
- const devDepsObj = tree?.devDependencies;
489
- const prodItems = toPkgArray(depsObj);
490
- const treeDevItems = toPkgArray(devDepsObj);
491
- if (treeDevItems.length > 0) {
492
- for (const { name, node } of treeDevItems) {
493
- const version = node && node.version || "";
494
- const resolvedPath = node && node.path || import_node_path4.default.join(opts.cwd || process.cwd(), "node_modules", name);
495
- report.local_dev_dependencies.push({ name, version, resolved_path: resolvedPath });
39
+ async function promptRuntimeSelection(io = {}) {
40
+ const input = io.input ?? process.stdin;
41
+ const output = io.output ?? process.stdout;
42
+ return new Promise((resolve) => {
43
+ const rl = import_node_readline.default.createInterface({ input, output });
44
+ output.write("\nSelect a runtime to use:\n");
45
+ output.write(" 1) gex-bun (Bun package manager)\n");
46
+ output.write(" 2) gex-npm (npm / Node.js package manager)\n\n");
47
+ rl.question("Enter your choice (1-2): ", (answer) => {
48
+ rl.close();
49
+ const choice = answer.trim().toLowerCase();
50
+ if (choice === "1" || choice === "gex-bun" || choice === "bun") {
51
+ resolve("bun");
52
+ return;
496
53
  }
497
- }
498
- const devKeys = treeDevItems.length > 0 ? new Set(treeDevItems.map((entry) => entry.name)) : new Set(Object.keys(pkgMeta?.devDependencies || {}));
499
- for (const { name, node } of prodItems) {
500
- const version = node && node.version || "";
501
- const resolvedPath = node && node.path || import_node_path4.default.join(opts.cwd || process.cwd(), "node_modules", name);
502
- const pkg = { name, version, resolved_path: resolvedPath };
503
- if (!treeDevItems.length && devKeys.has(name)) {
504
- report.local_dev_dependencies.push(pkg);
505
- } else {
506
- report.local_dependencies.push(pkg);
54
+ if (choice === "2" || choice === "gex-npm" || choice === "gex-node" || choice === "npm" || choice === "node") {
55
+ resolve("npm");
56
+ return;
507
57
  }
508
- }
509
- report.local_dependencies.sort((a, b) => a.name.localeCompare(b.name));
510
- report.local_dev_dependencies.sort((a, b) => a.name.localeCompare(b.name));
511
- } else if (opts.context === "global") {
512
- const depsObj = tree?.dependencies;
513
- const items = toPkgArray(depsObj);
514
- for (const { name, node } of items) {
515
- const version = node && node.version || "";
516
- const resolvedPath = node && node.path || import_node_path4.default.join(opts.globalRoot || "", name);
517
- const pkg = { name, version, resolved_path: resolvedPath };
518
- report.global_packages.push(pkg);
519
- }
520
- report.global_packages.sort((a, b) => a.name.localeCompare(b.name));
521
- }
522
- if (opts.includeTree) {
523
- report.tree = tree;
524
- }
525
- return report;
526
- }
527
-
528
- // src/runtimes/node/package-manager.ts
529
- async function getExecFileAsync3() {
530
- const { execFile } = await import("child_process");
531
- const { promisify: promisify2 } = await import("util");
532
- return promisify2(execFile);
533
- }
534
- async function npmLs(options = {}) {
535
- const args = ["ls", "--json"];
536
- if (options.global) args.push("--global");
537
- if (options.omitDev) args.push("--omit=dev");
538
- if (options.depth0) args.push("--depth=0");
539
- try {
540
- const execFileAsync = await getExecFileAsync3();
541
- const { stdout } = await execFileAsync("npm", args, {
542
- cwd: options.cwd,
543
- maxBuffer: 10 * 1024 * 1024
58
+ resolve(null);
544
59
  });
545
- if (stdout && stdout.trim()) return JSON.parse(stdout);
546
- return {};
547
- } catch (err) {
548
- const stdout = err?.stdout;
549
- if (typeof stdout === "string" && stdout.trim()) {
550
- try {
551
- return JSON.parse(stdout);
552
- } catch (parseErr) {
553
- if (process.env.DEBUG?.includes("gex")) {
554
- console.warn("npm ls stdout parse failed:", parseErr);
555
- }
556
- }
557
- }
558
- const stderr = err?.stderr;
559
- const msg = typeof stderr === "string" && stderr.trim() || err?.message || "npm ls failed";
560
- throw new Error(`npm ls failed: ${msg}`);
561
- }
562
- }
563
- async function npmRootGlobal() {
564
- try {
565
- const execFileAsync = await getExecFileAsync3();
566
- const { stdout } = await execFileAsync("npm", ["root", "-g"]);
567
- return stdout.trim();
568
- } catch (err) {
569
- const stderr = err?.stderr;
570
- const msg = typeof stderr === "string" && stderr.trim() || err?.message || "npm root -g failed";
571
- throw new Error(`npm root -g failed: ${msg}`);
572
- }
573
- }
574
-
575
- // src/runtimes/node/report.ts
576
- async function produceReport(ctx, options) {
577
- const toolVersion = await getToolVersion();
578
- const depth0 = !options.fullTree;
579
- const cwd = options.cwd || process.cwd();
580
- const tree = await npmLs({
581
- global: ctx === "global",
582
- omitDev: ctx === "local" ? Boolean(options.omitDev) : false,
583
- depth0,
584
- cwd
585
60
  });
586
- let project_description;
587
- let project_homepage;
588
- let project_bugs;
589
- if (ctx === "local") {
590
- try {
591
- const pkgRaw = await (0, import_promises4.readFile)(import_node_path5.default.join(cwd, "package.json"), "utf8");
592
- const pkg = JSON.parse(pkgRaw);
593
- project_description = pkg.description;
594
- project_homepage = pkg.homepage;
595
- if (typeof pkg.bugs === "string") project_bugs = pkg.bugs;
596
- else if (pkg.bugs && typeof pkg.bugs.url === "string") project_bugs = pkg.bugs.url;
597
- } catch {
598
- }
599
- }
600
- const globalRoot = ctx === "global" ? await npmRootGlobal().catch(() => void 0) : void 0;
601
- const report = await buildReportFromNpmTree(tree, {
602
- context: ctx,
603
- includeTree: Boolean(options.fullTree),
604
- omitDev: Boolean(options.omitDev),
605
- cwd,
606
- toolVersion,
607
- globalRoot
608
- });
609
- const markdownExtras = { project_description, project_homepage, project_bugs };
610
- return { report, markdownExtras };
611
61
  }
612
-
613
- // src/runtimes/node/commands.ts
614
- function addCommonOptions(cmd, { allowOmitDev }) {
615
- cmd.option(
616
- "-f, --output-format <format>",
617
- "Output format: md or json",
618
- (val) => val === "md" ? "md" : "json",
619
- "json"
620
- ).option("-o, --out-file <path>", "Write report to file").option("--full-tree", "Include full npm ls tree (omit depth=0 default)", false).option("-c, --check-outdated", "List outdated packages instead of printing the report", false).option(
621
- "-u, --update-outdated [packages...]",
622
- "Update outdated packages (omit package names to update every package)"
623
- );
624
- if (allowOmitDev) {
625
- cmd.option("--omit-dev", "Exclude devDependencies (local only)", false);
62
+ async function run(argv = process.argv, io = {}) {
63
+ void argv;
64
+ const choice = await promptRuntimeSelection(io);
65
+ const output = io.output ?? process.stdout;
66
+ if (choice === "bun") {
67
+ output.write(
68
+ "\nYou selected the Bun runtime.\nRun `gex-bun [command] [options]` to use the Bun CLI directly.\n"
69
+ );
70
+ return;
626
71
  }
627
- return cmd;
628
- }
629
- function createLocalCommand(program) {
630
- const localCmd = program.command("local", { isDefault: true }).description("Generate a report for the current project's dependencies");
631
- addCommonOptions(localCmd, { allowOmitDev: true });
632
- localCmd.action(async (opts) => {
633
- const outputFormat = opts.outputFormat ?? "json";
634
- const outFile = opts.outFile;
635
- const fullTree = Boolean(opts.fullTree);
636
- const omitDev = Boolean(opts.omitDev);
637
- const cwd = process.cwd();
638
- const selection = normalizeUpdateSelection(opts.updateOutdated);
639
- const result = await handleOutdatedWorkflow({
640
- checkOutdated: Boolean(opts.checkOutdated),
641
- selection,
642
- contextLabel: "local",
643
- outFile,
644
- fetchOutdated: () => npmOutdated({ cwd }),
645
- updateRunner: selection.shouldUpdate ? async (packages) => {
646
- await npmUpdate({ cwd, packages });
647
- } : void 0
648
- });
649
- if (opts.checkOutdated) {
650
- if (result.outdated.length === 0) console.log("All local packages are up to date.");
651
- else console.log(formatOutdatedTable(result.outdated));
652
- }
653
- if (!result.proceed) return;
654
- const finalOutFile = outFile;
655
- const { report, markdownExtras } = await produceReport("local", {
656
- outputFormat,
657
- outFile: finalOutFile,
658
- fullTree,
659
- omitDev
660
- });
661
- await outputReport(report, outputFormat, finalOutFile, markdownExtras);
662
- });
663
- return localCmd;
664
- }
665
- function createGlobalCommand(program) {
666
- const globalCmd = program.command("global").description("Generate a report of globally installed packages");
667
- addCommonOptions(globalCmd, { allowOmitDev: false });
668
- globalCmd.action(async (opts) => {
669
- const outputFormat = opts.outputFormat ?? "json";
670
- const outFile = opts.outFile;
671
- const fullTree = Boolean(opts.fullTree);
672
- const cwd = process.cwd();
673
- const selection = normalizeUpdateSelection(opts.updateOutdated);
674
- const result = await handleOutdatedWorkflow({
675
- checkOutdated: Boolean(opts.checkOutdated),
676
- selection,
677
- contextLabel: "global",
678
- outFile,
679
- fetchOutdated: () => npmOutdated({ cwd, global: true }),
680
- updateRunner: selection.shouldUpdate ? async (packages) => {
681
- await npmUpdate({ cwd, global: true, packages });
682
- } : void 0
683
- });
684
- if (opts.checkOutdated) {
685
- if (result.outdated.length === 0) console.log("All global packages are up to date.");
686
- else console.log(formatOutdatedTable(result.outdated));
687
- }
688
- if (!result.proceed) return;
689
- const finalOutFile = outFile;
690
- const { report, markdownExtras } = await produceReport("global", {
691
- outputFormat,
692
- outFile: finalOutFile,
693
- fullTree
694
- });
695
- await outputReport(report, outputFormat, finalOutFile, markdownExtras);
696
- });
697
- return globalCmd;
698
- }
699
- function createReadCommand(program) {
700
- const readCmd = program.command("read").description(
701
- "Read a previously generated report (JSON or Markdown) and either print package names or install them"
702
- ).argument("[report]", "Path to report file (JSON or Markdown)", "gex-report.json").option("-r, --report <path>", "Path to report file (JSON or Markdown)").option("-p, --print", "Print package names/versions from the report (default)", false).option("-i, --install", "Install packages from the report", false);
703
- readCmd.action(async (reportArg, opts) => {
704
- const chosen = opts.report || reportArg || "gex-report.json";
705
- const reportPath = import_node_path6.default.resolve(process.cwd(), chosen);
706
- try {
707
- const parsed = await loadReportFromFile(reportPath);
708
- const doInstall = Boolean(opts.install);
709
- const doPrint = Boolean(opts.print) || !doInstall;
710
- if (doPrint) {
711
- printFromReport(parsed);
712
- }
713
- if (doInstall) {
714
- await installFromReport(parsed, { cwd: process.cwd(), packageManager: "npm" });
715
- }
716
- } catch (err) {
717
- const isMd = isMarkdownReportFile(reportPath);
718
- const hint = isMd ? "Try generating a JSON report with: gex global -f json -o global.json, then: gex read global.json" : "Specify a report path with: gex read <path-to-report.json>";
719
- console.error(`Failed to read report at ${reportPath}: ${err?.message || err}`);
720
- console.error(hint);
721
- process.exitCode = 1;
722
- }
723
- });
724
- return readCmd;
725
- }
726
- async function createProgram() {
727
- const program = new import_commander.Command().name("gex").description("GEX: Dependency auditing and documentation for Node.js (local and global).").version(await getToolVersion());
728
- program.addHelpText("beforeAll", `
729
- ${ASCII_BANNER}`);
730
- createLocalCommand(program);
731
- createGlobalCommand(program);
732
- createReadCommand(program);
733
- return program;
734
- }
735
-
736
- // src/runtimes/node/cli.ts
737
- var import_meta2 = {};
738
- async function run(argv = process.argv) {
739
- const program = await createProgram();
740
- await program.parseAsync(argv);
72
+ if (choice === "npm") {
73
+ output.write(
74
+ "\nYou selected the npm/Node.js runtime.\nRun `gex-npm [command] [options]` to use the Node CLI directly.\n"
75
+ );
76
+ return;
77
+ }
78
+ output.write("Invalid selection. Please run `gex` again and choose 1 or 2.\n");
79
+ process.exitCode = 1;
741
80
  }
742
81
  var isMainModule = (() => {
743
82
  try {
744
83
  if (typeof require !== "undefined" && typeof module !== "undefined") {
745
84
  return require.main === module;
746
85
  }
747
- if (typeof import_meta2 !== "undefined") {
748
- return import_meta2.url === `file://${process.argv[1]}`;
86
+ if (typeof import_meta !== "undefined") {
87
+ return import_meta.url === `file://${process.argv[1]}`;
749
88
  }
750
89
  return false;
751
90
  } catch {
@@ -758,31 +97,6 @@ if (isMainModule) {
758
97
  process.exitCode = 1;
759
98
  });
760
99
  }
761
-
762
- // src/cli.ts
763
- var import_meta3 = {};
764
- async function run2(argv = process.argv) {
765
- return run(argv);
766
- }
767
- var isMainModule2 = (() => {
768
- try {
769
- if (typeof require !== "undefined" && typeof module !== "undefined") {
770
- return require.main === module;
771
- }
772
- if (typeof import_meta3 !== "undefined") {
773
- return import_meta3.url === `file://${process.argv[1]}`;
774
- }
775
- return false;
776
- } catch {
777
- return false;
778
- }
779
- })();
780
- if (isMainModule2) {
781
- run2().catch((error) => {
782
- console.error("CLI error:", error);
783
- process.exitCode = 1;
784
- });
785
- }
786
100
  // Annotate the CommonJS export names for ESM import in node:
787
101
  0 && (module.exports = {
788
102
  run