@ic-reactor/cli 0.0.0-dev → 0.0.0-dev2

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 (2) hide show
  1. package/dist/index.js +81 -10
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -46,12 +46,9 @@ function saveConfig(config, configPath = path.join(process.cwd(), CONFIG_FILE_NA
46
46
  fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
47
47
  }
48
48
  function getProjectRoot() {
49
- let currentDir = process.cwd();
50
- while (currentDir !== path.dirname(currentDir)) {
51
- if (fs.existsSync(path.join(currentDir, "package.json"))) {
52
- return currentDir;
53
- }
54
- currentDir = path.dirname(currentDir);
49
+ const configPath = findConfigFile();
50
+ if (configPath) {
51
+ return path.dirname(configPath);
55
52
  }
56
53
  return process.cwd();
57
54
  }
@@ -846,8 +843,9 @@ ${error.message}`
846
843
  if (options.all) {
847
844
  selectedMethods = methods;
848
845
  } else if (options.methods && options.methods.length > 0) {
849
- selectedMethods = methods.filter((m) => options.methods.includes(m.name));
850
- const notFound = options.methods.filter(
846
+ const requestedMethods = options.methods.flatMap((m) => m.split(",")).map((m) => m.trim()).filter((m) => m.length > 0);
847
+ selectedMethods = methods.filter((m) => requestedMethods.includes(m.name));
848
+ const notFound = requestedMethods.filter(
851
849
  (name) => !methods.some((m) => m.name === name)
852
850
  );
853
851
  if (notFound.length > 0) {
@@ -900,6 +898,11 @@ ${error.message}`
900
898
  value: "suspenseInfiniteQuery",
901
899
  label: "Suspense Infinite Query",
902
900
  hint: "Paginated with Suspense"
901
+ },
902
+ {
903
+ value: "skip",
904
+ label: "Skip",
905
+ hint: "Don't generate hook for this method"
903
906
  }
904
907
  ]
905
908
  });
@@ -907,11 +910,42 @@ ${error.message}`
907
910
  p2.cancel("Cancelled.");
908
911
  process.exit(0);
909
912
  }
913
+ if (hookType === "skip") {
914
+ p2.log.info(`Skipping ${pc2.dim(method.name)}`);
915
+ continue;
916
+ }
910
917
  methodsWithHookTypes.push({ method, hookType });
911
918
  } else {
919
+ const hookType = await p2.select({
920
+ message: `Hook type for ${pc2.yellow(method.name)} (mutation)`,
921
+ options: [
922
+ {
923
+ value: "mutation",
924
+ label: "Mutation",
925
+ hint: "Standard mutation hook"
926
+ },
927
+ {
928
+ value: "skip",
929
+ label: "Skip",
930
+ hint: "Don't generate hook for this method"
931
+ }
932
+ ]
933
+ });
934
+ if (p2.isCancel(hookType)) {
935
+ p2.cancel("Cancelled.");
936
+ process.exit(0);
937
+ }
938
+ if (hookType === "skip") {
939
+ p2.log.info(`Skipping ${pc2.dim(method.name)}`);
940
+ continue;
941
+ }
912
942
  methodsWithHookTypes.push({ method, hookType: "mutation" });
913
943
  }
914
944
  }
945
+ if (methodsWithHookTypes.length === 0) {
946
+ p2.log.warn("All methods were skipped. Nothing to generate.");
947
+ process.exit(0);
948
+ }
915
949
  const canisterOutDir = path3.join(projectRoot, config.outDir, selectedCanister);
916
950
  const hooksOutDir = path3.join(canisterOutDir, "hooks");
917
951
  ensureDir(hooksOutDir);
@@ -1448,8 +1482,9 @@ async function fetchCommand(options) {
1448
1482
  if (options.all) {
1449
1483
  selectedMethods = methods;
1450
1484
  } else if (options.methods && options.methods.length > 0) {
1451
- selectedMethods = methods.filter((m) => options.methods.includes(m.name));
1452
- const notFound = options.methods.filter(
1485
+ const requestedMethods = options.methods.flatMap((m) => m.split(",")).map((m) => m.trim()).filter((m) => m.length > 0);
1486
+ selectedMethods = methods.filter((m) => requestedMethods.includes(m.name));
1487
+ const notFound = requestedMethods.filter(
1453
1488
  (name) => !methods.some((m) => m.name === name)
1454
1489
  );
1455
1490
  if (notFound.length > 0) {
@@ -1482,6 +1517,11 @@ async function fetchCommand(options) {
1482
1517
  const hookType = await p5.select({
1483
1518
  message: `Hook type for ${pc5.cyan(method.name)}`,
1484
1519
  options: [
1520
+ {
1521
+ value: "skip",
1522
+ label: "Skip",
1523
+ hint: "Don't generate hook for this method"
1524
+ },
1485
1525
  { value: "query", label: "Query", hint: "Standard query hook" },
1486
1526
  {
1487
1527
  value: "suspenseQuery",
@@ -1504,11 +1544,42 @@ async function fetchCommand(options) {
1504
1544
  p5.cancel("Cancelled.");
1505
1545
  process.exit(0);
1506
1546
  }
1547
+ if (hookType === "skip") {
1548
+ p5.log.info(`Skipping ${pc5.dim(method.name)}`);
1549
+ continue;
1550
+ }
1507
1551
  methodsWithHookTypes.push({ method, hookType });
1508
1552
  } else {
1553
+ const hookType = await p5.select({
1554
+ message: `Hook type for ${pc5.yellow(method.name)} (mutation)`,
1555
+ options: [
1556
+ {
1557
+ value: "mutation",
1558
+ label: "Mutation",
1559
+ hint: "Standard mutation hook"
1560
+ },
1561
+ {
1562
+ value: "skip",
1563
+ label: "Skip",
1564
+ hint: "Don't generate hook for this method"
1565
+ }
1566
+ ]
1567
+ });
1568
+ if (p5.isCancel(hookType)) {
1569
+ p5.cancel("Cancelled.");
1570
+ process.exit(0);
1571
+ }
1572
+ if (hookType === "skip") {
1573
+ p5.log.info(`Skipping ${pc5.dim(method.name)}`);
1574
+ continue;
1575
+ }
1509
1576
  methodsWithHookTypes.push({ method, hookType: "mutation" });
1510
1577
  }
1511
1578
  }
1579
+ if (methodsWithHookTypes.length === 0) {
1580
+ p5.log.warn("All methods were skipped. Nothing to generate.");
1581
+ process.exit(0);
1582
+ }
1512
1583
  let configPath = findConfigFile();
1513
1584
  let config;
1514
1585
  if (!configPath) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ic-reactor/cli",
3
- "version": "0.0.0-dev",
3
+ "version": "0.0.0-dev2",
4
4
  "type": "module",
5
5
  "description": "CLI tool to generate shadcn-style React hooks for ICP canisters",
6
6
  "main": "dist/index.js",