Skip to content

Commit

Permalink
build: switch to modules (#1663)
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Apr 26, 2023
1 parent a51ba52 commit 3d5e1e7
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"parserOptions": {
"ecmaVersion": 2019,
"sourceType": "script"
"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
16 changes: 9 additions & 7 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 fs 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 Down Expand Up @@ -40,7 +42,7 @@ async function processFile(file, config) {
console.time(timeLabel)

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

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

Expand Down
14 changes: 8 additions & 6 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'

const fs = require('node:fs').promises
const path = require('node:path')
const process = require('node:process')
const picocolors = require('picocolors')
import fs from 'node:fs/promises'
import path from 'node:path'
import process from 'node:process'
import { fileURLToPath } from 'node:url'
import picocolors from '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 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
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
"docs-serve": "hugo server --port 4000 --disableFastRender",
"docs-build": "hugo --cleanDestinationDir --printUnusedTemplates",
"docs-test": "npm-run-all docs-build docs-test:vnu",
"docs-test:vnu": "node build/vnu-jar.js",
"pages": "node build/build-pages.js",
"docs-test:vnu": "node build/vnu-jar.mjs",
"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 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": "npm-run-all icons-font-*",
Expand All @@ -62,7 +62,7 @@
"test:eslint": "eslint --cache --cache-location .cache/.eslintcache --report-unused-disable-directives .",
"test:stylelint": "stylelint docs/assets/scss/ --cache --cache-location .cache/.stylelintcache",
"test:lockfile-lint": "lockfile-lint --allowed-hosts npm --allowed-schemes https: --empty-hostname false --type npm --path package-lock.json",
"test:check-icons": "node build/check-icons.js",
"test:check-icons": "node build/check-icons.mjs",
"test": "npm-run-all --parallel --aggregate-output --continue-on-error test:*"
},
"devDependencies": {
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 3d5e1e7

Please sign in to comment.