@yabasha/gex 1.3.5 → 1.3.7

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.mjs CHANGED
@@ -745,25 +745,6 @@ async function run(argv = process.argv) {
745
745
  const program = await createProgram();
746
746
  await program.parseAsync(argv);
747
747
  }
748
- var isMainModule = (() => {
749
- try {
750
- if (typeof __require !== "undefined" && typeof module !== "undefined") {
751
- return __require.main === module;
752
- }
753
- if (typeof import.meta !== "undefined") {
754
- return import.meta.url === `file://${process.argv[1]}`;
755
- }
756
- return false;
757
- } catch {
758
- return false;
759
- }
760
- })();
761
- if (isMainModule) {
762
- run().catch((error) => {
763
- console.error("CLI error:", error);
764
- process.exitCode = 1;
765
- });
766
- }
767
748
 
768
749
  // src/runtimes/bun/commands.ts
769
750
  import path9 from "path";
@@ -1183,66 +1164,166 @@ async function run2(argv = process.argv) {
1183
1164
  const program = await createProgram2();
1184
1165
  await program.parseAsync(argv);
1185
1166
  }
1186
- var isMainModule2 = (() => {
1187
- try {
1188
- if (typeof __require !== "undefined" && typeof module !== "undefined") {
1189
- return __require.main === module;
1190
- }
1191
- if (typeof import.meta !== "undefined") {
1192
- return import.meta.url === `file://${process.argv[1]}`;
1193
- }
1194
- return false;
1195
- } catch {
1196
- return false;
1197
- }
1198
- })();
1199
- if (isMainModule2) {
1200
- run2().catch((error) => {
1201
- console.error("Bun CLI error:", error);
1202
- process.exitCode = 1;
1203
- });
1204
- }
1205
1167
 
1206
1168
  // src/cli.ts
1207
- async function promptRuntimeSelection(io = {}) {
1208
- const input = io.input ?? process.stdin;
1209
- const output = io.output ?? process.stdout;
1169
+ var MENU_ITEMS = [
1170
+ {
1171
+ id: "1",
1172
+ runtime: "node",
1173
+ command: "local",
1174
+ label: "gex-node local \u2013 Node (npm) local project report"
1175
+ },
1176
+ {
1177
+ id: "2",
1178
+ runtime: "node",
1179
+ command: "global",
1180
+ label: "gex-node global \u2013 Node (npm) global packages report"
1181
+ },
1182
+ {
1183
+ id: "3",
1184
+ runtime: "node",
1185
+ command: "read",
1186
+ label: "gex-node read \u2013 Node (npm) read existing report"
1187
+ },
1188
+ {
1189
+ id: "4",
1190
+ runtime: "bun",
1191
+ command: "local",
1192
+ label: "gex-bun local \u2013 Bun local project report"
1193
+ },
1194
+ {
1195
+ id: "5",
1196
+ runtime: "bun",
1197
+ command: "global",
1198
+ label: "gex-bun global \u2013 Bun global packages report"
1199
+ },
1200
+ {
1201
+ id: "6",
1202
+ runtime: "bun",
1203
+ command: "read",
1204
+ label: "gex-bun read \u2013 Bun read existing report"
1205
+ }
1206
+ ];
1207
+ function getIO(io) {
1208
+ return {
1209
+ input: io.input ?? process.stdin,
1210
+ output: io.output ?? process.stdout
1211
+ };
1212
+ }
1213
+ async function askQuestion(prompt, io = {}) {
1214
+ const { input, output } = getIO(io);
1210
1215
  return new Promise((resolve) => {
1211
1216
  const rl = readline.createInterface({ input, output });
1212
- output.write("\nSelect a runtime to use:\n");
1213
- output.write(" 1) gex-bun (Bun package manager)\n");
1214
- output.write(" 2) gex-npm (npm / Node.js package manager)\n\n");
1215
- rl.question("Enter your choice (1-2): ", (answer) => {
1217
+ rl.question(prompt, (answer) => {
1216
1218
  rl.close();
1217
- const choice = answer.trim().toLowerCase();
1218
- if (choice === "1" || choice === "gex-bun" || choice === "bun") {
1219
- resolve("bun");
1220
- return;
1221
- }
1222
- if (choice === "2" || choice === "gex-npm" || choice === "gex-node" || choice === "npm" || choice === "node") {
1223
- resolve("npm");
1224
- return;
1225
- }
1226
- resolve(null);
1219
+ resolve(answer);
1227
1220
  });
1228
1221
  });
1229
1222
  }
1230
- async function run3(argv = process.argv, io = {}) {
1231
- const effectiveArgv = argv ?? process.argv;
1232
- const choice = await promptRuntimeSelection(io);
1233
- if (choice === "bun") {
1234
- await run2(effectiveArgv);
1235
- return;
1223
+ function parseArgLine(line) {
1224
+ const result = [];
1225
+ let current = "";
1226
+ let inSingleQuote = false;
1227
+ let inDoubleQuote = false;
1228
+ for (let i = 0; i < line.length; i += 1) {
1229
+ const ch = line[i];
1230
+ if (inSingleQuote) {
1231
+ if (ch === "'") {
1232
+ inSingleQuote = false;
1233
+ } else {
1234
+ current += ch;
1235
+ }
1236
+ continue;
1237
+ }
1238
+ if (inDoubleQuote) {
1239
+ if (ch === '"') {
1240
+ inDoubleQuote = false;
1241
+ } else {
1242
+ current += ch;
1243
+ }
1244
+ continue;
1245
+ }
1246
+ if (ch === "'") {
1247
+ inSingleQuote = true;
1248
+ continue;
1249
+ }
1250
+ if (ch === '"') {
1251
+ inDoubleQuote = true;
1252
+ continue;
1253
+ }
1254
+ if (ch === " " || ch === " ") {
1255
+ if (current) {
1256
+ result.push(current);
1257
+ current = "";
1258
+ }
1259
+ continue;
1260
+ }
1261
+ current += ch;
1262
+ }
1263
+ if (current) {
1264
+ result.push(current);
1265
+ }
1266
+ return result;
1267
+ }
1268
+ async function promptMenuSelection(io = {}) {
1269
+ const { output } = getIO(io);
1270
+ output.write("\nGEX interactive launcher\n");
1271
+ output.write("Choose a runtime and command to run:\n\n");
1272
+ for (const item of MENU_ITEMS) {
1273
+ output.write(` ${item.id}) ${item.label}
1274
+ `);
1275
+ }
1276
+ output.write(" q) Quit without running anything\n\n");
1277
+ const answer = (await askQuestion("Enter your choice (1-6 or q): ", io)).trim().toLowerCase();
1278
+ if (answer === "q" || answer === "quit" || answer === "exit") {
1279
+ output.write("\nExiting without running a command.\n");
1280
+ return null;
1281
+ }
1282
+ const selected = MENU_ITEMS.find((item) => item.id === answer);
1283
+ if (!selected) {
1284
+ output.write("Invalid selection. Please run `gex` again and choose a valid option.\n");
1285
+ process.exitCode = 1;
1286
+ return null;
1236
1287
  }
1237
- if (choice === "npm") {
1238
- await run(effectiveArgv);
1288
+ return selected;
1289
+ }
1290
+ async function runInteractive(io = {}) {
1291
+ const selection = await promptMenuSelection(io);
1292
+ if (!selection) return;
1293
+ const { output } = getIO(io);
1294
+ const binaryName = selection.runtime === "node" ? "gex-node" : "gex-bun";
1295
+ output.write(`
1296
+ Selected: ${binaryName} ${selection.command}
1297
+ `);
1298
+ const extraLine = await askQuestion(
1299
+ `Enter extra flags/arguments for "${binaryName} ${selection.command}" (or press Enter for none): `,
1300
+ io
1301
+ );
1302
+ const extraArgs = parseArgLine(extraLine.trim());
1303
+ const argv = [binaryName, selection.command, ...extraArgs];
1304
+ const renderedArgs = extraArgs.join(" ");
1305
+ const finalCommand = renderedArgs.length > 0 ? `${binaryName} ${selection.command} ${renderedArgs}` : `${binaryName} ${selection.command}`;
1306
+ output.write(`
1307
+ Running:
1308
+
1309
+ ${finalCommand}
1310
+
1311
+ `);
1312
+ if (selection.runtime === "node") {
1313
+ await run(argv);
1314
+ } else {
1315
+ await run2(argv);
1316
+ }
1317
+ }
1318
+ async function run3(argv = process.argv, io = {}) {
1319
+ const [, , ...rest] = argv;
1320
+ if (rest.length > 0) {
1321
+ await run(argv);
1239
1322
  return;
1240
1323
  }
1241
- const output = io.output ?? process.stdout;
1242
- output.write("Invalid selection. Please run `gex` again and choose 1 or 2.\n");
1243
- process.exitCode = 1;
1324
+ await runInteractive(io);
1244
1325
  }
1245
- var isMainModule3 = (() => {
1326
+ var isMainModule = (() => {
1246
1327
  try {
1247
1328
  if (typeof __require !== "undefined" && typeof module !== "undefined") {
1248
1329
  return __require.main === module;
@@ -1255,7 +1336,7 @@ var isMainModule3 = (() => {
1255
1336
  return false;
1256
1337
  }
1257
1338
  })();
1258
- if (isMainModule3) {
1339
+ if (isMainModule) {
1259
1340
  run3().catch((error) => {
1260
1341
  console.error("CLI error:", error);
1261
1342
  process.exitCode = 1;