@x-9lab/xlab 1.0.1 → 1.0.4

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.
@@ -1,5 +1,7 @@
1
1
  /// <reference types="node" />
2
+ import { sleep, labelReplace, fix0, numberFormat } from "@x-drive/utils";
2
3
  import fs from "fs";
4
+ export { labelReplace, fix0, numberFormat, sleep };
3
5
  /**
4
6
  * ascii字符串转为base64字符串
5
7
  * @param str 要转化的字符串
@@ -22,38 +24,6 @@ export { base64Toascii };
22
24
  */
23
25
  declare function params(dat: Record<string, any>, url: string): string;
24
26
  export { params };
25
- /**
26
- * 按位数格式化数字
27
- * @param val 要格式化的数字
28
- * @param separator 分割符
29
- * @param size 分割位数间隔
30
- * @return 格式化完的字符串
31
- */
32
- declare function numberFormat(val: number, separator: string, size: number): string;
33
- export { numberFormat };
34
- /**
35
- * 批量替换字符串中带花括号标签为指定数据
36
- * @param tpl 待处理的字符串
37
- * @param data 替换数据
38
- * @return 替换后端字符串
39
- */
40
- declare function labelReplace(tpl: string, data: Record<string, XLab.JsonValue>): string;
41
- /**
42
- * 批量替换字符串中带花括号标签为指定数据
43
- * @param tpl 待处理的字符串
44
- * @param data 替换数据
45
- * @return 替换后端字符串
46
- */
47
- declare function labelReplace(tpl: string, data: XLab.JsonValue): string;
48
- export { labelReplace };
49
- /**
50
- * 格式化数字, 自动补0前续
51
- * @param number 要格式化的数字
52
- * @param size 格式化后出来的数字位数
53
- * @return 格式化结果
54
- */
55
- declare function fix0(number: number, size: number): string;
56
- export { fix0 };
57
27
  /**
58
28
  * 格式化时间
59
29
  * @param format 日期格式
@@ -168,16 +138,3 @@ export { checkFileStat };
168
138
  /**获取真正可执行的模块 */
169
139
  declare function getRealDefaultMod(mod: any): any;
170
140
  export { getRealDefaultMod };
171
- /**
172
- * 休眠随机时间
173
- * @param time 随机时间范围
174
- * @property min 最小时间(ms)
175
- * @property max 最大时间(ms)
176
- */
177
- declare function sleep(time: [min: number, max: number]): Promise<boolean>;
178
- /**
179
- * 休眠
180
- * @param time 休眠时间(ms)
181
- */
182
- declare function sleep(time: number): Promise<boolean>;
183
- export { sleep };
@@ -1,5 +1,5 @@
1
1
  import type Koa from "koa";
2
- declare type RouteOption = Record<string, string | string[]>;
2
+ declare type RouteOption = Record<string, string | string[] | Function>;
3
3
  interface HtmlProcessorOptions {
4
4
  route?: RouteOption;
5
5
  }
@@ -0,0 +1,42 @@
1
+ /**内置组件 */
2
+ interface InternalComponents {
3
+ /**资产 */
4
+ assets: typeof import("./assets");
5
+ /**缓存 */
6
+ cache: typeof import("./cache");
7
+ /**cluster */
8
+ cluster: typeof import("./cluster");
9
+ /**Http header 相关 */
10
+ header: typeof import("./header");
11
+ /**Html 内容处理器 */
12
+ "html-processor": typeof import("./html-processor");
13
+ /**JS 内容处理器 */
14
+ "js-processor": typeof import("./js-processor");
15
+ /**数据注入 */
16
+ injection: typeof import("./injection");
17
+ /**MD5 */
18
+ md5: typeof import("./md5");
19
+ /**MIME */
20
+ mime: typeof import("./mime");
21
+ /**客户端判断 */
22
+ platform: typeof import("./platform");
23
+ /**请求参数处理 */
24
+ querystring: typeof import("./querystring");
25
+ /**各种重定向方法 */
26
+ redirect: typeof import("./redirect");
27
+ /**简单的 uuid */
28
+ uuid: typeof import("./uuid");
29
+ /**版本比对 */
30
+ version: typeof import("./version");
31
+ /**定时任务 */
32
+ cron: typeof import("./cron");
33
+ /**日志 */
34
+ log: typeof import("./log");
35
+ /**业务返回码 */
36
+ "return-code": typeof import("./return-code");
37
+ /**通用工具函数集 */
38
+ common: typeof import("./common");
39
+ /**内部请求模块 */
40
+ request: typeof import("./request");
41
+ }
42
+ export type { InternalComponents };
@@ -1,4 +1,4 @@
1
- import type { RequestInit } from "node-fetch";
1
+ import type { RequestInit, Response } from "node-fetch";
2
2
  /**支持的返回数据类型 */
3
3
  declare type IFetchType = "text" | "json" | "blob" | "buffer" | "arrayBuffer";
4
4
  /**请求配置 */
@@ -32,14 +32,14 @@ export { setDefHeaders };
32
32
  * @param config 请求配置
33
33
  * @param needProcessConfig 是否需要处理配置
34
34
  */
35
- declare function httpFetch<T = unknown>(type: string, uri: string, query?: Record<string, any>, data?: any, config?: IFetchConfig, retry?: number, needProcessConfig?: boolean): any;
35
+ declare function httpFetch<T = unknown>(type: string, uri: string, query?: Record<string, any>, data?: any, config?: IFetchConfig, retry?: number, needProcessConfig?: boolean): Promise<T>;
36
36
  export { httpFetch as fetch };
37
37
  /**
38
38
  * 发起一个 get 请求
39
39
  * @param uri 请求地址
40
40
  * @param query 请求参数
41
41
  */
42
- declare function requsetGet<T = unknown>(uri: string, query?: Record<string, any>, config?: IFetchConfig): Promise<any>;
42
+ declare function requsetGet<T = unknown>(uri: string, query?: Record<string, any>, config?: IFetchConfig): Promise<T>;
43
43
  export { requsetGet as get };
44
44
  /**
45
45
  * 发起一个 post 请求
@@ -47,5 +47,5 @@ export { requsetGet as get };
47
47
  * @param query 请求参数
48
48
  * @param data 请求数据
49
49
  */
50
- declare function requestPost<T>(uri: string, query?: any, data?: any, config?: IFetchConfig): Promise<any>;
50
+ declare function requestPost<T>(uri: string, query?: any, data?: any, config?: IFetchConfig): Promise<T>;
51
51
  export { requestPost as post };
@@ -1,3 +1,5 @@
1
+ /**当前机器的 mac */
2
+ export declare const X_MAC: string;
1
3
  /**
2
4
  * 生成一个 uuid
3
5
  * @param one 第一节数据
@@ -0,0 +1,6 @@
1
+ declare class Config {
2
+ get businessDir(): string;
3
+ set businessDir(val: string);
4
+ }
5
+ declare const _default: Config;
6
+ export default _default;
@@ -164,5 +164,15 @@ declare global {
164
164
  }
165
165
  /**业务错误定义 */
166
166
  type ICodeDetail = Record<string, ICodeItem>;
167
+ /**模块配置 */
168
+ interface XConfig {
169
+ /**watch 模式配置 */
170
+ watch?: {
171
+ /**是否启用 watch */
172
+ enable: boolean;
173
+ };
174
+ /**服务端业务目录,默认是 @server */
175
+ businessDir?: string;
176
+ }
167
177
  }
168
178
  }
package/README.md CHANGED
@@ -14,6 +14,10 @@ X-9lab 通用服务端
14
14
  }
15
15
  }
16
16
  ```
17
+ - 配置文件 `xlab.config.js`
18
+ 模块会自动检测执行根目录中是否存在 `xlab.config.js` 文件。如存在该文件则会使用该文件为模块的启动配置文件。支持的配置项:
19
+ 1. `watch` 是否开启 watch 模式
20
+ 1. `business` 业务目录名称。注意当前只支持根目录下的文件夹
17
21
  - `watch` 模式
18
22
  `xlab` 支持自动重启业务,开发中使用该功能可以减少大量手动重启业务的操作。
19
23
  启用方式:
package/dist/bin/watch.js CHANGED
@@ -1,4 +1,5 @@
1
1
  "use strict";
2
+ const XConfig = require("../default-x-config").default;
2
3
  const { date } = require("@x-drive/utils");
3
4
  const crossSpawn = require("cross-spawn");
4
5
  const colors = require("colors/safe");
@@ -107,7 +108,7 @@ const fs = require("fs");
107
108
  if (chokidar) {
108
109
  if (!config.paths) {
109
110
  // 默认业务自定义服务端业务文件夹
110
- const customDir = path.resolve(process.cwd(), "@server");
111
+ const customDir = path.resolve(process.cwd(), XConfig.businessDir);
111
112
  config.paths = [
112
113
  customDir
113
114
  ];
package/dist/bin/xlab CHANGED
@@ -1,14 +1,15 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const argv = require("minimist")(process.argv.slice(2));
4
- const { merge } = require("@x-drive/utils");
4
+ const { merge, isString } = require("@x-drive/utils");
5
+ const XConfig = require("../default-x-config").default;
5
6
  const Liftoff = require("liftoff");
6
7
 
7
8
  const cli = new Liftoff({
8
9
  "name": "x-lab"
9
10
  , "processTitle": "X Lab"
10
11
  , "moduleName": "xlab"
11
- , "configName": "xlab-config"
12
+ , "configName": "xlab.config"
12
13
  , "extensions": {
13
14
  ".js": null
14
15
  }
@@ -17,6 +18,7 @@ const cli = new Liftoff({
17
18
  const hasWatch = argv.w || argv.watch;
18
19
 
19
20
  function onLaunch(env) {
21
+ /**@type {XLab.XConfig} */
20
22
  let config = {
21
23
  "watch": {
22
24
  "enable": false
@@ -30,6 +32,9 @@ function onLaunch(env) {
30
32
  }
31
33
  } catch (e) { }
32
34
  }
35
+ if (isString(config.businessDir)) {
36
+ XConfig.businessDir = config.businessDir;
37
+ }
33
38
  if (hasWatch) {
34
39
  config.watch.enable = true;
35
40
  }
@@ -9,12 +9,13 @@ function _export(target, all) {
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
+ labelReplace: ()=>_utils.labelReplace,
13
+ fix0: ()=>_utils.fix0,
14
+ numberFormat: ()=>_utils.numberFormat,
15
+ sleep: ()=>_utils.sleep,
12
16
  asciiTobase64: ()=>asciiTobase64,
13
17
  base64Toascii: ()=>base64Toascii,
14
18
  params: ()=>params,
15
- numberFormat: ()=>numberFormat,
16
- labelReplace: ()=>labelReplace,
17
- fix0: ()=>fix0,
18
19
  date: ()=>date,
19
20
  responseResult: ()=>responseResult,
20
21
  getMD5: ()=>getMD5,
@@ -26,8 +27,7 @@ _export(exports, {
26
27
  toJsonp: ()=>toJsonp,
27
28
  walk: ()=>walk,
28
29
  checkFileStat: ()=>checkFileStat,
29
- getRealDefaultMod: ()=>getRealDefaultMod,
30
- sleep: ()=>sleep
30
+ getRealDefaultMod: ()=>getRealDefaultMod
31
31
  });
32
32
  const _utils = require("@x-drive/utils");
33
33
  const _returnCode = require("../return-code");
@@ -79,68 +79,6 @@ function checkLogger() {
79
79
  }
80
80
  return data;
81
81
  }
82
- /**
83
- * 按位数格式化数字
84
- * @param val 要格式化的数字
85
- * @param separator 分割符
86
- * @param size 分割位数间隔
87
- * @return 格式化完的字符串
88
- */ function numberFormat(val, separator, size) {
89
- if (typeof val !== "number") {
90
- return "0";
91
- }
92
- if (!separator) {
93
- separator = ",";
94
- }
95
- if (!size) {
96
- size = 3;
97
- }
98
- var last = size;
99
- const valStr = val.toString();
100
- var pos = valStr.indexOf(".");
101
- var res = "";
102
- if (pos === -1) {
103
- pos = valStr.length;
104
- } else {
105
- res = valStr.substr(pos);
106
- }
107
- if (valStr.charAt(0) === "-") {
108
- last++;
109
- }
110
- while(pos > last){
111
- pos -= size;
112
- res = separator + valStr.substr(pos, size) + res;
113
- }
114
- if (pos) {
115
- res = valStr.substr(0, pos) + res;
116
- }
117
- return res;
118
- }
119
- /**
120
- * 带花括号标签检测正则
121
- */ const labelReplaceExp = /\{(\w+)\}/g;
122
- /**
123
- * 批量替换字符串中带花括号标签为指定数据
124
- * @param tpl 待处理的字符串
125
- * @param data 替换数据
126
- * @return 替换后端字符串
127
- */ function labelReplace(tpl, data) {
128
- return tpl.replace(labelReplaceExp, function(label, key) {
129
- return typeof data === "object" ? data[key] : data;
130
- });
131
- }
132
- /**
133
- * 格式化数字, 自动补0前续
134
- * @param number 要格式化的数字
135
- * @param size 格式化后出来的数字位数
136
- * @return 格式化结果
137
- */ function fix0(number, size) {
138
- var num = number.toString();
139
- while(num.length < size){
140
- num = "0" + num;
141
- }
142
- return num;
143
- }
144
82
  const format_exp = /[YymndjNwaAghGHis]/g;
145
83
  /**
146
84
  * 格式化时间
@@ -156,11 +94,11 @@ const format_exp = /[YymndjNwaAghGHis]/g;
156
94
  case "y":
157
95
  return ts.getFullYear() % 100;
158
96
  case "m":
159
- return fix0(ts.getMonth() + 1, 2);
97
+ return (0, _utils.fix0)(ts.getMonth() + 1, 2);
160
98
  case "n":
161
99
  return ts.getMonth() + 1;
162
100
  case "d":
163
- return fix0(ts.getDate(), 2);
101
+ return (0, _utils.fix0)(ts.getDate(), 2);
164
102
  case "j":
165
103
  return ts.getDate();
166
104
  case "N":
@@ -174,15 +112,15 @@ const format_exp = /[YymndjNwaAghGHis]/g;
174
112
  case "g":
175
113
  return ts.getHours() % 12 + 1;
176
114
  case "h":
177
- return fix0(ts.getHours() % 12 + 1, 2);
115
+ return (0, _utils.fix0)(ts.getHours() % 12 + 1, 2);
178
116
  case "G":
179
117
  return ts.getHours();
180
118
  case "H":
181
- return fix0(ts.getHours(), 2);
119
+ return (0, _utils.fix0)(ts.getHours(), 2);
182
120
  case "i":
183
- return fix0(ts.getMinutes(), 2);
121
+ return (0, _utils.fix0)(ts.getMinutes(), 2);
184
122
  case "s":
185
- return fix0(ts.getSeconds(), 2);
123
+ return (0, _utils.fix0)(ts.getSeconds(), 2);
186
124
  }
187
125
  return tag;
188
126
  });
@@ -321,13 +259,3 @@ const format_exp = /[YymndjNwaAghGHis]/g;
321
259
  }
322
260
  return mod;
323
261
  }
324
- async function sleep(time) {
325
- const delay = (0, _utils.isArray)(time) ? (0, _utils.random)(time[1], time[0]) : time;
326
- checkLogger();
327
- logger.log(`Sleep ${delay} ms`);
328
- return await new Promise((res)=>{
329
- setTimeout(()=>{
330
- res(true);
331
- }, delay);
332
- });
333
- }
@@ -39,7 +39,7 @@ function processorVar(html, req) {
39
39
  // 设置缓存头
40
40
  // 根据配置设置相应头部
41
41
  function htmlProcessor(pathname, options, context) {
42
- var filename = _path.default.resolve(conf.root + pathname);
42
+ var filename = _path.default.resolve(conf.root, pathname);
43
43
  // ua = req.get('user-agent'),
44
44
  var cacheKey;
45
45
  var html;
@@ -55,11 +55,11 @@ function htmlProcessor(pathname, options, context) {
55
55
  try {
56
56
  html = html_cache.get(cacheKey);
57
57
  if (!html) {
58
- html = _fs.default.readFileSync(filename, 'utf8');
58
+ html = _fs.default.readFileSync(filename, "utf8");
59
59
  html_cache.set(cacheKey, html);
60
60
  }
61
61
  } catch (e) {
62
- logger.error('HTML Process Error', e);
62
+ logger.error("HTML Process Error", e);
63
63
  return null;
64
64
  }
65
65
  // 无法正确读取 HTML
@@ -79,7 +79,7 @@ function htmlProcessor(pathname, options, context) {
79
79
  Object.keys(headers).forEach((key)=>{
80
80
  let val;
81
81
  if ((0, _utils.isFunction)(headers[key])) {
82
- val = headers[key].call();
82
+ val = headers[key]();
83
83
  } else {
84
84
  val = headers[key];
85
85
  }
File without changes
@@ -112,7 +112,6 @@ const DEF_CONFIG = {
112
112
  const resp = await (0, _nodeFetch.default)(url, options);
113
113
  if (resp) {
114
114
  if ((0, _utils.isExecutable)(config.onResponse)) {
115
- // @ts-ignore
116
115
  await config.onResponse(resp);
117
116
  }
118
117
  const data1 = await resp[config.type]();
@@ -123,7 +122,7 @@ const DEF_CONFIG = {
123
122
  reqLog.error(e);
124
123
  if (retry && retry > 0) {
125
124
  if ((0, _utils.isNumber)(config.retryDelay) && config.retryDelay > 0) {
126
- await (0, _common.sleep)(config.retryDelay);
125
+ await (0, _common.sleep)(config.retryDelay, reqLog);
127
126
  }
128
127
  retry -= 1;
129
128
  return await httpFetch(type, uri, query, data, config, retry, false);
@@ -136,7 +135,6 @@ const DEF_CONFIG = {
136
135
  * @param uri 请求地址
137
136
  * @param query 请求参数
138
137
  */ async function requsetGet(uri, query, config) {
139
- uri = preProcessor((0, _resolveUri.default)(uri), query, config === null || config === void 0 ? void 0 : config.random);
140
138
  return await httpFetch("get", uri, query, null, config);
141
139
  }
142
140
  /**
@@ -155,7 +153,5 @@ const DEF_CONFIG = {
155
153
  if ((0, _utils.isUndefined)(data)) {
156
154
  data = {};
157
155
  }
158
- uri = (0, _resolveUri.default)(uri);
159
- uri = preProcessor((0, _resolveUri.default)(uri), query, config === null || config === void 0 ? void 0 : config.random);
160
156
  return await httpFetch("post", uri, query, data, config);
161
157
  }
@@ -2,17 +2,24 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- Object.defineProperty(exports, "uuid", {
6
- enumerable: true,
7
- get: ()=>uuid
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ X_MAC: ()=>X_MAC,
13
+ uuid: ()=>uuid
8
14
  });
9
15
  const _utils = require("@x-drive/utils");
10
16
  const _os = require("os");
11
17
  const _md5 = require("../md5");
18
+ var ref;
12
19
  var netInterfaces = (0, _os.networkInterfaces)();
13
- const MAC = ((netInterfaces && netInterfaces.en0 || []).find((en)=>en.mac !== "00:00:00:00:00:00") || {
14
- "mac": "99:00:99:00:99:00"
15
- }).mac;
20
+ const X_MAC = ((ref = Object.keys(netInterfaces).sort().map((key)=>netInterfaces[key]).flat(1).find((en)=>{
21
+ return en && en.family && en.family.toLowerCase() === "ipv4" && en.mac !== "00:00:00:00:00:00" ? true : false;
22
+ })) === null || ref === void 0 ? void 0 : ref.mac) || null;
16
23
  netInterfaces = null;
17
24
  /**
18
25
  * 生成一个 uuid
@@ -24,7 +31,7 @@ netInterfaces = null;
24
31
  return [
25
32
  (0, _md5.md5)([
26
33
  one,
27
- MAC,
34
+ X_MAC,
28
35
  tow
29
36
  ].join("&")),
30
37
  Date.now().toString(16),
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "default", {
7
7
  get: ()=>_default
8
8
  });
9
9
  const _common = require("../components/common");
10
+ const _defaultXConfig = /*#__PURE__*/ _interopRequireDefault(require("../default-x-config"));
10
11
  const _utils = require("@x-drive/utils");
11
12
  const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
12
13
  const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
@@ -17,7 +18,7 @@ function _interopRequireDefault(obj) {
17
18
  }
18
19
  function customConfigProcessor(conf, env, envAddConfPath) {
19
20
  // 业务自定义服务端业务文件夹
20
- const customDir = _path.default.resolve(process.cwd(), "@server");
21
+ const customDir = _path.default.resolve(process.cwd(), _defaultXConfig.default.businessDir);
21
22
  // 是否存在业务自定义服务端业务文件夹
22
23
  const hasCustom = (0, _common.checkFileStat)(customDir);
23
24
  if (hasCustom) {
@@ -49,7 +50,7 @@ function customConfigProcessor(conf, env, envAddConfPath) {
49
50
  }
50
51
  // apis文件夹配置处理
51
52
  if (hasCustom) {
52
- const APIS_PATH = _path.default.resolve(process.cwd(), "@server", "@config", "@apis");
53
+ const APIS_PATH = _path.default.resolve(process.cwd(), _defaultXConfig.default.businessDir, "@config", "@apis");
53
54
  if ((0, _common.checkFileStat)(APIS_PATH) && conf.passExtApis !== true) {
54
55
  let apis = [];
55
56
  _fs.default.readdirSync(APIS_PATH).forEach((file)=>{
package/dist/custom.js CHANGED
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "default", {
8
8
  });
9
9
  const _utils = require("@x-drive/utils");
10
10
  const _common = require("./components/common");
11
+ const _defaultXConfig = /*#__PURE__*/ _interopRequireDefault(require("./default-x-config"));
11
12
  const _config = require("./config");
12
13
  const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
13
14
  function _interopRequireDefault(obj) {
@@ -17,7 +18,7 @@ function _interopRequireDefault(obj) {
17
18
  }
18
19
  /**处理自定义业务 */ function processCustom() {
19
20
  const config = (0, _config.get)();
20
- const CustomPath = _path.default.resolve(process.cwd(), "@server", "custom");
21
+ const CustomPath = _path.default.resolve(process.cwd(), _defaultXConfig.default.businessDir, "custom");
21
22
  const hasCustom = (0, _common.checkFileStat)(CustomPath);
22
23
  if (!hasCustom) {
23
24
  return;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: ()=>_default
8
+ });
9
+ const _utils = require("@x-drive/utils");
10
+ /**默认业务目录 */ var businessDir = "@server";
11
+ let Config = class Config {
12
+ get businessDir() {
13
+ return businessDir;
14
+ }
15
+ set businessDir(val) {
16
+ if ((0, _utils.isString)(val)) {
17
+ businessDir = val;
18
+ }
19
+ }
20
+ };
21
+ const _default = new Config;
package/dist/global.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
+ const _defaultXConfig = /*#__PURE__*/ _interopRequireDefault(require("./default-x-config"));
5
6
  const _config = require("./config");
6
7
  const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
7
8
  function _interopRequireDefault(obj) {
@@ -27,7 +28,7 @@ function _interopRequireDefault(obj) {
27
28
  global.requireMod = requireMod;
28
29
  /**
29
30
  * model 存放路径
30
- */ const MODEL_PATH = _path.default.resolve(process.cwd(), "@server", "business", "@models");
31
+ */ const MODEL_PATH = _path.default.resolve(process.cwd(), _defaultXConfig.default.businessDir, "business", "@models");
31
32
  /**
32
33
  * 全局获取 model 的方法
33
34
  * @param name model 名称
@@ -38,7 +39,7 @@ global.requireMod = requireMod;
38
39
  global.requireModel = requireModel;
39
40
  /**
40
41
  * services 存放目录
41
- */ const SERVICES_PATH = _path.default.resolve(process.cwd(), "@server", "business", "@services");
42
+ */ const SERVICES_PATH = _path.default.resolve(process.cwd(), _defaultXConfig.default.businessDir, "business", "@services");
42
43
  /**
43
44
  * 全局获取 service 的方法
44
45
  * @param name service 名称
@@ -8,6 +8,12 @@ Object.defineProperty(exports, "default", {
8
8
  });
9
9
  const _common = require("./components/common");
10
10
  const _utils = require("@x-drive/utils");
11
+ const _defaultXConfig = /*#__PURE__*/ _interopRequireDefault(require("./default-x-config"));
12
+ function _interopRequireDefault(obj) {
13
+ return obj && obj.__esModule ? obj : {
14
+ default: obj
15
+ };
16
+ }
11
17
  const cwd = process.cwd();
12
18
  /**内部中间件 */ const INTERNAL_MIDDLEWARE = {
13
19
  "combo": true,
@@ -30,7 +36,7 @@ const cwd = process.cwd();
30
36
  if (INTERNAL_MIDDLEWARE[name]) {
31
37
  app.use((0, _common.getRealDefaultMod)(require(`./middleware/${name}`))(conf));
32
38
  } else {
33
- app.use((0, _common.getRealDefaultMod)(require(`${cwd}/@server/middleware/${name}`))(conf));
39
+ app.use((0, _common.getRealDefaultMod)(require(`${cwd}/${_defaultXConfig.default.businessDir}/middleware/${name}`))(conf));
34
40
  }
35
41
  masterLog(`MIDDLEWARE >>> [${name}] launch`);
36
42
  });
package/dist/router.js CHANGED
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "default", {
8
8
  });
9
9
  const _utils = require("@x-drive/utils");
10
10
  const _common = require("./components/common");
11
+ const _defaultXConfig = /*#__PURE__*/ _interopRequireDefault(require("./default-x-config"));
11
12
  const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
12
13
  function _interopRequireDefault(obj) {
13
14
  return obj && obj.__esModule ? obj : {
@@ -91,7 +92,7 @@ function _interopRequireDefault(obj) {
91
92
  var _p = _path.default.resolve(__dirname, "business");
92
93
  (0, _common.walk)(_p, 0, processBusiness);
93
94
  // 支持自定义 api
94
- _p = _path.default.resolve(process.cwd(), "@server", "business");
95
+ _p = _path.default.resolve(process.cwd(), _defaultXConfig.default.businessDir, "business");
95
96
  if (process.cwd() !== __dirname && (0, _common.checkFileStat)(_p)) {
96
97
  (0, _common.walk)(_p, 0, processBusiness);
97
98
  }
package/dist/server.js CHANGED
@@ -16,6 +16,7 @@ _export(exports, {
16
16
  require("./global");
17
17
  const _log = require("./components/log");
18
18
  const _cron = require("./components/cron");
19
+ const _defaultXConfig = /*#__PURE__*/ _interopRequireDefault(require("./default-x-config"));
19
20
  const _koaStatic = /*#__PURE__*/ _interopRequireDefault(require("koa-static"));
20
21
  const _koaRouter = /*#__PURE__*/ _interopRequireDefault(require("koa-router"));
21
22
  const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
@@ -113,7 +114,7 @@ app.use((0, _koaStatic.default)(_path.default.resolve(process.cwd(), _config.def
113
114
  app.use(_badRequest.default);
114
115
  if (_config.default.enableCron) {
115
116
  // 定时任务
116
- (0, _cron.on)(_path.default.resolve(process.cwd(), "@server", "cron"));
117
+ (0, _cron.on)(_path.default.resolve(process.cwd(), _defaultXConfig.default.businessDir, "cron"));
117
118
  }
118
119
  /**启动服务 */ function boot() {
119
120
  (0, _cluster.default)();
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@x-9lab/xlab",
3
- "version": "1.0.1",
3
+ "version": "1.0.4",
4
4
  "description": "9lab 服务端模块",
5
- "versionDesc": "替换 request",
5
+ "versionDesc": "修改配置文件名称, 修改服务端主要业务目录",
6
6
  "scripts": {
7
7
  "dev": "swc src -D ./src/bin --config-file .swcrc -d dist -w",
8
8
  "compile": "swc src -D ./src/bin --config-file .swcrc -d dist",
@@ -33,7 +33,7 @@
33
33
  "koa-router": "11.0.1",
34
34
  "http-proxy": "1.18.1",
35
35
  "koa-compress": "5.1.0",
36
- "@x-drive/utils": "1.1.19"
36
+ "@x-drive/utils": "1.1.22"
37
37
  },
38
38
  "devDependencies": {
39
39
  "co": "4.6.0",