-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomposeServiceWorker.js
44 lines (36 loc) · 1.28 KB
/
composeServiceWorker.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
const fg = require('fast-glob')
const fs = require('fs')
const myArgs = process.argv.slice(2)
let directory, numVersionCache
directory = myArgs[0]
numVersionCache = myArgs[1]
if (directory === undefined || numVersionCache === undefined) {
console.log('Commande: node prog repertoire_de_build version_de_cache')
console.log('Erreur, manque le répertoire de destination ou le numéro de version ! ')
process.exit(1)
}
async function liste(racine) {
let assets = `const CACHE_NAME = 'auxSonsDuJardin-v${numVersionCache}'\n`
assets += 'const urlsToCache = [\n'
const fichiers = await fg([racine + '/**/*'])
for (let i = 0; i < fichiers.length; i++) {
const fichier = fichiers[i].substring(racine.length, fichiers[i].length)
if (i < (fichiers.length - 1)) {
assets += ' "' + fichier + '",\n'
} else {
assets += ' "' + fichier + '"\n'
}
}
assets += ']\n'
return assets
}
async function chargerServiceWorkerListLess() {
try {
const rawdata = fs.readFileSync('./serviceWorkerListLess.js', 'utf8').toString()
const assets = await liste(directory)
fs.writeFileSync('./' + directory + '/serviceWorker.js', assets + rawdata, 'utf8')
} catch (error) {
console.log('Sauvegarde du service worker,', error)
}
}
chargerServiceWorkerListLess()