Skip to content

Commit 36f01cb

Browse files
author
mcarbonell
committed
feat: Auto-versionado PWA + fix categorías faltantes
- Crear script bump-version.js para auto-incrementar versión SW - Añadir prebuild hook en package.json - Fix getCategoryName para manejar guiones (data-analysts, ai-tools) - Versión bumpeada: v2.1.0 → v2.1.1 - Cada build invalida cache automáticamente
1 parent 75da5ff commit 36f01cb

File tree

4 files changed

+78
-7
lines changed

4 files changed

+78
-7
lines changed

extension/shared/i18n.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ export function t(key, params = {}, lang = null) {
215215

216216
// Get category name
217217
export function getCategoryName(category, lang = 'es') {
218-
const key = `category_${category.toLowerCase()}`;
218+
// Normalize category slug (replace hyphens with underscores for i18n keys)
219+
const normalized = category.toLowerCase().replace(/-/g, '_');
220+
const key = `category_${normalized}`;
219221
return t(key, {}, lang);
220222
}
221223

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
"description": "Fast, secure online tools. Everything processed in your browser.",
55
"main": "generate-site.js",
66
"scripts": {
7+
"prebuild": "node scripts/bump-version.js",
78
"build": "node generate-site.js",
89
"build:old": "node generate-tools.js",
910
"build:tools": "node scripts/generate-tools-json.js",
1011
"test": "node tests/automated-qa.js",
1112
"test:old": "node tests/run-all-tests.js",
12-
"serve": "npx http-server web -p 8000"
13+
"serve": "npx http-server web -p 8000",
14+
"version:bump": "node scripts/bump-version.js"
1315
},
1416
"keywords": [
1517
"tools",

scripts/bump-version.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Auto-increment Service Worker version on build
2+
3+
const fs = require('fs').promises;
4+
const path = require('path');
5+
6+
async function bumpVersion() {
7+
console.log('🔄 Bumping Service Worker version...');
8+
9+
const swPath = path.join(__dirname, '../web/sw.js');
10+
let swContent = await fs.readFile(swPath, 'utf8');
11+
12+
// Extract current version from CACHE_NAME
13+
const versionMatch = swContent.match(/const CACHE_NAME = ['"]fasttools-v(\d+\.\d+\.\d+)['"]/);
14+
15+
if (!versionMatch) {
16+
console.error('❌ Could not find version in CACHE_NAME');
17+
return;
18+
}
19+
20+
const currentVersion = versionMatch[1];
21+
const [major, minor, patch] = currentVersion.split('.').map(Number);
22+
23+
// Increment patch version
24+
const newVersion = `${major}.${minor}.${patch + 1}`;
25+
26+
// Update cache names
27+
swContent = swContent.replace(
28+
/const CACHE_NAME = ['"]fasttools-v\d+\.\d+\.\d+['"]/,
29+
`const CACHE_NAME = 'fasttools-v${newVersion}'`
30+
);
31+
32+
swContent = swContent.replace(
33+
/const STATIC_CACHE = ['"]fasttools-static-v\d+\.\d+\.\d+['"]/,
34+
`const STATIC_CACHE = 'fasttools-static-v${newVersion}'`
35+
);
36+
37+
swContent = swContent.replace(
38+
/const DYNAMIC_CACHE = ['"]fasttools-dynamic-v\d+\.\d+\.\d+['"]/,
39+
`const DYNAMIC_CACHE = 'fasttools-dynamic-v${newVersion}'`
40+
);
41+
42+
// Update version in console.log statements
43+
swContent = swContent.replace(
44+
/console\.log\('\[SW\] Installing Service Worker v\d+\.\d+\.\d+'/g,
45+
`console.log('[SW] Installing Service Worker v${newVersion}'`
46+
);
47+
48+
swContent = swContent.replace(
49+
/console\.log\('\[SW\] Activating Service Worker v\d+\.\d+\.\d+'/g,
50+
`console.log('[SW] Activating Service Worker v${newVersion}'`
51+
);
52+
53+
// Write updated sw.js
54+
await fs.writeFile(swPath, swContent, 'utf8');
55+
56+
console.log(`✅ Version bumped: v${currentVersion} → v${newVersion}`);
57+
console.log('📝 Updated sw.js with new version');
58+
59+
return newVersion;
60+
}
61+
62+
// Run if called directly
63+
if (require.main === module) {
64+
bumpVersion().catch(console.error);
65+
}
66+
67+
module.exports = { bumpVersion };

web/sw.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// sw.js - Service Worker para FastTools
22
// Cache name con version para invalidar cache cuando actualicemos
3-
const CACHE_NAME = 'fasttools-v2.1.0';
4-
const STATIC_CACHE = 'fasttools-static-v2.1.0';
5-
const DYNAMIC_CACHE = 'fasttools-dynamic-v2.1.0';
3+
const CACHE_NAME = 'fasttools-v2.1.1';
4+
const STATIC_CACHE = 'fasttools-static-v2.1.1';
5+
const DYNAMIC_CACHE = 'fasttools-dynamic-v2.1.1';
66

77
// Recursos críticos que deben estar siempre en cache
88
const STATIC_ASSETS = [
@@ -36,7 +36,7 @@ const MAX_CACHE_SIZE = 50; // Máximo número de items en cache dinámico
3636
* Se ejecuta cuando el SW se instala por primera vez
3737
*/
3838
self.addEventListener('install', (event) => {
39-
console.log('[SW] Installing Service Worker v2.1.0');
39+
console.log('[SW] Installing Service Worker v2.1.1');
4040

4141
event.waitUntil(
4242
(async () => {
@@ -63,7 +63,7 @@ self.addEventListener('install', (event) => {
6363
* Se ejecuta cuando el SW toma control de la página
6464
*/
6565
self.addEventListener('activate', (event) => {
66-
console.log('[SW] Activating Service Worker v2.1.0');
66+
console.log('[SW] Activating Service Worker v2.1.1');
6767

6868
event.waitUntil(
6969
(async () => {

0 commit comments

Comments
 (0)