@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.
- package/.github/workflows/deploy.yml +3 -3
- package/README.md +317 -104
- package/dist/chunk-JYASTIIW.js +42 -0
- package/dist/chunk-JYASTIIW.js.map +1 -0
- package/dist/chunk-LZ3YQWAR.js +2204 -0
- package/dist/chunk-LZ3YQWAR.js.map +1 -0
- package/dist/chunk-OKXOCNXP.js +105 -0
- package/dist/chunk-OKXOCNXP.js.map +1 -0
- package/dist/chunk-OYFWMYPG.js +52 -0
- package/dist/chunk-OYFWMYPG.js.map +1 -0
- package/dist/chunk-WKERTCM6.js +74 -0
- package/dist/chunk-WKERTCM6.js.map +1 -0
- package/dist/index.js +33 -6
- package/dist/index.js.map +1 -1
- package/dist/src/commands/init.d.ts +11 -0
- package/dist/src/commands/init.js +88 -0
- package/dist/src/commands/init.js.map +1 -0
- package/dist/src/commands/module/add.d.ts +14 -0
- package/dist/src/commands/module/add.js +136 -0
- package/dist/src/commands/module/add.js.map +1 -0
- package/dist/src/commands/module/list.d.ts +10 -0
- package/dist/src/commands/module/list.js +73 -0
- package/dist/src/commands/module/list.js.map +1 -0
- package/dist/src/commands/module/remove.d.ts +12 -0
- package/dist/src/commands/module/remove.js +71 -0
- package/dist/src/commands/module/remove.js.map +1 -0
- package/dist/src/commands/module/update.d.ts +11 -0
- package/dist/src/commands/module/update.js +52 -0
- package/dist/src/commands/module/update.js.map +1 -0
- package/dist/src/commands/run.d.ts +11 -0
- package/dist/src/commands/run.js +93 -0
- package/dist/src/commands/run.js.map +1 -0
- package/dist/src/utils/discovery.d.ts +13 -0
- package/dist/src/utils/discovery.js +9 -0
- package/dist/src/utils/git.d.ts +16 -0
- package/dist/src/utils/git.js +29 -0
- package/dist/src/utils/git.js.map +1 -0
- package/dist/src/utils/url-resolver.d.ts +15 -0
- package/dist/src/utils/url-resolver.js +9 -0
- package/dist/src/utils/url-resolver.js.map +1 -0
- package/index.ts +29 -5
- package/package.json +32 -30
- package/src/commands/init.ts +85 -0
- package/src/commands/module/add.ts +169 -0
- package/src/commands/module/list.ts +69 -0
- package/src/commands/module/remove.ts +74 -0
- package/src/commands/module/update.ts +50 -0
- package/src/commands/run.ts +98 -0
- package/src/utils/discovery.ts +134 -0
- package/src/utils/git.ts +65 -0
- package/src/utils/url-resolver.ts +57 -0
- package/test/e2e/lifecycle.e2e.test.ts +152 -0
- package/test/integration/commands/init.integration.test.ts +82 -0
- package/test/integration/commands/module.integration.test.ts +144 -0
- package/test/integration/commands/run.integration.test.ts +90 -0
- package/test/integration/utils/command-loading.integration.test.ts +80 -0
- package/test/unit/commands/init.test.ts +153 -0
- package/test/unit/commands/module/add.test.ts +262 -0
- package/test/unit/commands/module/list.test.ts +115 -0
- package/test/unit/commands/module/remove.test.ts +89 -0
- package/test/unit/commands/module/update.test.ts +91 -0
- package/test/unit/commands/run.test.ts +252 -0
- package/test/unit/utils/command-discovery.test.ts +176 -0
- package/test/unit/utils/git.test.ts +152 -0
- package/test/unit/utils/integration-helpers.test.ts +72 -0
- package/test/unit/utils/url-resolver.test.ts +39 -0
- package/test/utils/integration-helpers.ts +66 -0
- package/vitest.e2e.config.ts +0 -1
- package/dist/chunk-JDRAVUKK.js +0 -48
- package/dist/chunk-JDRAVUKK.js.map +0 -1
- package/dist/src/commands/admin/create-user.d.ts +0 -15
- package/dist/src/commands/admin/create-user.js +0 -49
- package/dist/src/commands/admin/create-user.js.map +0 -1
- package/dist/src/commands/branch/create.d.ts +0 -19
- package/dist/src/commands/branch/create.js +0 -59
- package/dist/src/commands/branch/create.js.map +0 -1
- package/dist/src/commands/branch/delete.d.ts +0 -15
- package/dist/src/commands/branch/delete.js +0 -50
- package/dist/src/commands/branch/delete.js.map +0 -1
- package/dist/src/commands/branch/get.d.ts +0 -15
- package/dist/src/commands/branch/get.js +0 -53
- package/dist/src/commands/branch/get.js.map +0 -1
- package/dist/src/commands/branch/list.d.ts +0 -15
- package/dist/src/commands/branch/list.js +0 -51
- package/dist/src/commands/branch/list.js.map +0 -1
- package/dist/src/commands/job/get.d.ts +0 -15
- package/dist/src/commands/job/get.js +0 -62
- package/dist/src/commands/job/get.js.map +0 -1
- package/dist/src/commands/job/list.d.ts +0 -15
- package/dist/src/commands/job/list.js +0 -57
- package/dist/src/commands/job/list.js.map +0 -1
- package/dist/src/commands/job/logs.d.ts +0 -15
- package/dist/src/commands/job/logs.js +0 -67
- package/dist/src/commands/job/logs.js.map +0 -1
- package/dist/src/commands/job/trigger.d.ts +0 -19
- package/dist/src/commands/job/trigger.js +0 -74
- package/dist/src/commands/job/trigger.js.map +0 -1
- package/dist/src/commands/login.d.ts +0 -8
- package/dist/src/commands/login.js +0 -31
- package/dist/src/commands/login.js.map +0 -1
- package/dist/src/commands/project/create.d.ts +0 -24
- package/dist/src/commands/project/create.js +0 -63
- package/dist/src/commands/project/create.js.map +0 -1
- package/dist/src/commands/project/delete.d.ts +0 -20
- package/dist/src/commands/project/delete.js +0 -58
- package/dist/src/commands/project/delete.js.map +0 -1
- package/dist/src/commands/project/get.d.ts +0 -15
- package/dist/src/commands/project/get.js +0 -49
- package/dist/src/commands/project/get.js.map +0 -1
- package/dist/src/commands/project/list.d.ts +0 -15
- package/dist/src/commands/project/list.js +0 -45
- package/dist/src/commands/project/list.js.map +0 -1
- package/dist/src/commands/project/update.d.ts +0 -19
- package/dist/src/commands/project/update.js +0 -66
- package/dist/src/commands/project/update.js.map +0 -1
- package/dist/src/commands/team/create.d.ts +0 -19
- package/dist/src/commands/team/create.js +0 -45
- package/dist/src/commands/team/create.js.map +0 -1
- package/dist/src/commands/team/delete.d.ts +0 -20
- package/dist/src/commands/team/delete.js +0 -52
- package/dist/src/commands/team/delete.js.map +0 -1
- package/dist/src/commands/team/get.d.ts +0 -15
- package/dist/src/commands/team/get.js +0 -42
- package/dist/src/commands/team/get.js.map +0 -1
- package/dist/src/commands/team/list.d.ts +0 -8
- package/dist/src/commands/team/list.js +0 -30
- package/dist/src/commands/team/list.js.map +0 -1
- package/dist/src/commands/team/member/invite.d.ts +0 -20
- package/dist/src/commands/team/member/invite.js +0 -54
- package/dist/src/commands/team/member/invite.js.map +0 -1
- package/dist/src/commands/team/member/remove.d.ts +0 -15
- package/dist/src/commands/team/member/remove.js +0 -43
- package/dist/src/commands/team/member/remove.js.map +0 -1
- package/dist/src/commands/team/update.d.ts +0 -19
- package/dist/src/commands/team/update.js +0 -55
- package/dist/src/commands/team/update.js.map +0 -1
- package/dist/src/commands/token/generate.d.ts +0 -19
- package/dist/src/commands/token/generate.js +0 -48
- package/dist/src/commands/token/generate.js.map +0 -1
- package/dist/src/commands/token/list.d.ts +0 -8
- package/dist/src/commands/token/list.js +0 -31
- package/dist/src/commands/token/list.js.map +0 -1
- package/dist/src/commands/token/revoke.d.ts +0 -15
- package/dist/src/commands/token/revoke.js +0 -38
- package/dist/src/commands/token/revoke.js.map +0 -1
- package/dist/src/commands/whoami.d.ts +0 -8
- package/dist/src/commands/whoami.js +0 -26
- package/dist/src/commands/whoami.js.map +0 -1
- package/dist/src/utils/nexical-client.d.ts +0 -10
- package/dist/src/utils/nexical-client.js +0 -12
- package/src/commands/admin/create-user.ts +0 -46
- package/src/commands/branch/create.ts +0 -57
- package/src/commands/branch/delete.ts +0 -47
- package/src/commands/branch/get.ts +0 -50
- package/src/commands/branch/list.ts +0 -50
- package/src/commands/job/get.ts +0 -59
- package/src/commands/job/list.ts +0 -56
- package/src/commands/job/logs.ts +0 -67
- package/src/commands/job/trigger.ts +0 -73
- package/src/commands/login.ts +0 -31
- package/src/commands/project/create.ts +0 -61
- package/src/commands/project/delete.ts +0 -56
- package/src/commands/project/get.ts +0 -46
- package/src/commands/project/list.ts +0 -44
- package/src/commands/project/update.ts +0 -63
- package/src/commands/team/create.ts +0 -43
- package/src/commands/team/delete.ts +0 -50
- package/src/commands/team/get.ts +0 -39
- package/src/commands/team/list.ts +0 -26
- package/src/commands/team/member/invite.ts +0 -56
- package/src/commands/team/member/remove.ts +0 -40
- package/src/commands/team/update.ts +0 -53
- package/src/commands/token/generate.ts +0 -45
- package/src/commands/token/list.ts +0 -27
- package/src/commands/token/revoke.ts +0 -35
- package/src/commands/whoami.ts +0 -21
- package/src/utils/nexical-client.ts +0 -47
- package/test/e2e/auth.e2e.test.ts +0 -46
- package/test/e2e/job-workflow.e2e.test.ts +0 -33
- package/test/e2e/project-lifecycle.e2e.test.ts +0 -48
- package/test/e2e/setup.ts +0 -237
- package/test/e2e/utils.ts +0 -33
- package/test/integration/commands/admin/create-user.test.ts +0 -51
- package/test/integration/commands/branch/create.test.ts +0 -51
- package/test/integration/commands/branch/delete.test.ts +0 -43
- package/test/integration/commands/branch/get.test.ts +0 -49
- package/test/integration/commands/branch/list.test.ts +0 -47
- package/test/integration/commands/job/get.test.ts +0 -54
- package/test/integration/commands/job/list.test.ts +0 -47
- package/test/integration/commands/job/logs.test.ts +0 -47
- package/test/integration/commands/job/trigger.test.ts +0 -57
- package/test/integration/commands/login.test.ts +0 -62
- package/test/integration/commands/project/create.test.ts +0 -53
- package/test/integration/commands/project/delete.test.ts +0 -43
- package/test/integration/commands/project/get.test.ts +0 -51
- package/test/integration/commands/project/list.test.ts +0 -47
- package/test/integration/commands/project/update.test.ts +0 -53
- package/test/integration/commands/team/create.test.ts +0 -53
- package/test/integration/commands/team/delete.test.ts +0 -43
- package/test/integration/commands/team/get.test.ts +0 -50
- package/test/integration/commands/team/list.test.ts +0 -47
- package/test/integration/commands/team/member/invite.test.ts +0 -46
- package/test/integration/commands/team/member/remove.test.ts +0 -43
- package/test/integration/commands/team/update.test.ts +0 -50
- package/test/integration/commands/token/generate.test.ts +0 -51
- package/test/integration/commands/token/list.test.ts +0 -47
- package/test/integration/commands/token/revoke.test.ts +0 -43
- package/test/integration/commands/whoami.test.ts +0 -49
- package/test/unit/commands/admin/create-user.test.ts +0 -51
- package/test/unit/commands/branch/create.test.ts +0 -57
- package/test/unit/commands/branch/delete.test.ts +0 -49
- package/test/unit/commands/branch/get.test.ts +0 -67
- package/test/unit/commands/branch/list.test.ts +0 -62
- package/test/unit/commands/job/get.test.ts +0 -76
- package/test/unit/commands/job/list.test.ts +0 -62
- package/test/unit/commands/job/logs.test.ts +0 -60
- package/test/unit/commands/job/trigger.test.ts +0 -75
- package/test/unit/commands/login.test.ts +0 -64
- package/test/unit/commands/project/create.test.ts +0 -64
- package/test/unit/commands/project/delete.test.ts +0 -72
- package/test/unit/commands/project/get.test.ts +0 -73
- package/test/unit/commands/project/list.test.ts +0 -62
- package/test/unit/commands/project/update.test.ts +0 -58
- package/test/unit/commands/team/create.test.ts +0 -68
- package/test/unit/commands/team/delete.test.ts +0 -71
- package/test/unit/commands/team/get.test.ts +0 -70
- package/test/unit/commands/team/list.test.ts +0 -56
- package/test/unit/commands/team/member/invite.test.ts +0 -52
- package/test/unit/commands/team/member/remove.test.ts +0 -49
- package/test/unit/commands/team/update.test.ts +0 -63
- package/test/unit/commands/token/generate.test.ts +0 -65
- package/test/unit/commands/token/list.test.ts +0 -58
- package/test/unit/commands/token/revoke.test.ts +0 -49
- package/test/unit/commands/whoami.test.ts +0 -49
- package/test/unit/utils/nexical-client.test.ts +0 -113
- /package/dist/src/utils/{nexical-client.js.map → discovery.js.map} +0 -0
|
@@ -0,0 +1,152 @@
|
|
|
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
|
+
}
|
|
59
|
+
}),
|
|
60
|
+
'README.md': '# E2E Starter',
|
|
61
|
+
'nexical.yml': 'name: e2e-test\nversion: 0.0.1', // ESSENTIAL for CLI to recognize project
|
|
62
|
+
'src/pages/index.astro': '--- ---',
|
|
63
|
+
'src/core/index.ts': '// core',
|
|
64
|
+
'src/core/package.json': JSON.stringify({
|
|
65
|
+
scripts: {
|
|
66
|
+
'build': 'astro build',
|
|
67
|
+
'dev': 'astro dev',
|
|
68
|
+
'preview': 'astro preview'
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// 3. Setup Mock Module Repo
|
|
74
|
+
moduleDir = path.join(testRoot, 'module-repo');
|
|
75
|
+
await createMockRepo(moduleDir, {
|
|
76
|
+
'package.json': JSON.stringify({ name: 'my-module', version: '0.1.0' }),
|
|
77
|
+
'module.yaml': 'name: my-test-module\nversion: 0.1.0', // Name matches E2E expectation
|
|
78
|
+
'index.ts': 'console.log("module")'
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
afterAll(async () => {
|
|
83
|
+
if (testRoot) await fs.remove(testRoot);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('should complete a full project lifecycle', async () => {
|
|
87
|
+
const projectDir = path.join(testRoot, 'my-project');
|
|
88
|
+
|
|
89
|
+
const env = {
|
|
90
|
+
// Essential for git inside init/module commands
|
|
91
|
+
GIT_AUTHOR_NAME: 'Test User',
|
|
92
|
+
GIT_AUTHOR_EMAIL: 'test@example.com',
|
|
93
|
+
GIT_COMMITTER_NAME: 'Test User',
|
|
94
|
+
GIT_COMMITTER_EMAIL: 'test@example.com',
|
|
95
|
+
GIT_ALLOW_PROTOCOL: 'file'
|
|
96
|
+
// DEBUG: 'true' - Removed to reduce noise
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// --- STEP 1: INIT ---
|
|
100
|
+
// Run: nexical init my-project --repo <starter>
|
|
101
|
+
const initResult = await runCLI([
|
|
102
|
+
'init',
|
|
103
|
+
'my-project',
|
|
104
|
+
'--repo', starterDir
|
|
105
|
+
], testRoot, { env });
|
|
106
|
+
|
|
107
|
+
// 4. Check git initialization (preserved history)
|
|
108
|
+
const { stdout: log } = await execa('git', ['log', '--oneline'], { cwd: projectDir });
|
|
109
|
+
const lines = log.split('\n').filter(Boolean);
|
|
110
|
+
expect(lines.length).toBeGreaterThanOrEqual(2);
|
|
111
|
+
expect(lines[0]).toContain('Initial site commit');
|
|
112
|
+
|
|
113
|
+
// --- STEP 2: MODULE ADD ---
|
|
114
|
+
// Run: nexical module add <module>
|
|
115
|
+
const modResult = await runCLI([
|
|
116
|
+
'module',
|
|
117
|
+
'add',
|
|
118
|
+
moduleDir,
|
|
119
|
+
'my-test-module' // Explicit name
|
|
120
|
+
], projectDir, { env });
|
|
121
|
+
|
|
122
|
+
if (modResult.exitCode !== 0) {
|
|
123
|
+
console.error('Module Add Failed:', modResult.stderr || modResult.stdout);
|
|
124
|
+
}
|
|
125
|
+
expect(modResult.exitCode).toBe(0);
|
|
126
|
+
expect(fs.existsSync(path.join(projectDir, 'modules/my-test-module'))).toBe(true);
|
|
127
|
+
|
|
128
|
+
// --- STEP 3: BUILD ---
|
|
129
|
+
// Run: nexical run build
|
|
130
|
+
// Should trigger our mock astro binary
|
|
131
|
+
const buildResult = await runCLI(['run', 'build'], projectDir, { env });
|
|
132
|
+
|
|
133
|
+
if (buildResult.exitCode !== 0) {
|
|
134
|
+
console.log(buildResult.stderr || buildResult.stdout);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
expect(buildResult.exitCode).toBe(0);
|
|
138
|
+
expect(buildResult.stdout).toContain('MOCK_ASTRO_EXECUTED build');
|
|
139
|
+
|
|
140
|
+
// --- STEP 4: PREVIEW ---
|
|
141
|
+
// Run: nexical run preview
|
|
142
|
+
const previewResult = await runCLI(['run', 'preview'], projectDir, { env });
|
|
143
|
+
|
|
144
|
+
expect(previewResult.exitCode).toBe(0);
|
|
145
|
+
expect(previewResult.stdout).toContain('MOCK_ASTRO_EXECUTED preview');
|
|
146
|
+
|
|
147
|
+
// --- STEP 5: CLEAN ---
|
|
148
|
+
// Clean is now handled by manual file operations or external scripts,
|
|
149
|
+
// it's no longer a top-level command.
|
|
150
|
+
|
|
151
|
+
}, 120000); // Long timeout for full chain
|
|
152
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
dependencies: {
|
|
23
|
+
'is-odd': '3.0.1'
|
|
24
|
+
}
|
|
25
|
+
}),
|
|
26
|
+
'README.md': '# Starter Template'
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Set Git Identity for the test process so InitCommand's commit works in CI
|
|
30
|
+
process.env.GIT_AUTHOR_NAME = 'Test User';
|
|
31
|
+
process.env.GIT_AUTHOR_EMAIL = 'test@example.com';
|
|
32
|
+
process.env.GIT_COMMITTER_NAME = 'Test User';
|
|
33
|
+
process.env.GIT_COMMITTER_EMAIL = 'test@example.com';
|
|
34
|
+
// Allow file protocol for local cloning in CI
|
|
35
|
+
process.env.GIT_ALLOW_PROTOCOL = 'file';
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
afterAll(async () => {
|
|
39
|
+
// await cleanupTestRoot(); // conflicting with parallel tests
|
|
40
|
+
if (tempDir) await fs.remove(tempDir);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should initialize a new project from a local git repo', async () => {
|
|
44
|
+
const targetProjectName = 'my-new-project';
|
|
45
|
+
const targetPath = path.join(tempDir, targetProjectName);
|
|
46
|
+
const cli = new CLI({ commandName: 'nexical' });
|
|
47
|
+
|
|
48
|
+
const command = new InitCommand(cli);
|
|
49
|
+
|
|
50
|
+
// Capture stdout/stderr? InitCommand uses consola.
|
|
51
|
+
// For integration, we care about the FS side effects.
|
|
52
|
+
|
|
53
|
+
await command.run({
|
|
54
|
+
directory: targetPath,
|
|
55
|
+
repo: starterRepoDir // Passing local path as repo URL
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// 1. Check directory exists
|
|
59
|
+
expect(fs.existsSync(targetPath)).toBe(true);
|
|
60
|
+
|
|
61
|
+
// 2. Check files cloned
|
|
62
|
+
expect(fs.existsSync(path.join(targetPath, 'package.json'))).toBe(true);
|
|
63
|
+
expect(fs.existsSync(path.join(targetPath, 'README.md'))).toBe(true);
|
|
64
|
+
|
|
65
|
+
// 3. Check git initialization
|
|
66
|
+
expect(fs.existsSync(path.join(targetPath, '.git'))).toBe(true);
|
|
67
|
+
|
|
68
|
+
// 4. Check git initialization (history should be preserved + one new commit)
|
|
69
|
+
const { stdout: log } = await execa('git', ['log', '--oneline'], { cwd: targetPath });
|
|
70
|
+
const lines = log.split('\n').filter(Boolean);
|
|
71
|
+
expect(lines.length).toBe(2); // Should have "Initial site commit" and "Initial commit"
|
|
72
|
+
expect(lines[0]).toContain('Initial site commit');
|
|
73
|
+
expect(lines[1]).toContain('Initial commit');
|
|
74
|
+
|
|
75
|
+
// 5. Check dependencies (optional, but command tries to install them)
|
|
76
|
+
// Since we are mocking the repo, it doesn't have a real lockfile or valid deps,
|
|
77
|
+
// so `npm install` might have failed or done nothing.
|
|
78
|
+
// However, `InitCommand` runs `npm install`. If that fails, the command throws/exits.
|
|
79
|
+
// We provided a minimal package.json so it should succeed.
|
|
80
|
+
expect(fs.existsSync(path.join(targetPath, 'node_modules'))).toBe(true);
|
|
81
|
+
}, 60000); // Increase timeout for real git/npm ops
|
|
82
|
+
});
|
|
@@ -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
|
+
});
|