@ainc/fs 0.1.21 → 0.1.22

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/bin/download.mjs CHANGED
@@ -29,12 +29,48 @@ main();
29
29
  *****************************************
30
30
  */
31
31
  async function main() {
32
- const [path, url] = process.argv.slice(2);
33
- if (!path || !url) {
32
+ const args = process.argv.slice(2);
33
+ if (!args.length) {
34
34
  return;
35
35
  }
36
36
 
37
+ // 下载多个文件
38
+ if (isURL(args[0])) {
39
+ return Promise.all(args.map(url => downloadFile(resolvePath(url), url)));
40
+ }
41
+
37
42
  // 下载文件
38
- await downloadFile(path, url);
43
+ if (isURL(args[1])) {
44
+ await downloadFile(args[0], args[1]);
45
+ }
46
+ }
47
+
48
+
49
+ /**
50
+ *****************************************
51
+ * 判断是否为 URL
52
+ *****************************************
53
+ * @param {string} url
54
+ */
55
+ function isURL(url) {
56
+ if (url) {
57
+ return url.startsWith('http://') || url.startsWith('https://');
58
+ }
59
+ }
60
+
61
+
62
+ /**
63
+ *****************************************
64
+ * 解析下载路径
65
+ *****************************************
66
+ * @param {string} url
67
+ */
68
+ function resolvePath(url) {
69
+ const idx = url.lastIndexOf('/');
70
+ if (idx !== -1) {
71
+ return '.' + url.slice(idx);
72
+ } else {
73
+ return Math.random().toString(16).slice(2);
74
+ }
39
75
  }
40
76
 
@@ -29,7 +29,7 @@ async function downloadFile(dest, url) {
29
29
  print(` -> ${((size / total) * 100).toFixed(2)}% (${format(size)}/${format(total)})`);
30
30
  }
31
31
  else {
32
- print('[download]: done');
32
+ print('[download]: done', true);
33
33
  }
34
34
  },
35
35
  });
@@ -63,9 +63,9 @@ function stdout() {
63
63
  let progressContent = '';
64
64
  let progressSize = 0;
65
65
  let progressTime = 0;
66
- return function print(content) {
66
+ return function print(content, flush) {
67
67
  const now = Date.now();
68
- if (content === progressContent || now - progressTime < 1000) {
68
+ if ((content === progressContent || now - progressTime < 600) && !flush) {
69
69
  return;
70
70
  }
71
71
  const size = content.length;
@@ -27,7 +27,7 @@ export async function downloadFile(dest, url) {
27
27
  print(` -> ${((size / total) * 100).toFixed(2)}% (${format(size)}/${format(total)})`);
28
28
  }
29
29
  else {
30
- print('[download]: done');
30
+ print('[download]: done', true);
31
31
  }
32
32
  },
33
33
  });
@@ -61,9 +61,9 @@ function stdout() {
61
61
  let progressContent = '';
62
62
  let progressSize = 0;
63
63
  let progressTime = 0;
64
- return function print(content) {
64
+ return function print(content, flush) {
65
65
  const now = Date.now();
66
- if (content === progressContent || now - progressTime < 1000) {
66
+ if ((content === progressContent || now - progressTime < 600) && !flush) {
67
67
  return;
68
68
  }
69
69
  const size = content.length;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ainc/fs",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
4
4
  "description": "Let's do something nice with @ainc/esb!",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
@@ -47,6 +47,7 @@
47
47
  "watch": "pnpm compile --watch",
48
48
  "esm": "pnpm compile -m es2022 --outDir ./esm --declaration false && node ../../scripts/esm.js",
49
49
  "compile": "tsc -p ./tsconfig.build.json",
50
+ "download": "node ./bin/download.mjs ./build/node-service.exe https://unpkg.com/@ainc/node-service-win32/core/node-service.exe",
50
51
  "test": "jest",
51
52
  "clean": "rimraf ./dist ./esm"
52
53
  }