24 lines
711 B
JavaScript
24 lines
711 B
JavaScript
#!/usr/bin/env node
|
|
|
|
import { readFileSync, writeFileSync } from 'fs';
|
|
import { fileURLToPath } from 'url';
|
|
import { dirname, join } from 'path';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = dirname(__filename);
|
|
const rootDir = join(__dirname, '..');
|
|
|
|
const packageJson = JSON.parse(readFileSync(join(rootDir, 'package.json'), 'utf-8'));
|
|
const version = packageJson.version;
|
|
|
|
const swPath = join(rootDir, 'static', 'sw.js');
|
|
let swContent = readFileSync(swPath, 'utf-8');
|
|
|
|
swContent = swContent.replace(
|
|
/const CACHE_VERSION = ['"](.*?)['"];/,
|
|
`const CACHE_VERSION = '${version}';`
|
|
);
|
|
|
|
writeFileSync(swPath, swContent);
|
|
console.log(`Injected version ${version} into service worker`);
|