@qqi/log 1.0.0 → 1.1.1
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/core.js +142 -0
- package/cjs/index.js +5 -100
- package/cjs/util.js +87 -0
- package/cjs/virtual-dog.js +60 -0
- package/es/core.js +140 -0
- package/es/eslint.config.d.ts +1222 -0
- package/es/index.js +2 -102
- package/es/rollup.config.d.ts +17 -0
- package/es/rollup.config.eg.d.ts +14 -0
- package/es/src/core.d.ts +9 -0
- package/es/src/index.d.ts +12 -7
- package/es/src/type.d.ts +11 -9
- package/es/src/util.d.ts +35 -0
- package/es/src/virtual-dog.d.ts +16 -0
- package/es/util.js +81 -0
- package/es/virtual-dog.js +58 -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,102 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
import { esc } from '@color-pen/static';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
* 创建 dev log 工厂函数
|
|
12
|
-
*
|
|
13
|
-
* @param options - 配置项
|
|
14
|
-
* @returns - dev log 工厂函数
|
|
15
|
-
*/
|
|
16
|
-
function Dog(options) {
|
|
17
|
-
if (isUndefined(options))
|
|
18
|
-
options = {
|
|
19
|
-
name: getRandomString(10),
|
|
20
|
-
type: false,
|
|
21
|
-
};
|
|
22
|
-
if (isBoolean(options))
|
|
23
|
-
options = {
|
|
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;
|
|
41
|
-
/** 默认 node 环境以获取到的环境值为准,而非 node 环境默认开启,并通过自定义的 @qqi/babel-plugin-remove-dog-calls 来进行过滤正式环境(环境值需要自定义) */
|
|
42
|
-
type = platform === 'node' ? setType(env ?? type) : true;
|
|
43
|
-
/// 原始的调用方法,在 type 值变化时会触发该值的更替
|
|
44
|
-
// 私有方法 error
|
|
45
|
-
const _privateFunc = {
|
|
46
|
-
error: blankCall,
|
|
47
|
-
warn: blankCall,
|
|
48
|
-
info: blankCall,
|
|
49
|
-
};
|
|
50
|
-
managePrint(type, _privateFunc, name);
|
|
51
|
-
/** 本体方法 */
|
|
52
|
-
const dog = (...str) => {
|
|
53
|
-
Reflect.apply(_privateFunc.info, this, str);
|
|
54
|
-
};
|
|
55
|
-
// 设置 prototype
|
|
56
|
-
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
|
-
return dog;
|
|
85
|
-
}
|
|
86
|
-
Dog.prototype.clear = () => {
|
|
87
|
-
if (platform === 'browser') {
|
|
88
|
-
console.clear();
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
console.log(esc.concat('c'));
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
/**
|
|
95
|
-
*
|
|
96
|
-
* @param options 配置项
|
|
97
|
-
* @returns 函数对象
|
|
98
|
-
*
|
|
99
|
-
*/
|
|
100
|
-
const DogConstructor = createConstructor(Dog);
|
|
101
|
-
|
|
102
|
-
export { DogConstructor as Dog };
|
|
1
|
+
export { Dog } from './core.js';
|
|
2
|
+
export { DogVirtual } from './virtual-dog.js';
|
|
@@ -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/core.d.ts
ADDED
package/es/src/index.d.ts
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import { DevLog, DogOptions } from './type';
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
6
|
-
*
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* @module @qqi/log/index
|
|
4
|
+
* @file index.ts
|
|
5
|
+
* @description _
|
|
6
|
+
* @author MrMudBean <Mr.MudBean@outlook.com>
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @copyright 2026 ©️ MrMudBean
|
|
9
|
+
* @since 2026-01-28 04:52
|
|
10
|
+
* @version 1.1.0
|
|
11
|
+
* @lastModified 2026-01-28 04:53
|
|
7
12
|
*/
|
|
8
|
-
|
|
9
|
-
export {
|
|
13
|
+
export { Dog } from './core';
|
|
14
|
+
export { DogVirtual } from './virtual-dog';
|
|
10
15
|
export type { DevLogType, DevLog } from './type';
|
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;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* @module @qqi/log/virtual-dog
|
|
4
|
+
* @file virtual-dog.ts
|
|
5
|
+
* @description _
|
|
6
|
+
* @author MrMudBean <Mr.MudBean@outlook.com>
|
|
7
|
+
* @license MIT
|
|
8
|
+
* @copyright 2026 ©️ MrMudBean
|
|
9
|
+
* @since 2026-01-28 04:52
|
|
10
|
+
* @version 1.1.0
|
|
11
|
+
* @lastModified 2026-01-28 04:53
|
|
12
|
+
*/
|
|
13
|
+
import { DevLog } from './type';
|
|
14
|
+
/** 虚拟狗,没有实现不打印 */
|
|
15
|
+
declare const DogVirtualConstructor: import("a-js-tools").CreateConstructor<DevLog, []>;
|
|
16
|
+
export { DogVirtualConstructor as DogVirtual };
|
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 };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { createConstructor } from 'a-js-tools';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
* @module @qqi/log/virtual-dog
|
|
6
|
+
* @file virtual-dog.ts
|
|
7
|
+
* @description _
|
|
8
|
+
* @author MrMudBean <Mr.MudBean@outlook.com>
|
|
9
|
+
* @license MIT
|
|
10
|
+
* @copyright 2026 ©️ MrMudBean
|
|
11
|
+
* @since 2026-01-28 04:52
|
|
12
|
+
* @version 1.1.0
|
|
13
|
+
* @lastModified 2026-01-28 04:53
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
function DogVirtualImt() {
|
|
19
|
+
/**
|
|
20
|
+
* 模拟类的构建
|
|
21
|
+
* @param _arg
|
|
22
|
+
*/
|
|
23
|
+
var _dev = function () {
|
|
24
|
+
};
|
|
25
|
+
Object.setPrototypeOf(_dev, this);
|
|
26
|
+
Object.defineProperties(this, {
|
|
27
|
+
info: {
|
|
28
|
+
value: function () {
|
|
29
|
+
},
|
|
30
|
+
configurable: false,
|
|
31
|
+
writable: false,
|
|
32
|
+
},
|
|
33
|
+
warn: {
|
|
34
|
+
value: function () {
|
|
35
|
+
},
|
|
36
|
+
configurable: false,
|
|
37
|
+
writable: false,
|
|
38
|
+
},
|
|
39
|
+
error: {
|
|
40
|
+
value: function () {
|
|
41
|
+
},
|
|
42
|
+
configurable: false,
|
|
43
|
+
writable: false,
|
|
44
|
+
},
|
|
45
|
+
type: {
|
|
46
|
+
get: function () {
|
|
47
|
+
return false;
|
|
48
|
+
},
|
|
49
|
+
set: function (_) { },
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
return _dev;
|
|
53
|
+
}
|
|
54
|
+
DogVirtualImt.prototype.clear = console.clear;
|
|
55
|
+
/** 虚拟狗,没有实现不打印 */
|
|
56
|
+
var DogVirtualConstructor = createConstructor(DogVirtualImt);
|
|
57
|
+
|
|
58
|
+
export { DogVirtualConstructor as DogVirtual };
|
package/package.json
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
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
package/cjs/setType.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const typeList = [
|
|
4
|
-
false,
|
|
5
|
-
true,
|
|
6
|
-
'all',
|
|
7
|
-
'info',
|
|
8
|
-
'error',
|
|
9
|
-
'warn',
|
|
10
|
-
];
|
|
11
|
-
/**
|
|
12
|
-
* 设置 type 的类型
|
|
13
|
-
*/
|
|
14
|
-
function setType(type) {
|
|
15
|
-
if (typeList.includes(type))
|
|
16
|
-
return type;
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
exports.setType = setType;
|
|
21
|
-
exports.typeList = typeList;
|