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>2020-12-30 22:37:41 +0300
committerMark Otto <otto@github.com>2021-01-05 09:12:48 +0300
commit117dabbe6938331abeb348167f6da08d4e320019 (patch)
tree16b0f115c52949877e95e5d148f59f0475ee4a4f /build
parent78b8c228c109d079d5ebc1ba2c6b4ddddf491593 (diff)
Tweak build-svgs.js
* change `process.argv` to `includes()`; should work with multiple arguments if we decide to add them later * switch to function declarations * remove redundant return await * catch errors in `processFile()` * add missing `await` in cheerio.load
Diffstat (limited to 'build')
-rw-r--r--build/build-svgs.js17
1 files changed, 10 insertions, 7 deletions
diff --git a/build/build-svgs.js b/build/build-svgs.js
index 8c282343e..584c726f4 100644
--- a/build/build-svgs.js
+++ b/build/build-svgs.js
@@ -11,7 +11,7 @@ const yaml = require('js-yaml')
const iconsDir = path.join(__dirname, '../icons/')
-const VERBOSE = process.argv[2] === '--verbose'
+const VERBOSE = process.argv.includes('--verbose')
const svgAttributes = {
xmlns: 'http://www.w3.org/2000/svg',
@@ -22,13 +22,13 @@ const svgAttributes = {
viewBox: '0 0 16 16'
}
-const getSvgoConfig = async () => {
+async function getSvgoConfig() {
const svgoConfigFile = await fs.readFile(path.join(__dirname, '../svgo.yml'), 'utf8')
- return await yaml.safeLoad(svgoConfigFile)
+ return yaml.safeLoad(svgoConfigFile)
}
-const processFile = async (file, config) => {
+async function processFile(file, config) {
const filepath = path.join(iconsDir, file)
const basename = path.basename(file, '.svg')
@@ -36,7 +36,7 @@ const processFile = async (file, config) => {
const svgo = await new SVGO(config)
const optimizedSvg = await svgo.optimize(originalSvg)
- const $ = cheerio.load(optimizedSvg.data, {
+ const $ = await cheerio.load(optimizedSvg.data, {
xml: {
xmlMode: true
}
@@ -76,11 +76,14 @@ const processFile = async (file, config) => {
const files = await fs.readdir(iconsDir)
const config = await getSvgoConfig()
- await Promise.all(files.map(file => processFile(file, config)))
+ await Promise.all(files.map(file => {
+ return processFile(file, config)
+ .catch(error => Promise.reject(error))
+ }))
const filesLength = files.length
- console.log(chalk.green(`\nSuccess, ${filesLength} icon${filesLength !== 1 ? 's' : ''} prepped!`))
+ console.log(chalk.green('\nSuccess, %s icon%s prepared!'), filesLength, filesLength !== 1 ? 's' : '')
console.timeEnd(timeLabel)
} catch (error) {
console.error(error)