refactor(extract-js): more stable at first download of Luciole

This commit is contained in:
Jérémy Dufraisse 2023-03-14 08:42:15 +01:00
parent 7e0717491f
commit 1d0aa5ac9e

View File

@ -116,29 +116,13 @@ const http = require('http');
let src = 'node_modules/Luciole/' let src = 'node_modules/Luciole/'
let currentPath = path.join(basePath, src) const importLucioleFont = () => {
if (!fs.existsSync(currentPath)) { copySync(
fs.mkdirSync(currentPath,{recursive :true})
}
const zipPath = path.join(currentPath,'Luciole_webfonts.zip')
const file = fs.createWriteStream(zipPath)
const request = http.get("http://www.luciole-vision.com/Fichiers/Luciole_webfonts.zip", function(response) {
response.pipe(file)
response.on('end', () => {
setTimeout(()=>{
var AdmZip = require("adm-zip")
var zip = new AdmZip(zipPath)
zip.extractAllTo(/*target path*/ currentPath, /*overwrite*/ true)
},500)
})
});
copySync(
'node_modules/Luciole/Luciole_webfonts/Read Me.txt', 'node_modules/Luciole/Luciole_webfonts/Read Me.txt',
'fonts/vendor/Luciole/Read Me.txt', 'fonts/vendor/Luciole/Read Me.txt',
{ overwrite: true } { overwrite: true }
) )
var arr = [ var arr = [
{ {
name:'Luciole-Regular', name:'Luciole-Regular',
style:'normal', style:'normal',
@ -159,9 +143,9 @@ var arr = [
style:'italic', style:'italic',
weight:'bold' weight:'bold'
} }
] ]
let css = "/* Webfont: Luciole */\n\n" let css = "/* Webfont: Luciole */\n\n"
arr.forEach((data)=>{ arr.forEach((data)=>{
let name = data.name let name = data.name
copySync( copySync(
`node_modules/Luciole/Luciole_webfonts/${name}/${name}.woff`, `node_modules/Luciole/Luciole_webfonts/${name}/${name}.woff`,
@ -178,14 +162,33 @@ arr.forEach((data)=>{
text-rendering: optimizeLegibility; text-rendering: optimizeLegibility;
} }
` `
}) })
fs.writeFileSync( fs.writeFileSync(
path.join( path.join(
basePath, basePath,
'fonts/vendor/Luciole/Luciole.css' 'fonts/vendor/Luciole/Luciole.css'
), ),
css css
) )
}
let currentPath = path.join(basePath, src)
if (!fs.existsSync(currentPath)) {
fs.mkdirSync(currentPath,{recursive :true})
}
const zipPath = path.join(currentPath,'Luciole_webfonts.zip')
const file = fs.createWriteStream(zipPath)
const request = http.get("http://www.luciole-vision.com/Fichiers/Luciole_webfonts.zip", function(response) {
response.pipe(file)
response.on('end', () => {
setTimeout(()=>{
var AdmZip = require("adm-zip")
var zip = new AdmZip(zipPath)
zip.extractAllTo(/*target path*/ currentPath, /*overwrite*/ true)
importLucioleFont()
},500)
})
});
// example // example