From 1d0aa5ac9e2195cd69c87165c93e6c577aa2e65f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Dufraisse?= Date: Tue, 14 Mar 2023 08:42:15 +0100 Subject: [PATCH] refactor(extract-js): more stable at first download of Luciole --- js/extract-files-from-node-modules.js | 111 +++++++++++++------------- 1 file changed, 57 insertions(+), 54 deletions(-) diff --git a/js/extract-files-from-node-modules.js b/js/extract-files-from-node-modules.js index da692e7..34c9aff 100644 --- a/js/extract-files-from-node-modules.js +++ b/js/extract-files-from-node-modules.js @@ -116,6 +116,62 @@ const http = require('http'); let src = 'node_modules/Luciole/' +const importLucioleFont = () => { + copySync( + 'node_modules/Luciole/Luciole_webfonts/Read Me.txt', + 'fonts/vendor/Luciole/Read Me.txt', + { overwrite: true } + ) + var arr = [ + { + name:'Luciole-Regular', + style:'normal', + weight:'normal' + }, + { + name:'Luciole-Italic', + style:'italic', + weight:'normal' + }, + { + name:'Luciole-Bold', + style:'normal', + weight:'bold' + }, + { + name:'Luciole-BoldItalic', + style:'italic', + weight:'bold' + } + ] + let css = "/* Webfont: Luciole */\n\n" + arr.forEach((data)=>{ + let name = data.name + copySync( + `node_modules/Luciole/Luciole_webfonts/${name}/${name}.woff`, + `fonts/vendor/Luciole/${name}/${name}.woff`, + { overwrite: true } + ) + css += +`/* Webfont: ${name} */ +@font-face { + font-family: 'Luciole'; + src: url('./${name}/${name}.woff') format('woff'); + font-style: ${data.style}; + font-weight: ${data.weight}; + text-rendering: optimizeLegibility; +} +` + }) + fs.writeFileSync( + path.join( + basePath, + 'fonts/vendor/Luciole/Luciole.css' + ), + css + ) +} + let currentPath = path.join(basePath, src) if (!fs.existsSync(currentPath)) { fs.mkdirSync(currentPath,{recursive :true}) @@ -129,64 +185,11 @@ const request = http.get("http://www.luciole-vision.com/Fichiers/Luciole_webfont var AdmZip = require("adm-zip") var zip = new AdmZip(zipPath) zip.extractAllTo(/*target path*/ currentPath, /*overwrite*/ true) + importLucioleFont() },500) }) }); -copySync( - 'node_modules/Luciole/Luciole_webfonts/Read Me.txt', - 'fonts/vendor/Luciole/Read Me.txt', - { overwrite: true } -) -var arr = [ - { - name:'Luciole-Regular', - style:'normal', - weight:'normal' - }, - { - name:'Luciole-Italic', - style:'italic', - weight:'normal' - }, - { - name:'Luciole-Bold', - style:'normal', - weight:'bold' - }, - { - name:'Luciole-BoldItalic', - style:'italic', - weight:'bold' - } -] -let css = "/* Webfont: Luciole */\n\n" -arr.forEach((data)=>{ - let name = data.name - copySync( - `node_modules/Luciole/Luciole_webfonts/${name}/${name}.woff`, - `fonts/vendor/Luciole/${name}/${name}.woff`, - { overwrite: true } - ) - css += -`/* Webfont: ${name} */ -@font-face { - font-family: 'Luciole'; - src: url('./${name}/${name}.woff') format('woff'); - font-style: ${data.style}; - font-weight: ${data.weight}; - text-rendering: optimizeLegibility; -} -` -}) -fs.writeFileSync( - path.join( - basePath, - 'fonts/vendor/Luciole/Luciole.css' - ), - css -) - // example // mergeFilesSync(