-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.js
40 lines (33 loc) · 1002 Bytes
/
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
'use strict';
const jsdom = require('jsdom');
const {writeFileSync} = require('fs');
const targets = process.argv.slice(2).map(target => target.split(':'));
const prefixes = {
cjs: 'module.exports = ',
es: 'export default '
};
const comment = `/**
* This file was automatically generated from \`build.js\`.
* Do not manually edit.
*/
`;
jsdom.env('https://html.spec.whatwg.org/multipage/syntax.html', (err, window) => {
if (err) {
throw err;
}
const document = window.document;
const codes = document.querySelector('dfn#void-elements')
.parentNode
.nextElementSibling
.textContent
.replace(/\s/gm,'')
.split(",")
.reduce((obj, code) => {
obj[code] = true;
return obj;
}, {});
for (const [file, format = 'cjs'] of targets) {
writeFileSync(file, `${comment}${prefixes[format]}${JSON.stringify(codes, null, 2)};\n`);
}
window.close();
});