codexmate 0.0.19 → 0.0.20
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/README.en.md +8 -4
- package/README.md +8 -4
- package/cli/config-health.js +338 -0
- package/cli.js +1136 -584
- package/lib/cli-models-utils.js +186 -27
- package/lib/cli-network-utils.js +117 -101
- package/package.json +8 -1
- package/web-ui/app.js +381 -5532
- package/web-ui/index.html +15 -2231
- package/web-ui/logic.agents-diff.mjs +386 -0
- package/web-ui/logic.claude.mjs +108 -0
- package/web-ui/logic.mjs +5 -793
- package/web-ui/logic.runtime.mjs +124 -0
- package/web-ui/logic.sessions.mjs +263 -0
- package/web-ui/modules/api.mjs +69 -0
- package/web-ui/modules/app.computed.dashboard.mjs +113 -0
- package/web-ui/modules/app.computed.index.mjs +13 -0
- package/web-ui/modules/app.computed.session.mjs +141 -0
- package/web-ui/modules/app.constants.mjs +15 -0
- package/web-ui/modules/app.methods.agents.mjs +493 -0
- package/web-ui/modules/app.methods.claude-config.mjs +174 -0
- package/web-ui/modules/app.methods.codex-config.mjs +640 -0
- package/web-ui/modules/app.methods.index.mjs +86 -0
- package/web-ui/modules/app.methods.install.mjs +157 -0
- package/web-ui/modules/app.methods.navigation.mjs +478 -0
- package/web-ui/modules/app.methods.openclaw-core.mjs +514 -0
- package/web-ui/modules/app.methods.openclaw-editing.mjs +337 -0
- package/web-ui/modules/app.methods.openclaw-persist.mjs +251 -0
- package/web-ui/modules/app.methods.providers.mjs +265 -0
- package/web-ui/modules/app.methods.runtime.mjs +323 -0
- package/web-ui/modules/app.methods.session-actions.mjs +457 -0
- package/web-ui/modules/app.methods.session-browser.mjs +435 -0
- package/web-ui/modules/app.methods.session-timeline.mjs +441 -0
- package/web-ui/modules/app.methods.session-trash.mjs +419 -0
- package/web-ui/modules/app.methods.startup-claude.mjs +406 -0
- package/web-ui/partials/index/layout-footer.html +69 -0
- package/web-ui/partials/index/layout-header.html +337 -0
- package/web-ui/partials/index/modal-config-template-agents.html +125 -0
- package/web-ui/partials/index/modal-confirm-toast.html +32 -0
- package/web-ui/partials/index/modal-health-check.html +72 -0
- package/web-ui/partials/index/modal-openclaw-config.html +275 -0
- package/web-ui/partials/index/modal-skills.html +184 -0
- package/web-ui/partials/index/modals-basic.html +196 -0
- package/web-ui/partials/index/panel-config-claude.html +100 -0
- package/web-ui/partials/index/panel-config-codex.html +237 -0
- package/web-ui/partials/index/panel-config-openclaw.html +84 -0
- package/web-ui/partials/index/panel-market.html +174 -0
- package/web-ui/partials/index/panel-sessions.html +387 -0
- package/web-ui/partials/index/panel-settings.html +166 -0
- package/web-ui/source-bundle.cjs +233 -0
- package/web-ui/styles/base-theme.css +373 -0
- package/web-ui/styles/controls-forms.css +354 -0
- package/web-ui/styles/feedback.css +108 -0
- package/web-ui/styles/health-check-dialog.css +144 -0
- package/web-ui/styles/layout-shell.css +330 -0
- package/web-ui/styles/modals-core.css +449 -0
- package/web-ui/styles/navigation-panels.css +381 -0
- package/web-ui/styles/openclaw-structured.css +266 -0
- package/web-ui/styles/responsive.css +416 -0
- package/web-ui/styles/sessions-list.css +414 -0
- package/web-ui/styles/sessions-preview.css +405 -0
- package/web-ui/styles/sessions-toolbar-trash.css +243 -0
- package/web-ui/styles/sessions-usage.css +276 -0
- package/web-ui/styles/skills-list.css +298 -0
- package/web-ui/styles/skills-market.css +335 -0
- package/web-ui/styles/titles-cards.css +407 -0
- package/web-ui/styles.css +16 -4668
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
<!-- 设置面板 -->
|
|
2
|
+
<div
|
|
3
|
+
v-show="mainTab === 'settings'"
|
|
4
|
+
class="mode-content"
|
|
5
|
+
id="panel-settings"
|
|
6
|
+
role="tabpanel"
|
|
7
|
+
:aria-labelledby="'tab-settings'">
|
|
8
|
+
<div class="config-subtabs settings-subtabs" role="tablist" aria-label="设置子标签">
|
|
9
|
+
<button
|
|
10
|
+
id="settings-tab-backup"
|
|
11
|
+
role="tab"
|
|
12
|
+
aria-controls="settings-panel-backup"
|
|
13
|
+
:aria-selected="settingsTab === 'backup'"
|
|
14
|
+
:tabindex="settingsTab === 'backup' ? 0 : -1"
|
|
15
|
+
:class="['config-subtab', { active: settingsTab === 'backup' }]"
|
|
16
|
+
@click="onSettingsTabClick('backup')">
|
|
17
|
+
备份与导入
|
|
18
|
+
</button>
|
|
19
|
+
<button
|
|
20
|
+
id="settings-tab-trash"
|
|
21
|
+
role="tab"
|
|
22
|
+
aria-controls="settings-panel-trash"
|
|
23
|
+
:aria-selected="settingsTab === 'trash'"
|
|
24
|
+
:tabindex="settingsTab === 'trash' ? 0 : -1"
|
|
25
|
+
:class="['config-subtab', { active: settingsTab === 'trash' }]"
|
|
26
|
+
@click="onSettingsTabClick('trash')">
|
|
27
|
+
回收站
|
|
28
|
+
<span class="settings-tab-badge">{{ sessionTrashCount }}</span>
|
|
29
|
+
</button>
|
|
30
|
+
<button
|
|
31
|
+
id="settings-tab-device"
|
|
32
|
+
role="tab"
|
|
33
|
+
aria-controls="settings-panel-device"
|
|
34
|
+
:aria-selected="settingsTab === 'device'"
|
|
35
|
+
:tabindex="settingsTab === 'device' ? 0 : -1"
|
|
36
|
+
:class="['config-subtab', { active: settingsTab === 'device' }]"
|
|
37
|
+
@click="onSettingsTabClick('device')">
|
|
38
|
+
设备
|
|
39
|
+
</button>
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
<div
|
|
43
|
+
v-show="settingsTab === 'backup'"
|
|
44
|
+
id="settings-panel-backup"
|
|
45
|
+
role="tabpanel"
|
|
46
|
+
aria-labelledby="settings-tab-backup">
|
|
47
|
+
<div class="selector-section">
|
|
48
|
+
<div class="selector-header">
|
|
49
|
+
<span class="selector-title">Claude 配置</span>
|
|
50
|
+
</div>
|
|
51
|
+
<button class="btn-tool" @click="downloadClaudeDirectory" :disabled="claudeDownloadLoading">
|
|
52
|
+
{{ claudeDownloadLoading ? ('备份中 ' + claudeDownloadProgress + '%') : '一键备份 ~/.claude' }}
|
|
53
|
+
</button>
|
|
54
|
+
<button class="btn-tool" @click="triggerClaudeImport" :disabled="claudeImportLoading">
|
|
55
|
+
{{ claudeImportLoading ? '导入中...' : '导入 ~/.claude 备份' }}
|
|
56
|
+
</button>
|
|
57
|
+
<input
|
|
58
|
+
ref="claudeImportInput"
|
|
59
|
+
class="sr-only"
|
|
60
|
+
type="file"
|
|
61
|
+
accept=".zip"
|
|
62
|
+
@change="handleClaudeImportChange">
|
|
63
|
+
</div>
|
|
64
|
+
<div class="selector-section">
|
|
65
|
+
<div class="selector-header">
|
|
66
|
+
<span class="selector-title">Codex 配置</span>
|
|
67
|
+
</div>
|
|
68
|
+
<button class="btn-tool" @click="downloadCodexDirectory" :disabled="codexDownloadLoading">
|
|
69
|
+
{{ codexDownloadLoading ? ('备份中 ' + codexDownloadProgress + '%') : '一键备份 ~/.codex' }}
|
|
70
|
+
</button>
|
|
71
|
+
<button class="btn-tool" @click="triggerCodexImport" :disabled="codexImportLoading">
|
|
72
|
+
{{ codexImportLoading ? '导入中...' : '导入 ~/.codex 备份' }}
|
|
73
|
+
</button>
|
|
74
|
+
<input
|
|
75
|
+
ref="codexImportInput"
|
|
76
|
+
class="sr-only"
|
|
77
|
+
type="file"
|
|
78
|
+
accept=".zip"
|
|
79
|
+
@change="handleCodexImportChange">
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
|
|
83
|
+
<div
|
|
84
|
+
v-show="settingsTab === 'trash'"
|
|
85
|
+
id="settings-panel-trash"
|
|
86
|
+
role="tabpanel"
|
|
87
|
+
aria-labelledby="settings-tab-trash">
|
|
88
|
+
<div class="selector-section">
|
|
89
|
+
<div class="selector-header settings-tab-header">
|
|
90
|
+
<div class="settings-tab-actions trash-header-actions">
|
|
91
|
+
<button class="btn-tool btn-tool-compact" @click="loadSessionTrash({ forceRefresh: true })" :disabled="sessionTrashLoading || sessionTrashClearing">
|
|
92
|
+
{{ sessionTrashLoading ? '刷新中...' : '刷新列表' }}
|
|
93
|
+
</button>
|
|
94
|
+
<button class="btn-tool btn-tool-compact" @click="clearSessionTrash" :disabled="sessionTrashClearing || sessionTrashLoading || !(Number(sessionTrashCount) > 0)">
|
|
95
|
+
{{ sessionTrashClearing ? '清空中...' : '清空回收站' }}
|
|
96
|
+
</button>
|
|
97
|
+
</div>
|
|
98
|
+
</div>
|
|
99
|
+
|
|
100
|
+
<div v-if="getSessionTrashViewState() === 'loading'" class="session-empty">
|
|
101
|
+
正在加载回收站...
|
|
102
|
+
</div>
|
|
103
|
+
<div v-else-if="getSessionTrashViewState() === 'empty'" class="session-empty">
|
|
104
|
+
回收站为空
|
|
105
|
+
</div>
|
|
106
|
+
<div v-else-if="getSessionTrashViewState() === 'retry'" class="session-empty">
|
|
107
|
+
回收站列表加载失败,请刷新重试
|
|
108
|
+
</div>
|
|
109
|
+
<div v-else class="trash-list">
|
|
110
|
+
<div v-for="item in visibleSessionTrashItems" :key="item.trashId" class="trash-item session-item session-card">
|
|
111
|
+
<div class="trash-item-header session-item-header">
|
|
112
|
+
<div class="trash-item-main">
|
|
113
|
+
<div class="trash-item-mainline">
|
|
114
|
+
<div class="trash-item-title">{{ item.title || item.sessionId }}</div>
|
|
115
|
+
<span class="session-count-badge">{{ item.messageCount ?? 0 }}</span>
|
|
116
|
+
</div>
|
|
117
|
+
<div class="trash-item-meta session-item-meta">
|
|
118
|
+
<span class="session-source">{{ item.sourceLabel }}</span>
|
|
119
|
+
</div>
|
|
120
|
+
</div>
|
|
121
|
+
<div class="trash-item-side">
|
|
122
|
+
<div class="trash-item-actions session-item-actions">
|
|
123
|
+
<button class="btn-mini" @click="restoreSessionTrash(item)" :disabled="sessionTrashLoading || sessionTrashClearing || isSessionTrashActionBusy(item)">
|
|
124
|
+
{{ sessionTrashRestoring[getSessionTrashActionKey(item)] ? '恢复中...' : '恢复' }}
|
|
125
|
+
</button>
|
|
126
|
+
<button class="btn-mini delete" @click="purgeSessionTrash(item)" :disabled="sessionTrashLoading || sessionTrashClearing || isSessionTrashActionBusy(item)">
|
|
127
|
+
{{ sessionTrashPurging[getSessionTrashActionKey(item)] ? '删除中...' : '彻底删除' }}
|
|
128
|
+
</button>
|
|
129
|
+
</div>
|
|
130
|
+
<div class="trash-item-time session-item-time">{{ item.deletedAt || item.updatedAt || 'unknown time' }}</div>
|
|
131
|
+
</div>
|
|
132
|
+
</div>
|
|
133
|
+
<div v-if="item.cwd" class="trash-item-path session-item-sub session-item-wrap">
|
|
134
|
+
<span class="trash-item-label">工作区</span>
|
|
135
|
+
<span>{{ item.cwd }}</span>
|
|
136
|
+
</div>
|
|
137
|
+
<div class="trash-item-path session-item-sub session-item-wrap">
|
|
138
|
+
<span class="trash-item-label">原文件</span>
|
|
139
|
+
<span>{{ item.originalFilePath }}</span>
|
|
140
|
+
</div>
|
|
141
|
+
</div>
|
|
142
|
+
<div v-if="sessionTrashHasMoreItems" class="trash-list-footer">
|
|
143
|
+
<button class="btn-tool btn-tool-compact" @click="loadMoreSessionTrashItems" :disabled="sessionTrashLoading || sessionTrashClearing">
|
|
144
|
+
加载更多(剩余 {{ sessionTrashHiddenCount }} 项)
|
|
145
|
+
</button>
|
|
146
|
+
</div>
|
|
147
|
+
</div>
|
|
148
|
+
</div>
|
|
149
|
+
</div>
|
|
150
|
+
|
|
151
|
+
<div
|
|
152
|
+
v-show="settingsTab === 'device'"
|
|
153
|
+
id="settings-panel-device"
|
|
154
|
+
role="tabpanel"
|
|
155
|
+
aria-labelledby="settings-tab-device">
|
|
156
|
+
<div class="selector-section">
|
|
157
|
+
<div class="selector-header">
|
|
158
|
+
<span class="selector-title">配置重置</span>
|
|
159
|
+
</div>
|
|
160
|
+
<div class="config-template-hint">先备份 config.toml,再写默认配置。</div>
|
|
161
|
+
<button class="btn-tool" @click="resetConfig" :disabled="resetConfigLoading || loading || !!initError">
|
|
162
|
+
{{ resetConfigLoading ? '重装中...' : '重装配置' }}
|
|
163
|
+
</button>
|
|
164
|
+
</div>
|
|
165
|
+
</div>
|
|
166
|
+
</div>
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const HTML_INCLUDE_RE = /^[ \t]*<!--\s*@include\s+(.+?)\s*-->\s*$/gm;
|
|
5
|
+
const CSS_IMPORT_RE = /^[ \t]*@import\s+(?:url\(\s*)?(['"]?)([^'")]+)\1\s*\)?\s*;/gm;
|
|
6
|
+
const JS_IMPORT_RE = /(?:^|\n)\s*import\s+(?:[\s\S]*?\s+from\s+)?['"](\.[^'"]+)['"]\s*;?/g;
|
|
7
|
+
const JS_EXPORT_FROM_RE = /(?:^|\n)\s*export\s+\*\s+from\s+['"](\.[^'"]+)['"]\s*;?/g;
|
|
8
|
+
const JS_RELATIVE_IMPORT_STATEMENT_RE = /(^|\n)([ \t]*)import\s+([\s\S]*?)\s+from\s+['"](\.[^'"]+)['"]\s*;?[ \t]*/g;
|
|
9
|
+
const IDENTIFIER_RE = /^[A-Za-z_$][\w$]*$/;
|
|
10
|
+
|
|
11
|
+
function stripBom(content) {
|
|
12
|
+
return content.replace(/^\uFEFF/, '');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function readUtf8Text(filePath) {
|
|
16
|
+
return stripBom(fs.readFileSync(filePath, 'utf8').replace(/\r\n?/g, '\n'));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function normalizeIncludeTarget(rawTarget) {
|
|
20
|
+
const trimmed = String(rawTarget || '').trim();
|
|
21
|
+
if (!trimmed) return '';
|
|
22
|
+
return trimmed.replace(/^['"]|['"]$/g, '');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function assertNoCircularDependency(filePath, stack) {
|
|
26
|
+
if (!stack.includes(filePath)) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const cycle = [...stack, filePath]
|
|
30
|
+
.map(item => path.relative(path.join(__dirname, '..'), item))
|
|
31
|
+
.join(' -> ');
|
|
32
|
+
throw new Error(`Detected circular source include: ${cycle}`);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function bundleHtmlFile(filePath, stack = []) {
|
|
36
|
+
assertNoCircularDependency(filePath, stack);
|
|
37
|
+
const source = readUtf8Text(filePath);
|
|
38
|
+
return source.replace(HTML_INCLUDE_RE, (_match, rawTarget) => {
|
|
39
|
+
const target = normalizeIncludeTarget(rawTarget);
|
|
40
|
+
if (!target) {
|
|
41
|
+
return '';
|
|
42
|
+
}
|
|
43
|
+
const targetPath = path.resolve(path.dirname(filePath), target);
|
|
44
|
+
return bundleHtmlFile(targetPath, [...stack, filePath]);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function bundleCssFile(filePath, stack = []) {
|
|
49
|
+
assertNoCircularDependency(filePath, stack);
|
|
50
|
+
const source = readUtf8Text(filePath);
|
|
51
|
+
return source.replace(CSS_IMPORT_RE, (match, _quote, rawTarget) => {
|
|
52
|
+
const target = normalizeIncludeTarget(rawTarget);
|
|
53
|
+
if (!target || !target.startsWith('.')) {
|
|
54
|
+
return match;
|
|
55
|
+
}
|
|
56
|
+
const targetPath = path.resolve(path.dirname(filePath), target);
|
|
57
|
+
return bundleCssFile(targetPath, [...stack, filePath]);
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function resolveJavaScriptDependencies(filePath) {
|
|
62
|
+
const source = readUtf8Text(filePath);
|
|
63
|
+
const dependencies = [];
|
|
64
|
+
for (const pattern of [JS_IMPORT_RE, JS_EXPORT_FROM_RE]) {
|
|
65
|
+
let match = pattern.exec(source);
|
|
66
|
+
while (match) {
|
|
67
|
+
const target = normalizeIncludeTarget(match[1]);
|
|
68
|
+
if (target.startsWith('.')) {
|
|
69
|
+
dependencies.push(path.resolve(path.dirname(filePath), target));
|
|
70
|
+
}
|
|
71
|
+
match = pattern.exec(source);
|
|
72
|
+
}
|
|
73
|
+
pattern.lastIndex = 0;
|
|
74
|
+
}
|
|
75
|
+
return dependencies;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function bundleJavaScriptFile(filePath, visited = new Set()) {
|
|
79
|
+
if (visited.has(filePath)) {
|
|
80
|
+
return '';
|
|
81
|
+
}
|
|
82
|
+
visited.add(filePath);
|
|
83
|
+
|
|
84
|
+
const relativePath = path.relative(path.join(__dirname, '..'), filePath).replace(/\\/g, '/');
|
|
85
|
+
const source = readUtf8Text(filePath);
|
|
86
|
+
const chunks = [
|
|
87
|
+
`// ===== FILE: ${relativePath} =====`,
|
|
88
|
+
source.trimEnd(),
|
|
89
|
+
''
|
|
90
|
+
];
|
|
91
|
+
|
|
92
|
+
for (const dependencyPath of resolveJavaScriptDependencies(filePath)) {
|
|
93
|
+
chunks.push(bundleJavaScriptFile(dependencyPath, visited).trimEnd());
|
|
94
|
+
chunks.push('');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return chunks.join('\n').trimEnd() + '\n';
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function collectJavaScriptFiles(filePath, ordered = [], visited = new Set(), stack = []) {
|
|
101
|
+
assertNoCircularDependency(filePath, stack);
|
|
102
|
+
if (visited.has(filePath)) {
|
|
103
|
+
return ordered;
|
|
104
|
+
}
|
|
105
|
+
visited.add(filePath);
|
|
106
|
+
for (const dependencyPath of resolveJavaScriptDependencies(filePath)) {
|
|
107
|
+
collectJavaScriptFiles(dependencyPath, ordered, visited, [...stack, filePath]);
|
|
108
|
+
}
|
|
109
|
+
ordered.push(filePath);
|
|
110
|
+
return ordered;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function splitCommaSeparatedSpecifiers(source) {
|
|
114
|
+
const items = [];
|
|
115
|
+
let current = '';
|
|
116
|
+
let depth = 0;
|
|
117
|
+
for (let i = 0; i < source.length; i += 1) {
|
|
118
|
+
const ch = source[i];
|
|
119
|
+
if (ch === '{' || ch === '[' || ch === '(') {
|
|
120
|
+
depth += 1;
|
|
121
|
+
} else if (ch === '}' || ch === ']' || ch === ')') {
|
|
122
|
+
depth = Math.max(0, depth - 1);
|
|
123
|
+
}
|
|
124
|
+
if (ch === ',' && depth === 0) {
|
|
125
|
+
items.push(current);
|
|
126
|
+
current = '';
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
current += ch;
|
|
130
|
+
}
|
|
131
|
+
if (current) {
|
|
132
|
+
items.push(current);
|
|
133
|
+
}
|
|
134
|
+
return items.map(item => item.trim()).filter(Boolean);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function buildRelativeImportAliasStatements(importClause, filePath) {
|
|
138
|
+
const clause = String(importClause || '').trim();
|
|
139
|
+
if (!clause) {
|
|
140
|
+
return '';
|
|
141
|
+
}
|
|
142
|
+
if (!clause.startsWith('{') || !clause.endsWith('}')) {
|
|
143
|
+
throw new Error(`Unsupported executable bundle import in ${filePath}: ${clause}`);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const innerClause = clause.slice(1, -1).trim();
|
|
147
|
+
if (!innerClause) {
|
|
148
|
+
return '';
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const statements = [];
|
|
152
|
+
for (const specifier of splitCommaSeparatedSpecifiers(innerClause)) {
|
|
153
|
+
const parts = specifier.split(/\s+as\s+/);
|
|
154
|
+
const imported = String(parts[0] || '').trim();
|
|
155
|
+
const local = String(parts[1] || imported).trim();
|
|
156
|
+
if (!IDENTIFIER_RE.test(imported) || !IDENTIFIER_RE.test(local)) {
|
|
157
|
+
throw new Error(`Unsupported executable bundle import specifier in ${filePath}: ${specifier}`);
|
|
158
|
+
}
|
|
159
|
+
if (local !== imported) {
|
|
160
|
+
statements.push(`const ${local} = ${imported};`);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return statements.join('\n');
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function transformJavaScriptModuleSource(source, options = {}) {
|
|
167
|
+
const preserveExports = !!options.preserveExports;
|
|
168
|
+
const sourcePath = typeof source === 'string' ? source : String(source || '');
|
|
169
|
+
let transformed = readUtf8Text(sourcePath);
|
|
170
|
+
transformed = transformed.replace(JS_RELATIVE_IMPORT_STATEMENT_RE, (_match, prefix, indent, importClause) => {
|
|
171
|
+
const aliases = buildRelativeImportAliasStatements(importClause, sourcePath);
|
|
172
|
+
if (!aliases) {
|
|
173
|
+
return prefix || '';
|
|
174
|
+
}
|
|
175
|
+
const indentedAliases = aliases
|
|
176
|
+
.split('\n')
|
|
177
|
+
.map(line => `${indent || ''}${line}`)
|
|
178
|
+
.join('\n');
|
|
179
|
+
return `${prefix || ''}${indentedAliases}\n`;
|
|
180
|
+
});
|
|
181
|
+
transformed = transformed.replace(/^[ \t]*export\s+\*\s+from\s+['"]\.[^'"]+['"]\s*;?\s*$/gm, '');
|
|
182
|
+
if (!preserveExports) {
|
|
183
|
+
transformed = transformed.replace(/(^|\n)([ \t]*)export\s+(?=(?:async\s+function|const|let|class|function)\b)/g, '$1$2');
|
|
184
|
+
}
|
|
185
|
+
return transformed.trimEnd();
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function bundleExecutableJavaScriptFile(entryPath, options = {}) {
|
|
189
|
+
const orderedFiles = collectJavaScriptFiles(entryPath);
|
|
190
|
+
const preserveExports = !!options.preserveExports;
|
|
191
|
+
const chunks = [];
|
|
192
|
+
for (const filePath of orderedFiles) {
|
|
193
|
+
const transformed = transformJavaScriptModuleSource(filePath, { preserveExports });
|
|
194
|
+
if (!transformed) {
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
chunks.push(transformed);
|
|
198
|
+
}
|
|
199
|
+
return chunks.join('\n\n').trimEnd() + '\n';
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function readBundledWebUiHtml(entryPath = path.join(__dirname, 'index.html')) {
|
|
203
|
+
return bundleHtmlFile(entryPath).trimEnd() + '\n';
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function readBundledWebUiCss(entryPath = path.join(__dirname, 'styles.css')) {
|
|
207
|
+
return bundleCssFile(entryPath).trimEnd() + '\n';
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function readBundledWebUiScript(entryPath = path.join(__dirname, 'app.js')) {
|
|
211
|
+
return bundleJavaScriptFile(entryPath);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function readExecutableBundledWebUiScript(entryPath = path.join(__dirname, 'app.js')) {
|
|
215
|
+
return bundleExecutableJavaScriptFile(entryPath, { preserveExports: false });
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function readExecutableBundledJavaScriptModule(entryPath) {
|
|
219
|
+
const resolvedEntryPath = path.isAbsolute(entryPath)
|
|
220
|
+
? entryPath
|
|
221
|
+
: path.resolve(__dirname, '..', entryPath);
|
|
222
|
+
return bundleExecutableJavaScriptFile(resolvedEntryPath, { preserveExports: true });
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
module.exports = {
|
|
226
|
+
collectJavaScriptFiles,
|
|
227
|
+
readUtf8Text,
|
|
228
|
+
readBundledWebUiHtml,
|
|
229
|
+
readBundledWebUiCss,
|
|
230
|
+
readBundledWebUiScript,
|
|
231
|
+
readExecutableBundledWebUiScript,
|
|
232
|
+
readExecutableBundledJavaScriptModule
|
|
233
|
+
};
|