@domain.js/main 0.2.2 → 0.2.3

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.
@@ -14,7 +14,7 @@ interface Deps {
14
14
  /** 对 params 的处理函数 */
15
15
  declare type Handler = (params: any) => void;
16
16
  /** 对执行结构的处理 */
17
- declare type ResHandler = (results: any, res: restify.Response) => void;
17
+ declare type ResHandler = (results: any, res: restify.Response, params?: any) => void;
18
18
  export declare function Router(deps: Deps): {
19
19
  get: (routePath: string, ctlAct: string, code?: number, isList?: boolean, handler?: Handler | undefined, resHandler?: ResHandler | undefined) => void;
20
20
  post: (routePath: string, ctlAct: string, code?: number, isList?: boolean, handler?: Handler | undefined, resHandler?: ResHandler | undefined) => void;
@@ -74,7 +74,7 @@ function Router(deps) {
74
74
  // eslint-disable-next-line max-params
75
75
  function register(verb, route, methodPath, code = 200, isList = false, handler, resHandler) {
76
76
  /**
77
- * 暂存起来,提供给apis接口来用
77
+ * 暂存起来,提供给apis接口来
78
78
  * apis接口用来返回当前 services 提供的可用的 api
79
79
  */
80
80
  apis.push(`[${verb.toUpperCase()}] ${route} Domain: ${methodPath}`);
@@ -97,7 +97,7 @@ function Router(deps) {
97
97
  if (results === null || results === undefined)
98
98
  results = "Ok";
99
99
  if (resHandler) {
100
- resHandler(results, res);
100
+ resHandler(results, res, params);
101
101
  }
102
102
  else if (isList) {
103
103
  const { _ignoreTotal, _format } = params;
@@ -12,7 +12,7 @@ export declare const md5: (str: {
12
12
  * @param type "strong" or "normal" or other string that custom character range string
13
13
  */
14
14
  export declare function randStr(len: number, type: "strong"): string;
15
- export declare function randStr(len: number, type: "normal"): string;
15
+ export declare function randStr(len: number, type?: "normal"): string;
16
16
  export declare function randStr(len: number, type: string): string;
17
17
  /**
18
18
  * Replace line breaks and tabs in the string with ordinary spaces
@@ -81,4 +81,19 @@ export declare const modifiyURL: (address: string, adds?: Params | undefined, re
81
81
  * @param intervalMS 间隔多久判断一次, 单位毫秒 默认 100
82
82
  */
83
83
  export declare const waitFor: (test: () => boolean, intervalMS?: number) => Promise<void>;
84
+ /**
85
+ * 读取录下的所有文件,之后返回数组
86
+ * params
87
+ * dir 要加载的目录
88
+ * exts 要加载的模块文件后缀,多个可以是数组, 默认为 coffee
89
+ * excludes 要排除的文件, 默认排除 index
90
+ */
91
+ /**
92
+ * 读取录下的所有文件,之后返回数组
93
+ * @param dir 要读取的目录
94
+ * @param exts 要读取的文件后缀,不包含 (.) 点,例如 jpg 而非 .jpg
95
+ * @param excludes 要排除的文件列表
96
+ * @param files 读取到的文件路径存放地址
97
+ */
98
+ export declare const deepReaddir: (dir: string, exts: Set<string>, excludes?: Set<string>, files?: string[]) => string[];
84
99
  export {};
@@ -22,9 +22,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
22
22
  return (mod && mod.__esModule) ? mod : { "default": mod };
23
23
  };
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.waitFor = exports.modifiyURL = exports.inExpired = exports.tryCatchLog = exports.deepFreeze = exports.sleep = exports.lcfirst = exports.ucfirst = exports.nt2space = exports.randStr = exports.md5 = void 0;
25
+ exports.deepReaddir = exports.waitFor = exports.modifiyURL = exports.inExpired = exports.tryCatchLog = exports.deepFreeze = exports.sleep = exports.lcfirst = exports.ucfirst = exports.nt2space = exports.randStr = exports.md5 = void 0;
26
26
  const async_1 = __importDefault(require("async"));
27
27
  const crypto = __importStar(require("crypto"));
28
+ const fs_1 = __importDefault(require("fs"));
29
+ const path_1 = __importDefault(require("path"));
28
30
  /** 随机字符串字典 */
29
31
  const RAND_STR_DICT = {
30
32
  normal: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
@@ -44,9 +46,8 @@ function randStr(len, type = "normal") {
44
46
  const dict = type === "strong" || type === "normal" ? RAND_STR_DICT[type] : type;
45
47
  const { length } = dict;
46
48
  /** 随机字符串的长度不能等于 0 或者负数 */
47
- len |= 0;
48
- len = Math.max(len, 3);
49
- return Array(len)
49
+ const _len = Math.max(3, len | 0);
50
+ return Array(_len)
50
51
  .fill("")
51
52
  .map(() => dict[Math.floor(Math.random() * length)])
52
53
  .join("");
@@ -162,3 +163,40 @@ const waitFor = async (test, intervalMS = 100) => {
162
163
  }, async () => test());
163
164
  };
164
165
  exports.waitFor = waitFor;
166
+ /**
167
+ * 读取录下的所有文件,之后返回数组
168
+ * params
169
+ * dir 要加载的目录
170
+ * exts 要加载的模块文件后缀,多个可以是数组, 默认为 coffee
171
+ * excludes 要排除的文件, 默认排除 index
172
+ */
173
+ /**
174
+ * 读取录下的所有文件,之后返回数组
175
+ * @param dir 要读取的目录
176
+ * @param exts 要读取的文件后缀,不包含 (.) 点,例如 jpg 而非 .jpg
177
+ * @param excludes 要排除的文件列表
178
+ * @param files 读取到的文件路径存放地址
179
+ */
180
+ const deepReaddir = (dir, exts, excludes = new Set(), files = []) => {
181
+ for (const x of fs_1.default.readdirSync(dir)) {
182
+ const file = path_1.default.resolve(dir, x);
183
+ const stat = fs_1.default.lstatSync(file);
184
+ if (stat.isFile()) {
185
+ // 忽略隐藏文件
186
+ if (x[0] === ".")
187
+ continue;
188
+ const arr = x.split(".");
189
+ const ext = arr.pop();
190
+ const name = arr.join(".");
191
+ // 如果是不希望的后缀或者排除的名称,则直接忽略/跳过
192
+ if ((ext && !exts.has(ext)) || excludes.has(name))
193
+ continue;
194
+ files.push(file);
195
+ }
196
+ else if (stat.isDirectory()) {
197
+ (0, exports.deepReaddir)(file, exts, excludes, files);
198
+ }
199
+ }
200
+ return files;
201
+ };
202
+ exports.deepReaddir = deepReaddir;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@domain.js/main",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "DDD framework",
5
5
  "main": "dist/index.js",
6
6
  "bin": {