agora-toolchain 3.8.2 → 3.9.0-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { defineConfig } from 'electron-vite';
|
|
2
2
|
import commonjs from '@rollup/plugin-commonjs';
|
|
3
3
|
import legacy from '@vitejs/plugin-legacy';
|
|
4
|
-
import { existsSync } from 'fs';
|
|
4
|
+
import { existsSync, writeFileSync, unlinkSync } from 'fs';
|
|
5
|
+
import path from 'path';
|
|
5
6
|
import { resolveCwd, resolveModule } from '../tools/paths';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -82,6 +83,88 @@ export default defineConfig(() => {
|
|
|
82
83
|
const preloadEntry = process.env.VITE_PRELOAD_ENTRY || 'electron/preload/index.js';
|
|
83
84
|
const rendererEntry =
|
|
84
85
|
process.env.VITE_RENDERER_ENTRY || 'electron/renderer/public/index.vite.html';
|
|
86
|
+
const rendererFragments = process.env.fcr_fragments || '';
|
|
87
|
+
|
|
88
|
+
const generatedFragmentFiles = [];
|
|
89
|
+
|
|
90
|
+
const ensureFragmentHtml = (fragmentName) => {
|
|
91
|
+
const filePath = resolveCwd(`${fragmentName}.html`);
|
|
92
|
+
|
|
93
|
+
if (existsSync(filePath)) {
|
|
94
|
+
return filePath;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const html = `<!doctype html>
|
|
98
|
+
<html lang="en">
|
|
99
|
+
<head>
|
|
100
|
+
<meta charset="UTF-8" />
|
|
101
|
+
<title></title>
|
|
102
|
+
</head>
|
|
103
|
+
<body>
|
|
104
|
+
<div id="root"></div>
|
|
105
|
+
</body>
|
|
106
|
+
<script type="module">
|
|
107
|
+
import { title, windowOptions, webPreferences } from '/src/fragments/${fragmentName}/index.tsx';
|
|
108
|
+
if (title) document.title = title;
|
|
109
|
+
if (window.runtime && window.runtime.setFragmentOptions) {
|
|
110
|
+
window.runtime.setFragmentOptions('${fragmentName}', windowOptions || {}, webPreferences || {});
|
|
111
|
+
}
|
|
112
|
+
</script>
|
|
113
|
+
</html>
|
|
114
|
+
`;
|
|
115
|
+
writeFileSync(filePath, html);
|
|
116
|
+
generatedFragmentFiles.push(filePath);
|
|
117
|
+
|
|
118
|
+
return filePath;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const parseRendererFragments = (value) => {
|
|
122
|
+
if (!value) return {};
|
|
123
|
+
|
|
124
|
+
return value
|
|
125
|
+
.split(',')
|
|
126
|
+
.map((item) => item.trim())
|
|
127
|
+
.filter(Boolean)
|
|
128
|
+
.reduce((acc, item) => {
|
|
129
|
+
if (
|
|
130
|
+
!item.includes('=') &&
|
|
131
|
+
!item.includes('/') &&
|
|
132
|
+
!item.includes('\\') &&
|
|
133
|
+
!item.includes('.')
|
|
134
|
+
) {
|
|
135
|
+
const fragmentName = item;
|
|
136
|
+
const htmlPath = ensureFragmentHtml(fragmentName);
|
|
137
|
+
if (htmlPath) {
|
|
138
|
+
acc[fragmentName] = htmlPath;
|
|
139
|
+
}
|
|
140
|
+
return acc;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const [name, fragmentPath] = item.includes('=') ? item.split('=') : [null, item];
|
|
144
|
+
const trimmedPath = fragmentPath?.trim();
|
|
145
|
+
const trimmedName =
|
|
146
|
+
(name && name.trim()) || path.basename(trimmedPath).replace(/\.html$/i, '');
|
|
147
|
+
|
|
148
|
+
if (!trimmedName || !trimmedPath) {
|
|
149
|
+
console.warn(`Invalid fragment entry: "${item}", expected name=path`);
|
|
150
|
+
return acc;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (trimmedName === 'index') {
|
|
154
|
+
console.warn(`Skip fragment entry "${item}" because "index" is reserved`);
|
|
155
|
+
return acc;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const resolvedPath = resolveCwd(trimmedPath);
|
|
159
|
+
if (!existsSync(resolvedPath)) {
|
|
160
|
+
console.warn(`Fragment entry not found: ${trimmedPath}`);
|
|
161
|
+
return acc;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
acc[trimmedName] = resolvedPath;
|
|
165
|
+
return acc;
|
|
166
|
+
}, {});
|
|
167
|
+
};
|
|
85
168
|
|
|
86
169
|
// Check if entry files exist
|
|
87
170
|
const mainEntryPath = resolveCwd(mainEntry);
|
|
@@ -95,7 +178,12 @@ export default defineConfig(() => {
|
|
|
95
178
|
console.log('Using electron-vite config with:');
|
|
96
179
|
console.log(' Main entry:', mainEntry, hasMain ? '✓' : '✗');
|
|
97
180
|
console.log(' Preload entry:', preloadEntry, hasPreload ? '✓' : '✗');
|
|
181
|
+
const fragmentEntries = parseRendererFragments(rendererFragments);
|
|
182
|
+
const fragmentKeys = Object.keys(fragmentEntries);
|
|
98
183
|
console.log(' Renderer entry:', rendererEntry, hasRenderer ? '✓' : '✗');
|
|
184
|
+
if (fragmentKeys.length) {
|
|
185
|
+
console.log(' Renderer fragments:', fragmentKeys.join(', '));
|
|
186
|
+
}
|
|
99
187
|
console.log(' Output dir prefix:', outDirPrefix);
|
|
100
188
|
|
|
101
189
|
if (!hasMain && !hasPreload && !hasRenderer) {
|
|
@@ -242,6 +330,17 @@ export default defineConfig(() => {
|
|
|
242
330
|
// MapIterator.find
|
|
243
331
|
additionalLegacyPolyfills: ['core-js/proposals/iterator-helpers'],
|
|
244
332
|
}),
|
|
333
|
+
{
|
|
334
|
+
name: 'fcr-clean-fragment-html',
|
|
335
|
+
closeBundle() {
|
|
336
|
+
if (!generatedFragmentFiles.length) return;
|
|
337
|
+
generatedFragmentFiles.forEach((filePath) => {
|
|
338
|
+
if (existsSync(filePath)) {
|
|
339
|
+
unlinkSync(filePath);
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
},
|
|
343
|
+
},
|
|
245
344
|
],
|
|
246
345
|
// 渲染进程构建配置
|
|
247
346
|
root: '.',
|
|
@@ -252,6 +351,7 @@ export default defineConfig(() => {
|
|
|
252
351
|
external,
|
|
253
352
|
input: {
|
|
254
353
|
index: resolveCwd(rendererEntry),
|
|
354
|
+
...fragmentEntries,
|
|
255
355
|
},
|
|
256
356
|
},
|
|
257
357
|
},
|
package/presets/webpack.base.js
CHANGED
package/env/tsconfig.json
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
// excluding regex trick: http://www.rexegg.com/regex-best-trick.html
|
|
2
|
-
|
|
3
|
-
// Not anything inside double quotes
|
|
4
|
-
// Not anything inside single quotes
|
|
5
|
-
// Not anything inside url()
|
|
6
|
-
// Any digit followed by px
|
|
7
|
-
// !singlequotes|!doublequotes|!url()|pixelunit
|
|
8
|
-
function getUnitRegexp(unit) {
|
|
9
|
-
return new RegExp('"[^"]+"|\'[^\']+\'|url\\([^\\)]+\\)|(\\d*\\.?\\d+)' + unit, 'g');
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
module.exports = {
|
|
13
|
-
getUnitRegexp,
|
|
14
|
-
};
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
var filterPropList = {
|
|
2
|
-
exact: function (list) {
|
|
3
|
-
return list.filter(function (m) {
|
|
4
|
-
return m.match(/^[^\*\!]+$/);
|
|
5
|
-
});
|
|
6
|
-
},
|
|
7
|
-
contain: function (list) {
|
|
8
|
-
return list
|
|
9
|
-
.filter(function (m) {
|
|
10
|
-
return m.match(/^\*.+\*$/);
|
|
11
|
-
})
|
|
12
|
-
.map(function (m) {
|
|
13
|
-
return m.substr(1, m.length - 2);
|
|
14
|
-
});
|
|
15
|
-
},
|
|
16
|
-
endWith: function (list) {
|
|
17
|
-
return list
|
|
18
|
-
.filter(function (m) {
|
|
19
|
-
return m.match(/^\*[^\*]+$/);
|
|
20
|
-
})
|
|
21
|
-
.map(function (m) {
|
|
22
|
-
return m.substr(1);
|
|
23
|
-
});
|
|
24
|
-
},
|
|
25
|
-
startWith: function (list) {
|
|
26
|
-
return list
|
|
27
|
-
.filter(function (m) {
|
|
28
|
-
return m.match(/^[^\*\!]+\*$/);
|
|
29
|
-
})
|
|
30
|
-
.map(function (m) {
|
|
31
|
-
return m.substr(0, m.length - 1);
|
|
32
|
-
});
|
|
33
|
-
},
|
|
34
|
-
notExact: function (list) {
|
|
35
|
-
return list
|
|
36
|
-
.filter(function (m) {
|
|
37
|
-
return m.match(/^\![^\*].*$/);
|
|
38
|
-
})
|
|
39
|
-
.map(function (m) {
|
|
40
|
-
return m.substr(1);
|
|
41
|
-
});
|
|
42
|
-
},
|
|
43
|
-
notContain: function (list) {
|
|
44
|
-
return list
|
|
45
|
-
.filter(function (m) {
|
|
46
|
-
return m.match(/^\!\*.+\*$/);
|
|
47
|
-
})
|
|
48
|
-
.map(function (m) {
|
|
49
|
-
return m.substr(2, m.length - 3);
|
|
50
|
-
});
|
|
51
|
-
},
|
|
52
|
-
notEndWith: function (list) {
|
|
53
|
-
return list
|
|
54
|
-
.filter(function (m) {
|
|
55
|
-
return m.match(/^\!\*[^\*]+$/);
|
|
56
|
-
})
|
|
57
|
-
.map(function (m) {
|
|
58
|
-
return m.substr(2);
|
|
59
|
-
});
|
|
60
|
-
},
|
|
61
|
-
notStartWith: function (list) {
|
|
62
|
-
return list
|
|
63
|
-
.filter(function (m) {
|
|
64
|
-
return m.match(/^\![^\*]+\*$/);
|
|
65
|
-
})
|
|
66
|
-
.map(function (m) {
|
|
67
|
-
return m.substr(1, m.length - 2);
|
|
68
|
-
});
|
|
69
|
-
},
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
function createPropListMatcher(propList) {
|
|
73
|
-
var hasWild = propList.indexOf('*') > -1;
|
|
74
|
-
var matchAll = hasWild && propList.length === 1;
|
|
75
|
-
var lists = {
|
|
76
|
-
exact: filterPropList.exact(propList),
|
|
77
|
-
contain: filterPropList.contain(propList),
|
|
78
|
-
startWith: filterPropList.startWith(propList),
|
|
79
|
-
endWith: filterPropList.endWith(propList),
|
|
80
|
-
notExact: filterPropList.notExact(propList),
|
|
81
|
-
notContain: filterPropList.notContain(propList),
|
|
82
|
-
notStartWith: filterPropList.notStartWith(propList),
|
|
83
|
-
notEndWith: filterPropList.notEndWith(propList),
|
|
84
|
-
};
|
|
85
|
-
return function (prop) {
|
|
86
|
-
if (matchAll) return true;
|
|
87
|
-
return (
|
|
88
|
-
(hasWild ||
|
|
89
|
-
lists.exact.indexOf(prop) > -1 ||
|
|
90
|
-
lists.contain.some(function (m) {
|
|
91
|
-
return prop.indexOf(m) > -1;
|
|
92
|
-
}) ||
|
|
93
|
-
lists.startWith.some(function (m) {
|
|
94
|
-
return prop.indexOf(m) === 0;
|
|
95
|
-
}) ||
|
|
96
|
-
lists.endWith.some(function (m) {
|
|
97
|
-
return prop.indexOf(m) === prop.length - m.length;
|
|
98
|
-
})) &&
|
|
99
|
-
!(
|
|
100
|
-
lists.notExact.indexOf(prop) > -1 ||
|
|
101
|
-
lists.notContain.some(function (m) {
|
|
102
|
-
return prop.indexOf(m) > -1;
|
|
103
|
-
}) ||
|
|
104
|
-
lists.notStartWith.some(function (m) {
|
|
105
|
-
return prop.indexOf(m) === 0;
|
|
106
|
-
}) ||
|
|
107
|
-
lists.notEndWith.some(function (m) {
|
|
108
|
-
return prop.indexOf(m) === prop.length - m.length;
|
|
109
|
-
})
|
|
110
|
-
)
|
|
111
|
-
);
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
module.exports = {
|
|
116
|
-
filterPropList,
|
|
117
|
-
createPropListMatcher,
|
|
118
|
-
};
|