@nexical/cli 0.1.6 → 0.10.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.
Files changed (236) hide show
  1. package/.github/workflows/deploy.yml +3 -3
  2. package/README.md +317 -104
  3. package/dist/chunk-JYASTIIW.js +42 -0
  4. package/dist/chunk-JYASTIIW.js.map +1 -0
  5. package/dist/chunk-LZ3YQWAR.js +2204 -0
  6. package/dist/chunk-LZ3YQWAR.js.map +1 -0
  7. package/dist/chunk-OKXOCNXP.js +105 -0
  8. package/dist/chunk-OKXOCNXP.js.map +1 -0
  9. package/dist/chunk-OYFWMYPG.js +52 -0
  10. package/dist/chunk-OYFWMYPG.js.map +1 -0
  11. package/dist/chunk-WKERTCM6.js +74 -0
  12. package/dist/chunk-WKERTCM6.js.map +1 -0
  13. package/dist/index.js +33 -6
  14. package/dist/index.js.map +1 -1
  15. package/dist/src/commands/init.d.ts +11 -0
  16. package/dist/src/commands/init.js +88 -0
  17. package/dist/src/commands/init.js.map +1 -0
  18. package/dist/src/commands/module/add.d.ts +14 -0
  19. package/dist/src/commands/module/add.js +136 -0
  20. package/dist/src/commands/module/add.js.map +1 -0
  21. package/dist/src/commands/module/list.d.ts +10 -0
  22. package/dist/src/commands/module/list.js +73 -0
  23. package/dist/src/commands/module/list.js.map +1 -0
  24. package/dist/src/commands/module/remove.d.ts +12 -0
  25. package/dist/src/commands/module/remove.js +71 -0
  26. package/dist/src/commands/module/remove.js.map +1 -0
  27. package/dist/src/commands/module/update.d.ts +11 -0
  28. package/dist/src/commands/module/update.js +52 -0
  29. package/dist/src/commands/module/update.js.map +1 -0
  30. package/dist/src/commands/run.d.ts +11 -0
  31. package/dist/src/commands/run.js +93 -0
  32. package/dist/src/commands/run.js.map +1 -0
  33. package/dist/src/utils/discovery.d.ts +13 -0
  34. package/dist/src/utils/discovery.js +9 -0
  35. package/dist/src/utils/git.d.ts +16 -0
  36. package/dist/src/utils/git.js +29 -0
  37. package/dist/src/utils/git.js.map +1 -0
  38. package/dist/src/utils/url-resolver.d.ts +15 -0
  39. package/dist/src/utils/url-resolver.js +9 -0
  40. package/dist/src/utils/url-resolver.js.map +1 -0
  41. package/index.ts +29 -5
  42. package/package.json +32 -30
  43. package/src/commands/init.ts +85 -0
  44. package/src/commands/module/add.ts +169 -0
  45. package/src/commands/module/list.ts +69 -0
  46. package/src/commands/module/remove.ts +74 -0
  47. package/src/commands/module/update.ts +50 -0
  48. package/src/commands/run.ts +98 -0
  49. package/src/utils/discovery.ts +134 -0
  50. package/src/utils/git.ts +65 -0
  51. package/src/utils/url-resolver.ts +57 -0
  52. package/test/e2e/lifecycle.e2e.test.ts +152 -0
  53. package/test/integration/commands/init.integration.test.ts +82 -0
  54. package/test/integration/commands/module.integration.test.ts +144 -0
  55. package/test/integration/commands/run.integration.test.ts +90 -0
  56. package/test/integration/utils/command-loading.integration.test.ts +80 -0
  57. package/test/unit/commands/init.test.ts +153 -0
  58. package/test/unit/commands/module/add.test.ts +262 -0
  59. package/test/unit/commands/module/list.test.ts +115 -0
  60. package/test/unit/commands/module/remove.test.ts +89 -0
  61. package/test/unit/commands/module/update.test.ts +91 -0
  62. package/test/unit/commands/run.test.ts +252 -0
  63. package/test/unit/utils/command-discovery.test.ts +176 -0
  64. package/test/unit/utils/git.test.ts +152 -0
  65. package/test/unit/utils/integration-helpers.test.ts +72 -0
  66. package/test/unit/utils/url-resolver.test.ts +39 -0
  67. package/test/utils/integration-helpers.ts +66 -0
  68. package/vitest.e2e.config.ts +0 -1
  69. package/dist/chunk-JDRAVUKK.js +0 -48
  70. package/dist/chunk-JDRAVUKK.js.map +0 -1
  71. package/dist/src/commands/admin/create-user.d.ts +0 -15
  72. package/dist/src/commands/admin/create-user.js +0 -49
  73. package/dist/src/commands/admin/create-user.js.map +0 -1
  74. package/dist/src/commands/branch/create.d.ts +0 -19
  75. package/dist/src/commands/branch/create.js +0 -59
  76. package/dist/src/commands/branch/create.js.map +0 -1
  77. package/dist/src/commands/branch/delete.d.ts +0 -15
  78. package/dist/src/commands/branch/delete.js +0 -50
  79. package/dist/src/commands/branch/delete.js.map +0 -1
  80. package/dist/src/commands/branch/get.d.ts +0 -15
  81. package/dist/src/commands/branch/get.js +0 -53
  82. package/dist/src/commands/branch/get.js.map +0 -1
  83. package/dist/src/commands/branch/list.d.ts +0 -15
  84. package/dist/src/commands/branch/list.js +0 -51
  85. package/dist/src/commands/branch/list.js.map +0 -1
  86. package/dist/src/commands/job/get.d.ts +0 -15
  87. package/dist/src/commands/job/get.js +0 -62
  88. package/dist/src/commands/job/get.js.map +0 -1
  89. package/dist/src/commands/job/list.d.ts +0 -15
  90. package/dist/src/commands/job/list.js +0 -57
  91. package/dist/src/commands/job/list.js.map +0 -1
  92. package/dist/src/commands/job/logs.d.ts +0 -15
  93. package/dist/src/commands/job/logs.js +0 -67
  94. package/dist/src/commands/job/logs.js.map +0 -1
  95. package/dist/src/commands/job/trigger.d.ts +0 -19
  96. package/dist/src/commands/job/trigger.js +0 -74
  97. package/dist/src/commands/job/trigger.js.map +0 -1
  98. package/dist/src/commands/login.d.ts +0 -8
  99. package/dist/src/commands/login.js +0 -31
  100. package/dist/src/commands/login.js.map +0 -1
  101. package/dist/src/commands/project/create.d.ts +0 -24
  102. package/dist/src/commands/project/create.js +0 -63
  103. package/dist/src/commands/project/create.js.map +0 -1
  104. package/dist/src/commands/project/delete.d.ts +0 -20
  105. package/dist/src/commands/project/delete.js +0 -58
  106. package/dist/src/commands/project/delete.js.map +0 -1
  107. package/dist/src/commands/project/get.d.ts +0 -15
  108. package/dist/src/commands/project/get.js +0 -49
  109. package/dist/src/commands/project/get.js.map +0 -1
  110. package/dist/src/commands/project/list.d.ts +0 -15
  111. package/dist/src/commands/project/list.js +0 -45
  112. package/dist/src/commands/project/list.js.map +0 -1
  113. package/dist/src/commands/project/update.d.ts +0 -19
  114. package/dist/src/commands/project/update.js +0 -66
  115. package/dist/src/commands/project/update.js.map +0 -1
  116. package/dist/src/commands/team/create.d.ts +0 -19
  117. package/dist/src/commands/team/create.js +0 -45
  118. package/dist/src/commands/team/create.js.map +0 -1
  119. package/dist/src/commands/team/delete.d.ts +0 -20
  120. package/dist/src/commands/team/delete.js +0 -52
  121. package/dist/src/commands/team/delete.js.map +0 -1
  122. package/dist/src/commands/team/get.d.ts +0 -15
  123. package/dist/src/commands/team/get.js +0 -42
  124. package/dist/src/commands/team/get.js.map +0 -1
  125. package/dist/src/commands/team/list.d.ts +0 -8
  126. package/dist/src/commands/team/list.js +0 -30
  127. package/dist/src/commands/team/list.js.map +0 -1
  128. package/dist/src/commands/team/member/invite.d.ts +0 -20
  129. package/dist/src/commands/team/member/invite.js +0 -54
  130. package/dist/src/commands/team/member/invite.js.map +0 -1
  131. package/dist/src/commands/team/member/remove.d.ts +0 -15
  132. package/dist/src/commands/team/member/remove.js +0 -43
  133. package/dist/src/commands/team/member/remove.js.map +0 -1
  134. package/dist/src/commands/team/update.d.ts +0 -19
  135. package/dist/src/commands/team/update.js +0 -55
  136. package/dist/src/commands/team/update.js.map +0 -1
  137. package/dist/src/commands/token/generate.d.ts +0 -19
  138. package/dist/src/commands/token/generate.js +0 -48
  139. package/dist/src/commands/token/generate.js.map +0 -1
  140. package/dist/src/commands/token/list.d.ts +0 -8
  141. package/dist/src/commands/token/list.js +0 -31
  142. package/dist/src/commands/token/list.js.map +0 -1
  143. package/dist/src/commands/token/revoke.d.ts +0 -15
  144. package/dist/src/commands/token/revoke.js +0 -38
  145. package/dist/src/commands/token/revoke.js.map +0 -1
  146. package/dist/src/commands/whoami.d.ts +0 -8
  147. package/dist/src/commands/whoami.js +0 -26
  148. package/dist/src/commands/whoami.js.map +0 -1
  149. package/dist/src/utils/nexical-client.d.ts +0 -10
  150. package/dist/src/utils/nexical-client.js +0 -12
  151. package/src/commands/admin/create-user.ts +0 -46
  152. package/src/commands/branch/create.ts +0 -57
  153. package/src/commands/branch/delete.ts +0 -47
  154. package/src/commands/branch/get.ts +0 -50
  155. package/src/commands/branch/list.ts +0 -50
  156. package/src/commands/job/get.ts +0 -59
  157. package/src/commands/job/list.ts +0 -56
  158. package/src/commands/job/logs.ts +0 -67
  159. package/src/commands/job/trigger.ts +0 -73
  160. package/src/commands/login.ts +0 -31
  161. package/src/commands/project/create.ts +0 -61
  162. package/src/commands/project/delete.ts +0 -56
  163. package/src/commands/project/get.ts +0 -46
  164. package/src/commands/project/list.ts +0 -44
  165. package/src/commands/project/update.ts +0 -63
  166. package/src/commands/team/create.ts +0 -43
  167. package/src/commands/team/delete.ts +0 -50
  168. package/src/commands/team/get.ts +0 -39
  169. package/src/commands/team/list.ts +0 -26
  170. package/src/commands/team/member/invite.ts +0 -56
  171. package/src/commands/team/member/remove.ts +0 -40
  172. package/src/commands/team/update.ts +0 -53
  173. package/src/commands/token/generate.ts +0 -45
  174. package/src/commands/token/list.ts +0 -27
  175. package/src/commands/token/revoke.ts +0 -35
  176. package/src/commands/whoami.ts +0 -21
  177. package/src/utils/nexical-client.ts +0 -47
  178. package/test/e2e/auth.e2e.test.ts +0 -46
  179. package/test/e2e/job-workflow.e2e.test.ts +0 -33
  180. package/test/e2e/project-lifecycle.e2e.test.ts +0 -48
  181. package/test/e2e/setup.ts +0 -237
  182. package/test/e2e/utils.ts +0 -33
  183. package/test/integration/commands/admin/create-user.test.ts +0 -51
  184. package/test/integration/commands/branch/create.test.ts +0 -51
  185. package/test/integration/commands/branch/delete.test.ts +0 -43
  186. package/test/integration/commands/branch/get.test.ts +0 -49
  187. package/test/integration/commands/branch/list.test.ts +0 -47
  188. package/test/integration/commands/job/get.test.ts +0 -54
  189. package/test/integration/commands/job/list.test.ts +0 -47
  190. package/test/integration/commands/job/logs.test.ts +0 -47
  191. package/test/integration/commands/job/trigger.test.ts +0 -57
  192. package/test/integration/commands/login.test.ts +0 -62
  193. package/test/integration/commands/project/create.test.ts +0 -53
  194. package/test/integration/commands/project/delete.test.ts +0 -43
  195. package/test/integration/commands/project/get.test.ts +0 -51
  196. package/test/integration/commands/project/list.test.ts +0 -47
  197. package/test/integration/commands/project/update.test.ts +0 -53
  198. package/test/integration/commands/team/create.test.ts +0 -53
  199. package/test/integration/commands/team/delete.test.ts +0 -43
  200. package/test/integration/commands/team/get.test.ts +0 -50
  201. package/test/integration/commands/team/list.test.ts +0 -47
  202. package/test/integration/commands/team/member/invite.test.ts +0 -46
  203. package/test/integration/commands/team/member/remove.test.ts +0 -43
  204. package/test/integration/commands/team/update.test.ts +0 -50
  205. package/test/integration/commands/token/generate.test.ts +0 -51
  206. package/test/integration/commands/token/list.test.ts +0 -47
  207. package/test/integration/commands/token/revoke.test.ts +0 -43
  208. package/test/integration/commands/whoami.test.ts +0 -49
  209. package/test/unit/commands/admin/create-user.test.ts +0 -51
  210. package/test/unit/commands/branch/create.test.ts +0 -57
  211. package/test/unit/commands/branch/delete.test.ts +0 -49
  212. package/test/unit/commands/branch/get.test.ts +0 -67
  213. package/test/unit/commands/branch/list.test.ts +0 -62
  214. package/test/unit/commands/job/get.test.ts +0 -76
  215. package/test/unit/commands/job/list.test.ts +0 -62
  216. package/test/unit/commands/job/logs.test.ts +0 -60
  217. package/test/unit/commands/job/trigger.test.ts +0 -75
  218. package/test/unit/commands/login.test.ts +0 -64
  219. package/test/unit/commands/project/create.test.ts +0 -64
  220. package/test/unit/commands/project/delete.test.ts +0 -72
  221. package/test/unit/commands/project/get.test.ts +0 -73
  222. package/test/unit/commands/project/list.test.ts +0 -62
  223. package/test/unit/commands/project/update.test.ts +0 -58
  224. package/test/unit/commands/team/create.test.ts +0 -68
  225. package/test/unit/commands/team/delete.test.ts +0 -71
  226. package/test/unit/commands/team/get.test.ts +0 -70
  227. package/test/unit/commands/team/list.test.ts +0 -56
  228. package/test/unit/commands/team/member/invite.test.ts +0 -52
  229. package/test/unit/commands/team/member/remove.test.ts +0 -49
  230. package/test/unit/commands/team/update.test.ts +0 -63
  231. package/test/unit/commands/token/generate.test.ts +0 -65
  232. package/test/unit/commands/token/list.test.ts +0 -58
  233. package/test/unit/commands/token/revoke.test.ts +0 -49
  234. package/test/unit/commands/whoami.test.ts +0 -49
  235. package/test/unit/utils/nexical-client.test.ts +0 -113
  236. /package/dist/src/utils/{nexical-client.js.map → discovery.js.map} +0 -0
@@ -0,0 +1,69 @@
1
+ import { BaseCommand, logger } from '@nexical/cli-core';
2
+ import fs from 'fs-extra';
3
+ import path from 'path';
4
+ import YAML from 'yaml';
5
+
6
+ export default class ModuleListCommand extends BaseCommand {
7
+ static usage = 'module list';
8
+ static description = 'List installed modules.';
9
+ static requiresProject = true;
10
+
11
+ async run() {
12
+ const projectRoot = this.projectRoot as string;
13
+ const modulesDir = path.resolve(projectRoot, 'modules');
14
+ logger.debug(`Scanning for modules in: ${modulesDir}`);
15
+
16
+ if (!(await fs.pathExists(modulesDir))) {
17
+ this.info('No modules installed (modules directory missing).');
18
+ return;
19
+ }
20
+
21
+ try {
22
+ const modules = await fs.readdir(modulesDir);
23
+ const validModules: { name: string; version: string; description: string }[] = [];
24
+
25
+ for (const moduleName of modules) {
26
+ const modulePath = path.join(modulesDir, moduleName);
27
+ if ((await fs.stat(modulePath)).isDirectory()) {
28
+ let version = 'unknown';
29
+ let description = '';
30
+
31
+ const pkgJsonPath = path.join(modulePath, 'package.json');
32
+ const moduleYamlPath = path.join(modulePath, 'module.yaml');
33
+ const moduleYmlPath = path.join(modulePath, 'module.yml');
34
+
35
+ let pkg: any = {};
36
+ let modConfig: any = {};
37
+
38
+ if (await fs.pathExists(pkgJsonPath)) {
39
+ try {
40
+ pkg = await fs.readJson(pkgJsonPath);
41
+ } catch (e) { /* ignore */ }
42
+ }
43
+
44
+ if (await fs.pathExists(moduleYamlPath) || await fs.pathExists(moduleYmlPath)) {
45
+ try {
46
+ const configPath = await fs.pathExists(moduleYamlPath) ? moduleYamlPath : moduleYmlPath;
47
+ const content = await fs.readFile(configPath, 'utf8');
48
+ modConfig = YAML.parse(content) || {};
49
+ } catch (e) { /* ignore */ }
50
+ }
51
+
52
+ version = pkg.version || 'unknown';
53
+ description = modConfig.description || pkg.description || '';
54
+ // Optionally use display name from module.yaml if present, but strictly list is usually dir name.
55
+ // Let's stick to dir name for "name" column, but description from module.yaml is good.
56
+ validModules.push({ name: moduleName, version, description });
57
+ }
58
+ }
59
+
60
+ if (validModules.length === 0) {
61
+ this.info('No modules installed.');
62
+ } else {
63
+ console.table(validModules);
64
+ }
65
+ } catch (error: any) {
66
+ this.error(`Failed to list modules: ${error.message}`);
67
+ }
68
+ }
69
+ }
@@ -0,0 +1,74 @@
1
+ import { type CommandDefinition, BaseCommand, logger, runCommand } from '@nexical/cli-core';
2
+ import fs from 'fs-extra';
3
+ import path from 'path';
4
+ import YAML from 'yaml';
5
+
6
+ export default class ModuleRemoveCommand extends BaseCommand {
7
+ static usage = 'module remove <name>';
8
+ static description = 'Remove an installed module.';
9
+ static requiresProject = true;
10
+
11
+ static args: CommandDefinition = {
12
+ args: [
13
+ { name: 'name', required: true, description: 'Name of the module to remove' }
14
+ ]
15
+ };
16
+
17
+ async run(options: any) {
18
+ const projectRoot = this.projectRoot as string;
19
+ let { name } = options;
20
+
21
+ const relativePath = `modules/${name}`;
22
+ const fullPath = path.resolve(projectRoot, relativePath);
23
+
24
+ logger.debug('Removing module at:', fullPath);
25
+
26
+ if (!(await fs.pathExists(fullPath))) {
27
+ this.error(`Module ${name} not found at ${relativePath}.`);
28
+ return;
29
+ }
30
+
31
+ this.info(`Removing module ${name}...`);
32
+
33
+ try {
34
+ await runCommand(`git submodule deinit -f ${relativePath}`, projectRoot);
35
+ await runCommand(`git rm -f ${relativePath}`, projectRoot);
36
+
37
+ // Clean up .git/modules
38
+ const gitModulesDir = path.resolve(projectRoot, '.git', 'modules', 'modules', name);
39
+ if (await fs.pathExists(gitModulesDir)) {
40
+ await fs.remove(gitModulesDir);
41
+ }
42
+
43
+ this.info('Syncing workspace dependencies...');
44
+ await runCommand('npm install', projectRoot);
45
+
46
+
47
+ await this.removeFromConfig(name);
48
+
49
+ this.success(`Module ${name} removed successfully.`);
50
+ } catch (e: any) {
51
+ this.error(`Failed to remove module: ${e.message}`);
52
+ }
53
+ }
54
+
55
+ private async removeFromConfig(moduleName: string) {
56
+ const projectRoot = this.projectRoot as string;
57
+ const configPath = path.join(projectRoot, 'nexical.yaml');
58
+
59
+ if (!await fs.pathExists(configPath)) return;
60
+
61
+ try {
62
+ const content = await fs.readFile(configPath, 'utf8');
63
+ let config = YAML.parse(content) || {};
64
+
65
+ if (config.modules && config.modules.includes(moduleName)) {
66
+ config.modules = config.modules.filter((m: string) => m !== moduleName);
67
+ await fs.writeFile(configPath, YAML.stringify(config));
68
+ logger.debug(`Removed ${moduleName} from nexical.yaml modules list.`);
69
+ }
70
+ } catch (e: any) {
71
+ logger.warn(`Failed to update nexical.yaml: ${e.message}`);
72
+ }
73
+ }
74
+ }
@@ -0,0 +1,50 @@
1
+ import { type CommandDefinition, BaseCommand, logger, runCommand } from '@nexical/cli-core';
2
+ import fs from 'fs-extra';
3
+ import path from 'path';
4
+
5
+ export default class ModuleUpdateCommand extends BaseCommand {
6
+ static usage = 'module update [name]';
7
+ static description = 'Update a specific module or all modules.';
8
+ static requiresProject = true;
9
+
10
+ static args: CommandDefinition = {
11
+ args: [
12
+ { name: 'name', required: false, description: 'Name of the module to update' }
13
+ ]
14
+ };
15
+
16
+ async run(options: any) {
17
+ const projectRoot = this.projectRoot as string;
18
+ let { name } = options;
19
+
20
+ this.info(name ? `Updating module ${name}...` : 'Updating all modules...');
21
+ logger.debug('Update context:', { name, projectRoot: projectRoot });
22
+
23
+ try {
24
+ if (name) {
25
+ const relativePath = `modules/${name}`;
26
+ const fullPath = path.resolve(projectRoot, relativePath);
27
+
28
+ if (!(await fs.pathExists(fullPath))) {
29
+ this.error(`Module ${name} not found.`);
30
+ return;
31
+ }
32
+
33
+ // Update specific module
34
+ // We enter the directory and pull? Or generic submodule update?
35
+ // Generic submodule update --remote src/modules/name
36
+ await runCommand(`git submodule update --remote --merge ${relativePath}`, projectRoot);
37
+ } else {
38
+ // Update all
39
+ await runCommand('git submodule update --remote --merge', projectRoot);
40
+ }
41
+
42
+ this.info('Syncing workspace dependencies...');
43
+ await runCommand('npm install', projectRoot);
44
+
45
+ this.success('Modules updated successfully.');
46
+ } catch (e: any) {
47
+ this.error(`Failed to update modules: ${e.message}`);
48
+ }
49
+ }
50
+ }
@@ -0,0 +1,98 @@
1
+ import { type CommandDefinition, BaseCommand, logger } from '@nexical/cli-core';
2
+ import fs from 'fs-extra';
3
+ import path from 'path';
4
+ import { spawn } from 'child_process';
5
+ import process from 'node:process';
6
+
7
+ export default class RunCommand extends BaseCommand {
8
+ static usage = 'run <script> [args...]';
9
+ static description = 'Run a script inside the Nexical environment.';
10
+ static requiresProject = true;
11
+
12
+ static args: CommandDefinition = {
13
+ args: [
14
+ { name: 'script', required: true, description: 'The script to run (script-name OR module:script-name)' },
15
+ { name: 'args...', required: false, description: 'Arguments for the script' }
16
+ ]
17
+ };
18
+
19
+ async run(options: any) {
20
+ const projectRoot = this.projectRoot as string;
21
+ const script = options.script;
22
+ const scriptArgs = options.args || [];
23
+
24
+ if (!script) {
25
+ this.error('Please specify a script to run.');
26
+ return;
27
+ }
28
+
29
+ logger.debug('Run command context:', { script, args: scriptArgs, projectRoot });
30
+
31
+ let execPath = projectRoot;
32
+ let scriptName = script;
33
+
34
+ // Handle module:script syntax
35
+ if (script.includes(':')) {
36
+ const [moduleName, name] = script.split(':');
37
+ execPath = path.resolve(projectRoot, 'modules', moduleName);
38
+ scriptName = name;
39
+
40
+ logger.debug(`Resolving module script: ${moduleName}:${scriptName} at ${execPath}`);
41
+ } else {
42
+ logger.debug(`Resolving core script: ${scriptName} at ${execPath}`);
43
+ }
44
+
45
+ // Validate script existence
46
+ const pkgJsonPath = path.join(execPath, 'package.json');
47
+ if (!(await fs.pathExists(pkgJsonPath))) {
48
+ this.error(`Failed to find package.json at ${execPath}`);
49
+ return;
50
+ }
51
+
52
+ try {
53
+ const pkg = await fs.readJson(pkgJsonPath);
54
+ if (!pkg.scripts || !pkg.scripts[scriptName]) {
55
+ const type = script.includes(':') ? `module ${script.split(':')[0]}` : 'Nexical core';
56
+ this.error(`Script "${scriptName}" does not exist in ${type}`);
57
+ return;
58
+ }
59
+ } catch (e: any) {
60
+ this.error(`Failed to read package.json at ${execPath}: ${e.message}`);
61
+ return;
62
+ }
63
+
64
+ const finalArgs = ['run', scriptName, '--', ...scriptArgs];
65
+ logger.debug(`Executing: npm ${finalArgs.join(' ')} in ${execPath}`);
66
+
67
+ const child = spawn('npm', finalArgs, {
68
+ cwd: execPath,
69
+ stdio: 'inherit',
70
+ env: {
71
+ ...process.env,
72
+ FORCE_COLOR: '1'
73
+ }
74
+ });
75
+
76
+ // Handle process termination to kill child
77
+ const cleanup = () => {
78
+ child.kill();
79
+ process.exit();
80
+ };
81
+
82
+ process.on('SIGINT', cleanup);
83
+ process.on('SIGTERM', cleanup);
84
+
85
+ await new Promise<void>((resolve) => {
86
+ child.on('close', (code) => {
87
+ // Remove listeners to prevent memory leaks if this command is run multiple times in-process (e.g. tests)
88
+ process.off('SIGINT', cleanup);
89
+ process.off('SIGTERM', cleanup);
90
+
91
+ if (code !== 0) {
92
+ process.exit(code || 1);
93
+ }
94
+ resolve();
95
+ });
96
+ });
97
+ }
98
+ }
@@ -0,0 +1,134 @@
1
+ import { logger } from '@nexical/cli-core';
2
+ import path from 'node:path';
3
+ import fs from 'node:fs';
4
+
5
+ /**
6
+ * Discovers command directories to load into the CLI.
7
+ *
8
+ * Scans for:
9
+ * 1. Core commands (projectRoot/src/commands)
10
+ * 2. Module commands (projectRoot/src/modules/ * /src/commands)
11
+ *
12
+ * @param projectRoot - The root directory of the project
13
+ * @returns Array of absolute paths to command directories
14
+ */
15
+ export function discoverCommandDirectories(projectRoot: string): string[] {
16
+ const directories: string[] = [];
17
+ const visited = new Set<string>();
18
+
19
+ const addDir = (dir: string) => {
20
+ const resolved = path.resolve(dir);
21
+ if (visited.has(resolved)) return;
22
+
23
+ if (fs.existsSync(resolved)) {
24
+ // Check if we already have a similar path (e.g. dist/src/commands vs src/commands)
25
+ // If we are adding src/commands and dist/src/commands already exists in visited, skip it
26
+ // and vice versa.
27
+ const isSrc = resolved.endsWith(path.join('src', 'commands'));
28
+ const isDist = resolved.includes(path.join('dist', 'src', 'commands')) ||
29
+ resolved.endsWith(path.join('dist', 'commands'));
30
+
31
+ if (isSrc) {
32
+ const distEquivalent1 = resolved.replace(path.sep + 'src' + path.sep, path.sep + 'dist' + path.sep + 'src' + path.sep);
33
+ const distEquivalent2 = resolved.replace(path.sep + 'src' + path.sep, path.sep + 'dist' + path.sep);
34
+ if (visited.has(distEquivalent1) || visited.has(distEquivalent2)) {
35
+ logger.debug(`Skipping ${resolved} because a dist version is already registered`);
36
+ return;
37
+ }
38
+ }
39
+
40
+ if (isDist) {
41
+ const srcEquivalent1 = resolved.replace(path.sep + 'dist' + path.sep, path.sep);
42
+ const srcEquivalent2 = resolved.replace(path.sep + 'dist' + path.sep + 'src' + path.sep, path.sep + 'src' + path.sep);
43
+ if (visited.has(srcEquivalent1) || visited.has(srcEquivalent2)) {
44
+ // If we just added src, and now we find dist, we should actually REPLACE src with dist
45
+ // but for now, the loop order prefers dist, so this case shouldn't happen much.
46
+ // However, let's keep it simple.
47
+ logger.debug(`Skipping ${resolved} because a src version is already registered`);
48
+ return;
49
+ }
50
+ }
51
+
52
+ logger.debug(`Found command directory: ${resolved}`);
53
+ directories.push(resolved);
54
+ visited.add(resolved);
55
+ } else {
56
+ logger.debug(`Command directory not found (skipping): ${resolved}`);
57
+ }
58
+ };
59
+
60
+ // 1. Core commands
61
+ // Search in projectRoot
62
+ const possibleCorePaths = [
63
+ path.join(projectRoot, 'src/commands'),
64
+ ];
65
+
66
+ possibleCorePaths.forEach(addDir);
67
+
68
+ // 2. Module commands
69
+ const possibleModuleDirs = [
70
+ path.join(projectRoot, 'modules'),
71
+ path.join(projectRoot, 'src', 'modules') // Support both flat and src-nested
72
+ ];
73
+
74
+ possibleModuleDirs.forEach(modulesDir => {
75
+ if (fs.existsSync(modulesDir)) {
76
+ try {
77
+ const modules = fs.readdirSync(modulesDir);
78
+ for (const mod of modules) {
79
+ // exclude system files/dirs like .keep
80
+ if (mod.startsWith('.')) continue;
81
+
82
+ const modPath = path.join(modulesDir, mod);
83
+ if (!fs.statSync(modPath).isDirectory()) continue;
84
+
85
+ // Check for commands inside the module/package
86
+ // Order matters: prefer dist if it exists
87
+ const possibleCmdPaths = [
88
+ path.join(modPath, 'dist/src/commands'),
89
+ path.join(modPath, 'dist/commands'),
90
+ path.join(modPath, 'src/commands')
91
+ ];
92
+
93
+ for (const cmdPath of possibleCmdPaths) {
94
+ if (fs.existsSync(cmdPath) && fs.statSync(cmdPath).isDirectory()) {
95
+ addDir(cmdPath);
96
+ }
97
+ }
98
+ }
99
+ } catch (e: any) {
100
+ logger.debug(`Error scanning modules directory ${modulesDir}: ${e.message}`);
101
+ }
102
+ }
103
+ });
104
+
105
+ // 3. Package commands (e.g. packages/*)
106
+ const packagesDir = path.join(projectRoot, 'packages');
107
+ if (fs.existsSync(packagesDir)) {
108
+ try {
109
+ const packages = fs.readdirSync(packagesDir);
110
+ for (const pkg of packages) {
111
+ if (pkg.startsWith('.')) continue;
112
+
113
+ const pkgPath = path.join(packagesDir, pkg);
114
+ if (!fs.statSync(pkgPath).isDirectory()) continue;
115
+
116
+ const possibleCmdPaths = [
117
+ path.join(pkgPath, 'dist/src/commands'),
118
+ path.join(pkgPath, 'dist/commands'),
119
+ path.join(pkgPath, 'src/commands')
120
+ ];
121
+
122
+ for (const cmdPath of possibleCmdPaths) {
123
+ if (fs.existsSync(cmdPath) && fs.statSync(cmdPath).isDirectory()) {
124
+ addDir(cmdPath);
125
+ }
126
+ }
127
+ }
128
+ } catch (e: any) {
129
+ logger.debug(`Error scanning packages directory: ${e.message}`);
130
+ }
131
+ }
132
+
133
+ return directories;
134
+ }
@@ -0,0 +1,65 @@
1
+ import { logger, runCommand } from '@nexical/cli-core';
2
+ import { exec } from 'node:child_process';
3
+ import { promisify } from 'node:util';
4
+
5
+ const execAsync = promisify(exec);
6
+
7
+ export async function clone(url: string, destination: string, options: { recursive?: boolean; depth?: number } = {}): Promise<void> {
8
+ const { recursive = false, depth } = options;
9
+ const cmd = `git clone ${recursive ? '--recursive ' : ''}${depth ? `--depth ${depth} ` : ''}${url} .`;
10
+ logger.debug(`Git clone: ${url} to ${destination}`);
11
+ await runCommand(cmd, destination);
12
+ }
13
+
14
+ export async function getRemoteUrl(cwd: string, remote = 'origin'): Promise<string> {
15
+ try {
16
+ const { stdout } = await execAsync(`git remote get-url ${remote}`, { cwd });
17
+ return stdout.trim();
18
+ } catch (e) {
19
+ console.error('getRemoteUrl failed:', e);
20
+ return '';
21
+ }
22
+ }
23
+
24
+ export async function updateSubmodules(cwd: string): Promise<void> {
25
+ logger.debug(`Updating submodules in ${cwd}`);
26
+ await runCommand('git submodule foreach --recursive "git checkout main && git pull origin main"', cwd);
27
+ }
28
+
29
+ export async function checkoutOrphan(branch: string, cwd: string): Promise<void> {
30
+ await runCommand(`git checkout --orphan ${branch}`, cwd);
31
+ }
32
+
33
+ export async function addAll(cwd: string): Promise<void> {
34
+ await runCommand('git add -A', cwd);
35
+ }
36
+
37
+ export async function commit(message: string, cwd: string): Promise<void> {
38
+ // Escape quotes in message if needed, for now assuming simple messages
39
+ await runCommand(`git commit -m "${message}"`, cwd);
40
+ }
41
+
42
+ export async function deleteBranch(branch: string, cwd: string): Promise<void> {
43
+ await runCommand(`git branch -D ${branch}`, cwd);
44
+ }
45
+
46
+ export async function renameBranch(branch: string, cwd: string): Promise<void> {
47
+ await runCommand(`git branch -m ${branch}`, cwd);
48
+ }
49
+
50
+ export async function removeRemote(remote: string, cwd: string): Promise<void> {
51
+ await runCommand(`git remote remove ${remote}`, cwd);
52
+ }
53
+
54
+ export async function renameRemote(oldName: string, newName: string, cwd: string): Promise<void> {
55
+ await runCommand(`git remote rename ${oldName} ${newName}`, cwd);
56
+ }
57
+
58
+ export async function branchExists(branch: string, cwd: string): Promise<boolean> {
59
+ try {
60
+ await execAsync(`git show-ref --verify --quiet refs/heads/${branch}`, { cwd });
61
+ return true;
62
+ } catch {
63
+ return false;
64
+ }
65
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Resolves a git URL from various shorthand formats.
3
+ *
4
+ * Supported formats:
5
+ * - gh@org/repo -> https://github.com/org/repo.git
6
+ * - gh@org/repo//path -> https://github.com/org/repo.git//path
7
+ * - https://github.com/org/repo -> https://github.com/org/repo.git
8
+ * - https://github.com/org/repo.git -> https://github.com/org/repo.git
9
+ *
10
+ * @param url The URL string to resolve
11
+ * @returns The fully qualified git URL with .git extension
12
+ */
13
+ export function resolveGitUrl(url: string): string {
14
+ if (!url) {
15
+ throw new Error('URL cannot be empty');
16
+ }
17
+
18
+ let resolved = url;
19
+
20
+ // Handle gh@ syntax
21
+ if (resolved.startsWith('gh@')) {
22
+ resolved = resolved.replace(/^gh@/, 'https://github.com/');
23
+ }
24
+
25
+ // Handle subpaths (split by //)
26
+ // We must be careful not to split the protocol (e.g. https://)
27
+ const protocolMatch = resolved.match(/^[a-z0-9]+:\/\//i);
28
+ let splitIndex = -1;
29
+
30
+ if (protocolMatch) {
31
+ splitIndex = resolved.indexOf('//', protocolMatch[0].length);
32
+ } else {
33
+ splitIndex = resolved.indexOf('//');
34
+ }
35
+
36
+ let repoUrl = resolved;
37
+ let subPath = '';
38
+
39
+ if (splitIndex !== -1) {
40
+ repoUrl = resolved.substring(0, splitIndex);
41
+ subPath = resolved.substring(splitIndex + 2);
42
+ }
43
+
44
+ // Ensure .git extension, but ONLY for remote URLs (not local paths)
45
+ const isLocal = repoUrl.startsWith('/') || repoUrl.startsWith('./') || repoUrl.startsWith('../') || repoUrl.startsWith('file:') || repoUrl.startsWith('~');
46
+
47
+ if (!isLocal && !repoUrl.endsWith('.git')) {
48
+ repoUrl += '.git';
49
+ }
50
+
51
+ // Reconstruction
52
+ if (subPath) {
53
+ return `${repoUrl}//${subPath}`;
54
+ }
55
+
56
+ return repoUrl;
57
+ }