@meituan-nocode/vite-plugin-nocode-compiler 0.1.0-beta.6 → 0.1.0-beta.8
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 +11 -16
- package/dist/index.d.ts +4 -7
- package/dist/index.js +12 -48
- package/package.json +3 -7
- package/dist/modules/base-compiler.d.ts +0 -51
- package/dist/modules/base-compiler.js +0 -44
- package/dist/modules/jsx-compiler.d.ts +0 -26
- package/dist/modules/jsx-compiler.js +0 -167
- package/dist/types.d.ts +0 -17
- package/dist/types.js +0 -2
- package/dist/utils/constants.d.ts +0 -23
- package/dist/utils/constants.js +0 -287
- package/dist/utils/utils.d.ts +0 -33
- package/dist/utils/utils.js +0 -79
package/README.md
CHANGED
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
## 功能
|
|
6
6
|
|
|
7
|
-
- 🚀 **多框架支持**:
|
|
7
|
+
- 🚀 **多框架支持**: 支持 JSX、TSX 和 Vue 文件
|
|
8
8
|
- 📦 **自动元素标记**: 为非 Three.js Fiber 和非 Drei 的元素自动添加 nocode 标识
|
|
9
9
|
- 🔄 **数组上下文检测**: 智能识别数组映射,添加索引信息
|
|
10
|
-
-
|
|
11
|
-
-
|
|
10
|
+
- 🎯 **简单配置**: 开箱即用,仅需最少配置
|
|
11
|
+
- ⚡️ **高性能**: 优化的编译过程,快速处理
|
|
12
12
|
|
|
13
13
|
## 安装
|
|
14
14
|
|
|
@@ -28,13 +28,15 @@ import { componentCompiler } from '@meituan-nocode/vite-plugin-nocode-compiler';
|
|
|
28
28
|
|
|
29
29
|
export default defineConfig({
|
|
30
30
|
plugins: [
|
|
31
|
-
componentCompiler(),
|
|
31
|
+
componentCompiler(), // 使用默认配置
|
|
32
32
|
// 其他插件...
|
|
33
33
|
],
|
|
34
34
|
});
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
-
###
|
|
37
|
+
### 启用调试日志
|
|
38
|
+
|
|
39
|
+
如果需要查看编译过程的详细日志:
|
|
38
40
|
|
|
39
41
|
```javascript
|
|
40
42
|
import { defineConfig } from 'vite';
|
|
@@ -43,27 +45,20 @@ import { componentCompiler } from '@meituan-nocode/vite-plugin-nocode-compiler';
|
|
|
43
45
|
export default defineConfig({
|
|
44
46
|
plugins: [
|
|
45
47
|
componentCompiler({
|
|
46
|
-
validExtensions: new Set(['.jsx', '.tsx']), // 支持的文件扩展名
|
|
47
48
|
enableLogging: true, // 启用调试日志
|
|
48
|
-
threeFiberElems: [
|
|
49
|
-
/* 自定义列表 */
|
|
50
|
-
], // 自定义 Three.js 元素
|
|
51
|
-
dreiElems: [
|
|
52
|
-
/* 自定义列表 */
|
|
53
|
-
], // 自定义 Drei 元素
|
|
54
49
|
}),
|
|
50
|
+
// 其他插件...
|
|
55
51
|
],
|
|
56
52
|
});
|
|
57
53
|
```
|
|
58
54
|
|
|
59
55
|
## 工作原理
|
|
60
56
|
|
|
61
|
-
插件会扫描 `.jsx`
|
|
57
|
+
插件会扫描 `.jsx`、`.tsx` 和 `.vue` 文件中的元素,对于不在 Three.js Fiber 元素列表和 Drei 元素列表中的元素,自动添加以下属性:
|
|
62
58
|
|
|
63
59
|
- `data-nocode-id`: 格式为 `文件路径:行号:列号`
|
|
64
|
-
- `data-nocode-name`: 元素名称
|
|
60
|
+
- `data-nocode-tag-name`: 元素名称
|
|
65
61
|
- `data-nocode-array`: 当元素在数组映射中时,包含数组名称
|
|
66
|
-
- `data-nocode-index`: 当元素在数组映射中时,包含索引变量
|
|
67
62
|
|
|
68
63
|
## 示例
|
|
69
64
|
|
|
@@ -106,7 +101,7 @@ function App() {
|
|
|
106
101
|
该插件采用模块化设计,支持多种前端框架:
|
|
107
102
|
|
|
108
103
|
- **JSX/TSX**: ✅ 已实现
|
|
109
|
-
- **Vue**:
|
|
104
|
+
- **Vue**: ✅ 已实现
|
|
110
105
|
|
|
111
106
|
详细架构说明请参考 [ARCHITECTURE.md](./ARCHITECTURE.md)
|
|
112
107
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @returns Vite 插件
|
|
7
|
-
*/
|
|
8
|
-
export declare function componentCompiler(options?: Partial<CompilerOptions>): Plugin;
|
|
2
|
+
export interface NocodeCompilerOptions {
|
|
3
|
+
enableLogging?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare function componentCompiler(options?: NocodeCompilerOptions): Plugin;
|
package/dist/index.js
CHANGED
|
@@ -1,62 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.componentCompiler = componentCompiler;
|
|
4
|
-
const
|
|
5
|
-
const base_compiler_1 = require("./modules/base-compiler");
|
|
6
|
-
const jsx_compiler_1 = require("./modules/jsx-compiler");
|
|
7
|
-
const utils_1 = require("./utils/utils");
|
|
8
|
-
/**
|
|
9
|
-
* 创建 nocode 编译器插件
|
|
10
|
-
* @param options 编译器选项
|
|
11
|
-
* @returns Vite 插件
|
|
12
|
-
*/
|
|
4
|
+
const nocode_compiler_core_1 = require("@meituan-nocode/nocode-compiler-core");
|
|
13
5
|
function componentCompiler(options = {}) {
|
|
14
|
-
|
|
15
|
-
const config = {
|
|
16
|
-
...constants_1.DEFAULT_CONFIG,
|
|
17
|
-
...options,
|
|
18
|
-
validExtensions: new Set([...Array.from(constants_1.DEFAULT_CONFIG.validExtensions), ...(options.validExtensions ? Array.from(options.validExtensions) : [])]),
|
|
19
|
-
threeFiberElems: options.threeFiberElems || constants_1.DEFAULT_CONFIG.threeFiberElems,
|
|
20
|
-
dreiElems: options.dreiElems || constants_1.DEFAULT_CONFIG.dreiElems,
|
|
21
|
-
};
|
|
22
|
-
// 创建编译器注册表
|
|
23
|
-
const registry = new base_compiler_1.CompilerRegistry();
|
|
24
|
-
// 注册 JSX 编译器
|
|
25
|
-
registry.register({
|
|
26
|
-
name: 'jsx',
|
|
27
|
-
supportedExtensions: jsx_compiler_1.JSXCompiler.supportedExtensions,
|
|
28
|
-
CompilerClass: jsx_compiler_1.JSXCompiler,
|
|
29
|
-
});
|
|
30
|
-
// 未来可以在这里注册 Vue 编译器
|
|
31
|
-
// registry.register({
|
|
32
|
-
// name: 'vue',
|
|
33
|
-
// supportedExtensions: VueCompiler.supportedExtensions,
|
|
34
|
-
// CompilerClass: VueCompiler,
|
|
35
|
-
// });
|
|
36
|
-
// 创建统计管理器
|
|
37
|
-
const statsManager = new utils_1.StatsManager();
|
|
6
|
+
const { enableLogging = false } = options;
|
|
38
7
|
return {
|
|
39
8
|
name: 'vite-plugin-nocode-compiler',
|
|
40
9
|
enforce: 'pre',
|
|
41
10
|
async transform(code, id) {
|
|
42
|
-
//
|
|
43
|
-
|
|
44
|
-
validExtensions: config.validExtensions,
|
|
45
|
-
threeFiberElems: config.threeFiberElems,
|
|
46
|
-
dreiElems: config.dreiElems,
|
|
47
|
-
enableLogging: config.enableLogging,
|
|
48
|
-
});
|
|
49
|
-
if (!compiler) {
|
|
11
|
+
// 检查文件是否在 node_modules 中
|
|
12
|
+
if (id.includes('node_modules')) {
|
|
50
13
|
return null;
|
|
51
14
|
}
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const result = await compiler.compile(code, id);
|
|
56
|
-
if (result) {
|
|
57
|
-
statsManager.incrementProcessedFiles();
|
|
58
|
-
// 这里可以添加元素计数,如果编译器返回相关信息的话
|
|
15
|
+
// 检查文件扩展名
|
|
16
|
+
if (!/\.(jsx?|tsx?)$/.test(id)) {
|
|
17
|
+
return null;
|
|
59
18
|
}
|
|
19
|
+
// 使用 jsxcompiler 编译
|
|
20
|
+
const jsxCompiler = new nocode_compiler_core_1.JSXCompiler({
|
|
21
|
+
enableLogging: enableLogging || false,
|
|
22
|
+
});
|
|
23
|
+
const result = jsxCompiler.compile(code, id);
|
|
60
24
|
return result;
|
|
61
25
|
},
|
|
62
26
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meituan-nocode/vite-plugin-nocode-compiler",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
4
|
-
"description": "nocode
|
|
3
|
+
"version": "0.1.0-beta.8",
|
|
4
|
+
"description": "nocode compiler plugin",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -17,15 +17,11 @@
|
|
|
17
17
|
"vite": "^5.4.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@types/babel__traverse": "^7.28.0",
|
|
21
20
|
"@types/node": "^20.0.0",
|
|
22
21
|
"typescript": "^5.0.0",
|
|
23
22
|
"vite": "^5.4.0"
|
|
24
23
|
},
|
|
25
24
|
"dependencies": {
|
|
26
|
-
"@
|
|
27
|
-
"@babel/traverse": "^7.28.4",
|
|
28
|
-
"@babel/types": "^7.23.0",
|
|
29
|
-
"magic-string": "^0.30.0"
|
|
25
|
+
"@meituan-nocode/nocode-compiler-core": "0.1.0-beta.14"
|
|
30
26
|
}
|
|
31
27
|
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 基础编译器接口
|
|
3
|
-
* 定义所有编译器(JSX、Vue等)的通用接口
|
|
4
|
-
*/
|
|
5
|
-
export interface BaseCompiler {
|
|
6
|
-
/**
|
|
7
|
-
* 编译代码
|
|
8
|
-
* @param code 源代码
|
|
9
|
-
* @param id 文件路径
|
|
10
|
-
* @returns 编译结果或null(如果不需要处理)
|
|
11
|
-
*/
|
|
12
|
-
compile(code: string, id: string): Promise<{
|
|
13
|
-
code: string;
|
|
14
|
-
map: any;
|
|
15
|
-
} | null>;
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* 编译器类构造函数类型
|
|
19
|
-
*/
|
|
20
|
-
export type CompilerConstructor = new (options: any) => BaseCompiler;
|
|
21
|
-
/**
|
|
22
|
-
* 编译器信息接口
|
|
23
|
-
*/
|
|
24
|
-
export interface CompilerInfo {
|
|
25
|
-
name: string;
|
|
26
|
-
supportedExtensions: string[];
|
|
27
|
-
CompilerClass: CompilerConstructor;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* 编译器注册表
|
|
31
|
-
* 管理不同类型的编译器
|
|
32
|
-
*/
|
|
33
|
-
export declare class CompilerRegistry {
|
|
34
|
-
private compilers;
|
|
35
|
-
/**
|
|
36
|
-
* 注册编译器
|
|
37
|
-
*/
|
|
38
|
-
register(info: CompilerInfo): void;
|
|
39
|
-
/**
|
|
40
|
-
* 获取编译器信息
|
|
41
|
-
*/
|
|
42
|
-
getCompilerInfo(name: string): CompilerInfo | undefined;
|
|
43
|
-
/**
|
|
44
|
-
* 获取所有支持的文件扩展名
|
|
45
|
-
*/
|
|
46
|
-
getAllSupportedExtensions(): string[];
|
|
47
|
-
/**
|
|
48
|
-
* 根据文件扩展名获取合适的编译器
|
|
49
|
-
*/
|
|
50
|
-
getCompilerForFile(filePath: string, options: any): BaseCompiler | null;
|
|
51
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CompilerRegistry = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* 编译器注册表
|
|
6
|
-
* 管理不同类型的编译器
|
|
7
|
-
*/
|
|
8
|
-
class CompilerRegistry {
|
|
9
|
-
compilers = new Map();
|
|
10
|
-
/**
|
|
11
|
-
* 注册编译器
|
|
12
|
-
*/
|
|
13
|
-
register(info) {
|
|
14
|
-
this.compilers.set(info.name, info);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* 获取编译器信息
|
|
18
|
-
*/
|
|
19
|
-
getCompilerInfo(name) {
|
|
20
|
-
return this.compilers.get(name);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* 获取所有支持的文件扩展名
|
|
24
|
-
*/
|
|
25
|
-
getAllSupportedExtensions() {
|
|
26
|
-
const extensions = [];
|
|
27
|
-
for (const info of this.compilers.values()) {
|
|
28
|
-
extensions.push(...info.supportedExtensions);
|
|
29
|
-
}
|
|
30
|
-
return [...new Set(extensions)];
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* 根据文件扩展名获取合适的编译器
|
|
34
|
-
*/
|
|
35
|
-
getCompilerForFile(filePath, options) {
|
|
36
|
-
for (const info of this.compilers.values()) {
|
|
37
|
-
if (info.supportedExtensions.some(ext => filePath.endsWith(ext))) {
|
|
38
|
-
return new info.CompilerClass(options);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
exports.CompilerRegistry = CompilerRegistry;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { BaseCompiler } from './base-compiler';
|
|
2
|
-
export interface JSXCompilerOptions {
|
|
3
|
-
validExtensions: Set<string>;
|
|
4
|
-
threeFiberElems: string[];
|
|
5
|
-
dreiElems: string[];
|
|
6
|
-
enableLogging?: boolean;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* JSX 编译器类
|
|
10
|
-
* 负责处理 JSX 文件的编译逻辑
|
|
11
|
-
*/
|
|
12
|
-
export declare class JSXCompiler implements BaseCompiler {
|
|
13
|
-
static readonly supportedExtensions: string[];
|
|
14
|
-
static readonly name = "jsx";
|
|
15
|
-
private options;
|
|
16
|
-
private logger;
|
|
17
|
-
private cwd;
|
|
18
|
-
constructor(options: JSXCompilerOptions);
|
|
19
|
-
/**
|
|
20
|
-
* 编译 JSX 代码
|
|
21
|
-
*/
|
|
22
|
-
compile(code: string, id: string): Promise<{
|
|
23
|
-
code: string;
|
|
24
|
-
map: any;
|
|
25
|
-
} | null>;
|
|
26
|
-
}
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.JSXCompiler = void 0;
|
|
7
|
-
const parser_1 = require("@babel/parser");
|
|
8
|
-
const traverse_1 = __importDefault(require("@babel/traverse"));
|
|
9
|
-
const magic_string_1 = __importDefault(require("magic-string"));
|
|
10
|
-
const path_1 = __importDefault(require("path"));
|
|
11
|
-
const utils_1 = require("../utils/utils");
|
|
12
|
-
/**
|
|
13
|
-
* JSX 编译器类
|
|
14
|
-
* 负责处理 JSX 文件的编译逻辑
|
|
15
|
-
*/
|
|
16
|
-
class JSXCompiler {
|
|
17
|
-
static supportedExtensions = ['.jsx'];
|
|
18
|
-
static name = 'jsx';
|
|
19
|
-
options;
|
|
20
|
-
logger;
|
|
21
|
-
cwd;
|
|
22
|
-
constructor(options) {
|
|
23
|
-
this.options = options;
|
|
24
|
-
this.logger = new utils_1.Logger(options.enableLogging);
|
|
25
|
-
this.cwd = process.cwd();
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* 编译 JSX 代码
|
|
29
|
-
*/
|
|
30
|
-
async compile(code, id) {
|
|
31
|
-
this.logger.log('\nProcessing file:', id);
|
|
32
|
-
if (!(0, utils_1.shouldProcessFile)(id, this.options.validExtensions)) {
|
|
33
|
-
this.logger.log('Skipping file (not .jsx or in node_modules):', id);
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
const relativePath = path_1.default.relative(this.cwd, id);
|
|
37
|
-
this.logger.log('Relative path:', relativePath);
|
|
38
|
-
try {
|
|
39
|
-
const parserOptions = {
|
|
40
|
-
sourceType: 'module',
|
|
41
|
-
plugins: ['jsx'],
|
|
42
|
-
};
|
|
43
|
-
const ast = (0, parser_1.parse)(code, parserOptions);
|
|
44
|
-
const magicString = new magic_string_1.default(code);
|
|
45
|
-
let changedElementsCount = 0;
|
|
46
|
-
let arrayContext = null;
|
|
47
|
-
// 使用 @babel/traverse 替代 estree-walker
|
|
48
|
-
(0, traverse_1.default)(ast, {
|
|
49
|
-
enter: path => {
|
|
50
|
-
const node = path.node;
|
|
51
|
-
// 检测数组的 map 调用
|
|
52
|
-
if (node.type === 'CallExpression') {
|
|
53
|
-
const callExpr = node;
|
|
54
|
-
if (callExpr.callee.type === 'MemberExpression') {
|
|
55
|
-
const memberExpr = callExpr.callee;
|
|
56
|
-
if (memberExpr.property.type === 'Identifier' && memberExpr.property.name === 'map') {
|
|
57
|
-
this.logger.log('Found array map:', node);
|
|
58
|
-
let arrayName = null;
|
|
59
|
-
// 获取数组名称
|
|
60
|
-
if (memberExpr.object.type === 'Identifier') {
|
|
61
|
-
arrayName = memberExpr.object.name;
|
|
62
|
-
}
|
|
63
|
-
else if (memberExpr.object.type === 'MemberExpression') {
|
|
64
|
-
const innerMember = memberExpr.object;
|
|
65
|
-
if (innerMember.object.type === 'Identifier' && innerMember.property.type === 'Identifier') {
|
|
66
|
-
arrayName = `${innerMember.object.name}.${innerMember.property.name}`;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
// 获取参数名(通常是 index)
|
|
70
|
-
let paramName = 'index';
|
|
71
|
-
if (callExpr.arguments.length > 0) {
|
|
72
|
-
const callback = callExpr.arguments[0];
|
|
73
|
-
if (callback.type === 'ArrowFunctionExpression' || callback.type === 'FunctionExpression') {
|
|
74
|
-
const func = callback;
|
|
75
|
-
if (func.params.length > 1 && func.params[1].type === 'Identifier') {
|
|
76
|
-
paramName = func.params[1].name;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (arrayName) {
|
|
81
|
-
arrayContext = { arrayName, paramName };
|
|
82
|
-
this.logger.log('Found array map:', { arrayName, paramName });
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
// 处理 JSX 开标签
|
|
88
|
-
if (node.type === 'JSXOpeningElement') {
|
|
89
|
-
const jsxOpeningElement = node;
|
|
90
|
-
let elementName;
|
|
91
|
-
// 获取元素名称
|
|
92
|
-
if (jsxOpeningElement.name.type === 'JSXIdentifier') {
|
|
93
|
-
elementName = jsxOpeningElement.name.name;
|
|
94
|
-
}
|
|
95
|
-
else if (jsxOpeningElement.name.type === 'JSXMemberExpression') {
|
|
96
|
-
const memberExpr = jsxOpeningElement.name;
|
|
97
|
-
if (memberExpr.object.type === 'JSXIdentifier' && memberExpr.property.type === 'JSXIdentifier') {
|
|
98
|
-
elementName = `${memberExpr.object.name}.${memberExpr.property.name}`;
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
// 跳过 Fragment
|
|
108
|
-
if (elementName === 'Fragment' || elementName === 'React.Fragment') {
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
const shouldTag = (0, utils_1.shouldTagElement)(elementName, this.options.threeFiberElems, this.options.dreiElems);
|
|
112
|
-
this.logger.log('Found JSX element:', {
|
|
113
|
-
elementName,
|
|
114
|
-
shouldTag,
|
|
115
|
-
hasArrayContext: !!arrayContext,
|
|
116
|
-
});
|
|
117
|
-
if (shouldTag) {
|
|
118
|
-
const line = node.loc?.start?.line ?? 0;
|
|
119
|
-
const col = node.loc?.start?.column ?? 0;
|
|
120
|
-
const attributes = (0, utils_1.generateDataAttributes)(relativePath, line, col, elementName, arrayContext);
|
|
121
|
-
this.logger.log('Adding attributes:', attributes);
|
|
122
|
-
// 使用 path 获取准确的节点位置信息
|
|
123
|
-
const nameEndPosition = jsxOpeningElement.name.end;
|
|
124
|
-
if (nameEndPosition !== null) {
|
|
125
|
-
magicString.appendLeft(nameEndPosition, attributes);
|
|
126
|
-
changedElementsCount++;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
exit: path => {
|
|
132
|
-
const node = path.node;
|
|
133
|
-
// 离开 map 调用时清除上下文
|
|
134
|
-
if (node.type === 'CallExpression') {
|
|
135
|
-
const callExpr = node;
|
|
136
|
-
if (callExpr.callee.type === 'MemberExpression') {
|
|
137
|
-
const memberExpr = callExpr.callee;
|
|
138
|
-
if (memberExpr.property.type === 'Identifier' && memberExpr.property.name === 'map') {
|
|
139
|
-
if (arrayContext) {
|
|
140
|
-
this.logger.log('Leaving array map context:', arrayContext.arrayName);
|
|
141
|
-
}
|
|
142
|
-
arrayContext = null;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
},
|
|
147
|
-
});
|
|
148
|
-
this.logger.log('File processing complete:', {
|
|
149
|
-
file: relativePath,
|
|
150
|
-
elementsChanged: changedElementsCount,
|
|
151
|
-
});
|
|
152
|
-
if (changedElementsCount > 0) {
|
|
153
|
-
this.logger.log('Modified code preview:', magicString.toString().slice(0, 500) + '...');
|
|
154
|
-
}
|
|
155
|
-
return {
|
|
156
|
-
code: magicString.toString(),
|
|
157
|
-
map: magicString.generateMap({ hires: true }),
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
catch (error) {
|
|
161
|
-
this.logger.error('Error processing file:', relativePath);
|
|
162
|
-
this.logger.error(error);
|
|
163
|
-
return null;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
exports.JSXCompiler = JSXCompiler;
|
package/dist/types.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Plugin } from 'vite';
|
|
2
|
-
export interface ArrayContext {
|
|
3
|
-
arrayName: string;
|
|
4
|
-
paramName: string;
|
|
5
|
-
}
|
|
6
|
-
export interface CompilerStats {
|
|
7
|
-
totalFiles: number;
|
|
8
|
-
processedFiles: number;
|
|
9
|
-
totalElements: number;
|
|
10
|
-
}
|
|
11
|
-
export interface CompilerOptions {
|
|
12
|
-
validExtensions?: Set<string>;
|
|
13
|
-
threeFiberElems?: string[];
|
|
14
|
-
dreiElems?: string[];
|
|
15
|
-
enableLogging?: boolean;
|
|
16
|
-
}
|
|
17
|
-
export type NocodeCompilerPlugin = (options?: Partial<CompilerOptions>) => Plugin;
|
package/dist/types.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Three.js Fiber 元素列表
|
|
3
|
-
* 这些元素不需要添加 nocode 标识
|
|
4
|
-
*/
|
|
5
|
-
export declare const threeFiberElems: string[];
|
|
6
|
-
/**
|
|
7
|
-
* Drei 元素列表
|
|
8
|
-
* 这些元素不需要添加 nocode 标识
|
|
9
|
-
*/
|
|
10
|
-
export declare const dreiElems: string[];
|
|
11
|
-
/**
|
|
12
|
-
* 支持的文件扩展名
|
|
13
|
-
*/
|
|
14
|
-
export declare const DEFAULT_VALID_EXTENSIONS: Set<string>;
|
|
15
|
-
/**
|
|
16
|
-
* 默认配置
|
|
17
|
-
*/
|
|
18
|
-
export declare const DEFAULT_CONFIG: {
|
|
19
|
-
validExtensions: Set<string>;
|
|
20
|
-
threeFiberElems: string[];
|
|
21
|
-
dreiElems: string[];
|
|
22
|
-
enableLogging: boolean;
|
|
23
|
-
};
|
package/dist/utils/constants.js
DELETED
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_CONFIG = exports.DEFAULT_VALID_EXTENSIONS = exports.dreiElems = exports.threeFiberElems = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Three.js Fiber 元素列表
|
|
6
|
-
* 这些元素不需要添加 nocode 标识
|
|
7
|
-
*/
|
|
8
|
-
exports.threeFiberElems = [
|
|
9
|
-
'object3D',
|
|
10
|
-
'audioListener',
|
|
11
|
-
'positionalAudio',
|
|
12
|
-
'mesh',
|
|
13
|
-
'batchedMesh',
|
|
14
|
-
'instancedMesh',
|
|
15
|
-
'scene',
|
|
16
|
-
'sprite',
|
|
17
|
-
'lOD',
|
|
18
|
-
'skinnedMesh',
|
|
19
|
-
'skeleton',
|
|
20
|
-
'bone',
|
|
21
|
-
'lineSegments',
|
|
22
|
-
'lineLoop',
|
|
23
|
-
'points',
|
|
24
|
-
'group',
|
|
25
|
-
'camera',
|
|
26
|
-
'perspectiveCamera',
|
|
27
|
-
'orthographicCamera',
|
|
28
|
-
'cubeCamera',
|
|
29
|
-
'arrayCamera',
|
|
30
|
-
'instancedBufferGeometry',
|
|
31
|
-
'bufferGeometry',
|
|
32
|
-
'boxBufferGeometry',
|
|
33
|
-
'circleBufferGeometry',
|
|
34
|
-
'coneBufferGeometry',
|
|
35
|
-
'cylinderBufferGeometry',
|
|
36
|
-
'dodecahedronBufferGeometry',
|
|
37
|
-
'extrudeBufferGeometry',
|
|
38
|
-
'icosahedronBufferGeometry',
|
|
39
|
-
'latheBufferGeometry',
|
|
40
|
-
'octahedronBufferGeometry',
|
|
41
|
-
'planeBufferGeometry',
|
|
42
|
-
'polyhedronBufferGeometry',
|
|
43
|
-
'ringBufferGeometry',
|
|
44
|
-
'shapeBufferGeometry',
|
|
45
|
-
'sphereBufferGeometry',
|
|
46
|
-
'tetrahedronBufferGeometry',
|
|
47
|
-
'torusBufferGeometry',
|
|
48
|
-
'torusKnotBufferGeometry',
|
|
49
|
-
'tubeBufferGeometry',
|
|
50
|
-
'wireframeGeometry',
|
|
51
|
-
'tetrahedronGeometry',
|
|
52
|
-
'octahedronGeometry',
|
|
53
|
-
'icosahedronGeometry',
|
|
54
|
-
'dodecahedronGeometry',
|
|
55
|
-
'polyhedronGeometry',
|
|
56
|
-
'tubeGeometry',
|
|
57
|
-
'torusKnotGeometry',
|
|
58
|
-
'torusGeometry',
|
|
59
|
-
'sphereGeometry',
|
|
60
|
-
'ringGeometry',
|
|
61
|
-
'planeGeometry',
|
|
62
|
-
'latheGeometry',
|
|
63
|
-
'shapeGeometry',
|
|
64
|
-
'extrudeGeometry',
|
|
65
|
-
'edgesGeometry',
|
|
66
|
-
'coneGeometry',
|
|
67
|
-
'cylinderGeometry',
|
|
68
|
-
'circleGeometry',
|
|
69
|
-
'boxGeometry',
|
|
70
|
-
'capsuleGeometry',
|
|
71
|
-
'material',
|
|
72
|
-
'shadowMaterial',
|
|
73
|
-
'spriteMaterial',
|
|
74
|
-
'rawShaderMaterial',
|
|
75
|
-
'shaderMaterial',
|
|
76
|
-
'pointsMaterial',
|
|
77
|
-
'meshPhysicalMaterial',
|
|
78
|
-
'meshStandardMaterial',
|
|
79
|
-
'meshPhongMaterial',
|
|
80
|
-
'meshToonMaterial',
|
|
81
|
-
'meshNormalMaterial',
|
|
82
|
-
'meshLambertMaterial',
|
|
83
|
-
'meshDepthMaterial',
|
|
84
|
-
'meshDistanceMaterial',
|
|
85
|
-
'meshBasicMaterial',
|
|
86
|
-
'meshMatcapMaterial',
|
|
87
|
-
'lineDashedMaterial',
|
|
88
|
-
'lineBasicMaterial',
|
|
89
|
-
'primitive',
|
|
90
|
-
'light',
|
|
91
|
-
'spotLightShadow',
|
|
92
|
-
'spotLight',
|
|
93
|
-
'pointLight',
|
|
94
|
-
'rectAreaLight',
|
|
95
|
-
'hemisphereLight',
|
|
96
|
-
'directionalLightShadow',
|
|
97
|
-
'directionalLight',
|
|
98
|
-
'ambientLight',
|
|
99
|
-
'lightShadow',
|
|
100
|
-
'ambientLightProbe',
|
|
101
|
-
'hemisphereLightProbe',
|
|
102
|
-
'lightProbe',
|
|
103
|
-
'spotLightHelper',
|
|
104
|
-
'skeletonHelper',
|
|
105
|
-
'pointLightHelper',
|
|
106
|
-
'hemisphereLightHelper',
|
|
107
|
-
'gridHelper',
|
|
108
|
-
'polarGridHelper',
|
|
109
|
-
'directionalLightHelper',
|
|
110
|
-
'cameraHelper',
|
|
111
|
-
'boxHelper',
|
|
112
|
-
'box3Helper',
|
|
113
|
-
'planeHelper',
|
|
114
|
-
'arrowHelper',
|
|
115
|
-
'axesHelper',
|
|
116
|
-
'texture',
|
|
117
|
-
'videoTexture',
|
|
118
|
-
'dataTexture',
|
|
119
|
-
'dataTexture3D',
|
|
120
|
-
'compressedTexture',
|
|
121
|
-
'cubeTexture',
|
|
122
|
-
'canvasTexture',
|
|
123
|
-
'depthTexture',
|
|
124
|
-
'raycaster',
|
|
125
|
-
'vector2',
|
|
126
|
-
'vector3',
|
|
127
|
-
'vector4',
|
|
128
|
-
'euler',
|
|
129
|
-
'matrix3',
|
|
130
|
-
'matrix4',
|
|
131
|
-
'quaternion',
|
|
132
|
-
'bufferAttribute',
|
|
133
|
-
'float16BufferAttribute',
|
|
134
|
-
'float32BufferAttribute',
|
|
135
|
-
'float64BufferAttribute',
|
|
136
|
-
'int8BufferAttribute',
|
|
137
|
-
'int16BufferAttribute',
|
|
138
|
-
'int32BufferAttribute',
|
|
139
|
-
'uint8BufferAttribute',
|
|
140
|
-
'uint16BufferAttribute',
|
|
141
|
-
'uint32BufferAttribute',
|
|
142
|
-
'instancedBufferAttribute',
|
|
143
|
-
'color',
|
|
144
|
-
'fog',
|
|
145
|
-
'fogExp2',
|
|
146
|
-
'shape',
|
|
147
|
-
'colorShiftMaterial',
|
|
148
|
-
];
|
|
149
|
-
/**
|
|
150
|
-
* Drei 元素列表
|
|
151
|
-
* 这些元素不需要添加 nocode 标识
|
|
152
|
-
*/
|
|
153
|
-
exports.dreiElems = [
|
|
154
|
-
'AsciiRenderer',
|
|
155
|
-
'Billboard',
|
|
156
|
-
'Clone',
|
|
157
|
-
'ComputedAttribute',
|
|
158
|
-
'Decal',
|
|
159
|
-
'Edges',
|
|
160
|
-
'Effects',
|
|
161
|
-
'GradientTexture',
|
|
162
|
-
'Image',
|
|
163
|
-
'MarchingCubes',
|
|
164
|
-
'Outlines',
|
|
165
|
-
'PositionalAudio',
|
|
166
|
-
'Sampler',
|
|
167
|
-
'ScreenSizer',
|
|
168
|
-
'ScreenSpace',
|
|
169
|
-
'Splat',
|
|
170
|
-
'Svg',
|
|
171
|
-
'Text',
|
|
172
|
-
'Text3D',
|
|
173
|
-
'Trail',
|
|
174
|
-
'CubeCamera',
|
|
175
|
-
'OrthographicCamera',
|
|
176
|
-
'PerspectiveCamera',
|
|
177
|
-
'CameraControls',
|
|
178
|
-
'FaceControls',
|
|
179
|
-
'KeyboardControls',
|
|
180
|
-
'MotionPathControls',
|
|
181
|
-
'PresentationControls',
|
|
182
|
-
'ScrollControls',
|
|
183
|
-
'DragControls',
|
|
184
|
-
'GizmoHelper',
|
|
185
|
-
'Grid',
|
|
186
|
-
'Helper',
|
|
187
|
-
'PivotControls',
|
|
188
|
-
'TransformControls',
|
|
189
|
-
'CubeTexture',
|
|
190
|
-
'Fbx',
|
|
191
|
-
'Gltf',
|
|
192
|
-
'Ktx2',
|
|
193
|
-
'Loader',
|
|
194
|
-
'Progress',
|
|
195
|
-
'ScreenVideoTexture',
|
|
196
|
-
'Texture',
|
|
197
|
-
'TrailTexture',
|
|
198
|
-
'VideoTexture',
|
|
199
|
-
'WebcamVideoTexture',
|
|
200
|
-
'CycleRaycast',
|
|
201
|
-
'DetectGPU',
|
|
202
|
-
'Example',
|
|
203
|
-
'FaceLandmarker',
|
|
204
|
-
'Fbo',
|
|
205
|
-
'Html',
|
|
206
|
-
'Select',
|
|
207
|
-
'SpriteAnimator',
|
|
208
|
-
'StatsGl',
|
|
209
|
-
'Stats',
|
|
210
|
-
'Trail',
|
|
211
|
-
'Wireframe',
|
|
212
|
-
'CurveModifier',
|
|
213
|
-
'AdaptiveDpr',
|
|
214
|
-
'AdaptiveEvents',
|
|
215
|
-
'BakeShadows',
|
|
216
|
-
'Bvh',
|
|
217
|
-
'Detailed',
|
|
218
|
-
'Instances',
|
|
219
|
-
'Merged',
|
|
220
|
-
'meshBounds',
|
|
221
|
-
'PerformanceMonitor',
|
|
222
|
-
'Points',
|
|
223
|
-
'Preload',
|
|
224
|
-
'Segments',
|
|
225
|
-
'Fisheye',
|
|
226
|
-
'Hud',
|
|
227
|
-
'Mask',
|
|
228
|
-
'MeshPortalMaterial',
|
|
229
|
-
'RenderCubeTexture',
|
|
230
|
-
'RenderTexture',
|
|
231
|
-
'View',
|
|
232
|
-
'MeshDiscardMaterial',
|
|
233
|
-
'MeshDistortMaterial',
|
|
234
|
-
'MeshReflectorMaterial',
|
|
235
|
-
'MeshRefractionMaterial',
|
|
236
|
-
'MeshTransmissionMaterial',
|
|
237
|
-
'MeshWobbleMaterial',
|
|
238
|
-
'PointMaterial',
|
|
239
|
-
'shaderMaterial',
|
|
240
|
-
'SoftShadows',
|
|
241
|
-
'CatmullRomLine',
|
|
242
|
-
'CubicBezierLine',
|
|
243
|
-
'Facemesh',
|
|
244
|
-
'Line',
|
|
245
|
-
'Mesh',
|
|
246
|
-
'QuadraticBezierLine',
|
|
247
|
-
'RoundedBox',
|
|
248
|
-
'ScreenQuad',
|
|
249
|
-
'AccumulativeShadows',
|
|
250
|
-
'Backdrop',
|
|
251
|
-
'BBAnchor',
|
|
252
|
-
'Bounds',
|
|
253
|
-
'CameraShake',
|
|
254
|
-
'Caustics',
|
|
255
|
-
'Center',
|
|
256
|
-
'Cloud',
|
|
257
|
-
'ContactShadows',
|
|
258
|
-
'Environment',
|
|
259
|
-
'Float',
|
|
260
|
-
'Lightformer',
|
|
261
|
-
'MatcapTexture',
|
|
262
|
-
'NormalTexture',
|
|
263
|
-
'RandomizedLight',
|
|
264
|
-
'Resize',
|
|
265
|
-
'ShadowAlpha',
|
|
266
|
-
'Shadow',
|
|
267
|
-
'Sky',
|
|
268
|
-
'Sparkles',
|
|
269
|
-
'SpotLightShadow',
|
|
270
|
-
'SpotLight',
|
|
271
|
-
'Stage',
|
|
272
|
-
'Stars',
|
|
273
|
-
'OrbitControls',
|
|
274
|
-
];
|
|
275
|
-
/**
|
|
276
|
-
* 支持的文件扩展名
|
|
277
|
-
*/
|
|
278
|
-
exports.DEFAULT_VALID_EXTENSIONS = new Set(['.jsx']);
|
|
279
|
-
/**
|
|
280
|
-
* 默认配置
|
|
281
|
-
*/
|
|
282
|
-
exports.DEFAULT_CONFIG = {
|
|
283
|
-
validExtensions: exports.DEFAULT_VALID_EXTENSIONS,
|
|
284
|
-
threeFiberElems: exports.threeFiberElems,
|
|
285
|
-
dreiElems: exports.dreiElems,
|
|
286
|
-
enableLogging: true,
|
|
287
|
-
};
|
package/dist/utils/utils.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { ArrayContext, CompilerStats } from '../types';
|
|
2
|
-
/**
|
|
3
|
-
* 判断是否需要给元素打标
|
|
4
|
-
*/
|
|
5
|
-
export declare function shouldTagElement(elementName: string, threeFiberElems: string[], dreiElems: string[]): boolean;
|
|
6
|
-
/**
|
|
7
|
-
* 生成数据属性字符串
|
|
8
|
-
*/
|
|
9
|
-
export declare function generateDataAttributes(relativePath: string, line: number, col: number, elementName: string, arrayContext?: ArrayContext | null): string;
|
|
10
|
-
/**
|
|
11
|
-
* 日志记录工具
|
|
12
|
-
*/
|
|
13
|
-
export declare class Logger {
|
|
14
|
-
private enableLogging;
|
|
15
|
-
constructor(enableLogging?: boolean);
|
|
16
|
-
log(message: string, ...args: any[]): void;
|
|
17
|
-
error(message: string, ...args: any[]): void;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* 统计信息管理
|
|
21
|
-
*/
|
|
22
|
-
export declare class StatsManager {
|
|
23
|
-
private stats;
|
|
24
|
-
constructor();
|
|
25
|
-
incrementTotalFiles(): void;
|
|
26
|
-
incrementProcessedFiles(): void;
|
|
27
|
-
addElements(count: number): void;
|
|
28
|
-
getStats(): CompilerStats;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* 检查文件是否应该被处理
|
|
32
|
-
*/
|
|
33
|
-
export declare function shouldProcessFile(id: string, validExtensions: Set<string>): boolean;
|
package/dist/utils/utils.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.StatsManager = exports.Logger = void 0;
|
|
7
|
-
exports.shouldTagElement = shouldTagElement;
|
|
8
|
-
exports.generateDataAttributes = generateDataAttributes;
|
|
9
|
-
exports.shouldProcessFile = shouldProcessFile;
|
|
10
|
-
const path_1 = __importDefault(require("path"));
|
|
11
|
-
/**
|
|
12
|
-
* 判断是否需要给元素打标
|
|
13
|
-
*/
|
|
14
|
-
function shouldTagElement(elementName, threeFiberElems, dreiElems) {
|
|
15
|
-
return !threeFiberElems.includes(elementName) && !dreiElems.includes(elementName);
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* 生成数据属性字符串
|
|
19
|
-
*/
|
|
20
|
-
function generateDataAttributes(relativePath, line, col, elementName, arrayContext) {
|
|
21
|
-
const dataComponentId = `${relativePath}:${line}:${col}`;
|
|
22
|
-
let arrayAttrs = '';
|
|
23
|
-
if (arrayContext) {
|
|
24
|
-
arrayAttrs = ` data-nocode-array="${arrayContext.arrayName}"`;
|
|
25
|
-
}
|
|
26
|
-
return ` data-nocode-id="${dataComponentId}" data-nocode-name="${elementName}"${arrayAttrs}`;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* 日志记录工具
|
|
30
|
-
*/
|
|
31
|
-
class Logger {
|
|
32
|
-
enableLogging;
|
|
33
|
-
constructor(enableLogging = true) {
|
|
34
|
-
this.enableLogging = enableLogging;
|
|
35
|
-
}
|
|
36
|
-
log(message, ...args) {
|
|
37
|
-
if (this.enableLogging) {
|
|
38
|
-
console.log(`[nocode-compiler] ${message}`, ...args);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
error(message, ...args) {
|
|
42
|
-
if (this.enableLogging) {
|
|
43
|
-
console.error(`[nocode-compiler] ${message}`, ...args);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.Logger = Logger;
|
|
48
|
-
/**
|
|
49
|
-
* 统计信息管理
|
|
50
|
-
*/
|
|
51
|
-
class StatsManager {
|
|
52
|
-
stats;
|
|
53
|
-
constructor() {
|
|
54
|
-
this.stats = {
|
|
55
|
-
totalFiles: 0,
|
|
56
|
-
processedFiles: 0,
|
|
57
|
-
totalElements: 0,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
incrementTotalFiles() {
|
|
61
|
-
this.stats.totalFiles++;
|
|
62
|
-
}
|
|
63
|
-
incrementProcessedFiles() {
|
|
64
|
-
this.stats.processedFiles++;
|
|
65
|
-
}
|
|
66
|
-
addElements(count) {
|
|
67
|
-
this.stats.totalElements += count;
|
|
68
|
-
}
|
|
69
|
-
getStats() {
|
|
70
|
-
return { ...this.stats };
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
exports.StatsManager = StatsManager;
|
|
74
|
-
/**
|
|
75
|
-
* 检查文件是否应该被处理
|
|
76
|
-
*/
|
|
77
|
-
function shouldProcessFile(id, validExtensions) {
|
|
78
|
-
return validExtensions.has(path_1.default.extname(id)) && !id.includes('node_modules');
|
|
79
|
-
}
|