@qqi/log 1.0.0 → 1.1.0
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/README.md +10 -0
- package/cjs/index.js +156 -75
- package/cjs/util.js +87 -0
- package/es/eslint.config.d.ts +1222 -0
- package/es/index.js +155 -75
- package/es/rollup.config.d.ts +17 -0
- package/es/rollup.config.eg.d.ts +14 -0
- package/es/src/index.d.ts +3 -0
- package/es/src/type.d.ts +11 -9
- package/es/src/util.d.ts +35 -0
- package/es/util.js +81 -0
- package/package.json +8 -2
- package/cjs/blankCall.js +0 -11
- package/cjs/managePrint.js +0 -53
- package/cjs/notSupport.js +0 -14
- package/cjs/parseError.js +0 -42
- package/cjs/platform.js +0 -7
- package/cjs/printError.js +0 -15
- package/cjs/printInfo.js +0 -15
- package/cjs/printWarn.js +0 -15
- package/cjs/setType.js +0 -21
- package/es/blankCall.js +0 -9
- package/es/managePrint.js +0 -51
- package/es/notSupport.js +0 -12
- package/es/parseError.js +0 -40
- package/es/platform.js +0 -5
- package/es/printError.js +0 -13
- package/es/printInfo.js +0 -13
- package/es/printWarn.js +0 -13
- package/es/setType.js +0 -18
- package/es/src/blankCall.d.ts +0 -6
- package/es/src/managePrint.d.ts +0 -3
- package/es/src/notSupport.d.ts +0 -7
- package/es/src/parseError.d.ts +0 -7
- package/es/src/platform.d.ts +0 -1
- package/es/src/printError.d.ts +0 -6
- package/es/src/printInfo.d.ts +0 -6
- package/es/src/printWarn.d.ts +0 -6
- package/es/src/setType.d.ts +0 -6
package/es/index.js
CHANGED
|
@@ -1,89 +1,134 @@
|
|
|
1
|
-
import { createConstructor, getRandomString } from 'a-js-tools';
|
|
2
|
-
import { setType } from './setType.js';
|
|
3
|
-
import { blankCall } from './blankCall.js';
|
|
4
|
-
import { managePrint } from './managePrint.js';
|
|
5
|
-
import { isUndefined, isBoolean, isString } from 'a-type-of-js';
|
|
6
|
-
import { platform } from './platform.js';
|
|
7
1
|
import { esc } from '@color-pen/static';
|
|
2
|
+
import { createConstructor, getRandomString } from 'a-js-tools';
|
|
3
|
+
import { bgCyanPen, bgBlackPen, bgBrightYellowPen } from 'color-pen';
|
|
4
|
+
import { parseOption, getEnv, platform, setType } from './util.js';
|
|
8
5
|
|
|
9
6
|
/**
|
|
10
7
|
*
|
|
11
|
-
*
|
|
8
|
+
* @param options 配置项
|
|
9
|
+
* @returns 函数对象
|
|
12
10
|
*
|
|
11
|
+
*/
|
|
12
|
+
var DogConstructor = createConstructor(Dog);
|
|
13
|
+
/**
|
|
14
|
+
* ## 创建 dev log 工厂函数
|
|
13
15
|
* @param options - 配置项
|
|
14
16
|
* @returns - dev log 工厂函数
|
|
15
17
|
*/
|
|
16
18
|
function Dog(options) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
name: getRandomString(10),
|
|
25
|
-
type: options,
|
|
26
|
-
};
|
|
27
|
-
if (isString(options))
|
|
28
|
-
options = {
|
|
29
|
-
name: options,
|
|
30
|
-
type: false,
|
|
31
|
-
};
|
|
32
|
-
let { name = '', type = false } = options;
|
|
33
|
-
// 处理 name
|
|
34
|
-
name = name.trim().replace(/\s+/g, '_');
|
|
35
|
-
/** 当前获取环境值 */
|
|
36
|
-
const _env = (platform === 'node' &&
|
|
37
|
-
(globalThis?.process.env[name.toUpperCase().concat('_DEV')] ??
|
|
38
|
-
globalThis?.process.env[name.toLowerCase().concat('_dev')])) ||
|
|
39
|
-
false;
|
|
40
|
-
const env = _env === 'false' ? false : _env === 'true' ? true : _env;
|
|
19
|
+
var _this = this;
|
|
20
|
+
var _p = parseOption(options);
|
|
21
|
+
this.name = _p.name || getRandomString(12);
|
|
22
|
+
this.fold = Boolean(_p.fold);
|
|
23
|
+
var env = getEnv(this.name);
|
|
24
|
+
var type = _p.type || false;
|
|
25
|
+
this.mark = '';
|
|
41
26
|
/** 默认 node 环境以获取到的环境值为准,而非 node 环境默认开启,并通过自定义的 @qqi/babel-plugin-remove-dog-calls 来进行过滤正式环境(环境值需要自定义) */
|
|
42
|
-
type = platform === 'node' ? setType(env
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
27
|
+
this.type = platform === 'node' ? setType(env !== null && env !== void 0 ? env : type) : true;
|
|
28
|
+
/**
|
|
29
|
+
* ## 解析 error
|
|
30
|
+
* @param type
|
|
31
|
+
*/
|
|
32
|
+
var prefix = function (type) {
|
|
33
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
34
|
+
try {
|
|
35
|
+
throw new Error();
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
var parseErrorResult = (((_a = error.stack) === null || _a === void 0 ? void 0 : _a.split('\n')) || []).map(function (item) {
|
|
39
|
+
var reg = /at\s(.*)\s\((.*):(\d*):(\d*)\)/;
|
|
40
|
+
var res = reg.exec(item);
|
|
41
|
+
if (res) {
|
|
42
|
+
return {
|
|
43
|
+
name: res[1],
|
|
44
|
+
path: res[2],
|
|
45
|
+
line: res[3],
|
|
46
|
+
column: res[4],
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
name: '',
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
var result = parseErrorResult.filter(function (e) { return e.name !== '' && e.path !== undefined; });
|
|
54
|
+
var res = (_d = (_c = (_b = result[3]) !== null && _b !== void 0 ? _b : result[2]) !== null && _c !== void 0 ? _c : result[1]) !== null && _d !== void 0 ? _d : result[0];
|
|
55
|
+
var startStr = " ".concat(type === 'info' ? '💡' : type === 'error' ? '❌' : '⚠️ ', " ").concat(new Date().toLocaleString(), " ");
|
|
56
|
+
var printStartPenStr = (type === 'info'
|
|
57
|
+
? bgCyanPen.brightWhite
|
|
58
|
+
: type === 'error'
|
|
59
|
+
? bgBlackPen.red
|
|
60
|
+
: bgBrightYellowPen.brightGreen)(startStr);
|
|
61
|
+
var mark = (_e = res === null || res === void 0 ? void 0 : res.name) !== null && _e !== void 0 ? _e : '';
|
|
62
|
+
if (_this.fold && mark) {
|
|
63
|
+
if (mark === _this.mark) ;
|
|
64
|
+
else {
|
|
65
|
+
if (_this.mark) {
|
|
66
|
+
console.groupEnd();
|
|
67
|
+
}
|
|
68
|
+
console.groupCollapsed(mark);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
_this.mark = mark;
|
|
72
|
+
return "".concat(printStartPenStr, " ").concat(mark, " ").concat((_f = res === null || res === void 0 ? void 0 : res.line) === null || _f === void 0 ? void 0 : _f.concat(' 行'), " ").concat((_g = res === null || res === void 0 ? void 0 : res.column) === null || _g === void 0 ? void 0 : _g.concat(' 列'));
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
this.info = function () {
|
|
76
|
+
var msg = [];
|
|
77
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
78
|
+
msg[_i] = arguments[_i];
|
|
79
|
+
}
|
|
80
|
+
if (_this.type === 'all' || _this.type === 'info' || _this.type === true) {
|
|
81
|
+
var _prefix = prefix('info');
|
|
82
|
+
msg.unshift(_prefix);
|
|
83
|
+
console.log.apply(console, msg);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* @param msg
|
|
88
|
+
*/
|
|
89
|
+
this.warn = function () {
|
|
90
|
+
var msg = [];
|
|
91
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
92
|
+
msg[_i] = arguments[_i];
|
|
93
|
+
}
|
|
94
|
+
if (_this.type === 'all' || _this.type === 'warn' || _this.type === true) {
|
|
95
|
+
var _prefix = prefix('warn');
|
|
96
|
+
msg.unshift(_prefix);
|
|
97
|
+
console.warn.apply(console, msg);
|
|
98
|
+
}
|
|
49
99
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
100
|
+
/**
|
|
101
|
+
*
|
|
102
|
+
* @param msg
|
|
103
|
+
*/
|
|
104
|
+
this.error = function () {
|
|
105
|
+
var msg = [];
|
|
106
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
107
|
+
msg[_i] = arguments[_i];
|
|
108
|
+
}
|
|
109
|
+
if (_this.type === 'all' || _this.type === 'error' || _this.type === true) {
|
|
110
|
+
var _prefix = prefix('error');
|
|
111
|
+
msg.unshift(_prefix);
|
|
112
|
+
console.error.apply(console, msg);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* 本体方法
|
|
117
|
+
* @param str
|
|
118
|
+
*/
|
|
119
|
+
var dog = function () {
|
|
120
|
+
var str = [];
|
|
121
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
122
|
+
str[_i] = arguments[_i];
|
|
123
|
+
}
|
|
124
|
+
_this.info(str);
|
|
54
125
|
};
|
|
55
126
|
// 设置 prototype
|
|
56
127
|
Object.setPrototypeOf(dog, this);
|
|
57
|
-
// 设置属性和方法
|
|
58
|
-
Object.defineProperties(this, {
|
|
59
|
-
type: {
|
|
60
|
-
get() {
|
|
61
|
-
return type || false;
|
|
62
|
-
},
|
|
63
|
-
set(value) {
|
|
64
|
-
const new_type = setType(value);
|
|
65
|
-
if (new_type !== type) {
|
|
66
|
-
type = new_type;
|
|
67
|
-
managePrint(type, _privateFunc, name);
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
error: {
|
|
72
|
-
value: (...str) => Reflect.apply(_privateFunc.error, this, str),
|
|
73
|
-
configurable: false,
|
|
74
|
-
enumerable: false,
|
|
75
|
-
writable: false,
|
|
76
|
-
},
|
|
77
|
-
warn: {
|
|
78
|
-
value: (...str) => Reflect.apply(_privateFunc.warn, this, str),
|
|
79
|
-
configurable: false,
|
|
80
|
-
enumerable: false,
|
|
81
|
-
writable: false,
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
128
|
return dog;
|
|
85
129
|
}
|
|
86
|
-
|
|
130
|
+
/** 原型上添加 clear 方法 */
|
|
131
|
+
Dog.prototype.clear = function () {
|
|
87
132
|
if (platform === 'browser') {
|
|
88
133
|
console.clear();
|
|
89
134
|
}
|
|
@@ -92,11 +137,46 @@ Dog.prototype.clear = () => {
|
|
|
92
137
|
}
|
|
93
138
|
};
|
|
94
139
|
/**
|
|
95
|
-
*
|
|
96
|
-
* @param options 配置项
|
|
97
|
-
* @returns 函数对象
|
|
98
140
|
*
|
|
99
141
|
*/
|
|
100
|
-
|
|
142
|
+
function DogVirtualImt() {
|
|
143
|
+
/**
|
|
144
|
+
* 模拟类的构建
|
|
145
|
+
* @param _arg
|
|
146
|
+
*/
|
|
147
|
+
var _dev = function () {
|
|
148
|
+
};
|
|
149
|
+
Object.setPrototypeOf(_dev, this);
|
|
150
|
+
Object.defineProperties(this, {
|
|
151
|
+
info: {
|
|
152
|
+
value: function () {
|
|
153
|
+
},
|
|
154
|
+
configurable: false,
|
|
155
|
+
writable: false,
|
|
156
|
+
},
|
|
157
|
+
warn: {
|
|
158
|
+
value: function () {
|
|
159
|
+
},
|
|
160
|
+
configurable: false,
|
|
161
|
+
writable: false,
|
|
162
|
+
},
|
|
163
|
+
error: {
|
|
164
|
+
value: function () {
|
|
165
|
+
},
|
|
166
|
+
configurable: false,
|
|
167
|
+
writable: false,
|
|
168
|
+
},
|
|
169
|
+
type: {
|
|
170
|
+
get: function () {
|
|
171
|
+
return false;
|
|
172
|
+
},
|
|
173
|
+
set: function (_) { },
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
return _dev;
|
|
177
|
+
}
|
|
178
|
+
DogVirtualImt.prototype.clear = console.clear;
|
|
179
|
+
/** 虚拟狗,没有实现不打印 */
|
|
180
|
+
var DogVirtualConstructor = createConstructor(DogVirtualImt);
|
|
101
181
|
|
|
102
|
-
export { DogConstructor as Dog };
|
|
182
|
+
export { DogConstructor as Dog, DogVirtualConstructor as DogVirtual };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare namespace _default {
|
|
2
|
+
namespace input {
|
|
3
|
+
let index: string;
|
|
4
|
+
}
|
|
5
|
+
let output: {
|
|
6
|
+
format: string;
|
|
7
|
+
entryFileNames: string;
|
|
8
|
+
preserveModules: boolean;
|
|
9
|
+
preserveModulesRoot: string;
|
|
10
|
+
sourcemap: boolean;
|
|
11
|
+
exports: string;
|
|
12
|
+
dir: string;
|
|
13
|
+
}[];
|
|
14
|
+
let external: (id: string) => boolean;
|
|
15
|
+
let plugins: import("rollup").Plugin<any>[];
|
|
16
|
+
}
|
|
17
|
+
export default _default;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare namespace _default {
|
|
2
|
+
let input: string;
|
|
3
|
+
namespace output {
|
|
4
|
+
let format: string;
|
|
5
|
+
let entryFileNames: string;
|
|
6
|
+
let preserveModules: boolean;
|
|
7
|
+
let sourcemap: boolean;
|
|
8
|
+
let exports: string;
|
|
9
|
+
let dir: string;
|
|
10
|
+
}
|
|
11
|
+
let external: (id: string) => boolean;
|
|
12
|
+
let plugins: import("rollup").Plugin<any>[];
|
|
13
|
+
}
|
|
14
|
+
export default _default;
|
package/es/src/index.d.ts
CHANGED
|
@@ -8,3 +8,6 @@ import { DevLog, DogOptions } from './type';
|
|
|
8
8
|
declare const DogConstructor: import("a-js-tools").CreateConstructor<DevLog, [options?: DogOptions | undefined]>;
|
|
9
9
|
export { DogConstructor as Dog };
|
|
10
10
|
export type { DevLogType, DevLog } from './type';
|
|
11
|
+
/** 虚拟狗,没有实现不打印 */
|
|
12
|
+
declare const DogVirtualConstructor: import("a-js-tools").CreateConstructor<DevLog, []>;
|
|
13
|
+
export { DogVirtualConstructor as DogVirtual };
|
package/es/src/type.d.ts
CHANGED
|
@@ -2,14 +2,20 @@ export type DevLogType = boolean | 'info' | 'error' | 'all' | 'warn';
|
|
|
2
2
|
export type DevLog = {
|
|
3
3
|
/** 打印信息本当作为 info 信息,在 type 为 `false`、`error`、`warn` 时不打印 */
|
|
4
4
|
(...str: unknown[]): void;
|
|
5
|
+
/** 当打印的版本为错误信息,在 type 为 `false`、`error`、`warn` 时不打印 */
|
|
6
|
+
info: (...str: unknown[]) => void;
|
|
5
7
|
/** 当打印的版本为错误信息,在 type 为 `false`、`info`、`warn` 时不打印 */
|
|
6
8
|
error: (...str: unknown[]) => void;
|
|
7
9
|
/** 当打印的版本为警示信息,在 type 为 `false`、`info`、`error` 时不打印 */
|
|
8
10
|
warn: (...str: unknown[]) => void;
|
|
9
11
|
/** node 平台执行依据 */
|
|
10
|
-
name:
|
|
12
|
+
name: string;
|
|
13
|
+
/** 同名(方法)折叠 */
|
|
14
|
+
fold: boolean;
|
|
11
15
|
/** 开启打印的类型 */
|
|
12
16
|
type: DevLogType;
|
|
17
|
+
/** 当前标记的名 */
|
|
18
|
+
mark: string;
|
|
13
19
|
/** 清除控制台 */
|
|
14
20
|
clear: () => void;
|
|
15
21
|
};
|
|
@@ -21,16 +27,12 @@ export interface PrivateFunc {
|
|
|
21
27
|
}
|
|
22
28
|
export type DogOptions = {
|
|
23
29
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
30
|
+
* ## 类型
|
|
26
31
|
* 但是该值将被传入的系统参数覆盖
|
|
27
|
-
*
|
|
28
32
|
*/
|
|
29
33
|
type?: DevLogType;
|
|
30
|
-
/**
|
|
31
|
-
* 该值将以 name_dev 的形式配置允许打印
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*/
|
|
34
|
+
/** 该值将以 name_dev 的形式配置允许打印 */
|
|
35
35
|
name?: string;
|
|
36
|
+
/** 同名文件打印消息是否折叠(控制台效果不明显) */
|
|
37
|
+
fold?: boolean;
|
|
36
38
|
} | string | boolean;
|
package/es/src/util.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* @module @qqi/log/util
|
|
4
|
+
* @file util.ts
|
|
5
|
+
* @description 工具
|
|
6
|
+
* @author MrMudBean <Mr.MudBean@outlook.com>
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @copyright 2026 ©️ MrMudBean
|
|
9
|
+
* @since 2026-01-28 03:11
|
|
10
|
+
* @version 1.0.1
|
|
11
|
+
* @lastModified 2026-01-28 04:34
|
|
12
|
+
*/
|
|
13
|
+
import { DevLogType } from '@qqi/log';
|
|
14
|
+
import { DogOptions } from './type';
|
|
15
|
+
export declare const typeList: DevLogType[];
|
|
16
|
+
/**
|
|
17
|
+
* ## 解析参数
|
|
18
|
+
* @param options
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseOption(options?: DogOptions): {
|
|
21
|
+
name?: string;
|
|
22
|
+
type?: DevLogType;
|
|
23
|
+
fold?: boolean;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* 获取当前的环境变量
|
|
27
|
+
* @param name
|
|
28
|
+
*/
|
|
29
|
+
export declare function getEnv(name?: string): DevLogType;
|
|
30
|
+
export declare const platform: string;
|
|
31
|
+
/**
|
|
32
|
+
* 设置 type 的类型
|
|
33
|
+
* @param type 新的类型
|
|
34
|
+
*/
|
|
35
|
+
export declare function setType(type: DevLogType): DevLogType;
|
package/es/util.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { isNode, getRandomString } from 'a-js-tools';
|
|
2
|
+
import { isUndefined, isBoolean, isString } from 'a-type-of-js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
* @module @qqi/log/util
|
|
7
|
+
* @file util.ts
|
|
8
|
+
* @description 工具
|
|
9
|
+
* @author MrMudBean <Mr.MudBean@outlook.com>
|
|
10
|
+
* @license MIT
|
|
11
|
+
* @copyright 2026 ©️ MrMudBean
|
|
12
|
+
* @since 2026-01-28 03:11
|
|
13
|
+
* @version 1.0.1
|
|
14
|
+
* @lastModified 2026-01-28 04:34
|
|
15
|
+
*/
|
|
16
|
+
var typeList = [
|
|
17
|
+
false,
|
|
18
|
+
true,
|
|
19
|
+
'all',
|
|
20
|
+
'info',
|
|
21
|
+
'error',
|
|
22
|
+
'warn',
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* ## 解析参数
|
|
26
|
+
* @param options
|
|
27
|
+
*/
|
|
28
|
+
function parseOption(options) {
|
|
29
|
+
var result = {
|
|
30
|
+
name: getRandomString(10),
|
|
31
|
+
type: false,
|
|
32
|
+
fold: false,
|
|
33
|
+
};
|
|
34
|
+
if (isUndefined(options))
|
|
35
|
+
return result;
|
|
36
|
+
if (isBoolean(options)) {
|
|
37
|
+
result.type = options;
|
|
38
|
+
return result;
|
|
39
|
+
}
|
|
40
|
+
if (isString(options)) {
|
|
41
|
+
// 处理 name
|
|
42
|
+
result.name = options.trim().replace(/\s+/g, '_');
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
if (isString(options.name)) {
|
|
46
|
+
result.name = options.name.trim().replace(/\s+/g, '_');
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
return options;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 获取当前的环境变量
|
|
53
|
+
* @param name
|
|
54
|
+
*/
|
|
55
|
+
function getEnv(name) {
|
|
56
|
+
var _a;
|
|
57
|
+
if (name === void 0) { name = getRandomString(10); }
|
|
58
|
+
/** 当前获取环境值 */
|
|
59
|
+
var _env = false;
|
|
60
|
+
if (platform === 'node' && ((_a = globalThis === null || globalThis === void 0 ? void 0 : globalThis.process) === null || _a === void 0 ? void 0 : _a.env)) {
|
|
61
|
+
var processEnv = process.env;
|
|
62
|
+
_env =
|
|
63
|
+
processEnv[name.toUpperCase().concat('_DEV')] ||
|
|
64
|
+
processEnv[name.toLowerCase().concat('_dev')] ||
|
|
65
|
+
false;
|
|
66
|
+
}
|
|
67
|
+
var env = _env === 'false' ? false : _env === 'true' ? true : _env;
|
|
68
|
+
return env;
|
|
69
|
+
}
|
|
70
|
+
var platform = isNode() ? 'node' : 'browser';
|
|
71
|
+
/**
|
|
72
|
+
* 设置 type 的类型
|
|
73
|
+
* @param type 新的类型
|
|
74
|
+
*/
|
|
75
|
+
function setType(type) {
|
|
76
|
+
if (typeList.includes(type))
|
|
77
|
+
return type;
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export { getEnv, parseOption, platform, setType, typeList };
|
package/package.json
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"name": "@qqi/log",
|
|
5
5
|
"main": "cjs/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
7
7
|
"types": "es/src/index.d.ts",
|
|
8
|
+
"author": {
|
|
9
|
+
"name": "泥豆君",
|
|
10
|
+
"email": "Mr.MudBean@outlook.com",
|
|
11
|
+
"url": "https://earthnut.dev"
|
|
12
|
+
},
|
|
8
13
|
"description": "原 @qqi/dev-log 中的 log 部分",
|
|
9
14
|
"sideEffects": false,
|
|
10
15
|
"license": "MIT",
|
|
@@ -38,7 +43,8 @@
|
|
|
38
43
|
},
|
|
39
44
|
"repository": {
|
|
40
45
|
"type": "git",
|
|
41
|
-
"url": "git+https://github.com/MrMudBean/qqi.git"
|
|
46
|
+
"url": "git+https://github.com/MrMudBean/qqi.git",
|
|
47
|
+
"directory": "packages/log"
|
|
42
48
|
},
|
|
43
49
|
"publishConfig": {
|
|
44
50
|
"access": "public",
|
package/cjs/blankCall.js
DELETED
package/cjs/managePrint.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var aTypeOfJs = require('a-type-of-js');
|
|
4
|
-
var notSupport = require('./notSupport.js');
|
|
5
|
-
var platform = require('./platform.js');
|
|
6
|
-
var blankCall = require('./blankCall.js');
|
|
7
|
-
var printError = require('./printError.js');
|
|
8
|
-
var printWarn = require('./printWarn.js');
|
|
9
|
-
var printInfo = require('./printInfo.js');
|
|
10
|
-
var setType = require('./setType.js');
|
|
11
|
-
|
|
12
|
-
/** 管理是否打印 */
|
|
13
|
-
function managePrint(type, privateFunc, name) {
|
|
14
|
-
if (platform.platform === 'node') {
|
|
15
|
-
const dev = globalThis?.process.env[name.toUpperCase().concat('_DEV')] ||
|
|
16
|
-
globalThis?.process.env[name.toLowerCase().concat('_dev')];
|
|
17
|
-
/// 当前禁止使用打印
|
|
18
|
-
/// node 环境未配置 NAME_DEV 环境变量
|
|
19
|
-
/// 显式配置 NAME_DEV 环境变量为 false
|
|
20
|
-
if (type === false || aTypeOfJs.isUndefined(dev) || dev === 'false') {
|
|
21
|
-
return Reflect.apply(notSupport.notSupport, privateFunc, []);
|
|
22
|
-
}
|
|
23
|
-
/// 将显示配置环境变量的值给 type
|
|
24
|
-
if ([...setType.typeList, 'true', 'false'].includes(dev)) {
|
|
25
|
-
type = dev === 'true' ? 'all' : dev;
|
|
26
|
-
}
|
|
27
|
-
privateFunc.info = ['all', 'info', true].includes(type)
|
|
28
|
-
? printInfo.printInfo
|
|
29
|
-
: blankCall.blankCall;
|
|
30
|
-
privateFunc.error = ['all', 'error', true].includes(type)
|
|
31
|
-
? printError.printError
|
|
32
|
-
: blankCall.blankCall;
|
|
33
|
-
privateFunc.warn = ['all', 'warn', true].includes(type)
|
|
34
|
-
? printWarn.printWarn
|
|
35
|
-
: blankCall.blankCall;
|
|
36
|
-
}
|
|
37
|
-
// 在 非 node 环境始终执行,搭配 @qqi/babel-plugin-remove-dog-calls 使用
|
|
38
|
-
else {
|
|
39
|
-
if (type === false)
|
|
40
|
-
return Reflect.apply(notSupport.notSupport, privateFunc, []);
|
|
41
|
-
privateFunc.info = ['all', 'info', true].includes(type)
|
|
42
|
-
? printInfo.printInfo
|
|
43
|
-
: blankCall.blankCall;
|
|
44
|
-
privateFunc.error = ['all', 'error', true].includes(type)
|
|
45
|
-
? printError.printError
|
|
46
|
-
: blankCall.blankCall;
|
|
47
|
-
privateFunc.warn = ['all', 'warn', true].includes(type)
|
|
48
|
-
? printWarn.printWarn
|
|
49
|
-
: blankCall.blankCall;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
exports.managePrint = managePrint;
|
package/cjs/notSupport.js
DELETED
package/cjs/parseError.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var colorPen = require('color-pen');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* 解析 error
|
|
8
|
-
*
|
|
9
|
-
*/
|
|
10
|
-
function parseError(type) {
|
|
11
|
-
try {
|
|
12
|
-
throw new Error();
|
|
13
|
-
}
|
|
14
|
-
catch (error) {
|
|
15
|
-
const parseErrorResult = (error.stack?.split('\n') || []).map(item => {
|
|
16
|
-
const reg = /at\s(.*)\s\((.*):(\d*):(\d*)\)/;
|
|
17
|
-
const res = reg.exec(item);
|
|
18
|
-
if (res) {
|
|
19
|
-
return {
|
|
20
|
-
name: res[1],
|
|
21
|
-
path: res[2],
|
|
22
|
-
line: res[3],
|
|
23
|
-
column: res[4],
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
return {
|
|
27
|
-
name: '',
|
|
28
|
-
};
|
|
29
|
-
});
|
|
30
|
-
const result = parseErrorResult.filter(e => e.name !== '' && e.path !== undefined);
|
|
31
|
-
const res = result[3] ?? result[2] ?? result[1] ?? result[0];
|
|
32
|
-
const startStr = ` ${type === 'info' ? '💡' : type === 'error' ? '❌' : '⚠️ '} ${new Date().toLocaleString()} `;
|
|
33
|
-
const printStartPenStr = (type === 'info'
|
|
34
|
-
? colorPen.pen.bgCyan.brightWhite
|
|
35
|
-
: type === 'error'
|
|
36
|
-
? colorPen.pen.bgBlack.red
|
|
37
|
-
: colorPen.pen.bgBrightYellow.brightGreen)(startStr);
|
|
38
|
-
console.log(`${printStartPenStr} ${res?.name ?? ''} ${res?.line?.concat(' 行')} ${res?.column?.concat(' 列')}`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
exports.parseError = parseError;
|
package/cjs/platform.js
DELETED
package/cjs/printError.js
DELETED
package/cjs/printInfo.js
DELETED
package/cjs/printWarn.js
DELETED