custom-menu-cli 1.0.4 → 2.0.0

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/menu.json CHANGED
@@ -19,6 +19,13 @@
19
19
  "name": "Up Service",
20
20
  "type": "action",
21
21
  "command": "echo 'Up A'"
22
+ },
23
+ {
24
+ "id": "1.3",
25
+ "name": "Restart Project A (from inside)",
26
+ "type": "custom-action",
27
+ "idList": ["1.1", "1.2"],
28
+ "confirm": true
22
29
  }
23
30
  ]
24
31
  },
@@ -28,6 +35,13 @@
28
35
  "type": "custom-action",
29
36
  "idList": ["1.1", "1.2"],
30
37
  "confirm": true
38
+ },
39
+ {
40
+ "id": "3",
41
+ "name": "Restart Project A (Nested)",
42
+ "type": "custom-action",
43
+ "idList": ["1.3"],
44
+ "confirm": true
31
45
  }
32
46
  ]
33
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "custom-menu-cli",
3
- "version": "1.0.4",
3
+ "version": "2.0.0",
4
4
  "description": "Menu interativo baseado em JSON para execução de comandos no terminal",
5
5
  "main": "index.js",
6
6
  "bin": "index.js",
package/src/actions.js CHANGED
@@ -14,14 +14,25 @@ async function handleAction(selected) {
14
14
  }
15
15
  }
16
16
 
17
- async function handleCustomAction(selected, flatMap) {
17
+ async function handleCustomAction(selected, flatMap, depth = 0) {
18
+ if (depth >= 3) {
19
+ console.log(chalk.red(`Maximum recursion depth (3) exceeded for custom action: ${selected.id}`));
20
+ return;
21
+ }
18
22
  const proceed = selected.confirm ? await confirmExecution(chalk.yellow(`Execute command list ${selected.idList.join(', ')}?`)) : true;
19
23
  if (proceed) {
20
24
  for (const id of selected.idList) {
21
25
  const cmd = flatMap[id];
22
- if (cmd?.command) {
23
- console.log(chalk.blue(`Executing command: [id: ${cmd.id} name: ${cmd.name} ]`));
24
- await terminal.execCommandSync(cmd.command);
26
+ if (cmd) {
27
+ if (cmd.type === 'action' && cmd.command) {
28
+ console.log(chalk.blue(`Executing command: [id: ${cmd.id} name: ${cmd.name} ]`));
29
+ await terminal.execCommandSync(cmd.command);
30
+ } else if (cmd.type === 'custom-action') {
31
+ console.log(chalk.blue(`Executing custom action: [id: ${cmd.id} name: ${cmd.name} ]`));
32
+ await handleCustomAction(cmd, flatMap, depth + 1);
33
+ } else {
34
+ console.log(chalk.red(`Unknown or unexecutable type for id: ${cmd.id}`));
35
+ }
25
36
  }
26
37
  }
27
38
  }