@stagepass/cli 1.0.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +169 -0
- package/bin/index.js +2 -76
- package/package.json +8 -4
- package/src/cli.js +123 -0
- package/src/commands/link.js +145 -57
- package/src/commands/reload.js +14 -11
- package/src/commands/start.js +21 -4
- package/src/commands/unlink.js +17 -30
- package/src/lib/caddyfile.js +338 -0
- package/src/lib/domain.js +125 -0
- package/src/lib/migrate.js +96 -0
- package/src/lib/origins.js +160 -0
- package/src/lib/paths.js +74 -0
- package/src/lib/projects.js +181 -0
- package/src/commands/__tests__/link.test.js +0 -113
- package/src/commands/__tests__/reload.test.js +0 -72
- package/src/commands/__tests__/unlink.test.js +0 -90
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { unlink } from '../unlink.js';
|
|
3
|
-
import fs from 'fs-extra';
|
|
4
|
-
import { execa } from 'execa';
|
|
5
|
-
import os from 'os';
|
|
6
|
-
import path from 'path';
|
|
7
|
-
|
|
8
|
-
// Mock dependencies
|
|
9
|
-
vi.mock('fs-extra');
|
|
10
|
-
vi.mock('execa');
|
|
11
|
-
vi.mock('ora', () => ({
|
|
12
|
-
default: vi.fn(() => ({
|
|
13
|
-
start: vi.fn(() => ({
|
|
14
|
-
succeed: vi.fn(),
|
|
15
|
-
fail: vi.fn(),
|
|
16
|
-
warn: vi.fn(),
|
|
17
|
-
})),
|
|
18
|
-
})),
|
|
19
|
-
}));
|
|
20
|
-
|
|
21
|
-
describe('unlink command', () => {
|
|
22
|
-
const mockCaddyDir = path.join(os.homedir(), '.stagepass');
|
|
23
|
-
const mockCaddyFile = path.join(mockCaddyDir, 'Caddyfile');
|
|
24
|
-
|
|
25
|
-
beforeEach(() => {
|
|
26
|
-
vi.clearAllMocks();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should remove domain block from Caddyfile', async () => {
|
|
30
|
-
const existingContent = `
|
|
31
|
-
# START: test.sp
|
|
32
|
-
test.sp {
|
|
33
|
-
root * "/some/path"
|
|
34
|
-
}
|
|
35
|
-
# END: test.sp
|
|
36
|
-
|
|
37
|
-
# START: other.sp
|
|
38
|
-
other.sp {
|
|
39
|
-
root * "/other/path"
|
|
40
|
-
}
|
|
41
|
-
# END: other.sp
|
|
42
|
-
`;
|
|
43
|
-
|
|
44
|
-
fs.pathExists.mockResolvedValue(true);
|
|
45
|
-
fs.readFile.mockResolvedValue(existingContent);
|
|
46
|
-
fs.writeFile.mockResolvedValue();
|
|
47
|
-
execa.mockResolvedValue({});
|
|
48
|
-
|
|
49
|
-
await unlink('test', {});
|
|
50
|
-
|
|
51
|
-
expect(fs.writeFile).toHaveBeenCalled();
|
|
52
|
-
const writtenContent = fs.writeFile.mock.calls[0][1];
|
|
53
|
-
expect(writtenContent).not.toContain('test.sp');
|
|
54
|
-
expect(writtenContent).toContain('other.sp');
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('should use current directory name if domain not provided', async () => {
|
|
58
|
-
const originalCwd = process.cwd;
|
|
59
|
-
process.cwd = vi.fn(() => '/test/my-project');
|
|
60
|
-
|
|
61
|
-
const existingContent = `
|
|
62
|
-
# START: my-project.sp
|
|
63
|
-
my-project.sp {
|
|
64
|
-
root * "/test/my-project"
|
|
65
|
-
}
|
|
66
|
-
# END: my-project.sp
|
|
67
|
-
`;
|
|
68
|
-
|
|
69
|
-
fs.pathExists.mockResolvedValue(true);
|
|
70
|
-
fs.readFile.mockResolvedValue(existingContent);
|
|
71
|
-
fs.writeFile.mockResolvedValue();
|
|
72
|
-
execa.mockResolvedValue({});
|
|
73
|
-
|
|
74
|
-
await unlink(undefined, {});
|
|
75
|
-
|
|
76
|
-
const writtenContent = fs.writeFile.mock.calls[0][1];
|
|
77
|
-
expect(writtenContent).not.toContain('my-project.sp');
|
|
78
|
-
|
|
79
|
-
process.cwd = originalCwd;
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('should fail if Caddyfile does not exist', async () => {
|
|
83
|
-
fs.pathExists.mockResolvedValue(false);
|
|
84
|
-
|
|
85
|
-
await unlink('test', {});
|
|
86
|
-
|
|
87
|
-
expect(fs.writeFile).not.toHaveBeenCalled();
|
|
88
|
-
expect(execa).not.toHaveBeenCalled();
|
|
89
|
-
});
|
|
90
|
-
});
|