-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhtmlplus.config.js
119 lines (104 loc) · 2.84 KB
/
htmlplus.config.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import {
assets,
customElement,
document,
extract,
parse,
read,
readme,
style,
validate,
visualStudioCode,
webTypes
} from '@htmlplus/element/transformer.js';
import fs from 'fs';
import path from 'path';
const DESTINATION = 'dist';
const PACKAGE = JSON.parse(fs.readFileSync('./package.json'));
export default [
read(),
parse(),
validate(),
extract(),
style(),
customElement({
prefix: 'plus-'
}),
assets({
destination(context) {
return `${DESTINATION}/elements/${context.fileName}`;
},
json(context) {
return `${DESTINATION}/elements/${context.fileName}/assets.json`;
}
}),
readme(),
document({
destination: `${DESTINATION}/json/document.json`,
transformer(context, element) {
element.description ||= context?.readmeContent
?.split('#')[1]
?.split('\n')
?.slice(1)
?.filter((line) => !!line.trim())[0]
?.trim();
}
}),
visualStudioCode({
destination: `${DESTINATION}/json/vscode.json`,
reference(context) {
return `https://www.htmlplus.io/javascript/element/${context.elementKey}`;
},
transformer(context, element) {
element.name = 'plus-' + element.name;
element.description ||= context?.readmeContent
?.split('#')[1]
?.split('\n')
?.slice(1)
?.filter((line) => !!line.trim())[0]
?.trim();
}
}),
webTypes({
destination: `${DESTINATION}/json/web-types.json`,
packageName: PACKAGE.name,
packageVersion: PACKAGE.version,
reference(context) {
return `https://www.htmlplus.io/javascript/element/${context.elementKey}`;
},
transformer(context, element) {
element.name = 'plus-' + element.name;
element.description ||= context?.readmeContent
?.split('#')[1]
?.split('\n')
?.slice(1)
?.filter((line) => !!line.trim())[0]
?.trim();
}
}),
{
name: 'theme',
finish: (global) => {
const outputs = {};
for (const context of global.contexts) {
try {
const directory = path.join(context.directoryPath, 'theme');
const files = fs.readdirSync(directory);
for (const file of files) {
const content = fs.readFileSync(path.join(directory, file), 'utf8');
outputs[`${file.replace('.css', '')}/${context.fileName}.css`] = content;
outputs[file] ||= '';
outputs[file] += content + '\n';
}
} catch {}
}
for (const output in outputs) {
if (!Object.hasOwnProperty.call(outputs, output)) return;
const file = path.join(DESTINATION, 'theme', output);
const directory = path.dirname(file);
if (!fs.existsSync(directory)) fs.mkdirSync(directory, { recursive: true });
fs.writeFileSync(file, outputs[output], 'utf8');
}
}
}
];