-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupdate-sw-version.cjs
More file actions
24 lines (20 loc) · 864 Bytes
/
Copy pathupdate-sw-version.cjs
File metadata and controls
24 lines (20 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Update service worker cache version from package.json
const fs = require('fs');
const path = require('path');
// Read package.json version
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
const version = packageJson.version;
// Read sw.js
const swPath = path.join(__dirname, 'sw.js');
let swContent = fs.readFileSync(swPath, 'utf8');
// Replace CACHE_NAME version
const cacheNameRegex = /const CACHE_NAME = ['"]esp32tool-v[\d.]+['"]/;
const newCacheName = `const CACHE_NAME = 'esp32tool-v${version}'`;
if (cacheNameRegex.test(swContent)) {
swContent = swContent.replace(cacheNameRegex, newCacheName);
fs.writeFileSync(swPath, swContent, 'utf8');
console.log(`✓ Updated sw.js CACHE_NAME to esp32tool-v${version}`);
} else {
console.error('✗ Could not find CACHE_NAME in sw.js');
process.exit(1);
}