@meituan-nocode/vite-plugin-nocode-compiler 0.1.0-beta.7 → 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 CHANGED
@@ -57,9 +57,8 @@ export default defineConfig({
57
57
  插件会扫描 `.jsx`、`.tsx` 和 `.vue` 文件中的元素,对于不在 Three.js Fiber 元素列表和 Drei 元素列表中的元素,自动添加以下属性:
58
58
 
59
59
  - `data-nocode-id`: 格式为 `文件路径:行号:列号`
60
- - `data-nocode-name`: 元素名称
60
+ - `data-nocode-tag-name`: 元素名称
61
61
  - `data-nocode-array`: 当元素在数组映射中时,包含数组名称
62
- - `data-nocode-content`: 元素content内容
63
62
 
64
63
  ## 示例
65
64
 
package/dist/index.d.ts CHANGED
@@ -1,19 +1,5 @@
1
1
  import type { Plugin } from 'vite';
2
- /**
3
- * 创建 nocode 编译器插件
4
- * @param options 编译器选项
5
- * @returns Vite 插件
6
- */
7
- /**
8
- * 创建 nocode 编译器插件,默认处理所有 jsx、tsx 和 vue 文件
9
- * @param options 编译器选项
10
- * @returns Vite 插件
11
- */
12
- export interface CompilerPluginOptions {
13
- /**
14
- * 是否启用日志
15
- * @default false
16
- */
2
+ export interface NocodeCompilerOptions {
17
3
  enableLogging?: boolean;
18
4
  }
19
- export declare function componentCompiler(options?: CompilerPluginOptions): Plugin;
5
+ export declare function componentCompiler(options?: NocodeCompilerOptions): Plugin;
package/dist/index.js CHANGED
@@ -1,53 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.componentCompiler = componentCompiler;
4
- const nocode_compiler_core_1 = require("@mcopilot-nocode/nocode-compiler-core");
4
+ const nocode_compiler_core_1 = require("@meituan-nocode/nocode-compiler-core");
5
5
  function componentCompiler(options = {}) {
6
6
  const { enableLogging = false } = options;
7
- // 构建基础配置
8
- const baseConfig = {
9
- validExtensions: new Set(['.jsx', '.tsx', '.vue']),
10
- threeFiberElems: nocode_compiler_core_1.DEFAULT_CONFIG.threeFiberElems,
11
- dreiElems: nocode_compiler_core_1.DEFAULT_CONFIG.dreiElems,
12
- enableLogging,
13
- };
14
- // 创建编译器注册表
15
- const registry = new nocode_compiler_core_1.CompilerRegistry();
16
- // 注册 JSX/TSX 编译器
17
- registry.register({
18
- extensionName: 'jsx',
19
- supportedExtensions: ['.jsx', '.tsx'],
20
- CompilerClass: nocode_compiler_core_1.JSXCompiler,
21
- });
22
- // 注册 Vue 编译器
23
- registry.register({
24
- extensionName: 'vue',
25
- supportedExtensions: ['.vue'],
26
- CompilerClass: nocode_compiler_core_1.VueCompiler,
27
- });
28
- // 创建统计管理器
29
- const statsManager = new nocode_compiler_core_1.StatsManager();
30
7
  return {
31
8
  name: 'vite-plugin-nocode-compiler',
32
9
  enforce: 'pre',
33
10
  async transform(code, id) {
34
- // 获取适合的编译器
35
- const compiler = registry.getCompilerForFile(id, {
36
- validExtensions: baseConfig.validExtensions,
37
- threeFiberElems: baseConfig.threeFiberElems,
38
- dreiElems: baseConfig.dreiElems,
39
- enableLogging: baseConfig.enableLogging,
40
- });
41
- if (!compiler) {
11
+ // 检查文件是否在 node_modules 中
12
+ if (id.includes('node_modules')) {
42
13
  return null;
43
14
  }
44
- // 统计文件处理
45
- statsManager.incrementTotalFiles();
46
- // 编译代码
47
- const result = await compiler.compile(code, id);
48
- if (result) {
49
- statsManager.incrementProcessedFiles();
15
+ // 检查文件扩展名
16
+ if (!/\.(jsx?|tsx?)$/.test(id)) {
17
+ return null;
50
18
  }
19
+ // 使用 jsxcompiler 编译
20
+ const jsxCompiler = new nocode_compiler_core_1.JSXCompiler({
21
+ enableLogging: enableLogging || false,
22
+ });
23
+ const result = jsxCompiler.compile(code, id);
51
24
  return result;
52
25
  },
53
26
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meituan-nocode/vite-plugin-nocode-compiler",
3
- "version": "0.1.0-beta.7",
3
+ "version": "0.1.0-beta.8",
4
4
  "description": "nocode compiler plugin",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -22,6 +22,6 @@
22
22
  "vite": "^5.4.0"
23
23
  },
24
24
  "dependencies": {
25
- "@mcopilot-nocode/nocode-compiler-core": "workspace:*"
25
+ "@meituan-nocode/nocode-compiler-core": "0.1.0-beta.14"
26
26
  }
27
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
- extensionName: 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(extensionName: 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.extensionName, info);
15
- }
16
- /**
17
- * 获取编译器信息
18
- */
19
- getCompilerInfo(extensionName) {
20
- return this.compilers.get(extensionName);
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,34 +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/TSX 编译器类
10
- * 负责处理 JSX/TSX 文件的编译逻辑
11
- *
12
- * 支持的文件类型:
13
- * - .jsx: React JSX 文件
14
- * - .tsx: React TypeScript JSX 文件
15
- *
16
- * 注意:
17
- * - TypeScript 类型信息在编译时会被擦除
18
- * - 编译器关注的是 JSX 结构而不是类型信息
19
- */
20
- export declare class JSXCompiler implements BaseCompiler {
21
- static readonly supportedExtensions: string[];
22
- static readonly extensionName = "jsx";
23
- private options;
24
- private logger;
25
- private cwd;
26
- constructor(options: JSXCompilerOptions);
27
- /**
28
- * 编译 JSX 代码
29
- */
30
- compile(code: string, id: string): Promise<{
31
- code: string;
32
- map: any;
33
- } | null>;
34
- }
@@ -1,211 +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/TSX 编译器类
14
- * 负责处理 JSX/TSX 文件的编译逻辑
15
- *
16
- * 支持的文件类型:
17
- * - .jsx: React JSX 文件
18
- * - .tsx: React TypeScript JSX 文件
19
- *
20
- * 注意:
21
- * - TypeScript 类型信息在编译时会被擦除
22
- * - 编译器关注的是 JSX 结构而不是类型信息
23
- */
24
- class JSXCompiler {
25
- static supportedExtensions = ['.jsx', '.tsx'];
26
- static extensionName = 'jsx';
27
- options;
28
- logger;
29
- cwd;
30
- constructor(options) {
31
- this.options = options;
32
- this.logger = new utils_1.Logger(options.enableLogging);
33
- this.cwd = process.cwd();
34
- }
35
- /**
36
- * 编译 JSX 代码
37
- */
38
- async compile(code, id) {
39
- this.logger.log('\nProcessing file:', id);
40
- if (!(0, utils_1.shouldProcessFile)(id, this.options.validExtensions)) {
41
- this.logger.log('Skipping file (not .jsx or in node_modules):', id);
42
- return null;
43
- }
44
- const relativePath = path_1.default.relative(this.cwd, id);
45
- this.logger.log('Relative path:', relativePath);
46
- try {
47
- const parserOptions = {
48
- sourceType: 'module',
49
- plugins: ['jsx', 'typescript'],
50
- };
51
- const ast = (0, parser_1.parse)(code, parserOptions);
52
- const magicString = new magic_string_1.default(code);
53
- let changedElementsCount = 0;
54
- let arrayContext = null;
55
- // 使用 @babel/traverse 替代 estree-walker
56
- (0, traverse_1.default)(ast, {
57
- enter: path => {
58
- const node = path.node;
59
- // 检测数组的 map 调用
60
- if (node.type === 'CallExpression') {
61
- const callExpr = node;
62
- if (callExpr.callee.type === 'MemberExpression') {
63
- const memberExpr = callExpr.callee;
64
- if (memberExpr.property.type === 'Identifier' && memberExpr.property.name === 'map') {
65
- this.logger.log('Found array map:', node);
66
- let arrayName = null;
67
- // 获取数组名称
68
- if (memberExpr.object.type === 'Identifier') {
69
- arrayName = memberExpr.object.name;
70
- }
71
- else if (memberExpr.object.type === 'MemberExpression') {
72
- const innerMember = memberExpr.object;
73
- if (innerMember.object.type === 'Identifier' && innerMember.property.type === 'Identifier') {
74
- arrayName = `${innerMember.object.name}.${innerMember.property.name}`;
75
- }
76
- }
77
- // 获取参数名(通常是 index)
78
- let paramName = 'index';
79
- if (callExpr.arguments.length > 0) {
80
- const callback = callExpr.arguments[0];
81
- if (callback.type === 'ArrowFunctionExpression' || callback.type === 'FunctionExpression') {
82
- const func = callback;
83
- if (func.params.length > 1 && func.params[1].type === 'Identifier') {
84
- paramName = func.params[1].name;
85
- }
86
- }
87
- }
88
- if (arrayName) {
89
- arrayContext = { arrayName, paramName };
90
- this.logger.log('Found array map:', { arrayName, paramName });
91
- }
92
- }
93
- }
94
- }
95
- // 处理 JSX 开标签
96
- if (node.type === 'JSXOpeningElement') {
97
- const jsxOpeningElement = node;
98
- let elementName;
99
- // 获取元素名称
100
- if (jsxOpeningElement.name.type === 'JSXIdentifier') {
101
- elementName = jsxOpeningElement.name.name;
102
- }
103
- else if (jsxOpeningElement.name.type === 'JSXMemberExpression') {
104
- const memberExpr = jsxOpeningElement.name;
105
- if (memberExpr.object.type === 'JSXIdentifier' && memberExpr.property.type === 'JSXIdentifier') {
106
- elementName = `${memberExpr.object.name}.${memberExpr.property.name}`;
107
- }
108
- else {
109
- return;
110
- }
111
- }
112
- else {
113
- return;
114
- }
115
- // 跳过 Fragment
116
- if (elementName === 'Fragment' || elementName === 'React.Fragment') {
117
- return;
118
- }
119
- const shouldTag = (0, utils_1.shouldTagElement)(elementName, this.options.threeFiberElems, this.options.dreiElems);
120
- this.logger.log('Found JSX element:', {
121
- elementName,
122
- shouldTag,
123
- hasArrayContext: !!arrayContext,
124
- });
125
- if (shouldTag) {
126
- const line = node.loc?.start?.line ?? 0;
127
- const col = node.loc?.start?.column ?? 0;
128
- // 收集元素内容
129
- const content = {};
130
- // 收集属性
131
- jsxOpeningElement.attributes.forEach(attr => {
132
- if (attr.type === 'JSXAttribute') {
133
- const attrName = attr.name.name;
134
- if (attrName === 'placeholder' || attrName === 'className') {
135
- if (attr.value?.type === 'StringLiteral') {
136
- content[attrName] = attr.value.value;
137
- }
138
- else if (attr.value?.type === 'JSXExpressionContainer' && attr.value.expression.type === 'StringLiteral') {
139
- content[attrName] = attr.value.expression.value;
140
- }
141
- }
142
- }
143
- });
144
- // 收集文本内容
145
- const parentPath = path.parentPath;
146
- if (parentPath && parentPath.node.type === 'JSXElement') {
147
- const textContent = parentPath.node.children
148
- .map((child) => {
149
- if (child.type === 'JSXText') {
150
- return child.value.trim();
151
- }
152
- else if (child.type === 'JSXExpressionContainer' && child.expression.type === 'StringLiteral') {
153
- return child.expression.value;
154
- }
155
- return '';
156
- })
157
- .filter(Boolean)
158
- .join(' ')
159
- .trim();
160
- if (textContent) {
161
- content.text = textContent;
162
- }
163
- }
164
- const attributes = (0, utils_1.generateDataAttributes)(relativePath, line, col, elementName, content, arrayContext);
165
- this.logger.log('Adding attributes:', attributes);
166
- // 使用 path 获取准确的节点位置信息
167
- const nameEndPosition = jsxOpeningElement.name.end;
168
- if (nameEndPosition !== null) {
169
- magicString.appendLeft(nameEndPosition, attributes);
170
- changedElementsCount++;
171
- }
172
- }
173
- }
174
- },
175
- exit: path => {
176
- const node = path.node;
177
- // 离开 map 调用时清除上下文
178
- if (node.type === 'CallExpression') {
179
- const callExpr = node;
180
- if (callExpr.callee.type === 'MemberExpression') {
181
- const memberExpr = callExpr.callee;
182
- if (memberExpr.property.type === 'Identifier' && memberExpr.property.name === 'map') {
183
- if (arrayContext) {
184
- this.logger.log('Leaving array map context:', arrayContext.arrayName);
185
- }
186
- arrayContext = null;
187
- }
188
- }
189
- }
190
- },
191
- });
192
- this.logger.log('File processing complete:', {
193
- file: relativePath,
194
- elementsChanged: changedElementsCount,
195
- });
196
- if (changedElementsCount > 0) {
197
- this.logger.log('Modified code preview:', magicString.toString().slice(0, 500) + '...');
198
- }
199
- return {
200
- code: magicString.toString(),
201
- map: magicString.generateMap({ hires: true }),
202
- };
203
- }
204
- catch (error) {
205
- this.logger.error('Error processing file:', relativePath);
206
- this.logger.error(error);
207
- return null;
208
- }
209
- }
210
- }
211
- exports.JSXCompiler = JSXCompiler;
@@ -1,26 +0,0 @@
1
- import type { BaseCompiler } from './base-compiler';
2
- export interface VueCompilerOptions {
3
- validExtensions: Set<string>;
4
- threeFiberElems: string[];
5
- dreiElems: string[];
6
- enableLogging?: boolean;
7
- }
8
- /**
9
- * Vue 编译器类
10
- * 负责处理 Vue 文件的编译逻辑
11
- */
12
- export declare class VueCompiler implements BaseCompiler {
13
- static readonly supportedExtensions: string[];
14
- static readonly extensionName = "vue";
15
- private options;
16
- private logger;
17
- private cwd;
18
- constructor(options: VueCompilerOptions);
19
- /**
20
- * 编译 Vue 代码
21
- */
22
- compile(code: string, id: string): Promise<{
23
- code: string;
24
- map: any;
25
- } | null>;
26
- }
@@ -1,129 +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.VueCompiler = void 0;
7
- const compiler_sfc_1 = require("@vue/compiler-sfc");
8
- const magic_string_1 = __importDefault(require("magic-string"));
9
- const path_1 = __importDefault(require("path"));
10
- const utils_1 = require("../utils/utils");
11
- /**
12
- * Vue 编译器类
13
- * 负责处理 Vue 文件的编译逻辑
14
- */
15
- class VueCompiler {
16
- static supportedExtensions = ['.vue'];
17
- static extensionName = 'vue';
18
- options;
19
- logger;
20
- cwd;
21
- constructor(options) {
22
- this.options = options;
23
- this.logger = new utils_1.Logger(options.enableLogging);
24
- this.cwd = process.cwd();
25
- }
26
- /**
27
- * 编译 Vue 代码
28
- */
29
- async compile(code, id) {
30
- this.logger.log('\nProcessing file:', id);
31
- if (!(0, utils_1.shouldProcessFile)(id, this.options.validExtensions)) {
32
- this.logger.log('Skipping file (not .vue or in node_modules):', id);
33
- return null;
34
- }
35
- const relativePath = path_1.default.relative(this.cwd, id);
36
- this.logger.log('Relative path:', relativePath);
37
- try {
38
- // 解析Vue SFC
39
- const { descriptor } = (0, compiler_sfc_1.parse)(code);
40
- if (!descriptor.template) {
41
- return null;
42
- }
43
- const magicString = new magic_string_1.default(code);
44
- let changedElementsCount = 0;
45
- // 获取template的AST
46
- const templateAst = descriptor.template.ast;
47
- if (!templateAst) {
48
- return null;
49
- }
50
- // 递归处理AST节点
51
- const processNode = (node, arrayContext = null) => {
52
- if (node.type !== 1) {
53
- // 1 表示元素节点
54
- return;
55
- }
56
- const elementName = node.tag;
57
- // 跳过内置组件
58
- if (elementName === 'template' || elementName === 'slot') {
59
- return;
60
- }
61
- const shouldTag = (0, utils_1.shouldTagElement)(elementName, this.options.threeFiberElems, this.options.dreiElems);
62
- if (shouldTag) {
63
- const line = node.loc.start.line;
64
- const col = node.loc.start.column;
65
- // 收集元素内容
66
- const content = {};
67
- // 收集属性
68
- if (node.props) {
69
- node.props.forEach((prop) => {
70
- if (prop.type === 6) {
71
- // 6 表示属性
72
- if (prop.name === 'placeholder' || prop.name === 'class') {
73
- content[prop.name === 'class' ? 'className' : prop.name] = prop.value?.content;
74
- }
75
- }
76
- });
77
- }
78
- // 收集文本内容
79
- if (node.children) {
80
- const textContent = node.children
81
- .filter((child) => child.type === 2) // 2 表示文本节点
82
- .map((child) => child.content.trim())
83
- .filter(Boolean)
84
- .join(' ');
85
- if (textContent) {
86
- content.text = textContent;
87
- }
88
- }
89
- const attributes = (0, utils_1.generateDataAttributes)(relativePath, line, col, elementName, content, arrayContext);
90
- // 在标签名后插入属性
91
- const insertPos = node.loc.start.offset + elementName.length + 1;
92
- magicString.appendLeft(insertPos, attributes);
93
- changedElementsCount++;
94
- }
95
- // 处理v-for上下文
96
- let vForContext = null;
97
- const vForProp = node.props?.find((p) => p.type === 7 && p.name === 'for'); // 7 表示指令
98
- if (vForProp) {
99
- const match = vForProp.exp?.content.match(/\((.*?),\s*(.*?)\)\s+in\s+(.*)/);
100
- if (match) {
101
- vForContext = {
102
- arrayName: match[3],
103
- paramName: match[2],
104
- };
105
- }
106
- }
107
- // 递归处理子节点
108
- if (node.children) {
109
- node.children.forEach((child) => processNode(child, vForContext || arrayContext));
110
- }
111
- };
112
- processNode(templateAst);
113
- this.logger.log('File processing complete:', {
114
- file: relativePath,
115
- elementsChanged: changedElementsCount,
116
- });
117
- return {
118
- code: magicString.toString(),
119
- map: magicString.generateMap({ hires: true }),
120
- };
121
- }
122
- catch (error) {
123
- this.logger.error('Error processing file:', relativePath);
124
- this.logger.error(error);
125
- return null;
126
- }
127
- }
128
- }
129
- exports.VueCompiler = VueCompiler;
@@ -1,9 +0,0 @@
1
- export interface ArrayContext {
2
- arrayName: string;
3
- paramName: string;
4
- }
5
- export interface CompilerStats {
6
- totalFiles: number;
7
- processedFiles: number;
8
- totalElements: number;
9
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -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
- };
@@ -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
- };
@@ -1,39 +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
- interface ElementContent {
10
- text?: string;
11
- placeholder?: string;
12
- className?: string;
13
- }
14
- export declare function generateDataAttributes(relativePath: string, line: number, col: number, elementName: string, content?: ElementContent, arrayContext?: ArrayContext | null): string;
15
- /**
16
- * 日志记录工具
17
- */
18
- export declare class Logger {
19
- private enableLogging;
20
- constructor(enableLogging?: boolean);
21
- log(message: string, ...args: any[]): void;
22
- error(message: string, ...args: any[]): void;
23
- }
24
- /**
25
- * 统计信息管理
26
- */
27
- export declare class StatsManager {
28
- private stats;
29
- constructor();
30
- incrementTotalFiles(): void;
31
- incrementProcessedFiles(): void;
32
- addElements(count: number): void;
33
- getStats(): CompilerStats;
34
- }
35
- /**
36
- * 检查文件是否应该被处理
37
- */
38
- export declare function shouldProcessFile(id: string, validExtensions: Set<string>): boolean;
39
- export {};
@@ -1,77 +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
- function generateDataAttributes(relativePath, line, col, elementName, content = {}, arrayContext) {
18
- const dataComponentId = `${relativePath}:${line}:${col}`;
19
- let arrayAttrs = '';
20
- if (arrayContext) {
21
- arrayAttrs = ` data-nocode-array="${arrayContext.arrayName}"`;
22
- }
23
- const contentAttr = Object.keys(content).length > 0 ? ` data-nocode-content="${encodeURIComponent(JSON.stringify(content))}"` : '';
24
- return ` data-nocode-id="${dataComponentId}" data-nocode-name="${elementName}"${arrayAttrs}${contentAttr}`;
25
- }
26
- /**
27
- * 日志记录工具
28
- */
29
- class Logger {
30
- enableLogging;
31
- constructor(enableLogging = true) {
32
- this.enableLogging = enableLogging;
33
- }
34
- log(message, ...args) {
35
- if (this.enableLogging) {
36
- console.log(`[nocode-compiler] ${message}`, ...args);
37
- }
38
- }
39
- error(message, ...args) {
40
- if (this.enableLogging) {
41
- console.error(`[nocode-compiler] ${message}`, ...args);
42
- }
43
- }
44
- }
45
- exports.Logger = Logger;
46
- /**
47
- * 统计信息管理
48
- */
49
- class StatsManager {
50
- stats;
51
- constructor() {
52
- this.stats = {
53
- totalFiles: 0,
54
- processedFiles: 0,
55
- totalElements: 0,
56
- };
57
- }
58
- incrementTotalFiles() {
59
- this.stats.totalFiles++;
60
- }
61
- incrementProcessedFiles() {
62
- this.stats.processedFiles++;
63
- }
64
- addElements(count) {
65
- this.stats.totalElements += count;
66
- }
67
- getStats() {
68
- return { ...this.stats };
69
- }
70
- }
71
- exports.StatsManager = StatsManager;
72
- /**
73
- * 检查文件是否应该被处理
74
- */
75
- function shouldProcessFile(id, validExtensions) {
76
- return validExtensions.has(path_1.default.extname(id)) && !id.includes('node_modules');
77
- }
@@ -1,42 +0,0 @@
1
- import type { Plugin } from 'vite';
2
- /**
3
- * 创建 nocode 编译器插件
4
- * @param options 编译器选项
5
- * @returns Vite 插件
6
- */
7
- export type FileType = 'jsx' | 'tsx' | 'vue';
8
- export interface CompilerPluginOptions {
9
- /**
10
- * 指定要处理的文件类型
11
- * @default ['jsx']
12
- * @example ['jsx', 'tsx', 'vue']
13
- */
14
- include?: FileType[];
15
- /**
16
- * Three.js 相关组件配置
17
- */
18
- three?: {
19
- /**
20
- * Three.js Fiber 组件列表
21
- */
22
- fiberElements?: string[];
23
- /**
24
- * Drei 组件列表
25
- */
26
- dreiElements?: string[];
27
- };
28
- /**
29
- * 调试选项
30
- */
31
- debug?: {
32
- /**
33
- * 是否启用日志
34
- */
35
- enableLogging?: boolean;
36
- /**
37
- * 是否在开发模式下跳过编译
38
- */
39
- skipInDev?: boolean;
40
- };
41
- }
42
- export declare function componentCompiler(options?: CompilerPluginOptions): Plugin;
@@ -1,69 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.componentCompiler = componentCompiler;
4
- const constants_1 = require("@mcopilot-nocode/nocode-compiler-core/utils/constants");
5
- const base_compiler_1 = require("@mcopilot-nocode/nocode-compiler-core/compilers/base-compiler");
6
- const jsx_compiler_1 = require("@mcopilot-nocode/nocode-compiler-core/compilers/jsx-compiler");
7
- const vue_compiler_1 = require("@mcopilot-nocode/nocode-compiler-core/compilers/vue-compiler");
8
- const utils_1 = require("@mcopilot-nocode/nocode-compiler-core/utils/utils");
9
- function componentCompiler(options = {}) {
10
- const { include = ['jsx'], three = {}, debug = {} } = options;
11
- // 构建基础配置
12
- const baseConfig = {
13
- validExtensions: new Set(),
14
- threeFiberElems: three.fiberElements || constants_1.DEFAULT_CONFIG.threeFiberElems,
15
- dreiElems: three.dreiElements || constants_1.DEFAULT_CONFIG.dreiElems,
16
- enableLogging: debug.enableLogging ?? false,
17
- };
18
- // 创建编译器注册表
19
- const registry = new base_compiler_1.CompilerRegistry();
20
- // 根据include配置注册对应的编译器
21
- const hasJsxOrTsx = include.includes('jsx') || include.includes('tsx');
22
- if (hasJsxOrTsx) {
23
- const extensions = [];
24
- if (include.includes('jsx'))
25
- extensions.push('.jsx');
26
- if (include.includes('tsx'))
27
- extensions.push('.tsx');
28
- extensions.forEach(ext => baseConfig.validExtensions.add(ext));
29
- registry.register({
30
- extensionName: 'jsx',
31
- supportedExtensions: extensions,
32
- CompilerClass: jsx_compiler_1.JSXCompiler,
33
- });
34
- }
35
- if (include.includes('vue')) {
36
- baseConfig.validExtensions.add('.vue');
37
- registry.register({
38
- extensionName: 'vue',
39
- supportedExtensions: ['.vue'],
40
- CompilerClass: vue_compiler_1.VueCompiler,
41
- });
42
- }
43
- // 创建统计管理器
44
- const statsManager = new utils_1.StatsManager();
45
- return {
46
- name: 'vite-plugin-nocode-compiler',
47
- enforce: 'pre',
48
- async transform(code, id) {
49
- // 获取适合的编译器
50
- const compiler = registry.getCompilerForFile(id, {
51
- validExtensions: baseConfig.validExtensions,
52
- threeFiberElems: baseConfig.threeFiberElems,
53
- dreiElems: baseConfig.dreiElems,
54
- enableLogging: baseConfig.enableLogging,
55
- });
56
- if (!compiler) {
57
- return null;
58
- }
59
- // 统计文件处理
60
- statsManager.incrementTotalFiles();
61
- // 编译代码
62
- const result = await compiler.compile(code, id);
63
- if (result) {
64
- statsManager.incrementProcessedFiles();
65
- }
66
- return result;
67
- },
68
- };
69
- }
@@ -1,8 +0,0 @@
1
- import type { Plugin } from 'vite';
2
- export interface CompilerOptions {
3
- validExtensions?: Set<string>;
4
- threeFiberElems?: string[];
5
- dreiElems?: string[];
6
- enableLogging?: boolean;
7
- }
8
- export type NocodeCompilerPlugin = (options?: Partial<CompilerOptions>) => Plugin;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });