forked from david-monichi/compas-open-scd-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-plugins.js
More file actions
108 lines (97 loc) · 3.99 KB
/
build-plugins.js
File metadata and controls
108 lines (97 loc) · 3.99 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
97
98
99
100
101
102
103
104
105
106
107
108
import { build, defineConfig } from 'vite';
import path from 'path';
import { readdir, stat } from 'fs/promises';
import { existsSync, rmSync } from 'fs';
const root = process.cwd();
const distDir = path.resolve(root, 'dist');
const pluginTypes = ['editors', 'menu', 'validators', 'wizards'];
function clearDistFolder(dir) {
if (existsSync(dir)) {
rmSync(dir, { recursive: true, force: true });
console.log(`Cleared output directory: ${dir}`);
} else {
console.log(`Output directory does not exist, so no clearing needed: ${dir}`);
}
}
async function buildAll() {
clearDistFolder(distDir);
for (const pluginType of pluginTypes) {
const folderPath = path.resolve(root, 'apps/plugins/src', pluginType);
// Check if the current plugin type folder exists.
try {
await stat(folderPath);
} catch (error) {
console.warn(`Source folder does not exist for plugin type "${pluginType}" at: ${folderPath}`);
continue;
}
// Read the contents of the folder.
let entries;
try {
entries = await readdir(folderPath);
} catch (error) {
console.error(`Error reading folder at ${folderPath}:`, error);
continue;
}
// Filter for TypeScript files.
const tsFiles = entries.filter(file => file.endsWith('.ts'));
// Process each TypeScript file.
for (const file of tsFiles) {
const filePath = path.resolve(folderPath, file);
const baseName = path.basename(file, '.ts');
const pluginName = `${baseName.charAt(0).toUpperCase()}${baseName.slice(1)}Plugin`;
const outFileName = baseName.toLowerCase();
const config = defineConfig({
build: {
lib: {
entry: filePath,
name: pluginName,
fileName: () => `${pluginType}/${outFileName}.js`,
formats: ['es'],
},
rollupOptions: {
external: [
'lit',
'lit-html',
'lit-element',
'@material/mwc-fab',
'@material/mwc-dialog',
'@material/mwc-button',
"@material/mwc-formfield",
"@material/mwc-icon",
"@material/mwc-icon-button",
"@material/mwc-icon-button-toggle",
"@material/mwc-list",
"@material/mwc-menu",
"@material/mwc-select",
"@material/mwc-switch",
"@material/mwc-textarea",
"@material/mwc-textfield"
],
output: {
inlineDynamicImports: true,
globals: {
lit: 'lit',
'lit-html': 'litHtml',
'lit-element': 'LitElement'
}
},
},
target: 'esnext',
emptyOutDir: false,
configFile: false,
},
resolve: {
alias: {
'@openscd/open-scd': path.resolve(root, 'libs/openscd/open-scd'),
'@openscd/core': path.resolve(root, 'libs/openscd/core'),
'@openscd/xml': path.resolve(root, 'libs/openscd/xml/src'),
},
},
});
console.log(`📦 Building Plugin ${pluginName} from ${pluginType}/${file}...`);
await build(config);
console.log(`✅ Built: ${pluginType}/${outFileName}.js`);
}
}
}
buildAll();