-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
build.js
executable file
·48 lines (38 loc) · 1.37 KB
/
build.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/**
* @typedef {import('type-fest').PackageJson} PackageJson
*/
import assert from 'node:assert/strict'
import fs from 'node:fs/promises'
import path from 'node:path'
const languageNames = new Intl.DisplayNames(['en'], {type: 'language'})
const cussUrl = new URL('node_modules/cuss/', import.meta.url)
const pkgUrl = new URL('package.json', cussUrl)
/** @type {PackageJson} */
const pkg = JSON.parse(String(await fs.readFile(pkgUrl)))
assert(pkg.exports, 'expected `exports` in `cuss`')
const files = [...new Set(Object.values(pkg.exports))]
let index = -1
/* eslint-disable no-await-in-loop */
while (++index < files.length) {
const basename = files[index]
assert(typeof basename === 'string', 'expected string exports in `cuss`')
const modUrl = new URL(basename, cussUrl)
/** @type {{cuss: Record<string, number>}} */
const mod = await import(modUrl.href)
const profanities = Object.keys(mod.cuss)
const stem = path.basename(basename, path.extname(basename))
const code = stem === 'index' ? 'en' : stem
const language = languageNames.of(code)
await fs.writeFile(
basename,
'/**\n * List of ' +
language +
' profane words.\n */\nexport const profanities = ' +
JSON.stringify(profanities, null, 2) +
'\n'
)
console.log(
'✓ ' + basename + ' (' + language + '; ' + profanities.length + ')'
)
}
/* eslint-enable no-await-in-loop */