@nexical/cli 0.1.7 → 0.11.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 (241) hide show
  1. package/.github/workflows/deploy.yml +3 -3
  2. package/GEMINI.md +193 -0
  3. package/README.md +317 -104
  4. package/dist/chunk-JYASTIIW.js +42 -0
  5. package/dist/chunk-JYASTIIW.js.map +1 -0
  6. package/dist/chunk-LZ3YQWAR.js +2204 -0
  7. package/dist/chunk-LZ3YQWAR.js.map +1 -0
  8. package/dist/chunk-OKXOCNXP.js +105 -0
  9. package/dist/chunk-OKXOCNXP.js.map +1 -0
  10. package/dist/chunk-OYFWMYPG.js +52 -0
  11. package/dist/chunk-OYFWMYPG.js.map +1 -0
  12. package/dist/chunk-WKERTCM6.js +74 -0
  13. package/dist/chunk-WKERTCM6.js.map +1 -0
  14. package/dist/index.js +32 -5
  15. package/dist/index.js.map +1 -1
  16. package/dist/src/commands/init.d.ts +11 -0
  17. package/dist/src/commands/init.js +89 -0
  18. package/dist/src/commands/init.js.map +1 -0
  19. package/dist/src/commands/module/add.d.ts +14 -0
  20. package/dist/src/commands/module/add.js +136 -0
  21. package/dist/src/commands/module/add.js.map +1 -0
  22. package/dist/src/commands/module/list.d.ts +10 -0
  23. package/dist/src/commands/module/list.js +73 -0
  24. package/dist/src/commands/module/list.js.map +1 -0
  25. package/dist/src/commands/module/remove.d.ts +12 -0
  26. package/dist/src/commands/module/remove.js +71 -0
  27. package/dist/src/commands/module/remove.js.map +1 -0
  28. package/dist/src/commands/module/update.d.ts +11 -0
  29. package/dist/src/commands/module/update.js +52 -0
  30. package/dist/src/commands/module/update.js.map +1 -0
  31. package/dist/src/commands/run.d.ts +11 -0
  32. package/dist/src/commands/run.js +93 -0
  33. package/dist/src/commands/run.js.map +1 -0
  34. package/dist/src/commands/{login.d.ts → setup.d.ts} +2 -2
  35. package/dist/src/commands/setup.js +62 -0
  36. package/dist/src/commands/setup.js.map +1 -0
  37. package/dist/src/utils/discovery.d.ts +13 -0
  38. package/dist/src/utils/discovery.js +9 -0
  39. package/dist/src/utils/git.d.ts +16 -0
  40. package/dist/src/utils/git.js +29 -0
  41. package/dist/src/utils/git.js.map +1 -0
  42. package/dist/src/utils/url-resolver.d.ts +15 -0
  43. package/dist/src/utils/url-resolver.js +9 -0
  44. package/dist/src/utils/url-resolver.js.map +1 -0
  45. package/index.ts +29 -5
  46. package/package.json +32 -30
  47. package/src/commands/init.ts +86 -0
  48. package/src/commands/module/add.ts +169 -0
  49. package/src/commands/module/list.ts +69 -0
  50. package/src/commands/module/remove.ts +74 -0
  51. package/src/commands/module/update.ts +50 -0
  52. package/src/commands/run.ts +98 -0
  53. package/src/commands/setup.ts +74 -0
  54. package/src/utils/discovery.ts +134 -0
  55. package/src/utils/git.ts +65 -0
  56. package/src/utils/url-resolver.ts +57 -0
  57. package/test/e2e/lifecycle.e2e.test.ts +153 -0
  58. package/test/integration/commands/init.integration.test.ts +85 -0
  59. package/test/integration/commands/module.integration.test.ts +144 -0
  60. package/test/integration/commands/run.integration.test.ts +90 -0
  61. package/test/integration/utils/command-loading.integration.test.ts +80 -0
  62. package/test/unit/commands/init.test.ts +153 -0
  63. package/test/unit/commands/module/add.test.ts +262 -0
  64. package/test/unit/commands/module/list.test.ts +115 -0
  65. package/test/unit/commands/module/remove.test.ts +89 -0
  66. package/test/unit/commands/module/update.test.ts +91 -0
  67. package/test/unit/commands/run.test.ts +252 -0
  68. package/test/unit/commands/setup.test.ts +169 -0
  69. package/test/unit/utils/command-discovery.test.ts +176 -0
  70. package/test/unit/utils/git.test.ts +152 -0
  71. package/test/unit/utils/integration-helpers.test.ts +72 -0
  72. package/test/unit/utils/url-resolver.test.ts +39 -0
  73. package/test/utils/integration-helpers.ts +66 -0
  74. package/vitest.e2e.config.ts +0 -1
  75. package/dist/chunk-JDRAVUKK.js +0 -48
  76. package/dist/chunk-JDRAVUKK.js.map +0 -1
  77. package/dist/src/commands/admin/create-user.d.ts +0 -15
  78. package/dist/src/commands/admin/create-user.js +0 -49
  79. package/dist/src/commands/admin/create-user.js.map +0 -1
  80. package/dist/src/commands/branch/create.d.ts +0 -19
  81. package/dist/src/commands/branch/create.js +0 -59
  82. package/dist/src/commands/branch/create.js.map +0 -1
  83. package/dist/src/commands/branch/delete.d.ts +0 -15
  84. package/dist/src/commands/branch/delete.js +0 -50
  85. package/dist/src/commands/branch/delete.js.map +0 -1
  86. package/dist/src/commands/branch/get.d.ts +0 -15
  87. package/dist/src/commands/branch/get.js +0 -53
  88. package/dist/src/commands/branch/get.js.map +0 -1
  89. package/dist/src/commands/branch/list.d.ts +0 -15
  90. package/dist/src/commands/branch/list.js +0 -51
  91. package/dist/src/commands/branch/list.js.map +0 -1
  92. package/dist/src/commands/job/get.d.ts +0 -15
  93. package/dist/src/commands/job/get.js +0 -62
  94. package/dist/src/commands/job/get.js.map +0 -1
  95. package/dist/src/commands/job/list.d.ts +0 -15
  96. package/dist/src/commands/job/list.js +0 -57
  97. package/dist/src/commands/job/list.js.map +0 -1
  98. package/dist/src/commands/job/logs.d.ts +0 -15
  99. package/dist/src/commands/job/logs.js +0 -67
  100. package/dist/src/commands/job/logs.js.map +0 -1
  101. package/dist/src/commands/job/trigger.d.ts +0 -19
  102. package/dist/src/commands/job/trigger.js +0 -74
  103. package/dist/src/commands/job/trigger.js.map +0 -1
  104. package/dist/src/commands/login.js +0 -31
  105. package/dist/src/commands/login.js.map +0 -1
  106. package/dist/src/commands/project/create.d.ts +0 -24
  107. package/dist/src/commands/project/create.js +0 -63
  108. package/dist/src/commands/project/create.js.map +0 -1
  109. package/dist/src/commands/project/delete.d.ts +0 -20
  110. package/dist/src/commands/project/delete.js +0 -58
  111. package/dist/src/commands/project/delete.js.map +0 -1
  112. package/dist/src/commands/project/get.d.ts +0 -15
  113. package/dist/src/commands/project/get.js +0 -49
  114. package/dist/src/commands/project/get.js.map +0 -1
  115. package/dist/src/commands/project/list.d.ts +0 -15
  116. package/dist/src/commands/project/list.js +0 -45
  117. package/dist/src/commands/project/list.js.map +0 -1
  118. package/dist/src/commands/project/update.d.ts +0 -19
  119. package/dist/src/commands/project/update.js +0 -66
  120. package/dist/src/commands/project/update.js.map +0 -1
  121. package/dist/src/commands/team/create.d.ts +0 -19
  122. package/dist/src/commands/team/create.js +0 -45
  123. package/dist/src/commands/team/create.js.map +0 -1
  124. package/dist/src/commands/team/delete.d.ts +0 -20
  125. package/dist/src/commands/team/delete.js +0 -52
  126. package/dist/src/commands/team/delete.js.map +0 -1
  127. package/dist/src/commands/team/get.d.ts +0 -15
  128. package/dist/src/commands/team/get.js +0 -42
  129. package/dist/src/commands/team/get.js.map +0 -1
  130. package/dist/src/commands/team/list.d.ts +0 -8
  131. package/dist/src/commands/team/list.js +0 -30
  132. package/dist/src/commands/team/list.js.map +0 -1
  133. package/dist/src/commands/team/member/invite.d.ts +0 -20
  134. package/dist/src/commands/team/member/invite.js +0 -54
  135. package/dist/src/commands/team/member/invite.js.map +0 -1
  136. package/dist/src/commands/team/member/remove.d.ts +0 -15
  137. package/dist/src/commands/team/member/remove.js +0 -43
  138. package/dist/src/commands/team/member/remove.js.map +0 -1
  139. package/dist/src/commands/team/update.d.ts +0 -19
  140. package/dist/src/commands/team/update.js +0 -55
  141. package/dist/src/commands/team/update.js.map +0 -1
  142. package/dist/src/commands/token/generate.d.ts +0 -19
  143. package/dist/src/commands/token/generate.js +0 -48
  144. package/dist/src/commands/token/generate.js.map +0 -1
  145. package/dist/src/commands/token/list.d.ts +0 -8
  146. package/dist/src/commands/token/list.js +0 -31
  147. package/dist/src/commands/token/list.js.map +0 -1
  148. package/dist/src/commands/token/revoke.d.ts +0 -15
  149. package/dist/src/commands/token/revoke.js +0 -38
  150. package/dist/src/commands/token/revoke.js.map +0 -1
  151. package/dist/src/commands/whoami.d.ts +0 -8
  152. package/dist/src/commands/whoami.js +0 -26
  153. package/dist/src/commands/whoami.js.map +0 -1
  154. package/dist/src/utils/nexical-client.d.ts +0 -10
  155. package/dist/src/utils/nexical-client.js +0 -12
  156. package/src/commands/admin/create-user.ts +0 -46
  157. package/src/commands/branch/create.ts +0 -57
  158. package/src/commands/branch/delete.ts +0 -47
  159. package/src/commands/branch/get.ts +0 -50
  160. package/src/commands/branch/list.ts +0 -50
  161. package/src/commands/job/get.ts +0 -59
  162. package/src/commands/job/list.ts +0 -56
  163. package/src/commands/job/logs.ts +0 -67
  164. package/src/commands/job/trigger.ts +0 -73
  165. package/src/commands/login.ts +0 -31
  166. package/src/commands/project/create.ts +0 -61
  167. package/src/commands/project/delete.ts +0 -56
  168. package/src/commands/project/get.ts +0 -46
  169. package/src/commands/project/list.ts +0 -44
  170. package/src/commands/project/update.ts +0 -63
  171. package/src/commands/team/create.ts +0 -43
  172. package/src/commands/team/delete.ts +0 -50
  173. package/src/commands/team/get.ts +0 -39
  174. package/src/commands/team/list.ts +0 -26
  175. package/src/commands/team/member/invite.ts +0 -56
  176. package/src/commands/team/member/remove.ts +0 -40
  177. package/src/commands/team/update.ts +0 -53
  178. package/src/commands/token/generate.ts +0 -45
  179. package/src/commands/token/list.ts +0 -27
  180. package/src/commands/token/revoke.ts +0 -35
  181. package/src/commands/whoami.ts +0 -21
  182. package/src/utils/nexical-client.ts +0 -47
  183. package/test/e2e/auth.e2e.test.ts +0 -46
  184. package/test/e2e/job-workflow.e2e.test.ts +0 -33
  185. package/test/e2e/project-lifecycle.e2e.test.ts +0 -48
  186. package/test/e2e/setup.ts +0 -237
  187. package/test/e2e/utils.ts +0 -33
  188. package/test/integration/commands/admin/create-user.test.ts +0 -51
  189. package/test/integration/commands/branch/create.test.ts +0 -51
  190. package/test/integration/commands/branch/delete.test.ts +0 -43
  191. package/test/integration/commands/branch/get.test.ts +0 -49
  192. package/test/integration/commands/branch/list.test.ts +0 -47
  193. package/test/integration/commands/job/get.test.ts +0 -54
  194. package/test/integration/commands/job/list.test.ts +0 -47
  195. package/test/integration/commands/job/logs.test.ts +0 -47
  196. package/test/integration/commands/job/trigger.test.ts +0 -57
  197. package/test/integration/commands/login.test.ts +0 -62
  198. package/test/integration/commands/project/create.test.ts +0 -53
  199. package/test/integration/commands/project/delete.test.ts +0 -43
  200. package/test/integration/commands/project/get.test.ts +0 -51
  201. package/test/integration/commands/project/list.test.ts +0 -47
  202. package/test/integration/commands/project/update.test.ts +0 -53
  203. package/test/integration/commands/team/create.test.ts +0 -53
  204. package/test/integration/commands/team/delete.test.ts +0 -43
  205. package/test/integration/commands/team/get.test.ts +0 -50
  206. package/test/integration/commands/team/list.test.ts +0 -47
  207. package/test/integration/commands/team/member/invite.test.ts +0 -46
  208. package/test/integration/commands/team/member/remove.test.ts +0 -43
  209. package/test/integration/commands/team/update.test.ts +0 -50
  210. package/test/integration/commands/token/generate.test.ts +0 -51
  211. package/test/integration/commands/token/list.test.ts +0 -47
  212. package/test/integration/commands/token/revoke.test.ts +0 -43
  213. package/test/integration/commands/whoami.test.ts +0 -49
  214. package/test/unit/commands/admin/create-user.test.ts +0 -51
  215. package/test/unit/commands/branch/create.test.ts +0 -57
  216. package/test/unit/commands/branch/delete.test.ts +0 -49
  217. package/test/unit/commands/branch/get.test.ts +0 -67
  218. package/test/unit/commands/branch/list.test.ts +0 -62
  219. package/test/unit/commands/job/get.test.ts +0 -76
  220. package/test/unit/commands/job/list.test.ts +0 -62
  221. package/test/unit/commands/job/logs.test.ts +0 -60
  222. package/test/unit/commands/job/trigger.test.ts +0 -75
  223. package/test/unit/commands/login.test.ts +0 -64
  224. package/test/unit/commands/project/create.test.ts +0 -64
  225. package/test/unit/commands/project/delete.test.ts +0 -72
  226. package/test/unit/commands/project/get.test.ts +0 -73
  227. package/test/unit/commands/project/list.test.ts +0 -62
  228. package/test/unit/commands/project/update.test.ts +0 -58
  229. package/test/unit/commands/team/create.test.ts +0 -68
  230. package/test/unit/commands/team/delete.test.ts +0 -71
  231. package/test/unit/commands/team/get.test.ts +0 -70
  232. package/test/unit/commands/team/list.test.ts +0 -56
  233. package/test/unit/commands/team/member/invite.test.ts +0 -52
  234. package/test/unit/commands/team/member/remove.test.ts +0 -49
  235. package/test/unit/commands/team/update.test.ts +0 -63
  236. package/test/unit/commands/token/generate.test.ts +0 -65
  237. package/test/unit/commands/token/list.test.ts +0 -58
  238. package/test/unit/commands/token/revoke.test.ts +0 -49
  239. package/test/unit/commands/whoami.test.ts +0 -49
  240. package/test/unit/utils/nexical-client.test.ts +0 -113
  241. /package/dist/src/utils/{nexical-client.js.map → discovery.js.map} +0 -0
@@ -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
+ }
@@ -0,0 +1,153 @@
1
+ import { describe, it, expect, beforeEach, afterAll } from 'vitest';
2
+ import { createTempDir, createMockRepo, runCLI } from '../utils/integration-helpers.js';
3
+ import path from 'node:path';
4
+ import fs from 'fs-extra';
5
+ import { execa } from 'execa';
6
+
7
+ describe('CLI Lifecycle E2E', () => {
8
+ let testRoot: string;
9
+ let starterDir: string;
10
+ let moduleDir: string;
11
+ let mockAstroDir: string;
12
+
13
+ beforeEach(async () => {
14
+ testRoot = await createTempDir('e2e-life-');
15
+
16
+ // 1. Setup Mock "Astro" package
17
+ // We create a local package that impersonates 'astro'.
18
+ // This avoids npm install downloading the internet.
19
+ mockAstroDir = path.join(testRoot, 'mock-astro');
20
+ await fs.ensureDir(mockAstroDir);
21
+ await fs.outputFile(path.join(mockAstroDir, 'package.json'), JSON.stringify({
22
+ name: 'astro',
23
+ version: '1.0.0',
24
+ bin: {
25
+ astro: './bin.js'
26
+ }
27
+ }));
28
+ // The mock binary acts as "npx astro"
29
+ await fs.outputFile(path.join(mockAstroDir, 'bin.js'), `#!/usr/bin/env node
30
+ const fs = require('fs');
31
+ const path = require('path');
32
+ const args = process.argv.slice(2);
33
+ console.log("MOCK_ASTRO_EXECUTED " + args.join(' '));
34
+
35
+ if (args[0] === 'build') {
36
+ const dist = path.join(process.cwd(), 'dist');
37
+ if (!fs.existsSync(dist)) fs.mkdirSync(dist, { recursive: true });
38
+ fs.writeFileSync(path.join(dist, 'index.html'), '<html></html>');
39
+ }
40
+ `);
41
+ await fs.chmod(path.join(mockAstroDir, 'bin.js'), '755');
42
+
43
+ // 2. Setup Mock Starter Repo
44
+ starterDir = path.join(testRoot, 'starter-repo');
45
+ // We need a package.json that points 'astro' to our mock
46
+ await createMockRepo(starterDir, {
47
+ 'package.json': JSON.stringify({
48
+ name: 'e2e-project',
49
+ version: '0.0.0',
50
+ dependencies: {
51
+ // Use file: protocol to point to local mock
52
+ 'astro': `file:${mockAstroDir}`
53
+ },
54
+ scripts: {
55
+ 'build': 'astro build',
56
+ 'dev': 'astro dev',
57
+ 'preview': 'astro preview',
58
+ 'setup': 'echo setup'
59
+ }
60
+ }),
61
+ 'README.md': '# E2E Starter',
62
+ 'nexical.yml': 'name: e2e-test\nversion: 0.0.1', // ESSENTIAL for CLI to recognize project
63
+ 'src/pages/index.astro': '--- ---',
64
+ 'src/core/index.ts': '// core',
65
+ 'src/core/package.json': JSON.stringify({
66
+ scripts: {
67
+ 'build': 'astro build',
68
+ 'dev': 'astro dev',
69
+ 'preview': 'astro preview'
70
+ }
71
+ })
72
+ });
73
+
74
+ // 3. Setup Mock Module Repo
75
+ moduleDir = path.join(testRoot, 'module-repo');
76
+ await createMockRepo(moduleDir, {
77
+ 'package.json': JSON.stringify({ name: 'my-module', version: '0.1.0' }),
78
+ 'module.yaml': 'name: my-test-module\nversion: 0.1.0', // Name matches E2E expectation
79
+ 'index.ts': 'console.log("module")'
80
+ });
81
+ });
82
+
83
+ afterAll(async () => {
84
+ if (testRoot) await fs.remove(testRoot);
85
+ });
86
+
87
+ it('should complete a full project lifecycle', async () => {
88
+ const projectDir = path.join(testRoot, 'my-project');
89
+
90
+ const env = {
91
+ // Essential for git inside init/module commands
92
+ GIT_AUTHOR_NAME: 'Test User',
93
+ GIT_AUTHOR_EMAIL: 'test@example.com',
94
+ GIT_COMMITTER_NAME: 'Test User',
95
+ GIT_COMMITTER_EMAIL: 'test@example.com',
96
+ GIT_ALLOW_PROTOCOL: 'file'
97
+ // DEBUG: 'true' - Removed to reduce noise
98
+ };
99
+
100
+ // --- STEP 1: INIT ---
101
+ // Run: nexical init my-project --repo <starter>
102
+ const initResult = await runCLI([
103
+ 'init',
104
+ 'my-project',
105
+ '--repo', starterDir
106
+ ], testRoot, { env });
107
+
108
+ // 4. Check git initialization (preserved history)
109
+ const { stdout: log } = await execa('git', ['log', '--oneline'], { cwd: projectDir });
110
+ const lines = log.split('\n').filter(Boolean);
111
+ expect(lines.length).toBeGreaterThanOrEqual(2);
112
+ expect(lines[0]).toContain('Initial site commit');
113
+
114
+ // --- STEP 2: MODULE ADD ---
115
+ // Run: nexical module add <module>
116
+ const modResult = await runCLI([
117
+ 'module',
118
+ 'add',
119
+ moduleDir,
120
+ 'my-test-module' // Explicit name
121
+ ], projectDir, { env });
122
+
123
+ if (modResult.exitCode !== 0) {
124
+ console.error('Module Add Failed:', modResult.stderr || modResult.stdout);
125
+ }
126
+ expect(modResult.exitCode).toBe(0);
127
+ expect(fs.existsSync(path.join(projectDir, 'modules/my-test-module'))).toBe(true);
128
+
129
+ // --- STEP 3: BUILD ---
130
+ // Run: nexical run build
131
+ // Should trigger our mock astro binary
132
+ const buildResult = await runCLI(['run', 'build'], projectDir, { env });
133
+
134
+ if (buildResult.exitCode !== 0) {
135
+ console.log(buildResult.stderr || buildResult.stdout);
136
+ }
137
+
138
+ expect(buildResult.exitCode).toBe(0);
139
+ expect(buildResult.stdout).toContain('MOCK_ASTRO_EXECUTED build');
140
+
141
+ // --- STEP 4: PREVIEW ---
142
+ // Run: nexical run preview
143
+ const previewResult = await runCLI(['run', 'preview'], projectDir, { env });
144
+
145
+ expect(previewResult.exitCode).toBe(0);
146
+ expect(previewResult.stdout).toContain('MOCK_ASTRO_EXECUTED preview');
147
+
148
+ // --- STEP 5: CLEAN ---
149
+ // Clean is now handled by manual file operations or external scripts,
150
+ // it's no longer a top-level command.
151
+
152
+ }, 120000); // Long timeout for full chain
153
+ });
@@ -0,0 +1,85 @@
1
+ import { CLI } from '@nexical/cli-core';
2
+ import { describe, it, expect, beforeEach, afterEach, afterAll } from 'vitest';
3
+ import InitCommand from '../../../src/commands/init.js';
4
+ import { createTempDir, createMockRepo, cleanupTestRoot } from '../../utils/integration-helpers.js';
5
+ import path from 'node:path';
6
+ import fs from 'fs-extra';
7
+ import { execa } from 'execa';
8
+
9
+ describe('InitCommand Integration', () => {
10
+ let tempDir: string;
11
+ let starterRepoDir: string;
12
+
13
+ beforeEach(async () => {
14
+ tempDir = await createTempDir('init-integration-');
15
+ const starterDir = await createTempDir('starter-repo-');
16
+
17
+ // precise setup of a starter repo
18
+ starterRepoDir = await createMockRepo(starterDir, {
19
+ 'package.json': JSON.stringify({
20
+ name: 'nexical-starter',
21
+ version: '0.0.0',
22
+ scripts: {
23
+ setup: 'echo setup'
24
+ },
25
+ dependencies: {
26
+ 'is-odd': '3.0.1'
27
+ }
28
+ }),
29
+ 'README.md': '# Starter Template'
30
+ });
31
+
32
+ // Set Git Identity for the test process so InitCommand's commit works in CI
33
+ process.env.GIT_AUTHOR_NAME = 'Test User';
34
+ process.env.GIT_AUTHOR_EMAIL = 'test@example.com';
35
+ process.env.GIT_COMMITTER_NAME = 'Test User';
36
+ process.env.GIT_COMMITTER_EMAIL = 'test@example.com';
37
+ // Allow file protocol for local cloning in CI
38
+ process.env.GIT_ALLOW_PROTOCOL = 'file';
39
+ });
40
+
41
+ afterAll(async () => {
42
+ // await cleanupTestRoot(); // conflicting with parallel tests
43
+ if (tempDir) await fs.remove(tempDir);
44
+ });
45
+
46
+ it('should initialize a new project from a local git repo', async () => {
47
+ const targetProjectName = 'my-new-project';
48
+ const targetPath = path.join(tempDir, targetProjectName);
49
+ const cli = new CLI({ commandName: 'nexical' });
50
+
51
+ const command = new InitCommand(cli);
52
+
53
+ // Capture stdout/stderr? InitCommand uses consola.
54
+ // For integration, we care about the FS side effects.
55
+
56
+ await command.run({
57
+ directory: targetPath,
58
+ repo: starterRepoDir // Passing local path as repo URL
59
+ });
60
+
61
+ // 1. Check directory exists
62
+ expect(fs.existsSync(targetPath)).toBe(true);
63
+
64
+ // 2. Check files cloned
65
+ expect(fs.existsSync(path.join(targetPath, 'package.json'))).toBe(true);
66
+ expect(fs.existsSync(path.join(targetPath, 'README.md'))).toBe(true);
67
+
68
+ // 3. Check git initialization
69
+ expect(fs.existsSync(path.join(targetPath, '.git'))).toBe(true);
70
+
71
+ // 4. Check git initialization (history should be preserved + one new commit)
72
+ const { stdout: log } = await execa('git', ['log', '--oneline'], { cwd: targetPath });
73
+ const lines = log.split('\n').filter(Boolean);
74
+ expect(lines.length).toBe(2); // Should have "Initial site commit" and "Initial commit"
75
+ expect(lines[0]).toContain('Initial site commit');
76
+ expect(lines[1]).toContain('Initial commit');
77
+
78
+ // 5. Check dependencies (optional, but command tries to install them)
79
+ // Since we are mocking the repo, it doesn't have a real lockfile or valid deps,
80
+ // so `npm install` might have failed or done nothing.
81
+ // However, `InitCommand` runs `npm install`. If that fails, the command throws/exits.
82
+ // We provided a minimal package.json so it should succeed.
83
+ expect(fs.existsSync(path.join(targetPath, 'node_modules'))).toBe(true);
84
+ }, 60000); // Increase timeout for real git/npm ops
85
+ });
@@ -0,0 +1,144 @@
1
+ import { CLI } from '@nexical/cli-core';
2
+ import { describe, it, expect, beforeEach, afterEach, afterAll, vi } from 'vitest';
3
+ import ModuleAddCommand from '../../../src/commands/module/add.js';
4
+ import ModuleRemoveCommand from '../../../src/commands/module/remove.js';
5
+ import ModuleListCommand from '../../../src/commands/module/list.js';
6
+ import ModuleUpdateCommand from '../../../src/commands/module/update.js';
7
+
8
+ import { createTempDir, createMockRepo, cleanupTestRoot } from '../../utils/integration-helpers.js';
9
+ import path from 'node:path';
10
+ import fs from 'fs-extra';
11
+
12
+ // Mock picocolors to return strings as-is for easy matching
13
+ vi.mock('picocolors', () => ({
14
+ default: {
15
+ bold: (s: string) => s,
16
+ cyan: (s: string) => s,
17
+ yellow: (s: string) => s,
18
+ dim: (s: string) => s,
19
+ red: (s: string) => s,
20
+ green: (s: string) => s,
21
+ blue: (s: string) => s,
22
+ magenta: (s: string) => s,
23
+ }
24
+ }));
25
+
26
+ describe('Module Commands Integration', () => {
27
+ let projectDir: string;
28
+ let moduleRepo: string;
29
+ let consoleTableSpy: any;
30
+ let consoleLogSpy: any;
31
+
32
+ beforeEach(async () => {
33
+ // 1. Create a "Project" that is a git repo
34
+ const temp = await createTempDir('module-project-');
35
+ projectDir = await createMockRepo(temp, {
36
+ 'package.json': '{"name": "test-project", "version": "1.0.0"}',
37
+ 'nexical.yaml': 'site: test\nmodules: []'
38
+ });
39
+
40
+ // Allow file protocol for submodules in this repo
41
+ // await execa('git', ['config', 'protocol.file.allow', 'always'], { cwd: projectDir }); // Config approach failed
42
+ process.env.GIT_ALLOW_PROTOCOL = 'file';
43
+
44
+ // 2. Create a "Module" that is a SEPARATE git repo
45
+ const modTemp = await createTempDir('module-source-');
46
+ moduleRepo = await createMockRepo(modTemp, {
47
+ 'package.json': '{"name": "my-module", "version": "1.0.0", "description": "Awesome module"}',
48
+ 'module.yaml': 'name: my-module\nversion: 1.0.0',
49
+ 'index.ts': 'export const hello = "world";'
50
+ });
51
+
52
+ consoleTableSpy = vi.spyOn(console, 'table').mockImplementation(() => { });
53
+ consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => { });
54
+
55
+ // Switch CWD to project for commands to find root
56
+ // Note: process.chdir behavior might persist, so we rely on mocking or careful cleanup
57
+ // But integration tests run sequentially in same thread usually with vitest unless configured otherwise.
58
+ // We will pass specific CWD to commands if possible, OR chdir and restore.
59
+ });
60
+
61
+ afterEach(() => {
62
+ vi.restoreAllMocks();
63
+ });
64
+
65
+ afterAll(async () => {
66
+ await cleanupTestRoot();
67
+ });
68
+
69
+ it('should add, list, update and remove a module', async () => {
70
+ const originalCwd = process.cwd();
71
+ const cli = new CLI({ commandName: 'nexical' });
72
+ try {
73
+ process.chdir(projectDir);
74
+
75
+ // 1. ADD MODULE
76
+ const addCmd = new ModuleAddCommand(cli);
77
+
78
+ await addCmd.init();
79
+ await addCmd.run({ url: moduleRepo, name: 'my-module' });
80
+
81
+ const modulePath = path.join(projectDir, 'modules/my-module');
82
+ expect(fs.existsSync(modulePath)).toBe(true);
83
+ expect(fs.existsSync(path.join(modulePath, 'package.json'))).toBe(true);
84
+
85
+ // Verify nexical.yaml updated
86
+ const config = await fs.readFile(path.join(projectDir, 'nexical.yaml'), 'utf8');
87
+ expect(config).toContain('modules:');
88
+ expect(config).toContain('- my-module');
89
+
90
+ // Check it is a submodule
91
+ // .git file in module dir pointing to gitdir
92
+ expect(fs.existsSync(path.join(modulePath, '.git'))).toBe(true);
93
+ const gitModules = await fs.readFile(path.join(projectDir, '.gitmodules'), 'utf-8');
94
+ expect(gitModules).toContain('path = modules/my-module');
95
+
96
+ // 2. LIST MODULES with valid module
97
+ const listCmd = new ModuleListCommand(cli);
98
+ await listCmd.init();
99
+ await listCmd.run();
100
+
101
+ // Check console.table called with module info
102
+ expect(consoleTableSpy).toHaveBeenCalledWith(expect.arrayContaining([
103
+ expect.objectContaining({
104
+ name: 'my-module',
105
+ version: '1.0.0',
106
+ description: 'Awesome module'
107
+ })
108
+ ]));
109
+
110
+ // 3. UPDATE MODULE
111
+ const updateCmd = new ModuleUpdateCommand(cli);
112
+ await updateCmd.init();
113
+ await updateCmd.run({ name: 'my-module' });
114
+ // Hard to check "update" without changing the remote first.
115
+ // But we verify it ran without throwing.
116
+
117
+ // 4. REMOVE MODULE
118
+ const removeCmd = new ModuleRemoveCommand(cli);
119
+ await removeCmd.init();
120
+ await removeCmd.run({ name: 'my-module' });
121
+
122
+ expect(fs.existsSync(modulePath)).toBe(false);
123
+
124
+ // Verify git cleanup
125
+ // .git/modules/modules/my-module should be gone
126
+ const gitInternalModuleDir = path.join(projectDir, '.git/modules/modules/my-module');
127
+ expect(fs.existsSync(gitInternalModuleDir)).toBe(false);
128
+
129
+ // .gitmodules entry gone? `git rm` usually handles this.
130
+ // Check if .gitmodules file exists (if empty it might remain or be deleted depending on git version, usually implicitly updated)
131
+ if (fs.existsSync(path.join(projectDir, '.gitmodules'))) {
132
+ const updatedGitModules = await fs.readFile(path.join(projectDir, '.gitmodules'), 'utf-8');
133
+ expect(updatedGitModules).not.toContain('modules/my-module');
134
+ }
135
+
136
+ // Verify nexical.yaml updated
137
+ const configRemoved = await fs.readFile(path.join(projectDir, 'nexical.yaml'), 'utf8');
138
+ expect(configRemoved).not.toContain('- my-module');
139
+
140
+ } finally {
141
+ process.chdir(originalCwd);
142
+ }
143
+ });
144
+ });
@@ -0,0 +1,90 @@
1
+ import { CLI } from '@nexical/cli-core';
2
+ import { describe, it, expect, beforeEach, afterEach, afterAll, vi } from 'vitest';
3
+ import RunCommand from '../../../src/commands/run.js';
4
+ import { createTempDir } from '../../utils/integration-helpers.js';
5
+ import path from 'node:path';
6
+ import fs from 'fs-extra';
7
+ import { spawn } from 'child_process';
8
+ import EventEmitter from 'events';
9
+
10
+ vi.mock('child_process', () => ({
11
+ spawn: vi.fn(),
12
+ exec: vi.fn(),
13
+ }));
14
+
15
+ describe('RunCommand Integration', () => {
16
+ let projectDir: string;
17
+ let spawnMock: any;
18
+
19
+ beforeEach(async () => {
20
+ projectDir = await createTempDir('run-project-');
21
+ vi.mocked(spawn).mockClear();
22
+
23
+ // Setup minimal env (New Architecture: no site/ directory)
24
+ await fs.ensureDir(projectDir);
25
+ await fs.outputFile(path.join(projectDir, 'package.json'), JSON.stringify({
26
+ name: 'nexical-core',
27
+ scripts: {
28
+ 'test-script': 'echo test'
29
+ }
30
+ }));
31
+
32
+ await fs.ensureDir(path.join(projectDir, 'modules', 'my-auth'));
33
+ await fs.outputFile(path.join(projectDir, 'modules', 'my-auth', 'package.json'), JSON.stringify({
34
+ scripts: {
35
+ 'seed': 'node seed.js'
36
+ }
37
+ }));
38
+
39
+ spawnMock = vi.mocked(spawn).mockImplementation(() => {
40
+ const child: any = new EventEmitter();
41
+ child.stdout = new EventEmitter();
42
+ child.stderr = new EventEmitter();
43
+ setTimeout(() => child.emit('close', 0), 10);
44
+ child.kill = vi.fn();
45
+ return child;
46
+ });
47
+ });
48
+
49
+ afterEach(() => {
50
+ vi.clearAllMocks();
51
+ vi.restoreAllMocks();
52
+ });
53
+
54
+ afterAll(async () => {
55
+ if (projectDir) await fs.remove(projectDir);
56
+ });
57
+
58
+ it('should run standard npm scripts', async () => {
59
+ const cli = new CLI({ commandName: 'nexical' });
60
+ const command = new RunCommand(cli);
61
+ Object.assign(command, { projectRoot: projectDir });
62
+
63
+ await command.run({ script: 'test-script', args: ['--flag'] });
64
+
65
+ expect(spawnMock).toHaveBeenCalledWith(
66
+ 'npm',
67
+ ['run', 'test-script', '--', '--flag'],
68
+ expect.objectContaining({
69
+ cwd: projectDir
70
+ })
71
+ );
72
+ });
73
+
74
+ it('should run module specific scripts', async () => {
75
+ const cli = new CLI({ commandName: 'nexical' });
76
+ const command = new RunCommand(cli);
77
+ Object.assign(command, { projectRoot: projectDir });
78
+
79
+ await command.run({ script: 'my-auth:seed', args: ['--force'] });
80
+
81
+ // Module scripts run via npm run scriptName inside module dir
82
+ expect(spawnMock).toHaveBeenCalledWith(
83
+ 'npm',
84
+ ['run', 'seed', '--', '--force'],
85
+ expect.objectContaining({
86
+ cwd: path.resolve(projectDir, 'modules', 'my-auth')
87
+ })
88
+ );
89
+ });
90
+ });
@@ -0,0 +1,80 @@
1
+
2
+ import { describe, it, expect, beforeAll, afterAll } from 'vitest';
3
+ import path from 'node:path';
4
+ import fs from 'fs-extra';
5
+ import { execa } from 'execa';
6
+
7
+ const CLI_ENTRY = path.resolve(__dirname, '../../../index.ts');
8
+ const TEST_TMP_DIR = path.resolve(__dirname, '../../.test-tmp/command-loading');
9
+
10
+ import { createRequire } from 'module';
11
+
12
+ const require = createRequire(import.meta.url);
13
+ const tsxPackagePath = require.resolve('tsx/package.json');
14
+ const tsxDir = path.dirname(tsxPackagePath);
15
+ const TSX_BIN = path.resolve(tsxDir, 'dist/cli.mjs');
16
+
17
+ console.log('Using TSX binary at:', TSX_BIN);
18
+
19
+ describe('Command Loading Integration', () => {
20
+ beforeAll(async () => {
21
+ await fs.ensureDir(TEST_TMP_DIR);
22
+ });
23
+
24
+ afterAll(async () => {
25
+ await fs.remove(TEST_TMP_DIR);
26
+ });
27
+
28
+ it('should load commands from modules', async () => {
29
+ // Create nexical.yaml to mock project root
30
+ await fs.writeFile(path.join(TEST_TMP_DIR, 'nexical.yaml'), 'name: test-project');
31
+
32
+ // Setup module structure
33
+ const moduleDir = path.join(TEST_TMP_DIR, 'src/modules/test-mod/src/commands');
34
+ await fs.ensureDir(moduleDir);
35
+
36
+ const commandFile = path.join(moduleDir, 'hello.ts');
37
+ const commandContent = `
38
+ import { BaseCommand } from '@nexical/cli-core';
39
+ export default class HelloCommand extends BaseCommand {
40
+ static description = 'Test hello command';
41
+ static args = {
42
+ args: [{ name: 'name', required: false }]
43
+ };
44
+
45
+ async run(options: any) {
46
+ console.log('Hello from test module!');
47
+ }
48
+ }
49
+ `;
50
+
51
+ const jsCommandContent = `
52
+ export default class HelloCommand {
53
+ constructor(cli) { this.cli = cli; }
54
+ async init() {}
55
+ async runInit(options) { return this.run(options); }
56
+ async run() { console.log('Hello from test module!'); }
57
+ }
58
+ HelloCommand.description = 'Test hello command';
59
+ HelloCommand.args = {};
60
+ `;
61
+
62
+ await fs.writeFile(path.join(moduleDir, 'hello.js'), jsCommandContent);
63
+
64
+ const { stdout, stderr } = await execa('node', [TSX_BIN, CLI_ENTRY, 'hello', '--debug'], {
65
+ cwd: TEST_TMP_DIR,
66
+ reject: false,
67
+ env: {
68
+ ...process.env,
69
+ FORCE_COLOR: '0'
70
+ }
71
+ });
72
+
73
+ if (!stdout.includes('Hello from test module!')) {
74
+ console.log('STDOUT:', stdout);
75
+ console.log('STDERR:', stderr);
76
+ }
77
+
78
+ expect(stdout).toContain('Hello from test module!');
79
+ }, 20000);
80
+ });