vanspod 0.3.1 → 0.4.1

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.md CHANGED
@@ -38,7 +38,7 @@ npm run dist
38
38
  npm pack --pack-destination dist
39
39
  ```
40
40
 
41
- exe 產物為 `dist/VansPod.exe`,本機套件為 `dist/vanspod-0.3.1.tgz`;可在 Windows 用 `npm install -g <套件路徑>` 安裝測試。圖片、favicon、系統匣與移除腳本均包含在發佈產物中。更新 logo 後執行 `powershell.exe -NoProfile -File scripts/build-icon.ps1` 重建多尺寸 Windows icon。
41
+ exe 產物為 `dist/VansPod.exe`,本機套件為 `dist/vanspod-0.4.1.tgz`;可在 Windows 用 `npm install -g <套件路徑>` 安裝測試。圖片、favicon、系統匣與移除腳本均包含在發佈產物中。更新 logo 後執行 `powershell.exe -NoProfile -File scripts/build-icon.ps1` 重建多尺寸 Windows icon。
42
42
 
43
43
  exe 發佈管道為本專案 GitHub Releases,npm 為公開 registry 的 [`vanspod`](https://www.npmjs.com/package/vanspod) 套件。更新時不要執行完整移除,否則會清除課堂資料。
44
44
 
@@ -46,12 +46,12 @@ exe 發佈管道為本專案 GitHub Releases,npm 為公開 registry 的 [`vans
46
46
 
47
47
  一般 push 不發佈;推送 `v*` tag 會在 Windows runner 安裝 Node.js 24、檢查型別、執行測試、打包並驗證 exe/npm 生命週期,全部通過後才建立 GitHub Release,最後發佈 npm 套件。學生從 Release 下載 `VansPod.exe`,同頁提供 `SHA256SUMS.txt`。
48
48
 
49
- 發版前同步 `package.json`、`package-lock.json` 與 `src/version.ts` 的版本;tag 必須等於 `v` 加版本號,否則流程失敗。以 `0.3.1` 為例:
49
+ 發版前同步 `package.json`、`package-lock.json` 與 `src/version.ts` 的版本;tag 必須等於 `v` 加版本號,否則流程失敗。以 `0.4.1` 為例:
50
50
 
51
51
  ```powershell
52
52
  git push origin master
53
- git tag -a v0.3.1 -m "VansPod 0.3.1"
54
- git push origin v0.3.1
53
+ git tag -a v0.4.1 -m "VansPod 0.4.1"
54
+ git push origin v0.4.1
55
55
  ```
56
56
 
57
57
  新版本使用新的版本號與 tag。相同 tag 的 Actions 重跑會更新該 Release 的產物。
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ClassroomApp = exports.ENVIRONMENT_TOOLS = void 0;
3
+ exports.ClassroomApp = exports.COPIED_KEY_NOTICE = exports.ENVIRONMENT_LABEL = exports.ENVIRONMENT_TOOLS = void 0;
4
4
  const secureStorage_1 = require("./secureStorage");
5
5
  const storageErrors_1 = require("./storageErrors");
6
6
  const adapterSettings_1 = require("./adapterSettings");
@@ -8,16 +8,18 @@ const clientRoutes_1 = require("./clientRoutes");
8
8
  const node_util_1 = require("node:util");
9
9
  const courseCatalog_1 = require("./courseCatalog");
10
10
  const modelProxy_1 = require("./modelProxy");
11
- exports.ENVIRONMENT_TOOLS = ["uv", "git", "node", "pwsh"];
12
- const ENVIRONMENT_LABEL = {
11
+ // 新工具加在最後,不改既有 id。
12
+ exports.ENVIRONMENT_TOOLS = ["uv", "git", "node", "pwsh", "vscode"];
13
+ exports.ENVIRONMENT_LABEL = {
13
14
  uv: "uv",
14
15
  git: "git",
15
16
  node: "Node.js",
16
17
  pwsh: "PowerShell 7",
18
+ vscode: "VS Code",
17
19
  };
18
20
  const LOCAL_LIST_NOTE = "這是本機清單。";
21
+ exports.COPIED_KEY_NOTICE = "已複製 Classroom API Key。請勿分享給不信任的人。";
19
22
  const INSTALL_UNAVAILABLE = "尚未指定專案資料夾,安裝不可用。";
20
- const REOPEN_TERMINAL = "請重開終端機再重新檢查。";
21
23
  const ENVIRONMENT_ABORTED = "已中止安裝。系統安裝程式可能仍在執行,請等待結束或稍後重新安裝。";
22
24
  const PROXY_CLIENTS = ["codex", "claude", "copilot"];
23
25
  class ClassroomApp {
@@ -63,14 +65,17 @@ class ClassroomApp {
63
65
  set mode(mode) { this.clientModes = { codex: mode, claude: mode }; }
64
66
  modelIds = [];
65
67
  modelProviders = [];
66
- environmentInstalled = {
67
- uv: false,
68
- git: false,
69
- node: false,
70
- pwsh: false,
71
- };
68
+ environmentReadiness = {};
72
69
  environmentSelected = new Set();
70
+ // 每次學生改勾選就加一;檢查開始後學生改過,檢查結束就不覆蓋他的勾選。
71
+ environmentSelectionEdits = 0;
72
+ environmentCheck;
73
+ // 任何一次檢查開始過就為真:啟動時的背景檢查只跑一次,學生已按過「重新檢查」也不再補跑。
74
+ initialEnvironmentCheckStarted = false;
73
75
  environmentNotice;
76
+ environmentLog;
77
+ // 背景 Environment Install 進行中才有:這次要裝的每個工具目前的階段。
78
+ environmentProgress;
74
79
  proxyRunning = false;
75
80
  mustRestart = [];
76
81
  modelRestart = [];
@@ -86,6 +91,13 @@ class ClassroomApp {
86
91
  this.connectionOperations = next.catch(() => { });
87
92
  return next;
88
93
  }
94
+ // 整頁畫面用這個:複製成功的提示只出現一次,重新整理就不會再讓法鬥說一遍。
95
+ pageView() {
96
+ const view = this.view();
97
+ if (this.notice === exports.COPIED_KEY_NOTICE)
98
+ this.notice = this.connectionNotice = undefined;
99
+ return view;
100
+ }
89
101
  view() {
90
102
  const view = {
91
103
  connected: this.connected,
@@ -101,6 +113,7 @@ class ClassroomApp {
101
113
  adapters: { ...this.adapters },
102
114
  adapterNotice: this.adapterNotice,
103
115
  tools: this.environmentTools(),
116
+ environmentInstalling: this.environmentProgress !== undefined,
104
117
  };
105
118
  if (this.connectionError)
106
119
  view.connectionError = this.connectionError;
@@ -161,6 +174,9 @@ class ClassroomApp {
161
174
  if (this.mode === "classroom" && this.modelIds[0]) {
162
175
  view.modelId = this.modelIds[0];
163
176
  }
177
+ if (this.environmentLog) {
178
+ view.environmentLogFolder = this.environmentLog.folder;
179
+ }
164
180
  if (this.environmentNotice) {
165
181
  view.environmentNotice = this.environmentNotice;
166
182
  }
@@ -188,73 +204,188 @@ class ClassroomApp {
188
204
  vsCodeChat: { ...this.clientRoutes.vsCodeChat },
189
205
  };
190
206
  }
191
- async checkEnvironment() {
192
- if (this.commandRunning) {
193
- return;
194
- }
195
- for (const tool of exports.ENVIRONMENT_TOOLS) {
196
- let installed = false;
207
+ /** 檢查全部工具的 Environment Tool Readiness;已有檢查在跑就等它,不重複探測。 */
208
+ checkEnvironment() {
209
+ if (this.environmentCheck)
210
+ return this.environmentCheck;
211
+ if (this.commandRunning)
212
+ return Promise.resolve();
213
+ this.initialEnvironmentCheckStarted = true;
214
+ const edits = this.environmentSelectionEdits;
215
+ const check = (async () => {
197
216
  try {
198
- installed = (await this.deps.environment.probe(tool)).installed;
199
- }
200
- catch {
201
- installed = false;
202
- }
203
- this.environmentInstalled[tool] = installed;
217
+ await this.probeAllEnvironmentTools();
218
+ // 檢查期間學生自己改過勾選,就保留他的選擇。
219
+ if (this.environmentSelectionEdits === edits)
220
+ this.selectNotReadyEnvironmentTools();
221
+ // 學生在 VansPod 外裝好 VS Code,按「重新檢查」也讓 VS Code Chat 跟著可用。
222
+ if (this.environmentReadiness.vscode?.readiness === "ready")
223
+ await this.redetectVsCodeChat();
224
+ }
225
+ finally {
226
+ this.environmentCheck = undefined;
227
+ }
228
+ })();
229
+ this.environmentCheck = check;
230
+ return check;
231
+ }
232
+ /** 每次檢查後的預設勾選:未就緒(未安裝或需要修復)的工具。 */
233
+ selectNotReadyEnvironmentTools() {
234
+ this.environmentSelected = new Set(exports.ENVIRONMENT_TOOLS.filter((id) => {
235
+ const checked = this.environmentReadiness[id];
236
+ return checked !== undefined && checked.readiness !== "ready";
237
+ }));
238
+ }
239
+ async probeAllEnvironmentTools() {
240
+ await Promise.all(exports.ENVIRONMENT_TOOLS.map((tool) => this.probeEnvironmentTool(tool)));
241
+ }
242
+ async probeEnvironmentTool(tool) {
243
+ let readiness;
244
+ try {
245
+ readiness = await this.deps.environment.probe(tool);
204
246
  }
247
+ catch {
248
+ readiness = { readiness: "missing" };
249
+ }
250
+ this.environmentReadiness[tool] = readiness;
251
+ return readiness;
252
+ }
253
+ /**
254
+ * 安裝後的驗證:environment 已經驗證過就採用它的結果,每個工具只檢查一次。
255
+ * 安裝程式要求重新開機、工具還不能用時算「需要修復」:裝過了,重新開機後再檢查(US32)。
256
+ */
257
+ async verifyInstalledTool(tool, result) {
258
+ let verified = result?.verified ?? await this.probeEnvironmentTool(tool);
259
+ if (result?.rebootRequired && verified.readiness === "missing")
260
+ verified = { ...verified, readiness: "needsRepair" };
261
+ this.environmentReadiness[tool] = verified;
262
+ return verified;
205
263
  }
206
264
  selectEnvironment(tools) {
207
265
  if (this.commandRunning) {
208
266
  return;
209
267
  }
268
+ this.environmentSelectionEdits += 1;
210
269
  this.environmentSelected = new Set(exports.ENVIRONMENT_TOOLS.filter((id) => tools.includes(id)));
211
270
  }
271
+ /** Environment Install:開發工具與 Project Folder 無關,沒選資料夾也能安裝。 */
212
272
  async confirmEnvironment() {
213
- if (this.stopping || this.commandRunning || !this.projectFolder) {
273
+ if (this.stopping || this.commandRunning) {
214
274
  return;
215
275
  }
216
276
  const selected = exports.ENVIRONMENT_TOOLS.filter((id) => this.environmentSelected.has(id));
217
277
  if (selected.length === 0) {
218
278
  return;
219
279
  }
220
- const cwd = this.projectFolder;
280
+ // 頁面請求不等安裝結束(見 start.ts 的 POST /environment);commandRunning 在整段背景安裝期間保持為真,
281
+ // exit guard、版本更新與移除都靠它詢問是否中止。
221
282
  this.commandRunning = true;
222
283
  this.environmentNotice = undefined;
284
+ const progress = {};
285
+ for (const tool of selected)
286
+ progress[tool] = { stage: "waiting" };
287
+ this.environmentProgress = progress;
223
288
  const abort = this.beginInstall();
224
- let succeeded = false;
289
+ const rebootSuggested = [];
290
+ const failures = [];
225
291
  try {
292
+ // 啟動時的背景檢查還沒結束就先等它,避免檢查與安裝後的驗證互相覆蓋。
293
+ if (this.environmentCheck)
294
+ await this.environmentCheck;
295
+ await this.startEnvironmentLog();
226
296
  for (const tool of selected) {
297
+ if (abort.signal.aborted)
298
+ break;
299
+ // 輪到這個工具:先是「準備中」,environment 開始下載或啟動安裝程式時再回報下載中、安裝中。
300
+ progress[tool] = { stage: "preparing" };
301
+ const report = (reported) => {
302
+ if (abort.signal.aborted)
303
+ return;
304
+ progress[tool] = { ...reported };
305
+ };
227
306
  let result;
228
307
  try {
229
- result = await this.deps.environment.install(tool, cwd, abort.signal);
308
+ result = await this.deps.environment.install(tool, abort.signal, report);
230
309
  }
231
310
  catch {
232
- break;
311
+ result = undefined;
233
312
  }
234
- if (abort.signal.aborted || !environmentInstallSucceeded(result)) {
313
+ if (abort.signal.aborted) {
235
314
  break;
236
315
  }
237
- succeeded = true;
316
+ // 安裝程式的結束碼只產生提示;裝好與否以立刻重新驗證為準。
317
+ // 驗證會讀登錄檔裡最新的 PATH,剛裝好的工具不必重開 VansPod 就看得到。
318
+ progress[tool] = { stage: "verifying" };
319
+ const verified = await this.verifyInstalledTool(tool, result);
320
+ await this.environmentLog?.verified(tool, verified).catch(() => { });
321
+ if (verified.readiness === "ready") {
322
+ progress[tool] = { stage: "done" };
323
+ if (result?.rebootRequired)
324
+ rebootSuggested.push(tool);
325
+ if (tool === "vscode")
326
+ await this.redetectVsCodeChat();
327
+ continue;
328
+ }
329
+ // 單一工具失敗不中斷後續工具;結果列出每個失敗的工具與原因。
330
+ progress[tool] = { stage: "failed" };
331
+ failures.push(environmentInstallFailure(exports.ENVIRONMENT_LABEL[tool], result, verified));
332
+ }
333
+ if (abort.signal.aborted) {
334
+ // 中止後重新檢查全部工具,畫面顯示實際狀態(ADR-0008);仍算在這次安裝裡。
335
+ await this.probeAllEnvironmentTools();
336
+ this.selectNotReadyEnvironmentTools();
238
337
  }
239
338
  }
240
339
  finally {
340
+ this.environmentProgress = undefined;
241
341
  this.endInstall();
242
342
  this.commandRunning = false;
243
343
  }
244
344
  if (abort.signal.aborted) {
245
- await this.checkEnvironment();
246
345
  this.environmentNotice = ENVIRONMENT_ABORTED;
346
+ await this.environmentLog?.finish("已中止").catch(() => { });
347
+ return;
247
348
  }
248
- else if (succeeded) {
249
- this.environmentNotice = REOPEN_TERMINAL;
349
+ const notices = [];
350
+ if (rebootSuggested.length > 0) {
351
+ notices.push(`${rebootSuggested.map((tool) => exports.ENVIRONMENT_LABEL[tool]).join("、")} 已就緒,建議重新開機。`);
250
352
  }
353
+ notices.push(...failures);
354
+ this.environmentNotice = notices.length > 0 ? notices.join("") : undefined;
355
+ // 安裝後的驗證也算一次檢查:再按「確認安裝」只處理仍未就緒的工具。
356
+ this.selectNotReadyEnvironmentTools();
357
+ await this.environmentLog?.finish(this.environmentNotice ?? "完成").catch(() => { });
358
+ }
359
+ /** 每次 Environment Install 開一份新紀錄;紀錄開不了也照常安裝。 */
360
+ async startEnvironmentLog() {
361
+ try {
362
+ this.environmentLog = await this.deps.environment.startLog?.();
363
+ }
364
+ catch {
365
+ this.environmentLog = undefined;
366
+ }
367
+ }
368
+ /** 結果畫面「開啟紀錄資料夾」:開啟最近一次安裝的紀錄資料夾。 */
369
+ async openEnvironmentLog() {
370
+ if (!this.environmentLog) {
371
+ return;
372
+ }
373
+ await this.deps.environment.openLogFolder?.(this.environmentLog.folder);
374
+ }
375
+ /** 「開啟 VS Code」只在 VS Code 已就緒時有效;有 Project Folder 就直接開那個資料夾。 */
376
+ async openVsCode() {
377
+ if (this.environmentReadiness.vscode?.readiness !== "ready") {
378
+ return;
379
+ }
380
+ await this.deps.environment.openVsCode?.(this.projectFolder);
251
381
  }
252
382
  environmentTools() {
253
383
  return exports.ENVIRONMENT_TOOLS.map((id) => ({
254
384
  id,
255
- label: ENVIRONMENT_LABEL[id],
256
- installed: this.environmentInstalled[id],
385
+ label: exports.ENVIRONMENT_LABEL[id],
386
+ ...(this.environmentReadiness[id] ?? { readiness: "checking" }),
257
387
  selected: this.environmentSelected.has(id),
388
+ ...(this.environmentProgress?.[id] ? { progress: { ...this.environmentProgress[id] } } : {}),
258
389
  }));
259
390
  }
260
391
  async copilotRequest(selection) {
@@ -1255,15 +1386,29 @@ class ClassroomApp {
1255
1386
  catch { /* The visible red state remains authoritative. */ }
1256
1387
  }
1257
1388
  }
1389
+ /** VS Code 剛就緒:只重新偵測 VS Code Chat 並啟動它的 Client Route,其他 Client Route 不動。 */
1390
+ async redetectVsCodeChat() {
1391
+ // 還沒啟動或正在停止就不碰 Client Route;啟動中的初始偵測先跑完,避免重複啟動路由。
1392
+ if (this.stopping || !this.initialization)
1393
+ return;
1394
+ await this.initialization.catch(() => undefined);
1395
+ if (this.stopping || this.detectedClients.vsCodeChat)
1396
+ return;
1397
+ await this.detectClient("vsCodeChat");
1398
+ if (this.detectedClients.vsCodeChat)
1399
+ await this.startVsCodeRoute();
1400
+ }
1258
1401
  async detectClients() {
1259
- await Promise.all(["codex", "claude", "vsCodeChat"].map(async (client) => {
1260
- try {
1261
- this.detectedClients[client] = await this.deps.detectClient?.(client) ?? false;
1262
- }
1263
- catch {
1264
- this.detectedClients[client] = false;
1265
- }
1266
- }));
1402
+ await Promise.all(["codex", "claude", "vsCodeChat"].map(client => this.detectClient(client)));
1403
+ }
1404
+ /** 偵測失敗就當作沒裝。 */
1405
+ async detectClient(client) {
1406
+ try {
1407
+ this.detectedClients[client] = await this.deps.detectClient?.(client) ?? false;
1408
+ }
1409
+ catch {
1410
+ this.detectedClients[client] = false;
1411
+ }
1267
1412
  }
1268
1413
  async reloadAllowlistNow() {
1269
1414
  if (!this.connected)
@@ -1442,7 +1587,7 @@ class ClassroomApp {
1442
1587
  this.notice = this.connectionNotice = "無法複製 Classroom API Key。請重新連線後再試。";
1443
1588
  return;
1444
1589
  }
1445
- this.notice = this.connectionNotice = "已複製 Classroom API Key。請勿分享給不信任的人。";
1590
+ this.notice = this.connectionNotice = exports.COPIED_KEY_NOTICE;
1446
1591
  }
1447
1592
  async copySnippet(snippetId) {
1448
1593
  const snippet = this.catalog?.snippets?.find((item) => item.id === snippetId);
@@ -1573,7 +1718,14 @@ class ClassroomApp {
1573
1718
  await this.startClaudeCodeRoute();
1574
1719
  await this.startVsCodeRoute();
1575
1720
  })();
1576
- await this.initialization;
1721
+ try {
1722
+ await this.initialization;
1723
+ }
1724
+ finally {
1725
+ // 連線與路由恢復後才在背景檢查一次開發工具,不和啟動時的客戶端偵測搶資源,也不擋住啟動。
1726
+ if (!this.initialEnvironmentCheckStarted)
1727
+ void this.checkEnvironment();
1728
+ }
1577
1729
  this.deps.proxy.start();
1578
1730
  this.proxyRunning = true;
1579
1731
  if (!this.routeRestartNoted) {
@@ -1762,15 +1914,17 @@ class ClassroomApp {
1762
1914
  }
1763
1915
  }
1764
1916
  exports.ClassroomApp = ClassroomApp;
1765
- function environmentInstallSucceeded(result) {
1766
- if (result.exitCode === 0) {
1767
- return true;
1768
- }
1769
- if (typeof result.exitCode !== "number") {
1770
- return false;
1771
- }
1772
- return (/already installed/i.test(result.output) ||
1773
- /no available upgrade found/i.test(result.output));
1917
+ /** 安裝後驗證未通過時的提示;安裝程式要求重新開機時,請學生重開機後再檢查。 */
1918
+ function environmentInstallFailure(label, result, verified) {
1919
+ const rejected = result?.failure
1920
+ ? `${result.failure},`
1921
+ : result?.exitAccepted === false && result.exitCode !== undefined
1922
+ ? `安裝失敗(結束碼 ${result.exitCode}),`
1923
+ : "";
1924
+ const state = verified.readiness === "missing" ? "安裝後仍偵測不到" : "安裝後仍需要修復";
1925
+ const reason = verified.reason ? `:${verified.reason}` : "";
1926
+ const next = result?.rebootRequired ? "請重新開機後按「重新檢查」。" : "請稍後按「重新檢查」。";
1927
+ return `${label} ${rejected}${state}${reason}。${next}`;
1774
1928
  }
1775
1929
  function usableCatalogYaml(value) {
1776
1930
  if (typeof value !== "string" || value.trim() === "") {
@@ -6,9 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.detectClient = detectClient;
7
7
  const node_child_process_1 = require("node:child_process");
8
8
  const promises_1 = __importDefault(require("node:fs/promises"));
9
- function succeeds(command, args) {
9
+ const systemPath_1 = require("./systemPath");
10
+ async function succeeds(command, args) {
11
+ const env = await (0, systemPath_1.envWithRegistryPath)();
10
12
  return new Promise(resolve => {
11
- (0, node_child_process_1.execFile)(command, args, { timeout: 8000, windowsHide: true, maxBuffer: 64 * 1024 }, error => resolve(!error));
13
+ (0, node_child_process_1.execFile)(command, args, { env, timeout: 8000, windowsHide: true, maxBuffer: 64 * 1024 }, error => resolve(!error));
12
14
  });
13
15
  }
14
16
  /** Detect a usable CLI, or a running/installed Codex desktop app; no model API call. */
@@ -4,9 +4,16 @@ exports.collectOutput = collectOutput;
4
4
  exports.shellLaunch = shellLaunch;
5
5
  exports.runCommand = runCommand;
6
6
  const node_child_process_1 = require("node:child_process");
7
+ const systemPath_1 = require("./systemPath");
7
8
  const ABORTED_NOTICE = "\n已中止。\n";
8
9
  const ABORT_GRACE_MS = 5000;
9
- function collectOutput(command, args, cwd, onOutput, signal) {
10
+ async function collectOutput(command, args, cwd, onOutput, signal,
11
+ /** 呼叫端已讀過登錄檔 PATH 時傳入,省下一次 PowerShell。 */
12
+ baseEnv) {
13
+ const env = baseEnv ?? await (0, systemPath_1.envWithRegistryPath)();
14
+ // 讀 PATH 期間學生可能已經按了停止;這時不要再啟動指令。
15
+ if (signal?.aborted)
16
+ return { exitCode: undefined, output: "", spawnError: false, aborted: true };
10
17
  return new Promise((resolve) => {
11
18
  let settled = false;
12
19
  let aborted = false;
@@ -19,7 +26,7 @@ function collectOutput(command, args, cwd, onOutput, signal) {
19
26
  };
20
27
  const child = (0, node_child_process_1.spawn)(command, args, {
21
28
  cwd,
22
- env: { ...process.env, PYTHONUTF8: "1", PYTHONIOENCODING: "utf-8" },
29
+ env: { ...env, PYTHONUTF8: "1", PYTHONIOENCODING: "utf-8" },
23
30
  windowsHide: process.platform === "win32",
24
31
  // A process group lets abort reach grandchildren such as servers started by uv.
25
32
  detached: process.platform !== "win32",
@@ -2,10 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.environmentIcons = void 0;
4
4
  // Brand icons from https://github.com/simple-icons/simple-icons (CC0-1.0).
5
- // PowerShell from 11.15.0; other icons from develop.
5
+ // PowerShell from 11.15.0; VS Code (visualstudiocode) from 7.21.0, before it was removed; other icons from develop.
6
6
  exports.environmentIcons = {
7
7
  "uv": "<svg aria-hidden=\"true\" fill=\"currentColor\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"m0 .1058.0504 11.9496.0403 9.5597c.0055 1.3199 1.08 2.3854 2.4 2.3798l9.5596-.0403 5.9749-.0252.6075-.0026c1.316-.0056 2.3799-1.0963 2.3799-2.4123h1.0946v2.3894L24 23.9042 23.8992.005 12.9056.0513l.0463 9.5245v5.9637h-1.9583L11.04 9.584 10.9936.0594Z\"/></svg>",
8
8
  "git": "<svg aria-hidden=\"true\" fill=\"currentColor\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M13.09 23.549a1.54 1.54 0 0 1-2.18 0L.451 13.089a1.54 1.54 0 0 1 0-2.179l7.191-7.19 2.733 2.733a1.85 1.85 0 0 0 .964 2.326v6.66a1.849 1.849 0 1 0 1.54 0V8.957l2.508 2.508a1.85 1.85 0 1 0 1.09-1.09l-2.634-2.634a1.85 1.85 0 0 0-2.378-2.377L8.73 2.63 10.91.451a1.54 1.54 0 0 1 2.179 0l10.459 10.46a1.54 1.54 0 0 1 0 2.179z\"/></svg>",
9
9
  "node": "<svg aria-hidden=\"true\" fill=\"currentColor\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M11.998,24c-0.321,0-0.641-0.084-0.922-0.247l-2.936-1.737c-0.438-0.245-0.224-0.332-0.08-0.383 c0.585-0.203,0.703-0.25,1.328-0.604c0.065-0.037,0.151-0.023,0.218,0.017l2.256,1.339c0.082,0.045,0.197,0.045,0.272,0l8.795-5.076 c0.082-0.047,0.134-0.141,0.134-0.238V6.921c0-0.099-0.053-0.192-0.137-0.242l-8.791-5.072c-0.081-0.047-0.189-0.047-0.271,0 L3.075,6.68C2.99,6.729,2.936,6.825,2.936,6.921v10.15c0,0.097,0.054,0.189,0.139,0.235l2.409,1.392 c1.307,0.654,2.108-0.116,2.108-0.89V7.787c0-0.142,0.114-0.253,0.256-0.253h1.115c0.139,0,0.255,0.112,0.255,0.253v10.021 c0,1.745-0.95,2.745-2.604,2.745c-0.508,0-0.909,0-2.026-0.551L2.28,18.675c-0.57-0.329-0.922-0.945-0.922-1.604V6.921 c0-0.659,0.353-1.275,0.922-1.603l8.795-5.082c0.557-0.315,1.296-0.315,1.848,0l8.794,5.082c0.57,0.329,0.924,0.944,0.924,1.603 v10.15c0,0.659-0.354,1.273-0.924,1.604l-8.794,5.078C12.643,23.916,12.324,24,11.998,24z M19.099,13.993 c0-1.9-1.284-2.406-3.987-2.763c-2.731-0.361-3.009-0.548-3.009-1.187c0-0.528,0.235-1.233,2.258-1.233 c1.807,0,2.473,0.389,2.747,1.607c0.024,0.115,0.129,0.199,0.247,0.199h1.141c0.071,0,0.138-0.031,0.186-0.081 c0.048-0.054,0.074-0.123,0.067-0.196c-0.177-2.098-1.571-3.076-4.388-3.076c-2.508,0-4.004,1.058-4.004,2.833 c0,1.925,1.488,2.457,3.895,2.695c2.88,0.282,3.103,0.703,3.103,1.269c0,0.983-0.789,1.402-2.642,1.402 c-2.327,0-2.839-0.584-3.011-1.742c-0.02-0.124-0.126-0.215-0.253-0.215h-1.137c-0.141,0-0.254,0.112-0.254,0.253 c0,1.482,0.806,3.248,4.655,3.248C17.501,17.007,19.099,15.91,19.099,13.993z\"/></svg>",
10
- "pwsh": "<svg aria-hidden=\"true\" fill=\"currentColor\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M23.181 2.974c.568 0 .923.463.792 1.035l-3.659 15.982c-.13.572-.697 1.035-1.265 1.035H.819c-.568 0-.923-.463-.792-1.035L3.686 4.009c.13-.572.697-1.035 1.265-1.035zm-8.375 9.346c.251-.394.227-.905-.09-1.243L9.122 5.125c-.38-.404-1.037-.407-1.466-.003-.429.402-.468 1.056-.088 1.46l4.662 4.96v.11l-7.42 5.374c-.45.327-.533.977-.187 1.453.346.476.991.597 1.44.27l8.229-5.91c.28-.196.438-.365.514-.52zm-2.796 4.399a.928.928 0 00-.934.923c0 .51.418.923.934.923h4.433a.928.928 0 00.934-.923.928.928 0 00-.934-.923z\"/></svg>"
10
+ "pwsh": "<svg aria-hidden=\"true\" fill=\"currentColor\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M23.181 2.974c.568 0 .923.463.792 1.035l-3.659 15.982c-.13.572-.697 1.035-1.265 1.035H.819c-.568 0-.923-.463-.792-1.035L3.686 4.009c.13-.572.697-1.035 1.265-1.035zm-8.375 9.346c.251-.394.227-.905-.09-1.243L9.122 5.125c-.38-.404-1.037-.407-1.466-.003-.429.402-.468 1.056-.088 1.46l4.662 4.96v.11l-7.42 5.374c-.45.327-.533.977-.187 1.453.346.476.991.597 1.44.27l8.229-5.91c.28-.196.438-.365.514-.52zm-2.796 4.399a.928.928 0 00-.934.923c0 .51.418.923.934.923h4.433a.928.928 0 00.934-.923.928.928 0 00-.934-.923z\"/></svg>",
11
+ "vscode": "<svg aria-hidden=\"true\" fill=\"currentColor\" viewBox=\"0 0 24 24\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M23.15 2.587L18.21.21a1.494 1.494 0 0 0-1.705.29l-9.46 8.63-4.12-3.128a.999.999 0 0 0-1.276.057L.327 7.261A1 1 0 0 0 .326 8.74L3.899 12 .326 15.26a1 1 0 0 0 .001 1.479L1.65 17.94a.999.999 0 0 0 1.276.057l4.12-3.128 9.46 8.63a1.492 1.492 0 0 0 1.704.29l4.942-2.377A1.5 1.5 0 0 0 24 20.06V3.939a1.5 1.5 0 0 0-.85-1.352zm-5.146 14.861L10.826 12l7.178-5.448v10.896z\"/></svg>"
11
12
  };
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.KEPT_INSTALL_LOGS = void 0;
7
+ exports.startInstallLogFile = startInstallLogFile;
8
+ const promises_1 = __importDefault(require("node:fs/promises"));
9
+ const node_path_1 = __importDefault(require("node:path"));
10
+ /** 只保留最近幾次 Environment Install 的紀錄,避免佔滿學生硬碟。 */
11
+ exports.KEPT_INSTALL_LOGS = 10;
12
+ function stamp(date) {
13
+ const two = (value) => String(value).padStart(2, "0");
14
+ return `${date.getFullYear()}-${two(date.getMonth() + 1)}-${two(date.getDate())}_${two(date.getHours())}${two(date.getMinutes())}${two(date.getSeconds())}`;
15
+ }
16
+ async function createRunFolder(root, name) {
17
+ await promises_1.default.mkdir(root, { recursive: true });
18
+ for (let attempt = 1;; attempt += 1) {
19
+ const folder = node_path_1.default.join(root, attempt === 1 ? name : `${name}-${attempt}`);
20
+ try {
21
+ await promises_1.default.mkdir(folder);
22
+ return folder;
23
+ }
24
+ catch (error) {
25
+ if (error.code !== "EEXIST")
26
+ throw error;
27
+ }
28
+ }
29
+ }
30
+ async function pruneOldLogs(root) {
31
+ const entries = await promises_1.default.readdir(root, { withFileTypes: true });
32
+ // 資料夾名稱以時間開頭,字串排序就是時間順序。
33
+ const folders = entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort();
34
+ const old = folders.slice(0, Math.max(0, folders.length - exports.KEPT_INSTALL_LOGS));
35
+ await Promise.all(old.map((name) => promises_1.default.rm(node_path_1.default.join(root, name), { recursive: true, force: true }).catch(() => { })));
36
+ }
37
+ /** 在 <managementDirectory>\InstallLogs 下建立本次安裝的紀錄資料夾,並刪掉超過保留數量的舊紀錄。 */
38
+ async function startInstallLogFile(managementDirectory, now) {
39
+ const root = node_path_1.default.join(managementDirectory, "InstallLogs");
40
+ const folder = await createRunFolder(root, stamp(now));
41
+ await pruneOldLogs(root).catch(() => { });
42
+ const file = node_path_1.default.join(folder, "install.log");
43
+ let pending = Promise.resolve();
44
+ return {
45
+ folder,
46
+ append(text) {
47
+ pending = pending.then(() => promises_1.default.appendFile(file, text, "utf8")).catch(() => { });
48
+ return pending;
49
+ },
50
+ };
51
+ }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.environmentProgressScript = void 0;
4
+ /**
5
+ * 背景 Environment Install 的進度輪詢:頁面帶 data-environment-progress 時,每 500ms 讀 /environment-status
6
+ * 更新每個工具的階段文字;安裝結束就重新整理頁面顯示結果。狀態在伺服器上,重新整理頁面後照樣接著輪詢。
7
+ */
8
+ exports.environmentProgressScript = `
9
+ (function () {
10
+ if (!document.querySelector("[data-environment-progress]")) return;
11
+ async function poll() {
12
+ try {
13
+ var response = await fetch("/environment-status", { cache: "no-store" });
14
+ if (!response.ok) throw new Error("status unavailable");
15
+ var status = await response.json();
16
+ if (!status.running) { window.location.reload(); return; }
17
+ status.tools.forEach(function (tool) {
18
+ document.querySelectorAll('[data-environment-stage="' + tool.id + '"]').forEach(function (stage) {
19
+ stage.textContent = tool.stage;
20
+ });
21
+ });
22
+ } catch (error) {}
23
+ setTimeout(poll, 500);
24
+ }
25
+ setTimeout(poll, 500);
26
+ })();
27
+ `;