-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathpurge-jsdelivr-cache.mjs
More file actions
93 lines (66 loc) · 2.04 KB
/
purge-jsdelivr-cache.mjs
File metadata and controls
93 lines (66 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env node
/**
* Purges the jsDelivr CDN cache for a given Handsontable version.
*
* Usage: node purge-jsdelivr-cache.mjs <version>
* e.g. node purge-jsdelivr-cache.mjs 12.1.3
*/
import { readdirSync } from 'fs';
import { join, relative } from 'path';
const version = process.argv[2];
if (!version) {
console.error('Usage: node purge-jsdelivr-cache.mjs <version>');
process.exit(1);
}
const [major, minor, patch] = version.split('.').map(Number);
const EXTENSIONS = ['.js', '.css'];
function collectFiles(dir) {
const results = [];
for (const entry of readdirSync(dir, { withFileTypes: true })) {
const fullPath = join(dir, entry.name);
if (entry.isDirectory()) {
results.push(...collectFiles(fullPath));
} else if (EXTENSIONS.some(ext => entry.name.endsWith(ext))) {
results.push(fullPath);
}
}
return results;
}
const PKG_DIR = 'handsontable/tmp';
const distDir = join(PKG_DIR, 'dist');
const stylesDir = join(PKG_DIR, 'styles');
const DIST_FILES = collectFiles(distDir)
.map(f => relative(distDir, f));
const STYLES_FILES = collectFiles(stylesDir)
.map(f => relative(stylesDir, f));
const tags = ['latest'];
if (patch !== 0) {
tags.push(`${major}`, `${major}.${minor}`);
} else if (minor !== 0) {
tags.push(`${major}`);
}
let failed = false;
for (const tag of tags) {
console.log(`\nPurging @${tag} cache...`);
for (const file of DIST_FILES) {
const url = `https://purge.jsdelivr.net/npm/handsontable@${tag}/dist/${file}`;
const res = await fetch(url);
console.log(`${res.status} @${tag}/dist/${file}`);
if (!res.ok) {
failed = true;
}
}
for (const file of STYLES_FILES) {
const url = `https://purge.jsdelivr.net/npm/handsontable@${tag}/styles/${file}`;
const res = await fetch(url);
console.log(`${res.status} @${tag}/styles/${file}`);
if (!res.ok) {
failed = true;
}
}
}
if (failed) {
console.error('\nSome purge requests failed (see above).');
process.exit(1);
}
console.log('\nAll purge requests completed successfully.');