@struggler/cli 1.0.3 → 1.0.6
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/.strugglerignore +6 -0
- package/Makefile +81 -0
- package/README.md +124 -0
- package/command/addVersion.js +11 -5
- package/command/deploy.js +75 -0
- package/command/index.js +2 -2
- package/command/init.js +20 -20
- package/command/refresh.js +87 -107
- package/command/upload.js +146 -168
- package/index.js +82 -28
- package/lib/cache.js +37 -0
- package/lib/config.js +35 -4
- package/lib/date.js +14 -0
- package/lib/deploy.js +132 -0
- package/lib/files.js +30 -4
- package/lib/i18n.js +191 -0
- package/lib/ignore.js +69 -0
- package/lib/output.js +37 -0
- package/lib/prefix.js +2 -16
- package/package.json +28 -27
- package/test/config.test.js +41 -0
- package/test/init.test.js +52 -0
- package/test/test.sh +2 -2
- package/test/upload.test.js +113 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
const test = require('node:test');
|
|
2
|
+
const assert = require('node:assert/strict');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const os = require('os');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const upload = require('../command/upload');
|
|
7
|
+
const deploy = require('../command/deploy');
|
|
8
|
+
|
|
9
|
+
function createWorkspace() {
|
|
10
|
+
const workspace = fs.mkdtempSync(path.join(os.tmpdir(), 'struggler-cli-upload-'));
|
|
11
|
+
fs.mkdirSync(path.join(workspace, 'command'), { recursive: true });
|
|
12
|
+
fs.mkdirSync(path.join(workspace, 'dist/assets'), { recursive: true });
|
|
13
|
+
|
|
14
|
+
fs.writeFileSync(path.join(workspace, 'command/qiniu.json'), JSON.stringify({
|
|
15
|
+
path: 'demo-app',
|
|
16
|
+
domain: 'https://cdn.example.com/',
|
|
17
|
+
}, null, 2));
|
|
18
|
+
fs.writeFileSync(path.join(workspace, 'command/config.json'), JSON.stringify({
|
|
19
|
+
publicPath: 'demo-app/202603131600/',
|
|
20
|
+
base: 'https://cdn.example.com/demo-app/202603131600/',
|
|
21
|
+
}, null, 2));
|
|
22
|
+
fs.writeFileSync(path.join(workspace, 'dist/index.html'), '<html></html>');
|
|
23
|
+
fs.writeFileSync(path.join(workspace, 'dist/assets/app.js'), 'console.log("ok")');
|
|
24
|
+
fs.writeFileSync(path.join(workspace, 'dist/assets/app.js.gz'), 'gzip');
|
|
25
|
+
fs.writeFileSync(path.join(workspace, 'dist/.DS_Store'), 'noise');
|
|
26
|
+
fs.writeFileSync(path.join(workspace, '.strugglerignore'), '.DS_Store\n');
|
|
27
|
+
|
|
28
|
+
return workspace;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
test('upload dry-run plans files, skips gz assets, and returns summary', async () => {
|
|
32
|
+
const previousCwd = process.cwd();
|
|
33
|
+
const workspace = createWorkspace();
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
process.chdir(workspace);
|
|
37
|
+
|
|
38
|
+
const summary = await upload({
|
|
39
|
+
config: './command/qiniu.json',
|
|
40
|
+
dir: './dist',
|
|
41
|
+
dryRun: true,
|
|
42
|
+
concurrency: '2',
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
assert.equal(summary.action, 'upload');
|
|
46
|
+
assert.equal(summary.dryRun, true);
|
|
47
|
+
assert.equal(summary.total, 2);
|
|
48
|
+
assert.equal(summary.failedCount, 0);
|
|
49
|
+
assert.deepEqual(
|
|
50
|
+
summary.succeeded.map((item) => item.key),
|
|
51
|
+
[
|
|
52
|
+
'demo-app/202603131600/assets/app.js',
|
|
53
|
+
'demo-app/202603131600/index.html',
|
|
54
|
+
]
|
|
55
|
+
);
|
|
56
|
+
assert.equal(summary.excludedPatterns.includes('.DS_Store'), true);
|
|
57
|
+
} finally {
|
|
58
|
+
process.chdir(previousCwd);
|
|
59
|
+
fs.rmSync(workspace, { recursive: true, force: true });
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('upload dry-run can write a manifest file', async () => {
|
|
64
|
+
const previousCwd = process.cwd();
|
|
65
|
+
const workspace = createWorkspace();
|
|
66
|
+
|
|
67
|
+
try {
|
|
68
|
+
process.chdir(workspace);
|
|
69
|
+
|
|
70
|
+
const summary = await upload({
|
|
71
|
+
config: './command/qiniu.json',
|
|
72
|
+
dir: './dist',
|
|
73
|
+
dryRun: true,
|
|
74
|
+
manifest: './artifacts/upload.json',
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
const manifestPath = path.resolve(workspace, 'artifacts/upload.json');
|
|
78
|
+
assert.equal(fs.existsSync(manifestPath), true);
|
|
79
|
+
assert.equal(summary.manifestPath, fs.realpathSync(manifestPath));
|
|
80
|
+
|
|
81
|
+
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
|
82
|
+
assert.equal(manifest.action, 'upload');
|
|
83
|
+
assert.equal(manifest.total, 2);
|
|
84
|
+
} finally {
|
|
85
|
+
process.chdir(previousCwd);
|
|
86
|
+
fs.rmSync(workspace, { recursive: true, force: true });
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('deploy dry-run supports skip-refresh and json-friendly summary data', async () => {
|
|
91
|
+
const previousCwd = process.cwd();
|
|
92
|
+
const workspace = createWorkspace();
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
process.chdir(workspace);
|
|
96
|
+
|
|
97
|
+
const summary = await deploy({
|
|
98
|
+
config: './command/qiniu.json',
|
|
99
|
+
dir: './dist',
|
|
100
|
+
dryRun: true,
|
|
101
|
+
json: true,
|
|
102
|
+
skipRefresh: true,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
assert.equal(summary.action, 'deploy');
|
|
106
|
+
assert.equal(summary.upload.total, 2);
|
|
107
|
+
assert.equal(summary.refresh.skipped, true);
|
|
108
|
+
assert.equal(summary.excludedPatterns.includes('.DS_Store'), true);
|
|
109
|
+
} finally {
|
|
110
|
+
process.chdir(previousCwd);
|
|
111
|
+
fs.rmSync(workspace, { recursive: true, force: true });
|
|
112
|
+
}
|
|
113
|
+
});
|