-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhtmlplus.config.js
More file actions
96 lines (81 loc) · 2.15 KB
/
Copy pathhtmlplus.config.js
File metadata and controls
96 lines (81 loc) · 2.15 KB
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
import fs from 'node:fs';
import path from 'node:path';
import {
assets,
customElement,
document,
extract,
parse,
read,
style,
validate,
visualStudioCode,
webTypes
} from '@htmlplus/element/transformer.js';
const DESTINATION = 'dist';
const PACKAGE = JSON.parse(fs.readFileSync('./package.json'));
export default [
read(),
parse(),
validate(),
extract(),
style({
source(context) {
return `${context.directoryPath}/styles.scss`;
}
}),
customElement(),
assets({
destination(context) {
return `${DESTINATION}/elements/${context.directoryName}`;
},
json(context) {
return `${DESTINATION}/elements/${context.directoryName}/assets.json`;
}
}),
document({
destination: `${DESTINATION}/json/document.json`,
transformer(_context, element) {
element.examples = element.examples?.split(',').map((example) => example.trim()) || [];
}
}),
visualStudioCode({
destination: `${DESTINATION}/json/vscode.json`,
reference(context) {
return `https://www.htmlplus.io/javascript/element/${context.elementKey.replace('plus-', '')}`;
}
}),
webTypes({
destination: `${DESTINATION}/json/web-types.json`,
packageName: PACKAGE.name,
packageVersion: PACKAGE.version,
reference(context) {
return `https://www.htmlplus.io/javascript/element/${context.elementKey.replace('plus-', '')}`;
}
}),
{
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.directoryName}.css`] = content;
outputs[file] ||= '';
outputs[file] += `${content}\n`;
}
} catch {}
}
for (const output in outputs) {
if (!Object.hasOwn(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');
}
}
}
];