@mbler/mcx-core 0.0.2-alpha → 0.0.2-alpha.r1
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/index.d.ts +119 -0
- package/package.json +3 -1
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { ParserOptions } from '@babel/parser';
|
|
2
|
+
|
|
3
|
+
interface BaseToken {
|
|
4
|
+
data: string;
|
|
5
|
+
type: TokenType;
|
|
6
|
+
startIndex?: number;
|
|
7
|
+
endIndex?: number;
|
|
8
|
+
startLine?: number;
|
|
9
|
+
loc?: MCXLoc;
|
|
10
|
+
}
|
|
11
|
+
interface TagToken extends BaseToken {
|
|
12
|
+
type: 'Tag';
|
|
13
|
+
}
|
|
14
|
+
interface TagEndToken extends BaseToken {
|
|
15
|
+
type: 'TagEnd';
|
|
16
|
+
}
|
|
17
|
+
type AttributeMap = Record<string, string | boolean>;
|
|
18
|
+
interface MCXLoc {
|
|
19
|
+
start: {
|
|
20
|
+
line: number;
|
|
21
|
+
index: number;
|
|
22
|
+
};
|
|
23
|
+
end: {
|
|
24
|
+
line: number;
|
|
25
|
+
index: number;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
interface ParsedTagNode {
|
|
29
|
+
start: TagToken;
|
|
30
|
+
name: string;
|
|
31
|
+
arr: AttributeMap;
|
|
32
|
+
content: (ParsedTagContentNode | ParsedTagNode)[];
|
|
33
|
+
end: TagEndToken | null;
|
|
34
|
+
loc: MCXLoc;
|
|
35
|
+
}
|
|
36
|
+
interface ParsedTagContentNode {
|
|
37
|
+
data: string;
|
|
38
|
+
type: 'TagContent';
|
|
39
|
+
}
|
|
40
|
+
type TokenType = 'Tag' | 'TagEnd' | 'Content';
|
|
41
|
+
type PropValue = number | string | object;
|
|
42
|
+
interface PropNode {
|
|
43
|
+
key: string;
|
|
44
|
+
value: PropValue;
|
|
45
|
+
type: "PropChar" | "PropObject";
|
|
46
|
+
}
|
|
47
|
+
type JsType = "boolean" | "number" | "string" | "object" | "function" | "bigint" | "symbol";
|
|
48
|
+
interface TypeVerifyBody {
|
|
49
|
+
[key: string]: JsType;
|
|
50
|
+
}
|
|
51
|
+
interface ParseReadFileOpt {
|
|
52
|
+
delay: number;
|
|
53
|
+
maxRetries: number;
|
|
54
|
+
want: 'string' | 'object';
|
|
55
|
+
}
|
|
56
|
+
type ReadFileOpt = Partial<ParseReadFileOpt>;
|
|
57
|
+
|
|
58
|
+
declare function PropParser(code: string): PropNode[];
|
|
59
|
+
|
|
60
|
+
declare class McxAst {
|
|
61
|
+
private text;
|
|
62
|
+
constructor(text: string);
|
|
63
|
+
private getAST;
|
|
64
|
+
get data(): ParsedTagNode[];
|
|
65
|
+
parseAST(): ParsedTagNode[];
|
|
66
|
+
/**
|
|
67
|
+
* 生成代码字符串(递归处理 content 数组)
|
|
68
|
+
* @param node 要生成代码的AST节点
|
|
69
|
+
* @returns 生成的代码字符串
|
|
70
|
+
*/
|
|
71
|
+
static generateCode(node: ParsedTagNode): string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface CompileUserConfig {
|
|
75
|
+
babelParser?: ParserOptions;
|
|
76
|
+
useTS?: boolean;
|
|
77
|
+
}
|
|
78
|
+
interface CompileOpt {
|
|
79
|
+
cacheDir: string;
|
|
80
|
+
main: string;
|
|
81
|
+
ProjectDir: string;
|
|
82
|
+
moduleDir: string;
|
|
83
|
+
moduleList: string[];
|
|
84
|
+
output: string;
|
|
85
|
+
isCache: boolean;
|
|
86
|
+
config: Partial<CompileUserConfig>;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
declare function CompileMcxDir(BuildOpt: CompileOpt): Promise<void>;
|
|
90
|
+
|
|
91
|
+
declare class McxUtlis {
|
|
92
|
+
/**
|
|
93
|
+
* 检查文件是否存在
|
|
94
|
+
* @param path 文件路径
|
|
95
|
+
* @returns 是否存在
|
|
96
|
+
*/
|
|
97
|
+
static FileExsit(path: string): Promise<boolean>;
|
|
98
|
+
/**
|
|
99
|
+
* 读取文件内容,支持返回 string 或 object,带重试机制
|
|
100
|
+
* @param filePath 文件路径
|
|
101
|
+
* @param opt 配置选项
|
|
102
|
+
* @returns 文件内容(string | object),出错时返回 {}
|
|
103
|
+
*/
|
|
104
|
+
static readFile(filePath: string, opt?: ReadFileOpt): Promise<object | string>;
|
|
105
|
+
static sleep(time: number): Promise<void>;
|
|
106
|
+
static TypeVerify(obj: any, types: TypeVerifyBody): boolean;
|
|
107
|
+
static AbsoluteJoin(baseDir: string, inputPath: string): string;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
declare const _default: {
|
|
111
|
+
load: typeof CompileMcxDir;
|
|
112
|
+
AST: {
|
|
113
|
+
tag: typeof McxAst;
|
|
114
|
+
prop: typeof PropParser;
|
|
115
|
+
};
|
|
116
|
+
utils: typeof McxUtlis;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export { _default as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mbler/mcx-core",
|
|
3
|
-
"version": "0.0.2-alpha",
|
|
3
|
+
"version": "0.0.2-alpha.r1",
|
|
4
4
|
"description": "a DSL compiler of mcx",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"scripts": {
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"registry": "https://registry.npmjs.org",
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
31
32
|
"author": "ruanhor",
|
|
32
33
|
"license": "MIT",
|
|
33
34
|
"devDependencies": {
|
|
@@ -38,6 +39,7 @@
|
|
|
38
39
|
"@types/babel__generator": "^7.27.0",
|
|
39
40
|
"@types/node": "^25.2.0",
|
|
40
41
|
"rollup": "^4.57.1",
|
|
42
|
+
"rollup-plugin-dts": "^6.3.0",
|
|
41
43
|
"tslib": "^2.8.1"
|
|
42
44
|
}
|
|
43
45
|
}
|