From 014a400b5e3e4c074ceb7c4b416dcdcf4ab47381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Dufraisse?= Date: Tue, 14 Mar 2023 09:03:21 +0100 Subject: [PATCH] refactor(Luciole): download it only if needed --- js/extract-files-from-node-modules.js | 51 +++++++++++++++-------- package.json | 1 + yarn.lock | 60 +++++++++++++++++---------- 3 files changed, 74 insertions(+), 38 deletions(-) diff --git a/js/extract-files-from-node-modules.js b/js/extract-files-from-node-modules.js index 34c9aff..fb3e48d 100644 --- a/js/extract-files-from-node-modules.js +++ b/js/extract-files-from-node-modules.js @@ -115,10 +115,9 @@ fetch('https://www.luciole-vision.com/Fichiers/Luciole_webfonts.zip') const http = require('http'); -let src = 'node_modules/Luciole/' -const importLucioleFont = () => { +const importLucioleFont = (srcPath) => { copySync( - 'node_modules/Luciole/Luciole_webfonts/Read Me.txt', + `${srcPath}/Luciole_webfonts/Read Me.txt`, 'fonts/vendor/Luciole/Read Me.txt', { overwrite: true } ) @@ -148,7 +147,7 @@ const importLucioleFont = () => { arr.forEach((data)=>{ let name = data.name copySync( - `node_modules/Luciole/Luciole_webfonts/${name}/${name}.woff`, + `${srcPath}/Luciole_webfonts/${name}/${name}.woff`, `fonts/vendor/Luciole/${name}/${name}.woff`, { overwrite: true } ) @@ -172,23 +171,41 @@ const importLucioleFont = () => { ) } +const downloadLuciole = (destPath,src) => { + const zipPath = path.join(destPath,'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*/ destPath, /*overwrite*/ true) + importLucioleFont(src) + },500) + }) + }); +} + +const checkLucioleFile = (destPath) => { + return fs.existsSync(path.join(destPath,'Luciole_webfonts.zip')) && + fs.existsSync(path.join(destPath,'Luciole_webfonts/Read Me.txt')) && + fs.existsSync(path.join(destPath,'Luciole_webfonts/Luciole-Regular/Luciole-Regular.woff')) && + fs.existsSync(path.join(destPath,'Luciole_webfonts/Luciole-Italic/Luciole-Italic.woff')) && + fs.existsSync(path.join(destPath,'Luciole_webfonts/Luciole-Bold/Luciole-Bold.woff')) && + fs.existsSync(path.join(destPath,'Luciole_webfonts/Luciole-BoldItalic/Luciole-BoldItalic.woff')) +} + +let src = 'node_modules/Luciole/' let currentPath = path.join(basePath, src) if (!fs.existsSync(currentPath)) { fs.mkdirSync(currentPath,{recursive :true}) + downloadLuciole(currentPath,src) +} else if (!checkLucioleFile(currentPath)) { + downloadLuciole(currentPath,src) +} else { + importLucioleFont(src) } -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 diff --git a/package.json b/package.json index 95fb763..d872c1a 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,5 @@ { + "license": "EUPL-1.2", "scripts": { "postinstall": "node ./js/extract-files-from-node-modules.js" }, diff --git a/yarn.lock b/yarn.lock index 11be20c..2be6b2e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -48,6 +48,14 @@ argparse@^2.0.1: resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38" integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q== +array-buffer-byte-length@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/array-buffer-byte-length/-/array-buffer-byte-length-1.0.0.tgz#fabe8bc193fea865f317fe7807085ee0dee5aead" + integrity sha512-LPuwb2P+NrQw3XhxGc36+XSvuBPopovXYTR9Ew++Du9Yb/bx5AzBfrIsBoj0EZUifjQU+sHL21sseZ3jerWO/A== + dependencies: + call-bind "^1.0.2" + is-array-buffer "^3.0.1" + array.prototype.reduce@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/array.prototype.reduce/-/array.prototype.reduce-1.0.5.tgz#6b20b0daa9d9734dd6bc7ea66b5bbce395471eac" @@ -135,9 +143,9 @@ caniuse-api@^3.0.0: lodash.uniq "^4.5.0" caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001449: - version "1.0.30001454" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001454.tgz#033f6df4452643a64173d02543902caa158dfd9a" - integrity sha512-4E63M5TBbgDoA9dQoFRdjL6iAmzTrz3rwYWoKDlvnvyvBxjCZ0rrUoX3THhEMie0/RYuTCeMbeTYLGAWgnLwEg== + version "1.0.30001466" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001466.tgz#c1e6197c540392e09709ecaa9e3e403428c53375" + integrity sha512-ewtFBSfWjEmxUgNBSZItFSmVtvk9zkwkl1OfRZlKA8slltRN+/C/tuGVrF9styXkN36Yu3+SeJ1qkXxDEyNZ5w== chalk@^2.4.1: version "2.4.2" @@ -399,9 +407,9 @@ dot-prop@^5.2.0: is-obj "^2.0.0" electron-to-chromium@^1.4.284: - version "1.4.301" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.301.tgz#175d9fa1509a5b062752c6db321051e610fe2eae" - integrity sha512-bz00ASIIDjcgszZKuEA1JEFhbDjqUNbQ/PEhNEl1wbixzYpeTp2H2QWjsQvAL2T1wJBdOwCF5hE896BoMwYKrA== + version "1.4.328" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.328.tgz#b4565ffa502542b561cea16086d6d9b916c7095a" + integrity sha512-DE9tTy2PNmy1v55AZAO542ui+MLC2cvINMK4P2LXGsJdput/ThVG9t+QGecPuAZZSgC8XoI+Jh9M1OG9IoNSCw== emoji-regex@^8.0.0: version "8.0.0" @@ -426,17 +434,17 @@ error-ex@^1.3.1: is-arrayish "^0.2.1" es-abstract@^1.17.2, es-abstract@^1.19.0, es-abstract@^1.20.4: - version "1.21.1" - resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.21.1.tgz#e6105a099967c08377830a0c9cb589d570dd86c6" - integrity sha512-QudMsPOz86xYz/1dG1OuGBKOELjCh99IIWHLzy5znUB6j8xG2yMA7bfTV86VSqKF+Y/H08vQPR+9jyXpuC6hfg== + version "1.21.2" + resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.21.2.tgz#a56b9695322c8a185dc25975aa3b8ec31d0e7eff" + integrity sha512-y/B5POM2iBnIxCiernH1G7rC9qQoM77lLIMQLuob0zhp8C56Po81+2Nj0WFKnd0pNReDTnkYryc+zhOzpEIROg== dependencies: + array-buffer-byte-length "^1.0.0" available-typed-arrays "^1.0.5" call-bind "^1.0.2" es-set-tostringtag "^2.0.1" es-to-primitive "^1.2.1" - function-bind "^1.1.1" function.prototype.name "^1.1.5" - get-intrinsic "^1.1.3" + get-intrinsic "^1.2.0" get-symbol-description "^1.0.0" globalthis "^1.0.3" gopd "^1.0.1" @@ -444,8 +452,8 @@ es-abstract@^1.17.2, es-abstract@^1.19.0, es-abstract@^1.20.4: has-property-descriptors "^1.0.0" has-proto "^1.0.1" has-symbols "^1.0.3" - internal-slot "^1.0.4" - is-array-buffer "^3.0.1" + internal-slot "^1.0.5" + is-array-buffer "^3.0.2" is-callable "^1.2.7" is-negative-zero "^2.0.2" is-regex "^1.1.4" @@ -453,11 +461,12 @@ es-abstract@^1.17.2, es-abstract@^1.19.0, es-abstract@^1.20.4: is-string "^1.0.7" is-typed-array "^1.1.10" is-weakref "^1.0.2" - object-inspect "^1.12.2" + object-inspect "^1.12.3" object-keys "^1.1.1" object.assign "^4.1.4" regexp.prototype.flags "^1.4.3" safe-regex-test "^1.0.0" + string.prototype.trim "^1.2.7" string.prototype.trimend "^1.0.6" string.prototype.trimstart "^1.0.6" typed-array-length "^1.0.4" @@ -671,7 +680,7 @@ indexes-of@^1.0.1: resolved "https://registry.yarnpkg.com/indexes-of/-/indexes-of-1.0.1.tgz#f30f716c8e2bd346c7b67d3df3915566a7c05607" integrity sha512-bup+4tap3Hympa+JBJUG7XuOsdNQ6fxt0MHyXMKuLBKn0OqsTfvUxkUrroEX1+B2VsSHvCjiIcZVxRtYa4nllA== -internal-slot@^1.0.4: +internal-slot@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/internal-slot/-/internal-slot-1.0.5.tgz#f2a2ee21f668f8627a4667f309dc0f4fb6674986" integrity sha512-Y+R5hJrzs52QCG2laLn4udYVnxsfny9CpOhNhUvk/SSSVyF6T27FzRbF0sroPidSu3X8oEAkOn2K804mjpt6UQ== @@ -685,13 +694,13 @@ is-absolute-url@^2.0.0: resolved "https://registry.yarnpkg.com/is-absolute-url/-/is-absolute-url-2.1.0.tgz#50530dfb84fcc9aa7dbe7852e83a37b93b9f2aa6" integrity sha512-vOx7VprsKyllwjSkLV79NIhpyLfr3jAp7VaTCMXOJHu4m0Ew1CZ2fcjASwmV1jI3BWuWHB013M48eyeldk9gYg== -is-array-buffer@^3.0.1: - version "3.0.1" - resolved "https://registry.yarnpkg.com/is-array-buffer/-/is-array-buffer-3.0.1.tgz#deb1db4fcae48308d54ef2442706c0393997052a" - integrity sha512-ASfLknmY8Xa2XtB4wmbz13Wu202baeA18cJBCeCy0wXUHZF0IPyVEXqKEcd+t2fNSLLL1vC6k7lxZEojNbISXQ== +is-array-buffer@^3.0.1, is-array-buffer@^3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/is-array-buffer/-/is-array-buffer-3.0.2.tgz#f2653ced8412081638ecb0ebbd0c41c6e0aecbbe" + integrity sha512-y+FyyR/w8vfIRq4eQcM1EYgSTnmHXPqaF+IgzgraytCFq5Xh8lllDVmAZolPJiZttZLeFSINPYMaEJ7/vWUa1w== dependencies: call-bind "^1.0.2" - get-intrinsic "^1.1.3" + get-intrinsic "^1.2.0" is-typed-array "^1.1.10" is-arrayish@^0.2.1: @@ -966,7 +975,7 @@ num2fraction@^1.2.2: resolved "https://registry.yarnpkg.com/num2fraction/-/num2fraction-1.2.2.tgz#6f682b6a027a4e9ddfa4564cd2589d1d4e669ede" integrity sha512-Y1wZESM7VUThYY+4W+X4ySH2maqcA+p7UR+w8VWNWVAd6lwuXXWz/w/Cz43J/dI2I+PS6wD5N+bJUF+gjWvIqg== -object-inspect@^1.12.2, object-inspect@^1.9.0: +object-inspect@^1.12.3, object-inspect@^1.9.0: version "1.12.3" resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.12.3.tgz#ba62dffd67ee256c8c086dfae69e016cd1f198b9" integrity sha512-geUvdk7c+eizMNUDkRpW1wJwgfOiOeHbxBR/hLXK1aT6zmVSO0jsQcs7fj6MGw89jC/cjGfLcNOrtMYtGqm81g== @@ -1443,6 +1452,15 @@ string-width@^4.1.0, string-width@^4.2.0: is-fullwidth-code-point "^3.0.0" strip-ansi "^6.0.1" +string.prototype.trim@^1.2.7: + version "1.2.7" + resolved "https://registry.yarnpkg.com/string.prototype.trim/-/string.prototype.trim-1.2.7.tgz#a68352740859f6893f14ce3ef1bb3037f7a90533" + integrity sha512-p6TmeT1T3411M8Cgg9wBTMRtY2q9+PNy9EV1i2lIXUN/btt763oIfxwN3RR8VU6wHX8j/1CFy0L+YuThm6bgOg== + dependencies: + call-bind "^1.0.2" + define-properties "^1.1.4" + es-abstract "^1.20.4" + string.prototype.trimend@^1.0.6: version "1.0.6" resolved "https://registry.yarnpkg.com/string.prototype.trimend/-/string.prototype.trimend-1.0.6.tgz#c4a27fa026d979d79c04f17397f250a462944533"