-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprocess.js
More file actions
36 lines (31 loc) · 1.07 KB
/
process.js
File metadata and controls
36 lines (31 loc) · 1.07 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
import { copyFile, readFile, readdir, rm, writeFile } from 'fs/promises';
(async () => {
const files = await readdir('dist');
const regex = /customElements\.define\((.*)\);export/;
await Promise.all(
files.map(async (file) => {
if (
!file.endsWith('.js') &&
!file.endsWith('.map') &&
!file.endsWith('.ts') &&
!file.endsWith('.css')
) {
const files = await readdir('dist/' + file);
await Promise.allSettled(files.map((f) => copyFile('dist/' + file + '/' + f, 'dist/' + f)));
await Promise.all(files.map((f) => rm('dist/' + file, { recursive: true })));
} else if (file.endsWith('.wc.js')) {
const path = `dist/${file}`;
const data = (await readFile(path)).toString();
const match = regex.exec(data);
if (match) {
await writeFile(
path,
data.replace(match[0], `try{customElements.define(${match[1]});}catch{};export`)
);
} else {
console.error(`No matches found in file: ${path}`);
}
}
})
);
})();