-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrelease.purge.js
56 lines (48 loc) · 1.66 KB
/
release.purge.js
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
const axios = require('axios');
const fs = require('fs');
const path = require('path');
function getCssFiles(dir, fileList = []) {
const files = fs.readdirSync(dir);
files.forEach((file) => {
const filePath = path.join(dir, file);
const stat = fs.statSync(filePath);
if (stat.isDirectory()) {
getCssFiles(filePath, fileList);
} else if (file.endsWith('.css')) {
const relativePath = path.relative(__dirname, filePath);
fileList.push(`/gh/JamsRepos/Jamfin@latest/${relativePath}`);
}
});
return fileList;
}
async function purgeCdnCache() {
try {
const cssDirectory = path.resolve(__dirname, './theme');
const paths = getCssFiles(cssDirectory);
const jsonPayload = {
path: paths,
};
const response = await axios.post('https://purge.jsdelivr.net/', jsonPayload, {
headers: {
'Content-Type': 'application/json',
},
});
const id = response.data.id;
let status = 'pending';
while (status === 'pending') {
await new Promise(resolve => setTimeout(resolve, 1000));
const statusResponse = await axios.get(`https://purge.jsdelivr.net/status/${id}`);
status = statusResponse.data.status;
}
if (status === 'finished') {
console.log('CDN cache purge finished successfully.');
} else {
console.error('CDN cache purge failed.');
process.exit(1);
}
} catch (error) {
console.error('Error during CDN cache purge:', error);
process.exit(1);
}
}
purgeCdnCache();