@react-grab/cli 0.1.1 → 0.1.3

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 (3) hide show
  1. package/dist/cli.cjs +149 -69
  2. package/dist/cli.js +148 -68
  3. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  var commander = require('commander');
5
5
  var pc = require('picocolors');
6
- var prompts3 = require('prompts');
6
+ var basePrompts = require('prompts');
7
7
  var child_process = require('child_process');
8
8
  var fs = require('fs');
9
9
  var path = require('path');
@@ -13,9 +13,52 @@ var ora = require('ora');
13
13
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
14
 
15
15
  var pc__default = /*#__PURE__*/_interopDefault(pc);
16
- var prompts3__default = /*#__PURE__*/_interopDefault(prompts3);
16
+ var basePrompts__default = /*#__PURE__*/_interopDefault(basePrompts);
17
17
  var ora__default = /*#__PURE__*/_interopDefault(ora);
18
18
 
19
+ var highlighter = {
20
+ error: pc__default.default.red,
21
+ warn: pc__default.default.yellow,
22
+ info: pc__default.default.cyan,
23
+ success: pc__default.default.green,
24
+ dim: pc__default.default.dim
25
+ };
26
+
27
+ // src/utils/logger.ts
28
+ var logger = {
29
+ error(...args) {
30
+ console.log(highlighter.error(args.join(" ")));
31
+ },
32
+ warn(...args) {
33
+ console.log(highlighter.warn(args.join(" ")));
34
+ },
35
+ info(...args) {
36
+ console.log(highlighter.info(args.join(" ")));
37
+ },
38
+ success(...args) {
39
+ console.log(highlighter.success(args.join(" ")));
40
+ },
41
+ dim(...args) {
42
+ console.log(highlighter.dim(args.join(" ")));
43
+ },
44
+ log(...args) {
45
+ console.log(args.join(" "));
46
+ },
47
+ break() {
48
+ console.log("");
49
+ }
50
+ };
51
+
52
+ // src/utils/prompts.ts
53
+ var onCancel = () => {
54
+ logger.break();
55
+ logger.log("Cancelled.");
56
+ logger.break();
57
+ process.exit(0);
58
+ };
59
+ var prompts = (questions) => {
60
+ return basePrompts__default.default(questions, { onCancel });
61
+ };
19
62
  var detectPackageManager = async (projectRoot) => {
20
63
  const detected = await ni.detect({ cwd: projectRoot });
21
64
  if (detected && ["npm", "yarn", "pnpm", "bun"].includes(detected)) {
@@ -421,38 +464,6 @@ ${BOLD}File: ${filePath}${RESET}`);
421
464
  console.log(formatDiff(diff));
422
465
  console.log("\u2500".repeat(60));
423
466
  };
424
- var highlighter = {
425
- error: pc__default.default.red,
426
- warn: pc__default.default.yellow,
427
- info: pc__default.default.cyan,
428
- success: pc__default.default.green,
429
- dim: pc__default.default.dim
430
- };
431
-
432
- // src/utils/logger.ts
433
- var logger = {
434
- error(...args) {
435
- console.log(highlighter.error(args.join(" ")));
436
- },
437
- warn(...args) {
438
- console.log(highlighter.warn(args.join(" ")));
439
- },
440
- info(...args) {
441
- console.log(highlighter.info(args.join(" ")));
442
- },
443
- success(...args) {
444
- console.log(highlighter.success(args.join(" ")));
445
- },
446
- dim(...args) {
447
- console.log(highlighter.dim(args.join(" ")));
448
- },
449
- log(...args) {
450
- console.log(args.join(" "));
451
- },
452
- break() {
453
- console.log("");
454
- }
455
- };
456
467
 
457
468
  // src/utils/handle-error.ts
458
469
  var handleError = (error) => {
@@ -1455,7 +1466,7 @@ var findReactGrabFile = (projectRoot, framework, nextRouterType) => {
1455
1466
  };
1456
1467
  var addOptionsToNextScript = (originalContent, options, filePath) => {
1457
1468
  const reactGrabScriptMatch = originalContent.match(
1458
- /(<Script[^>]*react-grab[^>]*)(\/?>)/is
1469
+ /(<Script[\s\S]*?react-grab[\s\S]*?)\s*(\/?>)/i
1459
1470
  );
1460
1471
  if (!reactGrabScriptMatch) {
1461
1472
  return {
@@ -1822,7 +1833,7 @@ var previewPackageJsonAgentRemoval = (projectRoot, agent) => {
1822
1833
  };
1823
1834
 
1824
1835
  // src/commands/add.ts
1825
- var VERSION = "0.1.0";
1836
+ var VERSION = "0.1.2";
1826
1837
  var formatInstalledAgentNames = (agents) => agents.map((agent) => AGENT_NAMES[agent] || agent).join(", ");
1827
1838
  var add = new commander.Command().name("add").alias("install").description("add an agent integration").argument("[agent]", `agent to add (${AGENTS.join(", ")})`).option("-y, --yes", "skip confirmation prompts", false).option(
1828
1839
  "-c, --cwd <cwd>",
@@ -1881,7 +1892,7 @@ var add = new commander.Command().name("add").alias("install").description("add
1881
1892
  );
1882
1893
  logger.break();
1883
1894
  logger.warn(`${installedNames} is already installed.`);
1884
- const { action } = await prompts3__default.default({
1895
+ const { action } = await prompts({
1885
1896
  type: "select",
1886
1897
  name: "action",
1887
1898
  message: "How would you like to proceed?",
@@ -1915,7 +1926,7 @@ var add = new commander.Command().name("add").alias("install").description("add
1915
1926
  logger.warn(`Currently installed: ${installedNames}`);
1916
1927
  logger.break();
1917
1928
  }
1918
- const { agent } = await prompts3__default.default({
1929
+ const { agent } = await prompts({
1919
1930
  type: "select",
1920
1931
  name: "agent",
1921
1932
  message: `Which ${highlighter.info("agent integration")} would you like to add?`,
@@ -1933,7 +1944,7 @@ var add = new commander.Command().name("add").alias("install").description("add
1933
1944
  const installedNames = formatInstalledAgentNames(
1934
1945
  projectInfo.installedAgents
1935
1946
  );
1936
- const { action } = await prompts3__default.default({
1947
+ const { action } = await prompts({
1937
1948
  type: "select",
1938
1949
  name: "action",
1939
1950
  message: "How would you like to proceed?",
@@ -2078,7 +2089,7 @@ var add = new commander.Command().name("add").alias("install").description("add
2078
2089
  }
2079
2090
  if (!isNonInteractive && agentsToRemove.length === 0) {
2080
2091
  logger.break();
2081
- const { proceed } = await prompts3__default.default({
2092
+ const { proceed } = await prompts({
2082
2093
  type: "confirm",
2083
2094
  name: "proceed",
2084
2095
  message: "Apply these changes?",
@@ -2158,7 +2169,7 @@ var MAX_KEY_HOLD_DURATION_MS = 2e3;
2158
2169
  var MAX_CONTEXT_LINES = 50;
2159
2170
 
2160
2171
  // src/commands/configure.ts
2161
- var VERSION2 = "0.1.0";
2172
+ var VERSION2 = "0.1.2";
2162
2173
  var isMac = process.platform === "darwin";
2163
2174
  var META_LABEL = isMac ? "Cmd" : "Win";
2164
2175
  var ALT_LABEL = isMac ? "Option" : "Alt";
@@ -2440,7 +2451,7 @@ var configure = new commander.Command().name("configure").alias("config").descri
2440
2451
  logger.log(` Max context lines: ${highlighter.info(String(lines))}`);
2441
2452
  }
2442
2453
  } else {
2443
- const { selectedOption } = await prompts3__default.default({
2454
+ const { selectedOption } = await prompts({
2444
2455
  type: "autocomplete",
2445
2456
  name: "selectedOption",
2446
2457
  message: "Search for an option to configure:",
@@ -2460,7 +2471,7 @@ var configure = new commander.Command().name("configure").alias("config").descri
2460
2471
  process.exit(1);
2461
2472
  }
2462
2473
  if (selectedOption === "activationKey") {
2463
- const { selectedCombo } = await prompts3__default.default({
2474
+ const { selectedCombo } = await prompts({
2464
2475
  type: "autocomplete",
2465
2476
  name: "selectedCombo",
2466
2477
  message: "Type key combination (e.g. ctrl+shift+g):",
@@ -2477,7 +2488,7 @@ var configure = new commander.Command().name("configure").alias("config").descri
2477
2488
  );
2478
2489
  }
2479
2490
  if (selectedOption === "activationMode") {
2480
- const { activationMode } = await prompts3__default.default({
2491
+ const { activationMode } = await prompts({
2481
2492
  type: "select",
2482
2493
  name: "activationMode",
2483
2494
  message: `Select ${highlighter.info("activation mode")}:`,
@@ -2497,7 +2508,7 @@ var configure = new commander.Command().name("configure").alias("config").descri
2497
2508
  collectedOptions.activationMode = activationMode;
2498
2509
  }
2499
2510
  if (selectedOption === "keyHoldDuration") {
2500
- const { keyHoldDuration } = await prompts3__default.default({
2511
+ const { keyHoldDuration } = await prompts({
2501
2512
  type: "number",
2502
2513
  name: "keyHoldDuration",
2503
2514
  message: `Enter ${highlighter.info("key hold duration")} in milliseconds:`,
@@ -2512,7 +2523,7 @@ var configure = new commander.Command().name("configure").alias("config").descri
2512
2523
  collectedOptions.keyHoldDuration = keyHoldDuration;
2513
2524
  }
2514
2525
  if (selectedOption === "allowActivationInsideInput") {
2515
- const { allowActivationInsideInput } = await prompts3__default.default({
2526
+ const { allowActivationInsideInput } = await prompts({
2516
2527
  type: "confirm",
2517
2528
  name: "allowActivationInsideInput",
2518
2529
  message: `Allow activation ${highlighter.info("inside input fields")}?`,
@@ -2525,7 +2536,7 @@ var configure = new commander.Command().name("configure").alias("config").descri
2525
2536
  collectedOptions.allowActivationInsideInput = allowActivationInsideInput;
2526
2537
  }
2527
2538
  if (selectedOption === "maxContextLines") {
2528
- const { maxContextLines } = await prompts3__default.default({
2539
+ const { maxContextLines } = await prompts({
2529
2540
  type: "number",
2530
2541
  name: "maxContextLines",
2531
2542
  message: `Enter ${highlighter.info("max context lines")} to include:`,
@@ -2565,7 +2576,7 @@ var configure = new commander.Command().name("configure").alias("config").descri
2565
2576
  printDiff(result.filePath, result.originalContent, result.newContent);
2566
2577
  if (!opts.yes) {
2567
2578
  logger.break();
2568
- const { proceed } = await prompts3__default.default({
2579
+ const { proceed } = await prompts({
2569
2580
  type: "confirm",
2570
2581
  name: "proceed",
2571
2582
  message: "Apply these changes?",
@@ -2658,7 +2669,7 @@ var uninstallPackagesWithFeedback = (packages, packageManager, projectRoot) => {
2658
2669
  };
2659
2670
 
2660
2671
  // src/commands/init.ts
2661
- var VERSION3 = "0.1.0";
2672
+ var VERSION3 = "0.1.2";
2662
2673
  var REPORT_URL = "https://react-grab.com/api/report-cli";
2663
2674
  var DOCS_URL = "https://github.com/aidenybai/react-grab";
2664
2675
  var reportToCli = (type, config, error) => {
@@ -2785,7 +2796,7 @@ var init = new commander.Command().name("init").description("initialize React Gr
2785
2796
  );
2786
2797
  logger.break();
2787
2798
  }
2788
- const { wantCustomizeOptions } = await prompts3__default.default({
2799
+ const { wantCustomizeOptions } = await prompts({
2789
2800
  type: "confirm",
2790
2801
  name: "wantCustomizeOptions",
2791
2802
  message: `Would you like to customize ${highlighter.info("options")}?`,
@@ -2806,7 +2817,7 @@ var init = new commander.Command().name("init").description("initialize React Gr
2806
2817
  ` Activation key: ${highlighter.info(formatActivationKeyDisplay2(collectedOptions.activationKey))}`
2807
2818
  );
2808
2819
  } else {
2809
- const { wantActivationKey } = await prompts3__default.default({
2820
+ const { wantActivationKey } = await prompts({
2810
2821
  type: "confirm",
2811
2822
  name: "wantActivationKey",
2812
2823
  message: `Configure ${highlighter.info("activation key")}?`,
@@ -2817,7 +2828,7 @@ var init = new commander.Command().name("init").description("initialize React Gr
2817
2828
  process.exit(1);
2818
2829
  }
2819
2830
  if (wantActivationKey) {
2820
- const { key } = await prompts3__default.default({
2831
+ const { key } = await prompts({
2821
2832
  type: "text",
2822
2833
  name: "key",
2823
2834
  message: "Enter the activation key (e.g., g, k, space):",
@@ -2833,7 +2844,7 @@ var init = new commander.Command().name("init").description("initialize React Gr
2833
2844
  );
2834
2845
  }
2835
2846
  }
2836
- const { activationMode } = await prompts3__default.default({
2847
+ const { activationMode } = await prompts({
2837
2848
  type: "select",
2838
2849
  name: "activationMode",
2839
2850
  message: `Select ${highlighter.info("activation mode")}:`,
@@ -2852,7 +2863,7 @@ var init = new commander.Command().name("init").description("initialize React Gr
2852
2863
  }
2853
2864
  collectedOptions.activationMode = activationMode;
2854
2865
  if (activationMode === "hold") {
2855
- const { keyHoldDuration } = await prompts3__default.default({
2866
+ const { keyHoldDuration } = await prompts({
2856
2867
  type: "number",
2857
2868
  name: "keyHoldDuration",
2858
2869
  message: `Enter ${highlighter.info("key hold duration")} in milliseconds:`,
@@ -2866,7 +2877,7 @@ var init = new commander.Command().name("init").description("initialize React Gr
2866
2877
  }
2867
2878
  collectedOptions.keyHoldDuration = keyHoldDuration;
2868
2879
  }
2869
- const { allowActivationInsideInput } = await prompts3__default.default({
2880
+ const { allowActivationInsideInput } = await prompts({
2870
2881
  type: "confirm",
2871
2882
  name: "allowActivationInsideInput",
2872
2883
  message: `Allow activation ${highlighter.info("inside input fields")}?`,
@@ -2877,7 +2888,7 @@ var init = new commander.Command().name("init").description("initialize React Gr
2877
2888
  process.exit(1);
2878
2889
  }
2879
2890
  collectedOptions.allowActivationInsideInput = allowActivationInsideInput;
2880
- const { maxContextLines } = await prompts3__default.default({
2891
+ const { maxContextLines } = await prompts({
2881
2892
  type: "number",
2882
2893
  name: "maxContextLines",
2883
2894
  message: `Enter ${highlighter.info("max context lines")} to include:`,
@@ -2911,7 +2922,7 @@ var init = new commander.Command().name("init").description("initialize React Gr
2911
2922
  optionsResult.newContent
2912
2923
  );
2913
2924
  logger.break();
2914
- const { proceed } = await prompts3__default.default({
2925
+ const { proceed } = await prompts({
2915
2926
  type: "confirm",
2916
2927
  name: "proceed",
2917
2928
  message: "Apply these changes?",
@@ -2935,7 +2946,7 @@ var init = new commander.Command().name("init").description("initialize React Gr
2935
2946
  );
2936
2947
  if (availableAgents.length > 0) {
2937
2948
  logger.break();
2938
- const { wantAddAgent } = await prompts3__default.default({
2949
+ const { wantAddAgent } = await prompts({
2939
2950
  type: "confirm",
2940
2951
  name: "wantAddAgent",
2941
2952
  message: `Would you like to add an ${highlighter.info("agent integration")}?`,
@@ -2946,7 +2957,7 @@ var init = new commander.Command().name("init").description("initialize React Gr
2946
2957
  process.exit(1);
2947
2958
  }
2948
2959
  if (wantAddAgent) {
2949
- const { agent } = await prompts3__default.default({
2960
+ const { agent } = await prompts({
2950
2961
  type: "select",
2951
2962
  name: "agent",
2952
2963
  message: `Which ${highlighter.info("agent integration")} would you like to add?`,
@@ -2968,7 +2979,7 @@ var init = new commander.Command().name("init").description("initialize React Gr
2968
2979
  const installedNames = formatInstalledAgentNames2(
2969
2980
  projectInfo.installedAgents
2970
2981
  );
2971
- const { action } = await prompts3__default.default({
2982
+ const { action } = await prompts({
2972
2983
  type: "select",
2973
2984
  name: "action",
2974
2985
  message: "How would you like to proceed?",
@@ -3039,7 +3050,7 @@ var init = new commander.Command().name("init").description("initialize React Gr
3039
3050
  }
3040
3051
  if (agentsToRemove2.length === 0) {
3041
3052
  logger.break();
3042
- const { proceed } = await prompts3__default.default({
3053
+ const { proceed } = await prompts({
3043
3054
  type: "confirm",
3044
3055
  name: "proceed",
3045
3056
  message: "Apply these changes?",
@@ -3084,6 +3095,75 @@ var init = new commander.Command().name("init").description("initialize React Gr
3084
3095
  }
3085
3096
  }
3086
3097
  }
3098
+ } else {
3099
+ const result2 = previewTransform(
3100
+ projectInfo.projectRoot,
3101
+ projectInfo.framework,
3102
+ projectInfo.nextRouterType,
3103
+ agentIntegration2,
3104
+ true
3105
+ );
3106
+ const packageJsonResult2 = previewPackageJsonTransform(
3107
+ projectInfo.projectRoot,
3108
+ agentIntegration2,
3109
+ projectInfo.installedAgents,
3110
+ projectInfo.packageManager
3111
+ );
3112
+ if (!result2.success) {
3113
+ logger.break();
3114
+ logger.error(result2.message);
3115
+ logger.break();
3116
+ process.exit(1);
3117
+ }
3118
+ const hasLayoutChanges2 = !result2.noChanges && result2.originalContent && result2.newContent;
3119
+ const hasPackageJsonChanges2 = packageJsonResult2.success && !packageJsonResult2.noChanges && packageJsonResult2.originalContent && packageJsonResult2.newContent;
3120
+ if (hasLayoutChanges2 || hasPackageJsonChanges2) {
3121
+ logger.break();
3122
+ if (hasLayoutChanges2) {
3123
+ printDiff(
3124
+ result2.filePath,
3125
+ result2.originalContent,
3126
+ result2.newContent
3127
+ );
3128
+ }
3129
+ if (hasPackageJsonChanges2) {
3130
+ if (hasLayoutChanges2) {
3131
+ logger.break();
3132
+ }
3133
+ printDiff(
3134
+ packageJsonResult2.filePath,
3135
+ packageJsonResult2.originalContent,
3136
+ packageJsonResult2.newContent
3137
+ );
3138
+ }
3139
+ logger.break();
3140
+ const { proceed } = await prompts({
3141
+ type: "confirm",
3142
+ name: "proceed",
3143
+ message: "Apply these changes?",
3144
+ initial: true
3145
+ });
3146
+ if (!proceed) {
3147
+ logger.break();
3148
+ logger.log("Agent addition cancelled.");
3149
+ } else {
3150
+ installPackagesWithFeedback(
3151
+ getPackagesToInstall(agentIntegration2, false),
3152
+ projectInfo.packageManager,
3153
+ projectInfo.projectRoot
3154
+ );
3155
+ if (hasLayoutChanges2) {
3156
+ applyTransformWithFeedback(result2);
3157
+ }
3158
+ if (hasPackageJsonChanges2) {
3159
+ applyPackageJsonWithFeedback(packageJsonResult2);
3160
+ }
3161
+ logger.break();
3162
+ logger.success(
3163
+ `${getAgentName(agentIntegration2)} has been added.`
3164
+ );
3165
+ }
3166
+ }
3087
3167
  }
3088
3168
  }
3089
3169
  }
@@ -3121,7 +3201,7 @@ var init = new commander.Command().name("init").description("initialize React Gr
3121
3201
  return 0;
3122
3202
  }
3123
3203
  );
3124
- const { selectedProject } = await prompts3__default.default({
3204
+ const { selectedProject } = await prompts({
3125
3205
  type: "select",
3126
3206
  name: "selectedProject",
3127
3207
  message: "Select a project to install React Grab:",
@@ -3188,7 +3268,7 @@ var init = new commander.Command().name("init").description("initialize React Gr
3188
3268
  const agentsToRemove = [];
3189
3269
  if (!isNonInteractive && !opts.agent) {
3190
3270
  logger.break();
3191
- const { wantAddAgent } = await prompts3__default.default({
3271
+ const { wantAddAgent } = await prompts({
3192
3272
  type: "confirm",
3193
3273
  name: "wantAddAgent",
3194
3274
  message: `Would you like to add an ${highlighter.info("agent integration")}?`,
@@ -3199,7 +3279,7 @@ var init = new commander.Command().name("init").description("initialize React Gr
3199
3279
  process.exit(1);
3200
3280
  }
3201
3281
  if (wantAddAgent) {
3202
- const { agent } = await prompts3__default.default({
3282
+ const { agent } = await prompts({
3203
3283
  type: "select",
3204
3284
  name: "agent",
3205
3285
  message: `Which ${highlighter.info("agent integration")} would you like to add?`,
@@ -3266,7 +3346,7 @@ var init = new commander.Command().name("init").description("initialize React Gr
3266
3346
  logger.warn("Please verify the changes before committing.");
3267
3347
  if (!isNonInteractive) {
3268
3348
  logger.break();
3269
- const { proceed } = await prompts3__default.default({
3349
+ const { proceed } = await prompts({
3270
3350
  type: "confirm",
3271
3351
  name: "proceed",
3272
3352
  message: "Apply these changes?",
@@ -3325,7 +3405,7 @@ var init = new commander.Command().name("init").description("initialize React Gr
3325
3405
  reportToCli("error", void 0, error);
3326
3406
  }
3327
3407
  });
3328
- var VERSION4 = "0.1.0";
3408
+ var VERSION4 = "0.1.2";
3329
3409
  var remove = new commander.Command().name("remove").description("remove an agent integration").argument(
3330
3410
  "[agent]",
3331
3411
  "agent to remove (claude-code, cursor, opencode, codex, gemini, amp, ami)"
@@ -3374,7 +3454,7 @@ var remove = new commander.Command().name("remove").description("remove an agent
3374
3454
  agentToRemove = agentArg;
3375
3455
  } else if (!isNonInteractive) {
3376
3456
  logger.break();
3377
- const { agent } = await prompts3__default.default({
3457
+ const { agent } = await prompts({
3378
3458
  type: "select",
3379
3459
  name: "agent",
3380
3460
  message: `Which ${highlighter.info("agent integration")} would you like to remove?`,
@@ -3434,7 +3514,7 @@ var remove = new commander.Command().name("remove").description("remove an agent
3434
3514
  }
3435
3515
  if (!isNonInteractive) {
3436
3516
  logger.break();
3437
- const { proceed } = await prompts3__default.default({
3517
+ const { proceed } = await prompts({
3438
3518
  type: "confirm",
3439
3519
  name: "proceed",
3440
3520
  message: "Apply these changes?",
@@ -3504,7 +3584,7 @@ var remove = new commander.Command().name("remove").description("remove an agent
3504
3584
  });
3505
3585
 
3506
3586
  // src/cli.ts
3507
- var VERSION5 = "0.1.0";
3587
+ var VERSION5 = "0.1.2";
3508
3588
  var VERSION_API_URL = "https://www.react-grab.com/api/version";
3509
3589
  process.on("SIGINT", () => process.exit(0));
3510
3590
  process.on("SIGTERM", () => process.exit(0));
package/dist/cli.js CHANGED
@@ -1,13 +1,56 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command } from 'commander';
3
3
  import pc from 'picocolors';
4
- import prompts3 from 'prompts';
4
+ import basePrompts from 'prompts';
5
5
  import { execSync } from 'child_process';
6
6
  import { readFileSync, existsSync, writeFileSync, accessSync, constants, readdirSync } from 'fs';
7
7
  import { join, basename } from 'path';
8
8
  import { detect } from '@antfu/ni';
9
9
  import ora from 'ora';
10
10
 
11
+ var highlighter = {
12
+ error: pc.red,
13
+ warn: pc.yellow,
14
+ info: pc.cyan,
15
+ success: pc.green,
16
+ dim: pc.dim
17
+ };
18
+
19
+ // src/utils/logger.ts
20
+ var logger = {
21
+ error(...args) {
22
+ console.log(highlighter.error(args.join(" ")));
23
+ },
24
+ warn(...args) {
25
+ console.log(highlighter.warn(args.join(" ")));
26
+ },
27
+ info(...args) {
28
+ console.log(highlighter.info(args.join(" ")));
29
+ },
30
+ success(...args) {
31
+ console.log(highlighter.success(args.join(" ")));
32
+ },
33
+ dim(...args) {
34
+ console.log(highlighter.dim(args.join(" ")));
35
+ },
36
+ log(...args) {
37
+ console.log(args.join(" "));
38
+ },
39
+ break() {
40
+ console.log("");
41
+ }
42
+ };
43
+
44
+ // src/utils/prompts.ts
45
+ var onCancel = () => {
46
+ logger.break();
47
+ logger.log("Cancelled.");
48
+ logger.break();
49
+ process.exit(0);
50
+ };
51
+ var prompts = (questions) => {
52
+ return basePrompts(questions, { onCancel });
53
+ };
11
54
  var detectPackageManager = async (projectRoot) => {
12
55
  const detected = await detect({ cwd: projectRoot });
13
56
  if (detected && ["npm", "yarn", "pnpm", "bun"].includes(detected)) {
@@ -413,38 +456,6 @@ ${BOLD}File: ${filePath}${RESET}`);
413
456
  console.log(formatDiff(diff));
414
457
  console.log("\u2500".repeat(60));
415
458
  };
416
- var highlighter = {
417
- error: pc.red,
418
- warn: pc.yellow,
419
- info: pc.cyan,
420
- success: pc.green,
421
- dim: pc.dim
422
- };
423
-
424
- // src/utils/logger.ts
425
- var logger = {
426
- error(...args) {
427
- console.log(highlighter.error(args.join(" ")));
428
- },
429
- warn(...args) {
430
- console.log(highlighter.warn(args.join(" ")));
431
- },
432
- info(...args) {
433
- console.log(highlighter.info(args.join(" ")));
434
- },
435
- success(...args) {
436
- console.log(highlighter.success(args.join(" ")));
437
- },
438
- dim(...args) {
439
- console.log(highlighter.dim(args.join(" ")));
440
- },
441
- log(...args) {
442
- console.log(args.join(" "));
443
- },
444
- break() {
445
- console.log("");
446
- }
447
- };
448
459
 
449
460
  // src/utils/handle-error.ts
450
461
  var handleError = (error) => {
@@ -1447,7 +1458,7 @@ var findReactGrabFile = (projectRoot, framework, nextRouterType) => {
1447
1458
  };
1448
1459
  var addOptionsToNextScript = (originalContent, options, filePath) => {
1449
1460
  const reactGrabScriptMatch = originalContent.match(
1450
- /(<Script[^>]*react-grab[^>]*)(\/?>)/is
1461
+ /(<Script[\s\S]*?react-grab[\s\S]*?)\s*(\/?>)/i
1451
1462
  );
1452
1463
  if (!reactGrabScriptMatch) {
1453
1464
  return {
@@ -1814,7 +1825,7 @@ var previewPackageJsonAgentRemoval = (projectRoot, agent) => {
1814
1825
  };
1815
1826
 
1816
1827
  // src/commands/add.ts
1817
- var VERSION = "0.1.0";
1828
+ var VERSION = "0.1.2";
1818
1829
  var formatInstalledAgentNames = (agents) => agents.map((agent) => AGENT_NAMES[agent] || agent).join(", ");
1819
1830
  var add = new Command().name("add").alias("install").description("add an agent integration").argument("[agent]", `agent to add (${AGENTS.join(", ")})`).option("-y, --yes", "skip confirmation prompts", false).option(
1820
1831
  "-c, --cwd <cwd>",
@@ -1873,7 +1884,7 @@ var add = new Command().name("add").alias("install").description("add an agent i
1873
1884
  );
1874
1885
  logger.break();
1875
1886
  logger.warn(`${installedNames} is already installed.`);
1876
- const { action } = await prompts3({
1887
+ const { action } = await prompts({
1877
1888
  type: "select",
1878
1889
  name: "action",
1879
1890
  message: "How would you like to proceed?",
@@ -1907,7 +1918,7 @@ var add = new Command().name("add").alias("install").description("add an agent i
1907
1918
  logger.warn(`Currently installed: ${installedNames}`);
1908
1919
  logger.break();
1909
1920
  }
1910
- const { agent } = await prompts3({
1921
+ const { agent } = await prompts({
1911
1922
  type: "select",
1912
1923
  name: "agent",
1913
1924
  message: `Which ${highlighter.info("agent integration")} would you like to add?`,
@@ -1925,7 +1936,7 @@ var add = new Command().name("add").alias("install").description("add an agent i
1925
1936
  const installedNames = formatInstalledAgentNames(
1926
1937
  projectInfo.installedAgents
1927
1938
  );
1928
- const { action } = await prompts3({
1939
+ const { action } = await prompts({
1929
1940
  type: "select",
1930
1941
  name: "action",
1931
1942
  message: "How would you like to proceed?",
@@ -2070,7 +2081,7 @@ var add = new Command().name("add").alias("install").description("add an agent i
2070
2081
  }
2071
2082
  if (!isNonInteractive && agentsToRemove.length === 0) {
2072
2083
  logger.break();
2073
- const { proceed } = await prompts3({
2084
+ const { proceed } = await prompts({
2074
2085
  type: "confirm",
2075
2086
  name: "proceed",
2076
2087
  message: "Apply these changes?",
@@ -2150,7 +2161,7 @@ var MAX_KEY_HOLD_DURATION_MS = 2e3;
2150
2161
  var MAX_CONTEXT_LINES = 50;
2151
2162
 
2152
2163
  // src/commands/configure.ts
2153
- var VERSION2 = "0.1.0";
2164
+ var VERSION2 = "0.1.2";
2154
2165
  var isMac = process.platform === "darwin";
2155
2166
  var META_LABEL = isMac ? "Cmd" : "Win";
2156
2167
  var ALT_LABEL = isMac ? "Option" : "Alt";
@@ -2432,7 +2443,7 @@ var configure = new Command().name("configure").alias("config").description("con
2432
2443
  logger.log(` Max context lines: ${highlighter.info(String(lines))}`);
2433
2444
  }
2434
2445
  } else {
2435
- const { selectedOption } = await prompts3({
2446
+ const { selectedOption } = await prompts({
2436
2447
  type: "autocomplete",
2437
2448
  name: "selectedOption",
2438
2449
  message: "Search for an option to configure:",
@@ -2452,7 +2463,7 @@ var configure = new Command().name("configure").alias("config").description("con
2452
2463
  process.exit(1);
2453
2464
  }
2454
2465
  if (selectedOption === "activationKey") {
2455
- const { selectedCombo } = await prompts3({
2466
+ const { selectedCombo } = await prompts({
2456
2467
  type: "autocomplete",
2457
2468
  name: "selectedCombo",
2458
2469
  message: "Type key combination (e.g. ctrl+shift+g):",
@@ -2469,7 +2480,7 @@ var configure = new Command().name("configure").alias("config").description("con
2469
2480
  );
2470
2481
  }
2471
2482
  if (selectedOption === "activationMode") {
2472
- const { activationMode } = await prompts3({
2483
+ const { activationMode } = await prompts({
2473
2484
  type: "select",
2474
2485
  name: "activationMode",
2475
2486
  message: `Select ${highlighter.info("activation mode")}:`,
@@ -2489,7 +2500,7 @@ var configure = new Command().name("configure").alias("config").description("con
2489
2500
  collectedOptions.activationMode = activationMode;
2490
2501
  }
2491
2502
  if (selectedOption === "keyHoldDuration") {
2492
- const { keyHoldDuration } = await prompts3({
2503
+ const { keyHoldDuration } = await prompts({
2493
2504
  type: "number",
2494
2505
  name: "keyHoldDuration",
2495
2506
  message: `Enter ${highlighter.info("key hold duration")} in milliseconds:`,
@@ -2504,7 +2515,7 @@ var configure = new Command().name("configure").alias("config").description("con
2504
2515
  collectedOptions.keyHoldDuration = keyHoldDuration;
2505
2516
  }
2506
2517
  if (selectedOption === "allowActivationInsideInput") {
2507
- const { allowActivationInsideInput } = await prompts3({
2518
+ const { allowActivationInsideInput } = await prompts({
2508
2519
  type: "confirm",
2509
2520
  name: "allowActivationInsideInput",
2510
2521
  message: `Allow activation ${highlighter.info("inside input fields")}?`,
@@ -2517,7 +2528,7 @@ var configure = new Command().name("configure").alias("config").description("con
2517
2528
  collectedOptions.allowActivationInsideInput = allowActivationInsideInput;
2518
2529
  }
2519
2530
  if (selectedOption === "maxContextLines") {
2520
- const { maxContextLines } = await prompts3({
2531
+ const { maxContextLines } = await prompts({
2521
2532
  type: "number",
2522
2533
  name: "maxContextLines",
2523
2534
  message: `Enter ${highlighter.info("max context lines")} to include:`,
@@ -2557,7 +2568,7 @@ var configure = new Command().name("configure").alias("config").description("con
2557
2568
  printDiff(result.filePath, result.originalContent, result.newContent);
2558
2569
  if (!opts.yes) {
2559
2570
  logger.break();
2560
- const { proceed } = await prompts3({
2571
+ const { proceed } = await prompts({
2561
2572
  type: "confirm",
2562
2573
  name: "proceed",
2563
2574
  message: "Apply these changes?",
@@ -2650,7 +2661,7 @@ var uninstallPackagesWithFeedback = (packages, packageManager, projectRoot) => {
2650
2661
  };
2651
2662
 
2652
2663
  // src/commands/init.ts
2653
- var VERSION3 = "0.1.0";
2664
+ var VERSION3 = "0.1.2";
2654
2665
  var REPORT_URL = "https://react-grab.com/api/report-cli";
2655
2666
  var DOCS_URL = "https://github.com/aidenybai/react-grab";
2656
2667
  var reportToCli = (type, config, error) => {
@@ -2777,7 +2788,7 @@ var init = new Command().name("init").description("initialize React Grab in your
2777
2788
  );
2778
2789
  logger.break();
2779
2790
  }
2780
- const { wantCustomizeOptions } = await prompts3({
2791
+ const { wantCustomizeOptions } = await prompts({
2781
2792
  type: "confirm",
2782
2793
  name: "wantCustomizeOptions",
2783
2794
  message: `Would you like to customize ${highlighter.info("options")}?`,
@@ -2798,7 +2809,7 @@ var init = new Command().name("init").description("initialize React Grab in your
2798
2809
  ` Activation key: ${highlighter.info(formatActivationKeyDisplay2(collectedOptions.activationKey))}`
2799
2810
  );
2800
2811
  } else {
2801
- const { wantActivationKey } = await prompts3({
2812
+ const { wantActivationKey } = await prompts({
2802
2813
  type: "confirm",
2803
2814
  name: "wantActivationKey",
2804
2815
  message: `Configure ${highlighter.info("activation key")}?`,
@@ -2809,7 +2820,7 @@ var init = new Command().name("init").description("initialize React Grab in your
2809
2820
  process.exit(1);
2810
2821
  }
2811
2822
  if (wantActivationKey) {
2812
- const { key } = await prompts3({
2823
+ const { key } = await prompts({
2813
2824
  type: "text",
2814
2825
  name: "key",
2815
2826
  message: "Enter the activation key (e.g., g, k, space):",
@@ -2825,7 +2836,7 @@ var init = new Command().name("init").description("initialize React Grab in your
2825
2836
  );
2826
2837
  }
2827
2838
  }
2828
- const { activationMode } = await prompts3({
2839
+ const { activationMode } = await prompts({
2829
2840
  type: "select",
2830
2841
  name: "activationMode",
2831
2842
  message: `Select ${highlighter.info("activation mode")}:`,
@@ -2844,7 +2855,7 @@ var init = new Command().name("init").description("initialize React Grab in your
2844
2855
  }
2845
2856
  collectedOptions.activationMode = activationMode;
2846
2857
  if (activationMode === "hold") {
2847
- const { keyHoldDuration } = await prompts3({
2858
+ const { keyHoldDuration } = await prompts({
2848
2859
  type: "number",
2849
2860
  name: "keyHoldDuration",
2850
2861
  message: `Enter ${highlighter.info("key hold duration")} in milliseconds:`,
@@ -2858,7 +2869,7 @@ var init = new Command().name("init").description("initialize React Grab in your
2858
2869
  }
2859
2870
  collectedOptions.keyHoldDuration = keyHoldDuration;
2860
2871
  }
2861
- const { allowActivationInsideInput } = await prompts3({
2872
+ const { allowActivationInsideInput } = await prompts({
2862
2873
  type: "confirm",
2863
2874
  name: "allowActivationInsideInput",
2864
2875
  message: `Allow activation ${highlighter.info("inside input fields")}?`,
@@ -2869,7 +2880,7 @@ var init = new Command().name("init").description("initialize React Grab in your
2869
2880
  process.exit(1);
2870
2881
  }
2871
2882
  collectedOptions.allowActivationInsideInput = allowActivationInsideInput;
2872
- const { maxContextLines } = await prompts3({
2883
+ const { maxContextLines } = await prompts({
2873
2884
  type: "number",
2874
2885
  name: "maxContextLines",
2875
2886
  message: `Enter ${highlighter.info("max context lines")} to include:`,
@@ -2903,7 +2914,7 @@ var init = new Command().name("init").description("initialize React Grab in your
2903
2914
  optionsResult.newContent
2904
2915
  );
2905
2916
  logger.break();
2906
- const { proceed } = await prompts3({
2917
+ const { proceed } = await prompts({
2907
2918
  type: "confirm",
2908
2919
  name: "proceed",
2909
2920
  message: "Apply these changes?",
@@ -2927,7 +2938,7 @@ var init = new Command().name("init").description("initialize React Grab in your
2927
2938
  );
2928
2939
  if (availableAgents.length > 0) {
2929
2940
  logger.break();
2930
- const { wantAddAgent } = await prompts3({
2941
+ const { wantAddAgent } = await prompts({
2931
2942
  type: "confirm",
2932
2943
  name: "wantAddAgent",
2933
2944
  message: `Would you like to add an ${highlighter.info("agent integration")}?`,
@@ -2938,7 +2949,7 @@ var init = new Command().name("init").description("initialize React Grab in your
2938
2949
  process.exit(1);
2939
2950
  }
2940
2951
  if (wantAddAgent) {
2941
- const { agent } = await prompts3({
2952
+ const { agent } = await prompts({
2942
2953
  type: "select",
2943
2954
  name: "agent",
2944
2955
  message: `Which ${highlighter.info("agent integration")} would you like to add?`,
@@ -2960,7 +2971,7 @@ var init = new Command().name("init").description("initialize React Grab in your
2960
2971
  const installedNames = formatInstalledAgentNames2(
2961
2972
  projectInfo.installedAgents
2962
2973
  );
2963
- const { action } = await prompts3({
2974
+ const { action } = await prompts({
2964
2975
  type: "select",
2965
2976
  name: "action",
2966
2977
  message: "How would you like to proceed?",
@@ -3031,7 +3042,7 @@ var init = new Command().name("init").description("initialize React Grab in your
3031
3042
  }
3032
3043
  if (agentsToRemove2.length === 0) {
3033
3044
  logger.break();
3034
- const { proceed } = await prompts3({
3045
+ const { proceed } = await prompts({
3035
3046
  type: "confirm",
3036
3047
  name: "proceed",
3037
3048
  message: "Apply these changes?",
@@ -3076,6 +3087,75 @@ var init = new Command().name("init").description("initialize React Grab in your
3076
3087
  }
3077
3088
  }
3078
3089
  }
3090
+ } else {
3091
+ const result2 = previewTransform(
3092
+ projectInfo.projectRoot,
3093
+ projectInfo.framework,
3094
+ projectInfo.nextRouterType,
3095
+ agentIntegration2,
3096
+ true
3097
+ );
3098
+ const packageJsonResult2 = previewPackageJsonTransform(
3099
+ projectInfo.projectRoot,
3100
+ agentIntegration2,
3101
+ projectInfo.installedAgents,
3102
+ projectInfo.packageManager
3103
+ );
3104
+ if (!result2.success) {
3105
+ logger.break();
3106
+ logger.error(result2.message);
3107
+ logger.break();
3108
+ process.exit(1);
3109
+ }
3110
+ const hasLayoutChanges2 = !result2.noChanges && result2.originalContent && result2.newContent;
3111
+ const hasPackageJsonChanges2 = packageJsonResult2.success && !packageJsonResult2.noChanges && packageJsonResult2.originalContent && packageJsonResult2.newContent;
3112
+ if (hasLayoutChanges2 || hasPackageJsonChanges2) {
3113
+ logger.break();
3114
+ if (hasLayoutChanges2) {
3115
+ printDiff(
3116
+ result2.filePath,
3117
+ result2.originalContent,
3118
+ result2.newContent
3119
+ );
3120
+ }
3121
+ if (hasPackageJsonChanges2) {
3122
+ if (hasLayoutChanges2) {
3123
+ logger.break();
3124
+ }
3125
+ printDiff(
3126
+ packageJsonResult2.filePath,
3127
+ packageJsonResult2.originalContent,
3128
+ packageJsonResult2.newContent
3129
+ );
3130
+ }
3131
+ logger.break();
3132
+ const { proceed } = await prompts({
3133
+ type: "confirm",
3134
+ name: "proceed",
3135
+ message: "Apply these changes?",
3136
+ initial: true
3137
+ });
3138
+ if (!proceed) {
3139
+ logger.break();
3140
+ logger.log("Agent addition cancelled.");
3141
+ } else {
3142
+ installPackagesWithFeedback(
3143
+ getPackagesToInstall(agentIntegration2, false),
3144
+ projectInfo.packageManager,
3145
+ projectInfo.projectRoot
3146
+ );
3147
+ if (hasLayoutChanges2) {
3148
+ applyTransformWithFeedback(result2);
3149
+ }
3150
+ if (hasPackageJsonChanges2) {
3151
+ applyPackageJsonWithFeedback(packageJsonResult2);
3152
+ }
3153
+ logger.break();
3154
+ logger.success(
3155
+ `${getAgentName(agentIntegration2)} has been added.`
3156
+ );
3157
+ }
3158
+ }
3079
3159
  }
3080
3160
  }
3081
3161
  }
@@ -3113,7 +3193,7 @@ var init = new Command().name("init").description("initialize React Grab in your
3113
3193
  return 0;
3114
3194
  }
3115
3195
  );
3116
- const { selectedProject } = await prompts3({
3196
+ const { selectedProject } = await prompts({
3117
3197
  type: "select",
3118
3198
  name: "selectedProject",
3119
3199
  message: "Select a project to install React Grab:",
@@ -3180,7 +3260,7 @@ var init = new Command().name("init").description("initialize React Grab in your
3180
3260
  const agentsToRemove = [];
3181
3261
  if (!isNonInteractive && !opts.agent) {
3182
3262
  logger.break();
3183
- const { wantAddAgent } = await prompts3({
3263
+ const { wantAddAgent } = await prompts({
3184
3264
  type: "confirm",
3185
3265
  name: "wantAddAgent",
3186
3266
  message: `Would you like to add an ${highlighter.info("agent integration")}?`,
@@ -3191,7 +3271,7 @@ var init = new Command().name("init").description("initialize React Grab in your
3191
3271
  process.exit(1);
3192
3272
  }
3193
3273
  if (wantAddAgent) {
3194
- const { agent } = await prompts3({
3274
+ const { agent } = await prompts({
3195
3275
  type: "select",
3196
3276
  name: "agent",
3197
3277
  message: `Which ${highlighter.info("agent integration")} would you like to add?`,
@@ -3258,7 +3338,7 @@ var init = new Command().name("init").description("initialize React Grab in your
3258
3338
  logger.warn("Please verify the changes before committing.");
3259
3339
  if (!isNonInteractive) {
3260
3340
  logger.break();
3261
- const { proceed } = await prompts3({
3341
+ const { proceed } = await prompts({
3262
3342
  type: "confirm",
3263
3343
  name: "proceed",
3264
3344
  message: "Apply these changes?",
@@ -3317,7 +3397,7 @@ var init = new Command().name("init").description("initialize React Grab in your
3317
3397
  reportToCli("error", void 0, error);
3318
3398
  }
3319
3399
  });
3320
- var VERSION4 = "0.1.0";
3400
+ var VERSION4 = "0.1.2";
3321
3401
  var remove = new Command().name("remove").description("remove an agent integration").argument(
3322
3402
  "[agent]",
3323
3403
  "agent to remove (claude-code, cursor, opencode, codex, gemini, amp, ami)"
@@ -3366,7 +3446,7 @@ var remove = new Command().name("remove").description("remove an agent integrati
3366
3446
  agentToRemove = agentArg;
3367
3447
  } else if (!isNonInteractive) {
3368
3448
  logger.break();
3369
- const { agent } = await prompts3({
3449
+ const { agent } = await prompts({
3370
3450
  type: "select",
3371
3451
  name: "agent",
3372
3452
  message: `Which ${highlighter.info("agent integration")} would you like to remove?`,
@@ -3426,7 +3506,7 @@ var remove = new Command().name("remove").description("remove an agent integrati
3426
3506
  }
3427
3507
  if (!isNonInteractive) {
3428
3508
  logger.break();
3429
- const { proceed } = await prompts3({
3509
+ const { proceed } = await prompts({
3430
3510
  type: "confirm",
3431
3511
  name: "proceed",
3432
3512
  message: "Apply these changes?",
@@ -3496,7 +3576,7 @@ var remove = new Command().name("remove").description("remove an agent integrati
3496
3576
  });
3497
3577
 
3498
3578
  // src/cli.ts
3499
- var VERSION5 = "0.1.0";
3579
+ var VERSION5 = "0.1.2";
3500
3580
  var VERSION_API_URL = "https://www.react-grab.com/api/version";
3501
3581
  process.on("SIGINT", () => process.exit(0));
3502
3582
  process.on("SIGTERM", () => process.exit(0));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-grab/cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "bin": {
5
5
  "react-grab": "./dist/cli.js"
6
6
  },