ソースを参照

Refactor: use external dependencies

SukkaW 3 年 前
コミット
31e9f31e37
3 ファイル変更14 行追加41 行削除
  1. 2 41
      Build/build-mitm-hostname.js
  2. 11 0
      package-lock.json
  3. 1 0
      package.json

+ 2 - 41
Build/build-mitm-hostname.js

@@ -2,6 +2,8 @@ const fs = require('fs');
 const { promises: fsPromises } = fs;
 const { promises: fsPromises } = fs;
 const pathFn = require('path');
 const pathFn = require('path');
 const table = require('table');
 const table = require('table');
+const listDir = require('@sukka/listdir');
+const { green, yellow } = require('picocolors');
 
 
 const PRESET_MITM_HOSTNAMES = [
 const PRESET_MITM_HOSTNAMES = [
   '*baidu.com',
   '*baidu.com',
@@ -158,13 +160,6 @@ const PRESET_MITM_HOSTNAMES = [
 })();
 })();
 
 
 /** Util function */
 /** Util function */
-function green(...args) {
-  return `\u001b[32m${args.join(' ')}\u001b[0m`;
-}
-function yellow(...args) {
-  return `\u001b[33m${args.join(' ')}\u001b[0m`;
-}
-
 function parseDomain(input) {
 function parseDomain(input) {
   try {
   try {
     const url = new URL(`https://${input}`);
     const url = new URL(`https://${input}`);
@@ -195,37 +190,3 @@ function escapeRegExp(string = '') {
     ? string.replace(reRegExpChar, '\\$&')
     ? string.replace(reRegExpChar, '\\$&')
     : string;
     : string;
 }
 }
-
-function listDir(path, options) {
-  const results = [];
-  options = Object.assign({ ignoreHidden: true, ignorePattern: null }, options);
-  return listDirWalker(path, results, '', options).then(() => results);
-}
-function listDirWalker(path, results, parent, options) {
-  const promises = [];
-  return readAndFilterDir(path, options).then(items => {
-    items.forEach(item => {
-      const currentPath = pathFn.join(parent, item.name);
-      if (item.isDirectory()) {
-        promises.push(listDirWalker(pathFn.join(path, item.name), results, currentPath, options));
-      }
-      else {
-        results.push(currentPath);
-      }
-    });
-  }).then(() => Promise.all(promises));
-}
-function readAndFilterDir(path, options) {
-  const { ignoreHidden = true, ignorePattern } = options;
-  return fs.promises.readdir(path, Object.assign(Object.assign({}, options), { withFileTypes: true }))
-    .then(results => {
-      if (ignoreHidden) {
-        results = results.filter(({ name }) => !name.startsWith('.'));
-      }
-      if (ignorePattern) {
-        results = results.filter(({ name }) => !ignorePattern.test(name));
-      }
-      return results;
-    });
-}
-

+ 11 - 0
package-lock.json

@@ -10,6 +10,7 @@
       "license": "ISC",
       "license": "ISC",
       "dependencies": {
       "dependencies": {
         "@sukka/listdir": "^0.2.0",
         "@sukka/listdir": "^0.2.0",
+        "picocolors": "^1.0.0",
         "piscina": "^3.1.0",
         "piscina": "^3.1.0",
         "table": "^6.7.3",
         "table": "^6.7.3",
         "undici": "^5.0.0"
         "undici": "^5.0.0"
@@ -189,6 +190,11 @@
       "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
       "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
       "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="
       "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="
     },
     },
+    "node_modules/picocolors": {
+      "version": "1.0.0",
+      "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz",
+      "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ=="
+    },
     "node_modules/piscina": {
     "node_modules/piscina": {
       "version": "3.1.0",
       "version": "3.1.0",
       "resolved": "https://registry.npmjs.org/piscina/-/piscina-3.1.0.tgz",
       "resolved": "https://registry.npmjs.org/piscina/-/piscina-3.1.0.tgz",
@@ -420,6 +426,11 @@
       "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
       "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
       "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="
       "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="
     },
     },
+    "picocolors": {
+      "version": "1.0.0",
+      "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz",
+      "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ=="
+    },
     "piscina": {
     "piscina": {
       "version": "3.1.0",
       "version": "3.1.0",
       "resolved": "https://registry.npmjs.org/piscina/-/piscina-3.1.0.tgz",
       "resolved": "https://registry.npmjs.org/piscina/-/piscina-3.1.0.tgz",

+ 1 - 0
package.json

@@ -15,6 +15,7 @@
   "license": "ISC",
   "license": "ISC",
   "dependencies": {
   "dependencies": {
     "@sukka/listdir": "^0.2.0",
     "@sukka/listdir": "^0.2.0",
+    "picocolors": "^1.0.0",
     "piscina": "^3.1.0",
     "piscina": "^3.1.0",
     "table": "^6.7.3",
     "table": "^6.7.3",
     "undici": "^5.0.0"
     "undici": "^5.0.0"