diff --git a/bin/convert.js b/bin/convert.js index 6e2cb0b58..7be1cd0ee 100644 --- a/bin/convert.js +++ b/bin/convert.js @@ -1,6 +1,11 @@ const fs = require('fs') const path = require('path') const { createConverter } = require('convert-svg-to-png') +const terminalOverwrite = require('terminal-overwrite') + +// Fix memoryleak warning +const maxConvertProcesses = 50 +process.setMaxListeners(maxConvertProcesses + 1) const appPaths = () => { const fileDir = path.dirname(require.main.filename).split('/') @@ -57,6 +62,11 @@ function checkFileExists(imagePath) { return fileExists } +/** + * Check if path is a file + * @param {*} filePath + * @returns + */ function checkIfFile(filePath) { return fs.statSync(filePath).isFile() } @@ -82,16 +92,27 @@ const converter = createConverter() ;(async () => { // Main script const files = fs.readdirSync(appPaths().iconPath) - const totalFiles = files.length + const batchNum = Math.ceil(totalFiles / maxConvertProcesses) + let batchCount = 1 do { + let percentComplete = `${ + 100 - Math.round((100 / totalFiles) * files.length) + }%` + terminalOverwrite( + `Processing Batch: ${batchCount} of ${batchNum} (${percentComplete})` + ) + await Promise.all( - files.splice(0, 50).map(async (fileName) => { + files.splice(0, maxConvertProcesses).map(async (fileName) => { const image = { id: fileName, path: `${appPaths().iconPath}/${fileName}`, convertPath: `${appPaths().convertPath}/${fileName}`, + /** + * Convert SVG to PNG and copy to new folder. + */ async convertAndCopy() { for (let attempt = 1; attempt <= 3; attempt++) { try { @@ -126,8 +147,9 @@ const converter = createConverter() // Check if converted file exists. const convertFilePath = getConvertFileName(this.path) if (checkFileExists(convertFilePath)) { - // If file has changed in past 7 days. - if (dateDiff(this.path) > 8) { + // If file has changed in past 30 days. + const fileAge = dateDiff(this.path) + if (fileAge > 30) { return null } } @@ -146,8 +168,7 @@ const converter = createConverter() await image.processFile() }) ) - - console.log(`${100 - Math.round((100 / totalFiles) * files.length)}%`) + batchCount++ } while (files.length) await converter.destroy() diff --git a/package.json b/package.json index 2ea8cd917..ff4ca5aab 100644 --- a/package.json +++ b/package.json @@ -13,14 +13,15 @@ "eslint-plugin-json": "^2.1.2", "eslint-plugin-nuxt": "^1.0.0", "eslint-plugin-prettier": "^3.1.4", - "prettier": "^2.1.2" + "prettier": "^2.1.2", + "terminal-overwrite": "^2.0.1" }, "scripts": { "link": "node ./bin/link.js", "lint": "eslint src/**/*.{js,json}", "lint:fix": "eslint --fix src/**/*.{js,json}", "validate": "yarn run lint && jsonlint -qV ./schema.json ./src/technologies/ && node ./bin/validate.js", - "convert": "node ./bin/convert.js", + "convert": "node --no-warnings ./bin/convert.js", "prettify": "jsonlint -si --trim-trailing-commas --enforce-double-quotes ./src/categories.json ./src/technologies/*.json", "build": "yarn run link && yarn run validate && yarn run prettify && yarn run convert && node ./bin/build.js", "build:safari": "xcrun safari-web-extension-converter --swift --project-location build --force src/drivers/webextension" diff --git a/yarn.lock b/yarn.lock index bfe7a6371..483a6a6ba 100644 --- a/yarn.lock +++ b/yarn.lock @@ -354,6 +354,11 @@ ansi-colors@^4.1.1: resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348" integrity sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA== +ansi-regex@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998" + integrity sha1-7QMXwyIGT3lGbAKWa922Bas32Zg= + ansi-regex@^5.0.0: version "5.0.1" resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304" @@ -508,6 +513,13 @@ clean-regexp@^1.0.0: dependencies: escape-string-regexp "^1.0.5" +cli-cursor@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5" + integrity sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU= + dependencies: + restore-cursor "^2.0.0" + color-convert@^1.9.0: version "1.9.3" resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8" @@ -1334,6 +1346,11 @@ is-extglob@^2.1.1: resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2" integrity sha1-qIwCU1eR8C7TfHahueqXc8gz+MI= +is-fullwidth-code-point@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f" + integrity sha1-o7MKXE8ZkYMWeqq5O+764937ZU8= + is-fullwidth-code-point@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d" @@ -1551,6 +1568,11 @@ mime@^2.0.3: resolved "https://registry.yarnpkg.com/mime/-/mime-2.5.2.tgz#6e3dc6cc2b9510643830e5f19d5cb753da5eeabe" integrity sha512-tqkh47FzKeCPD2PUiPB6pkbMzsCasjxAfC62/Wap5qrUWcb+sFasXUC5I3gYM5iBM8v/Qpn4UK0x+j0iHyFPDg== +mimic-fn@^1.0.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022" + integrity sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ== + minimatch@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" @@ -1652,6 +1674,13 @@ once@^1.3.0: dependencies: wrappy "1" +onetime@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/onetime/-/onetime-2.0.1.tgz#067428230fd67443b2794b22bba528b6867962d4" + integrity sha1-BnQoIw/WdEOyeUsiu6UotoZ5YtQ= + dependencies: + mimic-fn "^1.0.0" + optionator@^0.9.1: version "0.9.1" resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.9.1.tgz#4f236a6373dae0566a6d43e1326674f50c291499" @@ -1930,6 +1959,14 @@ resolve@^1.10.0, resolve@^1.10.1, resolve@^1.12.0, resolve@^1.13.1, resolve@^1.1 is-core-module "^2.2.0" path-parse "^1.0.6" +restore-cursor@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-2.0.0.tgz#9f7ee287f82fd326d4fd162923d62129eee0dfaf" + integrity sha1-n37ih/gv0ybU/RYpI9YhKe7g368= + dependencies: + onetime "^2.0.0" + signal-exit "^3.0.2" + rimraf@^2.6.1: version "2.7.1" resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.7.1.tgz#35797f13a7fdadc566142c29d4f07ccad483e3ec" @@ -1994,6 +2031,11 @@ shebang-regex@^3.0.0: resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A== +signal-exit@^3.0.2: + version "3.0.7" + resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.7.tgz#a9a1767f8af84155114eaabd73f99273c8f59ad9" + integrity sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ== + slice-ansi@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-4.0.0.tgz#500e8dd0fd55b05815086255b3195adf2a45fe6b" @@ -2039,6 +2081,14 @@ sprintf-js@~1.0.2: resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" integrity sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw= +string-width@^2.0.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e" + integrity sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw== + dependencies: + is-fullwidth-code-point "^2.0.0" + strip-ansi "^4.0.0" + string-width@^4.2.0: version "4.2.2" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.2.tgz#dafd4f9559a7585cfba529c6a0a4f73488ebd4c5" @@ -2071,6 +2121,13 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" +strip-ansi@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-4.0.0.tgz#a8479022eb1ac368a871389b635262c505ee368f" + integrity sha1-qEeQIusaw2iocTibY1JixQXuNo8= + dependencies: + ansi-regex "^3.0.0" + strip-ansi@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.0.tgz#0b1571dd7669ccd4f3e06e14ef1eed26225ae532" @@ -2114,6 +2171,14 @@ table@^6.0.4: string-width "^4.2.0" strip-ansi "^6.0.0" +terminal-overwrite@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/terminal-overwrite/-/terminal-overwrite-2.0.1.tgz#c732aefeba38900667bf088b4f1b12edbee62841" + integrity sha1-xzKu/ro4kAZnvwiLTxsS7b7mKEE= + dependencies: + cli-cursor "^2.0.0" + string-width "^2.0.0" + text-table@^0.2.0: version "0.2.0" resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"