diff --git a/lib/make-badge.js b/lib/make-badge.js index 965c8e88706ea..4cd0e5ff3725b 100644 --- a/lib/make-badge.js +++ b/lib/make-badge.js @@ -13,7 +13,7 @@ const badgeKeyWidthCache = new LruCache(1000); const templates = {}; const templateFiles = fs.readdirSync(path.join(__dirname, '..', 'templates')); dot.templateSettings.strip = false; // Do not strip whitespace. -templateFiles.forEach(function(filename) { +templateFiles.forEach(async function(filename) { if (filename[0] === '.') { return; } const templateData = fs.readFileSync( path.join(__dirname, '..', 'templates', filename)).toString(); @@ -32,37 +32,41 @@ templateFiles.forEach(function(filename) { mapping.set(mapKey, match); return mapKey; }); - compressSvg(untemplatedSvg, function(object) { - if (object.error !== undefined) { - console.error(`Template ${filename}: ${object.error}\n` + - ' Generated untemplated SVG:\n' + - `---\n${untemplatedSvg}---\n`); - return; - } - // Substitute dot code back. - let svg = object.data; - const unmappedKeys = []; - mapping.forEach(function(value, key) { - let keySubstituted = false; - svg = svg.replace(RegExp(key, 'g'), function() { - keySubstituted = true; - return value; - }); - if (!keySubstituted) { - unmappedKeys.push(key); - } + + const svgo = new SVGO(); + const { data, error } = await svgo.optimize(untemplatedSvg); + + if (error !== undefined) { + console.error(`Template ${filename}: ${error}\n` + + ' Generated untemplated SVG:\n' + + `---\n${untemplatedSvg}---\n`); + return; + } + + // Substitute dot code back. + let svg = data; + const unmappedKeys = []; + mapping.forEach(function(value, key) { + let keySubstituted = false; + svg = svg.replace(RegExp(key, 'g'), function() { + keySubstituted = true; + return value; }); - if (unmappedKeys.length > 0) { - console.error(`Template ${filename} has unmapped keys ` + - `${unmappedKeys.join(', ')}.\n` + - ' Generated untemplated SVG:\n' + - `---\n${untemplatedSvg}\n---\n` + - ' Generated template:\n' + - `---\n${svg}\n---\n`); - return; + if (!keySubstituted) { + unmappedKeys.push(key); } - templates[style + '-' + extension] = dot.template(svg); }); + if (unmappedKeys.length > 0) { + console.error(`Template ${filename} has unmapped keys ` + + `${unmappedKeys.join(', ')}.\n` + + ' Generated untemplated SVG:\n' + + `---\n${untemplatedSvg}\n---\n` + + ' Generated template:\n' + + `---\n${svg}\n---\n`); + return; + } + + templates[style + '-' + extension] = dot.template(svg); } }); @@ -84,11 +88,6 @@ function capitalize(s) { const definedColorschemes = require(path.join(__dirname, 'colorscheme.json')); -function compressSvg(string, callback) { - const svgo = new SVGO(); - svgo.optimize(string, callback); -} - const cssColor = /^#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})$/; // Inject the measurer to avoid placing any persistent state in this module. diff --git a/package-lock.json b/package-lock.json index f79ba9229fc2e..bc36ea4978f15 100644 --- a/package-lock.json +++ b/package-lock.json @@ -382,12 +382,14 @@ "ansi-regex": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", - "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=" + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", + "dev": true }, "ansi-styles": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", - "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=" + "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", + "dev": true }, "any-promise": { "version": "1.3.0", @@ -2413,6 +2415,7 @@ "version": "1.1.3", "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", + "dev": true, "requires": { "ansi-styles": "2.2.1", "escape-string-regexp": "1.0.5", @@ -2704,14 +2707,6 @@ "resolved": "https://registry.npmjs.org/cjson/-/cjson-0.2.1.tgz", "integrity": "sha1-c82KrWXZ4VBfmvF0TTt5wVJ2gqU=" }, - "clap": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/clap/-/clap-1.2.3.tgz", - "integrity": "sha512-4CoL/A3hf90V3VIEjeuhSvlGFEHKzOz+Wfc2IVZc+FaUgU0ZQafJTP49fvnULipOPcAfqhyI2duwQyns6xqjYA==", - "requires": { - "chalk": "1.1.3" - } - }, "class-utils": { "version": "0.3.6", "resolved": "https://registry.npmjs.org/class-utils/-/class-utils-0.3.6.tgz", @@ -2855,11 +2850,11 @@ "integrity": "sha1-bqa989hTrlTMuOR7+gvz+QMfsYQ=" }, "coa": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/coa/-/coa-1.0.4.tgz", - "integrity": "sha1-qe8VNmDWqGqL3sAomlxoTSF0Mv0=", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/coa/-/coa-2.0.1.tgz", + "integrity": "sha512-5wfTTO8E2/ja4jFSxePXlG5nRu5bBtL/r1HCIpJW/lzT6yDtKl0u0Z4o/Vpz32IpKmBn7HerheEZQgA9N2DarQ==", "requires": { - "q": "1.5.0" + "q": "1.5.1" } }, "code-point-at": { @@ -3306,18 +3301,47 @@ "nth-check": "1.0.1" } }, + "css-select-base-adapter": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/css-select-base-adapter/-/css-select-base-adapter-0.1.0.tgz", + "integrity": "sha1-AQKz0UYw34bD65+p9UVicBBs+ZA=" + }, + "css-tree": { + "version": "1.0.0-alpha25", + "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-1.0.0-alpha25.tgz", + "integrity": "sha512-XC6xLW/JqIGirnZuUWHXCHRaAjje2b3OIB0Vj5RIJo6mIi/AdJo30quQl5LxUl0gkXDIrTrFGbMlcZjyFplz1A==", + "requires": { + "mdn-data": "1.1.0", + "source-map": "0.5.7" + } + }, + "css-url-regex": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/css-url-regex/-/css-url-regex-1.1.0.tgz", + "integrity": "sha1-g4NCMMyfdMRX3lnuvRVD/uuDt+w=" + }, "css-what": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/css-what/-/css-what-2.1.0.tgz", "integrity": "sha1-lGfQMsOM+u+58teVASUwYvh/ob0=" }, "csso": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/csso/-/csso-2.3.2.tgz", - "integrity": "sha1-3dUsWHAz9J6Utx/FVWnyUuj/X4U=", + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/csso/-/csso-3.5.0.tgz", + "integrity": "sha512-WtJjFP3ZsSdWhiZr4/k1B9uHPgYjFYnDxfbaJxk1hz5PDLIJ5BCRWkJqaztZ0DbP8d2ZIVwUPIJb2YmCwkPaMw==", "requires": { - "clap": "1.2.3", - "source-map": "0.5.7" + "css-tree": "1.0.0-alpha.27" + }, + "dependencies": { + "css-tree": { + "version": "1.0.0-alpha.27", + "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-1.0.0-alpha.27.tgz", + "integrity": "sha512-BAYp9FyN4jLXjfvRpTDchBllDptqlK9I7OsagXCG9Am5C+5jc8eRZHgqb9x500W2OKS14MMlpQc/nmh/aA7TEQ==", + "requires": { + "mdn-data": "1.1.0", + "source-map": "0.5.7" + } + } } }, "cssom": { @@ -6387,6 +6411,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", + "dev": true, "requires": { "ansi-regex": "2.1.1" } @@ -7467,18 +7492,18 @@ "dev": true }, "js-yaml": { - "version": "3.7.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.7.0.tgz", - "integrity": "sha1-XJZ93YN6m/3KXy3oQlOr6KHAO4A=", + "version": "3.10.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.10.0.tgz", + "integrity": "sha512-O2v52ffjLa9VeM43J4XocZE//WT9N0IiwDa3KSHH7Tu8CtH+1qM8SIZvnsTh6v+4yFy5KUY3BHUVwjpfAWsjIA==", "requires": { "argparse": "1.0.9", - "esprima": "2.7.3" + "esprima": "4.0.0" }, "dependencies": { "esprima": { - "version": "2.7.3", - "resolved": "https://registry.npmjs.org/esprima/-/esprima-2.7.3.tgz", - "integrity": "sha1-luO3DVd59q1JzQMmc9HDEnZ7pYE=" + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.0.tgz", + "integrity": "sha512-oftTcaMu/EGrEIu904mWteKIv8vMuOgGYo7EhVJJN00R/EED9DCua/xxHRdYnKtcECzVg7xOWhflvJMnqcFZjw==" } } }, @@ -8198,6 +8223,11 @@ } } }, + "mdn-data": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-1.1.0.tgz", + "integrity": "sha512-jC6B3BFC07cCOU8xx1d+sQtDkVIpGKWv4TzK7pN7PyObdbwlIFJbHYk8ofvr0zrU8SkV1rSi87KAHhWCdLGw1Q==" + }, "mem": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/mem/-/mem-1.1.0.tgz", @@ -9475,6 +9505,15 @@ "object-keys": "1.0.11" } }, + "object.getownpropertydescriptors": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/object.getownpropertydescriptors/-/object.getownpropertydescriptors-2.0.3.tgz", + "integrity": "sha1-h1jIRvW0B62rDyNuCYbxSwUcqhY=", + "requires": { + "define-properties": "1.1.2", + "es-abstract": "1.9.0" + } + }, "object.omit": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/object.omit/-/object.omit-2.0.1.tgz", @@ -9502,6 +9541,17 @@ } } }, + "object.values": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/object.values/-/object.values-1.0.4.tgz", + "integrity": "sha1-5STaCbT2b/Bd9FdUbscqyZ8TBpo=", + "requires": { + "define-properties": "1.1.2", + "es-abstract": "1.9.0", + "function-bind": "1.1.1", + "has": "1.0.1" + } + }, "on-finished": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", @@ -10163,9 +10213,9 @@ "integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=" }, "q": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/q/-/q-1.5.0.tgz", - "integrity": "sha1-3QG6ydBtMObyGa7LglPunr3DCPE=" + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz", + "integrity": "sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=" }, "qs": { "version": "6.4.0", @@ -11609,6 +11659,11 @@ "safe-buffer": "5.1.1" } }, + "stable": { + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/stable/-/stable-0.1.6.tgz", + "integrity": "sha1-kQ9dKu17Ugxud3SZwfMuE5/eyxA=" + }, "stack-trace": { "version": "0.0.9", "resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.9.tgz", @@ -12012,6 +12067,7 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "dev": true, "requires": { "ansi-regex": "2.1.1" } @@ -12095,7 +12151,8 @@ "supports-color": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", - "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=" + "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", + "dev": true }, "supports-hyperlinks": { "version": "1.0.1", @@ -12119,17 +12176,37 @@ } }, "svgo": { - "version": "0.7.2", - "resolved": "https://registry.npmjs.org/svgo/-/svgo-0.7.2.tgz", - "integrity": "sha1-n1dyQTlSE1xv779Ar+ak+qiLS7U=", + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/svgo/-/svgo-1.0.5.tgz", + "integrity": "sha512-nYrifviB77aNKDNKKyuay3M9aYiK6Hv5gJVDdjj2ZXTQmI8WZc8+UPLR5IpVlktJfSu3co/4XcWgrgI6seGBPg==", "requires": { - "coa": "1.0.4", + "coa": "2.0.1", "colors": "1.1.2", - "csso": "2.3.2", - "js-yaml": "3.7.0", + "css-select": "1.3.0-rc0", + "css-select-base-adapter": "0.1.0", + "css-tree": "1.0.0-alpha25", + "css-url-regex": "1.1.0", + "csso": "3.5.0", + "js-yaml": "3.10.0", "mkdirp": "0.5.1", + "object.values": "1.0.4", "sax": "1.2.4", - "whet.extend": "0.9.9" + "stable": "0.1.6", + "unquote": "1.1.1", + "util.promisify": "1.0.0" + }, + "dependencies": { + "css-select": { + "version": "1.3.0-rc0", + "resolved": "https://registry.npmjs.org/css-select/-/css-select-1.3.0-rc0.tgz", + "integrity": "sha1-b5MZaqrnN2ZuoQNqjLFKj8t6kjE=", + "requires": { + "boolbase": "1.0.0", + "css-what": "2.1.0", + "domutils": "1.5.1", + "nth-check": "1.0.1" + } + } } }, "symbol-tree": { @@ -12729,6 +12806,11 @@ "crypto-random-string": "1.0.0" } }, + "unquote": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/unquote/-/unquote-1.1.1.tgz", + "integrity": "sha1-j97XMk7G6IoP+LkF58CYzcCG1UQ=" + }, "unset-value": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unset-value/-/unset-value-1.0.0.tgz", @@ -13002,6 +13084,15 @@ "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" }, + "util.promisify": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/util.promisify/-/util.promisify-1.0.0.tgz", + "integrity": "sha512-i+6qA2MPhvoKLuxnJNpXAGhg7HphQOSUq2LKMZD0m15EiskXUkMvKdF4Uui0WYeCUGea+o2cw/ZuwehtfsrNkA==", + "requires": { + "define-properties": "1.1.2", + "object.getownpropertydescriptors": "2.0.3" + } + }, "uuid": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz", @@ -13297,11 +13388,6 @@ "tr46": "0.0.3" } }, - "whet.extend": { - "version": "0.9.9", - "resolved": "https://registry.npmjs.org/whet.extend/-/whet.extend-0.9.9.tgz", - "integrity": "sha1-+HfVv2SMl+WqVC+twW1qJZucEaE=" - }, "which": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/which/-/which-1.3.0.tgz", diff --git a/package.json b/package.json index 9d3c5ac126ac0..52538a115ab4d 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "redis": "~2.6.2", "request": "~2.85.0", "semver": "~5.5.0", - "svgo": "~0.7.1", + "svgo": "~1.0.5", "xml2js": "~0.4.16", "xmldom": "~0.1.27", "xpath": "~0.0.27"