@coffic/cosy-ui 0.6.36 → 0.6.40
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/dist/assets/book.png +0 -0
- package/dist/card/CardCourse.astro +32 -0
- package/dist/card/index.ts +1 -1
- package/dist/cosy.ts +6 -0
- package/dist/database/BaseDB.ts +204 -168
- package/dist/database/BlogDB.ts +8 -8
- package/dist/database/CourseDB.ts +5 -5
- package/dist/database/ExperimentDB.ts +6 -6
- package/dist/database/LessonDB.ts +6 -6
- package/dist/database/MetaDB.ts +4 -4
- package/dist/entities/BaseDoc.ts +31 -4
- package/dist/entities/BlogDoc.ts +40 -0
- package/dist/entities/CourseDoc.ts +5 -5
- package/dist/entities/ExperimentDoc.ts +6 -6
- package/dist/entities/LessonDoc.ts +40 -6
- package/dist/index.ts +1 -1
- package/dist/index_collection.ts +84 -84
- package/dist/utils/lang_entry.ts +240 -0
- package/dist/utils/lang_package.ts +144 -215
- package/dist/utils/language.ts +7 -8
- package/dist/utils/link.ts +3 -3
- package/dist/utils/logger.ts +119 -103
- package/dist/utils/path.ts +3 -3
- package/package.json +1 -1
package/dist/utils/logger.ts
CHANGED
@@ -5,110 +5,126 @@ const SHOW_TIMESTAMP = false;
|
|
5
5
|
|
6
6
|
// ANSI 颜色代码
|
7
7
|
const colors = {
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
reset: '\x1b[0m',
|
9
|
+
debug: '\x1b[36m', // 青色
|
10
|
+
info: '\x1b[32m', // 绿色
|
11
|
+
warn: '\x1b[33m', // 黄色
|
12
|
+
error: '\x1b[31m', // 红色
|
13
|
+
gray: '\x1b[90m', // 灰色用于时间戳
|
14
14
|
};
|
15
15
|
|
16
|
-
class Logger {
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
16
|
+
export class Logger {
|
17
|
+
private topic: string = '';
|
18
|
+
|
19
|
+
private formatArray(arr: any[]): string {
|
20
|
+
const MAX_LINES = 70;
|
21
|
+
const MAX_LENGTH = 100;
|
22
|
+
|
23
|
+
const truncateString = (str: string): string => {
|
24
|
+
return str.length > MAX_LENGTH ? str.slice(0, MAX_LENGTH) + '...' : str;
|
25
|
+
};
|
26
|
+
|
27
|
+
const truncateObject = (obj: any): any => {
|
28
|
+
if (typeof obj !== 'object' || obj === null) {
|
29
|
+
return typeof obj === 'string' ? truncateString(obj) : obj;
|
30
|
+
}
|
31
|
+
|
32
|
+
const result: any = Array.isArray(obj) ? [] : {};
|
33
|
+
for (const [key, value] of Object.entries(obj)) {
|
34
|
+
result[key] =
|
35
|
+
typeof value === 'string'
|
36
|
+
? truncateString(value)
|
37
|
+
: typeof value === 'object'
|
38
|
+
? truncateObject(value)
|
39
|
+
: value;
|
40
|
+
}
|
41
|
+
return result;
|
42
|
+
};
|
43
|
+
|
44
|
+
const items = arr.slice(0, MAX_LINES).map((item) => {
|
45
|
+
const truncatedItem = truncateObject(item);
|
46
|
+
// 使用2个空格缩进,并在每行前添加 " • "
|
47
|
+
const jsonString = JSON.stringify(truncatedItem, null, 2)
|
48
|
+
.split('\n')
|
49
|
+
.map((line, index) => (index === 0 ? ` • ${line}` : ` ${line}`))
|
50
|
+
.join('\n');
|
51
|
+
return jsonString;
|
52
|
+
});
|
53
|
+
|
54
|
+
let output = items.join('\n');
|
55
|
+
if (arr.length > MAX_LINES) {
|
56
|
+
const remainingCount = arr.length - MAX_LINES;
|
57
|
+
output += `\n ⋮ ... and ${remainingCount} more items`;
|
58
|
+
}
|
59
|
+
|
60
|
+
return output;
|
61
|
+
}
|
62
|
+
|
63
|
+
private log(level: LogLevel, message: string | object | any[], newLine: boolean = false) {
|
64
|
+
// 使用本地时间,并格式化为 HH:mm:ss 格式
|
65
|
+
const timestamp = new Date().toLocaleTimeString('zh-CN', {
|
66
|
+
hour12: false,
|
67
|
+
hour: '2-digit',
|
68
|
+
minute: '2-digit',
|
69
|
+
second: '2-digit',
|
70
|
+
});
|
71
|
+
|
72
|
+
const formattedMessage = Array.isArray(message)
|
73
|
+
? this.formatArray(message)
|
74
|
+
: typeof message === 'object'
|
75
|
+
? JSON.stringify(message, null, 2)
|
76
|
+
: message;
|
77
|
+
|
78
|
+
const timestampPart = SHOW_TIMESTAMP ? `${colors.gray}${timestamp}${colors.reset} ` : '';
|
79
|
+
|
80
|
+
const emoji = {
|
81
|
+
debug: '🔍',
|
82
|
+
info: '🐳',
|
83
|
+
warn: '🚨',
|
84
|
+
error: '❌',
|
85
|
+
}[level];
|
86
|
+
|
87
|
+
if (newLine) {
|
88
|
+
console.log("")
|
89
|
+
}
|
90
|
+
|
91
|
+
console.log(
|
92
|
+
timestampPart +
|
93
|
+
`${colors[level]}${emoji} ` +
|
94
|
+
this.getPrefix() +
|
95
|
+
`${level.toUpperCase()}${colors.reset} ` +
|
96
|
+
`${colors.gray}:${colors.reset} ` +
|
97
|
+
`${colors[level]}${formattedMessage}${colors.reset}`
|
98
|
+
);
|
99
|
+
}
|
100
|
+
|
101
|
+
private getPrefix() {
|
102
|
+
return this.topic ? `[${this.topic}] ` : '';
|
103
|
+
}
|
104
|
+
|
105
|
+
constructor(topic: string = '') {
|
106
|
+
this.topic = topic;
|
107
|
+
}
|
108
|
+
|
109
|
+
debug(message: string | object) {
|
110
|
+
this.log('debug', message);
|
111
|
+
}
|
112
|
+
|
113
|
+
info(message: string | object) {
|
114
|
+
this.log('info', message);
|
115
|
+
}
|
116
|
+
|
117
|
+
warn(message: string | object) {
|
118
|
+
this.log('warn', message);
|
119
|
+
}
|
120
|
+
|
121
|
+
error(message: string | object) {
|
122
|
+
this.log('error', message, true);
|
123
|
+
}
|
124
|
+
|
125
|
+
array(title: string, arr: any[]) {
|
126
|
+
this.log('info', title + '\n' + this.formatArray(arr));
|
127
|
+
}
|
112
128
|
}
|
113
129
|
|
114
|
-
export const
|
130
|
+
export const defaultLogger = new Logger();
|
package/dist/utils/path.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { cosyLogger } from '../cosy';
|
2
2
|
|
3
3
|
/**
|
4
4
|
* 判断当前路径是否匹配目标路径
|
@@ -10,13 +10,13 @@ export function isPathMatch(currentPath: string, targetPath: string): boolean {
|
|
10
10
|
const debug = false;
|
11
11
|
|
12
12
|
if (debug) {
|
13
|
-
|
13
|
+
cosyLogger.info(`判断 ${currentPath} 是否匹配 ${targetPath}`);
|
14
14
|
}
|
15
15
|
|
16
16
|
// 如果完全匹配,直接返回
|
17
17
|
if (currentPath === targetPath) {
|
18
18
|
if (debug) {
|
19
|
-
|
19
|
+
cosyLogger.info(`${currentPath} 完全匹配 ${targetPath}`);
|
20
20
|
}
|
21
21
|
return true;
|
22
22
|
}
|