Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/icons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/build
diff options
context:
space:
mode:
authorXhmikosR <xhmikosr@gmail.com>2019-09-16 09:30:45 +0300
committerXhmikosR <xhmikosr@gmail.com>2019-09-16 13:17:03 +0300
commit74d723bec1b7aae99a9bd96b1ba107906cd3cc4f (patch)
treed0b42ee4f669d13d3a339fd526baec3f27f3f260 /build
parenteb0b9b039cf6790e36ddb0b4c22f14f1810f9c4d (diff)
build-svgs.js: ES6-ify and simplify.
Diffstat (limited to 'build')
-rw-r--r--build/build-svgs.js40
1 files changed, 16 insertions, 24 deletions
diff --git a/build/build-svgs.js b/build/build-svgs.js
index 205978ccd..6a7d8adf5 100644
--- a/build/build-svgs.js
+++ b/build/build-svgs.js
@@ -2,10 +2,9 @@
const fs = require('fs')
const path = require('path')
+const chalk = require('chalk')
const cheerio = require('cheerio')
-const chalk = require('chalk');
-const log = console.log;
const iconsDir = path.join(__dirname, '../icons/')
const svgAttributes = {
@@ -14,7 +13,7 @@ const svgAttributes = {
height: '20',
viewBox: '0 0 20 20',
fill: 'currentColor',
- xmlns: 'http://www.w3.org/2000/svg',
+ xmlns: 'http://www.w3.org/2000/svg'
}
fs.readdir(iconsDir, (error, files) => {
@@ -22,7 +21,7 @@ fs.readdir(iconsDir, (error, files) => {
throw error
}
- files.forEach((file, index) => {
+ files.forEach(file => {
file = path.join(iconsDir, file)
fs.readFile(file, 'utf8', (err, data) => {
@@ -30,37 +29,30 @@ fs.readdir(iconsDir, (error, files) => {
throw err
}
- const $ = cheerio.load(data);
- const svg = $('svg');
+ const $ = cheerio.load(data)
+ const svg = $('svg')
- svg.replaceWith(function () {
- return $('<svg>').append($(this).html());
- });
+ svg.replaceWith(() => $('<svg>').append($(this).html()))
- const entries = Object.entries(svgAttributes)
- for (const [attr, val] of entries) {
- $(svg).removeAttr(attr);
- $(svg).attr(attr, val);
+ for (const [attr, val] of Object.entries(svgAttributes)) {
+ $(svg).removeAttr(attr)
+ $(svg).attr(attr, val)
}
- const filename = path.basename(file, '.svg')
- $(svg).attr('class', 'bi bi-' + filename)
+ $(svg).attr('class', `bi bi-${path.basename(file, '.svg')}`)
- const result = $(svg)
-
- fs.writeFile(file, result, 'utf8', err => {
+ fs.writeFile(file, $(svg), 'utf8', err => {
if (err) {
throw err
}
- log(`- ${path.basename(file, '.svg')}`)
+ console.log(`- ${path.basename(file, '.svg')}`)
})
})
})
- function logSuccess() {
- log(chalk.green('\nSuccess, ' + files.length + ' icons prepped!'))
- }
- setTimeout(logSuccess, 1000);
-
+ // the setTimeout should be removed
+ setTimeout(() => {
+ console.log(chalk.green(`\nSuccess, ${files.length} icons prepped!`))
+ }, 1000)
})