dk-frontend-skills 3.0.5 → 3.0.7

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,6 +1,6 @@
1
1
  {
2
2
  "name": "dk-frontend-skills",
3
- "version": "3.0.5",
3
+ "version": "3.0.7",
4
4
  "description": "dk-engineer - 幽默沉稳靠谱的前端开发助手 Claude Skills 配置包,一键注入 .claude/ 技能目录和 CLAUDE.md 人设配置",
5
5
  "author": "XiaoMa",
6
6
  "license": "MIT",
package/scripts/cli.js CHANGED
@@ -81,13 +81,17 @@ async function downloadAndInstallSkill(name, index) {
81
81
 
82
82
  for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
83
83
  const tempFile = path.join(tempDir, skillInfo.fileName);
84
+ let barStarted = false;
84
85
  try {
85
- bar.start(100, 0);
86
86
  await downloadFile(url, tempFile, (d, t) => {
87
+ if (!barStarted) {
88
+ bar.start(t || skillInfo.size || 100, 0);
89
+ barStarted = true;
90
+ }
87
91
  bar.setTotal(t || skillInfo.size || 100);
88
92
  bar.update(d);
89
93
  });
90
- bar.stop();
94
+ if (barStarted) bar.stop();
91
95
 
92
96
  if (fs.existsSync(destDir)) fs.rmSync(destDir, { recursive: true, force: true });
93
97
  fs.mkdirSync(destDir, { recursive: true });
package/scripts/core.js CHANGED
@@ -1,5 +1,8 @@
1
1
  const fs = require("fs");
2
2
  const path = require("path");
3
+ const https = require("https");
4
+ const http = require("http");
5
+ const { URL } = require("url");
3
6
 
4
7
  // 时间戳格式:YYYY-MM-DD HH:mm:ss
5
8
  function timestamp() {
@@ -223,36 +226,82 @@ function isValidGzip(filePath) {
223
226
 
224
227
  /**
225
228
  * 从远程下载文件到本地临时路径
229
+ * 使用 https.get 替代 fetch,Windows 下更稳定
226
230
  */
227
- async function downloadFile(url, destPath, onProgress) {
228
- const response = await fetch(url);
229
- if (!response.ok) {
230
- throw new Error(`HTTP ${response.status} ${response.statusText}`);
231
- }
232
-
233
- const total = parseInt(response.headers.get("content-length") || "0", 10);
234
- let downloaded = 0;
235
-
236
- const reader = response.body.getReader();
237
- const writer = fs.createWriteStream(destPath);
238
-
239
- try {
240
- while (true) {
241
- const { done, value } = await reader.read();
242
- if (done) break;
243
- downloaded += value.length;
244
- if (onProgress) onProgress(downloaded, total);
245
- writer.write(value);
231
+ function downloadFile(url, destPath, onProgress) {
232
+ return new Promise((resolve, reject) => {
233
+ const writer = fs.createWriteStream(destPath);
234
+
235
+ function doRequest(targetUrl) {
236
+ const targetParsed = new URL(targetUrl);
237
+ const mod = targetParsed.protocol === "https:" ? https : http;
238
+
239
+ mod.get(targetParsed, (response) => {
240
+ // 处理重定向(GitHub Releases 可能会跳转)
241
+ if (
242
+ response.statusCode >= 300 &&
243
+ response.statusCode < 400 &&
244
+ response.headers.location
245
+ ) {
246
+ writer.destroy();
247
+ doRequest(response.headers.location);
248
+ return;
249
+ }
250
+
251
+ if (response.statusCode !== 200) {
252
+ writer.destroy();
253
+ fs.rmSync(destPath, { force: true });
254
+ reject(
255
+ new Error(`HTTP ${response.statusCode} ${response.statusMessage}`),
256
+ );
257
+ return;
258
+ }
259
+
260
+ const total = parseInt(
261
+ response.headers["content-length"] || "0",
262
+ 10,
263
+ );
264
+ let downloaded = 0;
265
+
266
+ response.on("data", (chunk) => {
267
+ downloaded += chunk.length;
268
+ if (onProgress) onProgress(downloaded, total);
269
+ const ok = writer.write(chunk);
270
+ if (!ok) response.pause();
271
+ });
272
+
273
+ writer.on("drain", () => response.resume());
274
+
275
+ response.on("end", () => {
276
+ writer.end(() => {
277
+ // 下载完后校验 gzip 格式
278
+ if (!isValidGzip(destPath)) {
279
+ fs.rmSync(destPath, { force: true });
280
+ reject(
281
+ new Error(
282
+ "下载的文件不是有效的压缩包,可能是 GitHub Release 尚未创建或链接错误",
283
+ ),
284
+ );
285
+ return;
286
+ }
287
+ resolve();
288
+ });
289
+ });
290
+
291
+ response.on("error", (err) => {
292
+ writer.destroy();
293
+ fs.rmSync(destPath, { force: true });
294
+ reject(err);
295
+ });
296
+ }).on("error", (err) => {
297
+ writer.destroy();
298
+ fs.rmSync(destPath, { force: true });
299
+ reject(err);
300
+ });
246
301
  }
247
- } finally {
248
- writer.close();
249
- }
250
302
 
251
- // 下载完后校验 gzip 格式
252
- if (fs.existsSync(destPath) && !isValidGzip(destPath)) {
253
- fs.rmSync(destPath, { force: true });
254
- throw new Error("下载的文件不是有效的压缩包,可能是 GitHub Release 尚未创建或链接错误");
255
- }
303
+ doRequest(url);
304
+ });
256
305
  }
257
306
 
258
307
  module.exports = {