Skip to content

Commit

Permalink
Switch to modules
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Mar 28, 2023
1 parent a98d3ea commit 15fc46d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 35 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"node": true
},
"parserOptions": {
"ecmaVersion": 2019
"ecmaVersion": 2020,
"sourceType": "module"
},
"extends": "eslint:recommended",
"rules": {
Expand Down
10 changes: 6 additions & 4 deletions build/build-pages.js → build/build-pages.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/usr/bin/env node

'use strict'
import fs from 'node:fs/promises'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import picocolors from 'picocolors'

const fs = require('node:fs').promises
const path = require('node:path')
const picocolors = require('picocolors')
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(fileURLToPath(import.meta.url))

const iconsDir = path.join(__dirname, '../icons/')
const pagesDir = path.join(__dirname, '../docs/content/icons/')
Expand Down
22 changes: 12 additions & 10 deletions build/build-svgs.js → build/build-svgs.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/usr/bin/env node

'use strict'
import { readdir, readFile, writeFile } from 'node:fs/promises'
import path from 'node:path'
import process from 'node:process'
import { fileURLToPath } from 'node:url'
import picocolors from 'picocolors'
import { loadConfig, optimize } from 'svgo'

const fs = require('node:fs').promises
const path = require('node:path')
const process = require('node:process')
const picocolors = require('picocolors')
const { loadConfig, optimize } = require('svgo')
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(fileURLToPath(import.meta.url))

const iconsDir = path.join(__dirname, '../icons/')

Expand All @@ -16,14 +18,14 @@ async function processFile(file, config) {
const filepath = path.join(iconsDir, file)
const basename = path.basename(file, '.svg')

const originalSvg = await fs.readFile(filepath, 'utf8')
const originalSvg = await readFile(filepath, 'utf8')
const { data: optimizedSvg } = await optimize(originalSvg, { path: filepath, ...config })

// svgo will always add a final newline when in pretty mode
const resultSvg = optimizedSvg.trim()

if (resultSvg !== originalSvg) {
await fs.writeFile(filepath, resultSvg, 'utf8')
await writeFile(filepath, resultSvg, 'utf8')
}

if (VERBOSE) {
Expand All @@ -39,8 +41,8 @@ async function processFile(file, config) {
console.log(picocolors.cyan(`[${basename}] started`))
console.time(timeLabel)

const files = await fs.readdir(iconsDir)
const config = await loadConfig(path.join(__dirname, '../svgo.config.js'))
const files = await readdir(iconsDir)
const config = await loadConfig(path.join(__dirname, '../svgo.config.mjs'))

await Promise.all(files.map(file => processFile(file, config)))

Expand Down
16 changes: 9 additions & 7 deletions build/check-icons.js → build/check-icons.mjs
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#!/usr/bin/env node

'use strict'
import { readdir, readFile } from 'node:fs/promises'
import path from 'node:path'
import process from 'node:process'
import { fileURLToPath } from 'node:url'
import picocolors from 'picocolors'

const fs = require('node:fs').promises
const path = require('node:path')
const process = require('node:process')
const picocolors = require('picocolors')
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(fileURLToPath(import.meta.url))

const fontJsonPath = path.join(__dirname, '../font/bootstrap-icons.json')
const iconsDir = path.join(__dirname, '../icons/')
Expand All @@ -18,9 +20,9 @@ const iconsDir = path.join(__dirname, '../icons/')
console.log(picocolors.cyan(`[${basename}] started`))
console.time(timeLabel)

const fontJsonString = await fs.readFile(fontJsonPath, 'utf8')
const fontJsonString = await readFile(fontJsonPath, 'utf8')
const fontJson = JSON.parse(fontJsonString)
const svgFiles = await fs.readdir(iconsDir)
const svgFiles = await readdir(iconsDir)

const jsonIconList = Object.keys(fontJson)
const svgIconList = svgFiles.map(svg => path.basename(svg, path.extname(svg)))
Expand Down
6 changes: 2 additions & 4 deletions build/vnu-jar.js → build/vnu-jar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
*/

'use strict'

const { execFile, spawn } = require('node:child_process')
const vnu = require('vnu-jar')
import { execFile, spawn } from 'node:child_process'
import vnu from 'vnu-jar'

execFile('java', ['-version'], (error, stdout, stderr) => {
if (error) {
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@
"start": "npm run docs-serve",
"docs-serve": "hugo server --port 4000 --disableFastRender",
"docs-build": "hugo --cleanDestinationDir --printUnusedTemplates",
"pages": "node build/build-pages.js",
"pages": "node build/build-pages.mjs",
"icons": "npm-run-all icons-main --aggregate-output --parallel icons-sprite icons-font",
"icons-main": "node build/build-svgs.js",
"icons-main": "node build/build-svgs.mjs",
"icons-zip": "cross-env-shell \"rm -rf bootstrap-icons-$npm_package_version && rm -f bootstrap-icons-$npm_package_version.zip && cp -r icons/ bootstrap-icons-$npm_package_version && cp bootstrap-icons.svg bootstrap-icons-$npm_package_version && cp -r font/ bootstrap-icons-$npm_package_version && zip -qr9 bootstrap-icons-$npm_package_version.zip bootstrap-icons-$npm_package_version && rm -rf bootstrap-icons-$npm_package_version\"",
"icons-sprite": "svg-sprite --config svg-sprite.json --log=info icons/*.svg",
"icons-font": "fantasticon",
"release": "npm-run-all icons docs-build icons-zip",
"netlify": "cross-env-shell HUGO_BASEURL=$DEPLOY_PRIME_URL npm-run-all icons docs-build",
"test:fusv": "fusv docs/assets/scss/",
"test:eslint": "eslint --cache --cache-location node_modules/.cache/.eslintcache --report-unused-disable-directives .",
"test:eslint": "eslint --cache --cache-location node_modules/.cache/.eslintcache --report-unused-disable-directives --ext .js,.mjs .",
"test:stylelint": "stylelint docs/assets/scss/ --cache --cache-location node_modules/.cache/.stylelintcache --rd",
"test:lockfile-lint": "lockfile-lint --allowed-hosts npm --allowed-schemes https: --empty-hostname false --type npm --path package-lock.json",
"test:vnu": "node build/vnu-jar.js",
"test:check-icons": "node build/check-icons.js",
"test:vnu": "node build/vnu-jar.mjs",
"test:check-icons": "node build/check-icons.mjs",
"test": "npm-run-all docs-build --parallel --aggregate-output --continue-on-error test:*"
},
"style": "font/bootstrap-icons.css",
Expand Down
6 changes: 2 additions & 4 deletions svgo.config.js → svgo.config.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict'
import path from 'node:path'

const path = require('node:path')

module.exports = {
export default {
multipass: true,
js2svg: {
pretty: true,
Expand Down

0 comments on commit 15fc46d

Please sign in to comment.