@meituan-nocode/vite-plugin-nocode-compiler 0.1.0-beta.2 → 0.1.0-beta.20-z
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 +153 -79
- package/dist/index.cjs.js +1 -0
- package/dist/index.d.ts +13 -6
- package/dist/index.es.js +30 -0
- package/dist/index.js +87 -47
- package/dist/utils.d.ts +9 -0
- package/dist/utils.js +19 -0
- package/package.json +14 -12
- 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 -157
- 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
|
@@ -1,129 +1,203 @@
|
|
|
1
1
|
# @meituan-nocode/vite-plugin-nocode-compiler
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Vite 插件,用于在构建过程中处理 Vue 和 React 组件,添加 nocode 相关的标记。该插件支持自动检测项目框架类型(Vue/React),并应用相应的编译逻辑。
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 特性
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
7
|
+
- ✅ 支持 Vue 和 React 组件的处理
|
|
8
|
+
- ✅ 自动检测项目框架类型
|
|
9
|
+
- ✅ 兼容 Vite 4.x 和 5.x 版本
|
|
10
|
+
- ✅ 可配置的日志输出
|
|
11
|
+
- ✅ 支持 ESM 和 CommonJS 导入方式
|
|
12
12
|
|
|
13
13
|
## 安装
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
+
# npm
|
|
16
17
|
npm install @meituan-nocode/vite-plugin-nocode-compiler --save-dev
|
|
18
|
+
|
|
19
|
+
# yarn
|
|
20
|
+
yarn add @meituan-nocode/vite-plugin-nocode-compiler --dev
|
|
21
|
+
|
|
22
|
+
# pnpm
|
|
23
|
+
pnpm add @meituan-nocode/vite-plugin-nocode-compiler -D
|
|
17
24
|
```
|
|
18
25
|
|
|
19
|
-
##
|
|
26
|
+
## 在测试项目中引入和使用
|
|
20
27
|
|
|
21
|
-
###
|
|
28
|
+
### 1. 安装依赖
|
|
22
29
|
|
|
23
|
-
|
|
30
|
+
首先确保安装了必要的依赖:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# 安装 vite-plugin-nocode-compiler
|
|
34
|
+
npm install @meituan-nocode/vite-plugin-nocode-compiler --save-dev
|
|
35
|
+
|
|
36
|
+
# 确保安装了 vite
|
|
37
|
+
npm install vite --save-dev
|
|
38
|
+
```
|
|
24
39
|
|
|
25
|
-
|
|
40
|
+
### 2. 配置 Vite
|
|
41
|
+
|
|
42
|
+
在测试项目的根目录创建或修改 `vite.config.js` 或 `vite.config.ts` 文件:
|
|
43
|
+
|
|
44
|
+
#### ESM 方式 (推荐)
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
// vite.config.js / vite.config.ts
|
|
26
48
|
import { defineConfig } from 'vite';
|
|
27
|
-
import {
|
|
49
|
+
import { NocodeCompiler } from '@meituan-nocode/vite-plugin-nocode-compiler';
|
|
50
|
+
// 或者使用默认导出
|
|
51
|
+
// import NocodeCompiler from '@meituan-nocode/vite-plugin-nocode-compiler';
|
|
28
52
|
|
|
29
53
|
export default defineConfig({
|
|
30
54
|
plugins: [
|
|
31
|
-
|
|
32
|
-
|
|
55
|
+
NocodeCompiler({
|
|
56
|
+
enableLogging: true, // 开启日志,方便调试
|
|
57
|
+
}),
|
|
33
58
|
],
|
|
34
59
|
});
|
|
35
60
|
```
|
|
36
61
|
|
|
37
|
-
|
|
62
|
+
#### CommonJS 方式
|
|
38
63
|
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
|
|
64
|
+
```js
|
|
65
|
+
// vite.config.js
|
|
66
|
+
const { defineConfig } = require('vite');
|
|
67
|
+
const { NocodeCompiler } = require('@meituan-nocode/vite-plugin-nocode-compiler');
|
|
42
68
|
|
|
43
|
-
|
|
69
|
+
module.exports = defineConfig({
|
|
44
70
|
plugins: [
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
enableLogging: true, // 启用调试日志
|
|
48
|
-
threeFiberElems: [
|
|
49
|
-
/* 自定义列表 */
|
|
50
|
-
], // 自定义 Three.js 元素
|
|
51
|
-
dreiElems: [
|
|
52
|
-
/* 自定义列表 */
|
|
53
|
-
], // 自定义 Drei 元素
|
|
71
|
+
NocodeCompiler({
|
|
72
|
+
enableLogging: true, // 开启日志,方便调试
|
|
54
73
|
}),
|
|
55
74
|
],
|
|
56
75
|
});
|
|
57
76
|
```
|
|
58
77
|
|
|
59
|
-
|
|
78
|
+
### 3. 运行测试项目
|
|
60
79
|
|
|
61
|
-
|
|
80
|
+
配置完成后,可以通过以下命令启动测试项目:
|
|
62
81
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
82
|
+
```bash
|
|
83
|
+
# 开发模式
|
|
84
|
+
npx vite
|
|
85
|
+
|
|
86
|
+
# 或构建
|
|
87
|
+
npx vite build
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 4. 验证插件是否正常工作
|
|
67
91
|
|
|
68
|
-
|
|
92
|
+
如果启用了 `enableLogging: true`,在构建过程中会看到插件的日志输出,包括检测到的框架类型和处理的文件信息。
|
|
69
93
|
|
|
70
|
-
|
|
94
|
+
## 使用方法详解
|
|
95
|
+
|
|
96
|
+
### ESM 导入 (推荐)
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
// vite.config.js / vite.config.ts
|
|
100
|
+
import { defineConfig } from 'vite';
|
|
101
|
+
import { NocodeCompiler } from '@meituan-nocode/vite-plugin-nocode-compiler';
|
|
102
|
+
// 或者使用默认导入
|
|
103
|
+
// import NocodeCompiler from '@meituan-nocode/vite-plugin-nocode-compiler';
|
|
71
104
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
</div>
|
|
81
|
-
);
|
|
82
|
-
}
|
|
105
|
+
export default defineConfig({
|
|
106
|
+
plugins: [
|
|
107
|
+
NocodeCompiler({
|
|
108
|
+
enableLogging: true,
|
|
109
|
+
// 其他配置选项
|
|
110
|
+
}),
|
|
111
|
+
],
|
|
112
|
+
});
|
|
83
113
|
```
|
|
84
114
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
115
|
+
### CommonJS 导入
|
|
116
|
+
|
|
117
|
+
```js
|
|
118
|
+
// vite.config.js
|
|
119
|
+
const { defineConfig } = require('vite');
|
|
120
|
+
const { NocodeCompiler } = require('@meituan-nocode/vite-plugin-nocode-compiler');
|
|
121
|
+
// 或者使用默认导入并解构
|
|
122
|
+
// const pkg = require('@meituan-nocode/vite-plugin-nocode-compiler');
|
|
123
|
+
// const { NocodeCompiler } = pkg;
|
|
124
|
+
|
|
125
|
+
module.exports = defineConfig({
|
|
126
|
+
plugins: [
|
|
127
|
+
NocodeCompiler({
|
|
128
|
+
enableLogging: true,
|
|
129
|
+
// 其他配置选项
|
|
130
|
+
}),
|
|
131
|
+
],
|
|
132
|
+
});
|
|
102
133
|
```
|
|
103
134
|
|
|
104
|
-
##
|
|
135
|
+
## 配置选项
|
|
105
136
|
|
|
106
|
-
|
|
137
|
+
| 选项 | 类型 | 默认值 | 描述 |
|
|
138
|
+
| --------------- | --------- | ------- | ------------------------------------------------------ |
|
|
139
|
+
| `enableLogging` | `boolean` | `false` | 是否启用日志输出,开启后会输出详细的处理过程和调试信息 |
|
|
107
140
|
|
|
108
|
-
|
|
109
|
-
- **Vue**: 🚧 接口已预留,等待实现
|
|
141
|
+
## 处理的文件类型
|
|
110
142
|
|
|
111
|
-
|
|
143
|
+
插件会处理以下文件类型:
|
|
112
144
|
|
|
113
|
-
|
|
145
|
+
- Vue 文件: `.vue` 文件
|
|
146
|
+
- JSX/TSX 文件: `.jsx`, `.tsx` 文件
|
|
147
|
+
- 包含 JSX 语法的 JS/TS 文件: `.js`, `.ts` 文件
|
|
114
148
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
149
|
+
## 依赖关系
|
|
150
|
+
|
|
151
|
+
该插件依赖于 `@meituan-nocode/nocode-compiler-core` 包,它提供了核心的编译逻辑:
|
|
118
152
|
|
|
119
|
-
|
|
120
|
-
|
|
153
|
+
- Vue 组件编译器 (`VueCompiler`)
|
|
154
|
+
- JSX 组件编译器 (`JSXCompiler`)
|
|
155
|
+
- 代码转换器 (`CodeTransformer`)
|
|
156
|
+
|
|
157
|
+
## 在 monorepo 项目中使用
|
|
158
|
+
|
|
159
|
+
在 monorepo 项目中,可以在各子项目的 `vite.config.js` 中分别配置插件:
|
|
160
|
+
|
|
161
|
+
```js
|
|
162
|
+
// 子项目的 vite.config.js
|
|
163
|
+
import { defineConfig } from 'vite';
|
|
164
|
+
import { NocodeCompiler } from '@meituan-nocode/vite-plugin-nocode-compiler';
|
|
165
|
+
|
|
166
|
+
export default defineConfig({
|
|
167
|
+
plugins: [
|
|
168
|
+
NocodeCompiler({
|
|
169
|
+
enableLogging: true,
|
|
170
|
+
}),
|
|
171
|
+
],
|
|
172
|
+
});
|
|
121
173
|
```
|
|
122
174
|
|
|
123
|
-
##
|
|
175
|
+
## 常见问题
|
|
176
|
+
|
|
177
|
+
### Q: 如何确认插件正在正常工作?
|
|
178
|
+
|
|
179
|
+
A: 开启 `enableLogging` 选项,构建时会输出详细的处理日志,包括检测到的框架类型和处理的文件。
|
|
180
|
+
|
|
181
|
+
### Q: 插件处理哪些文件类型?
|
|
182
|
+
|
|
183
|
+
A: 插件会处理以下文件类型:
|
|
184
|
+
|
|
185
|
+
- Vue 框架: `.vue` 文件
|
|
186
|
+
- React 框架: `.jsx`, `.tsx` 文件,以及包含 JSX 语法的 `.js`, `.ts` 文件
|
|
187
|
+
|
|
188
|
+
### Q: 如何在 monorepo 项目中使用?
|
|
189
|
+
|
|
190
|
+
A: 在各子项目的 `vite.config.js` 中分别配置插件即可。如果子项目共享配置,确保正确设置相关选项。
|
|
191
|
+
|
|
192
|
+
### Q: 如何排查插件不工作的问题?
|
|
193
|
+
|
|
194
|
+
A:
|
|
124
195
|
|
|
125
|
-
|
|
196
|
+
1. 确保 `vite.config.js` 中正确导入和配置了插件
|
|
197
|
+
2. 开启 `enableLogging: true` 查看详细日志
|
|
198
|
+
3. 检查项目中是否有需要处理的 Vue 或 JSX/TSX 文件
|
|
199
|
+
4. 确认 Vite 版本兼容性(支持 Vite 4.x 和 5.x)
|
|
126
200
|
|
|
127
|
-
##
|
|
201
|
+
## 许可证
|
|
128
202
|
|
|
129
|
-
|
|
203
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const m=require("@meituan-nocode/nocode-compiler-core");function f(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const p=f(m),d=[".js",".ts",".mjs",".mts",".jsx",".tsx"],g=["isJsx","isTsx","lang.jsx","lang.tsx"];function j(e){return d.some(t=>e.endsWith(t))}const{CodeTransformer:x}=p;function i(e={}){const t=new x(e);return{name:"vite-plugin-nocode-compiler",enforce:"pre",async transform(n,r){if(r.includes("node_modules"))return null;const[a,u]=r.split("?",2);let o=a;const s=new URLSearchParams(u);let l="";return j(o)||o.endsWith(".vue")&&(g.some(c=>s.get(c)!==null)||s.get("lang")==="tsx"||s.get("lang")==="jsx")?l="jsx":(o.endsWith(".html")&&s.get("type")==="template"&&s.has("vue")||o.endsWith(".vue")&&s.get("type")!=="style"&&s.get("raw")===null)&&(l="vue"),l?t.transformCode({content:n,filePath:o,fileType:l}):n}}}exports.NocodeCompiler=i;exports.default=i;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export interface NocodeCompilerOptions {
|
|
2
|
+
enableLogging?: boolean;
|
|
3
|
+
entryFileMarker?: boolean;
|
|
4
|
+
}
|
|
3
5
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
6
|
+
* Vite插件
|
|
7
|
+
* 用于在构建过程中处理Vue和React组件,添加nocode相关的标记
|
|
8
|
+
* 兼容 Vite 4.x 和 5.x 版本
|
|
7
9
|
*/
|
|
8
|
-
export declare function
|
|
10
|
+
export declare function NocodeCompiler(options?: NocodeCompilerOptions): {
|
|
11
|
+
name: string;
|
|
12
|
+
enforce: "pre";
|
|
13
|
+
transform(code: string, id: string): Promise<string | null>;
|
|
14
|
+
};
|
|
15
|
+
export default NocodeCompiler;
|
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as u from "@meituan-nocode/nocode-compiler-core";
|
|
2
|
+
const c = [".js", ".ts", ".mjs", ".mts", ".jsx", ".tsx"], f = ["isJsx", "isTsx", "lang.jsx", "lang.tsx"];
|
|
3
|
+
function p(n) {
|
|
4
|
+
return c.some((r) => n.endsWith(r));
|
|
5
|
+
}
|
|
6
|
+
const { CodeTransformer: x } = u;
|
|
7
|
+
function d(n = {}) {
|
|
8
|
+
const r = new x(n);
|
|
9
|
+
return {
|
|
10
|
+
name: "vite-plugin-nocode-compiler",
|
|
11
|
+
enforce: "pre",
|
|
12
|
+
async transform(o, l) {
|
|
13
|
+
if (l.includes("node_modules"))
|
|
14
|
+
return null;
|
|
15
|
+
const [i, a] = l.split("?", 2);
|
|
16
|
+
let t = i;
|
|
17
|
+
const e = new URLSearchParams(a);
|
|
18
|
+
let s = "";
|
|
19
|
+
return p(t) || t.endsWith(".vue") && (f.some((m) => e.get(m) !== null) || e.get("lang") === "tsx" || e.get("lang") === "jsx") ? s = "jsx" : (t.endsWith(".html") && e.get("type") === "template" && e.has("vue") || t.endsWith(".vue") && e.get("type") !== "style" && e.get("raw") === null) && (s = "vue"), s ? r.transformCode({
|
|
20
|
+
content: o,
|
|
21
|
+
filePath: t,
|
|
22
|
+
fileType: s
|
|
23
|
+
}) : o;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
d as NocodeCompiler,
|
|
29
|
+
d as default
|
|
30
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -1,63 +1,103 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
36
|
+
exports.NocodeCompiler = NocodeCompiler;
|
|
37
|
+
const compilerCore = __importStar(require("@meituan-nocode/nocode-compiler-core"));
|
|
38
|
+
const { CodeTransformer } = compilerCore;
|
|
39
|
+
const utils_1 = require("./utils");
|
|
40
|
+
// 检查是否安装了@vue/compiler-dom
|
|
41
|
+
let vueCompilerAvailable = false;
|
|
42
|
+
try {
|
|
43
|
+
require('@vue/compiler-dom');
|
|
44
|
+
vueCompilerAvailable = true;
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
console.warn('[vite-plugin-nocode-compiler] @vue/compiler-dom not found. Vue compilation will be skipped.');
|
|
48
|
+
}
|
|
8
49
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
50
|
+
* Vite插件
|
|
51
|
+
* 用于在构建过程中处理Vue和React组件,添加nocode相关的标记
|
|
52
|
+
* 兼容 Vite 4.x 和 5.x 版本
|
|
12
53
|
*/
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
54
|
+
function NocodeCompiler(options = {}) {
|
|
55
|
+
options = {
|
|
56
|
+
enableLogging: false,
|
|
57
|
+
entryFileMarker: false,
|
|
17
58
|
...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
59
|
};
|
|
22
|
-
//
|
|
23
|
-
const
|
|
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();
|
|
60
|
+
// 创建代码转换器实例
|
|
61
|
+
const codeTransformer = new CodeTransformer(options);
|
|
38
62
|
return {
|
|
39
63
|
name: 'vite-plugin-nocode-compiler',
|
|
40
64
|
enforce: 'pre',
|
|
41
65
|
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) {
|
|
66
|
+
// 跳过node_modules
|
|
67
|
+
if (id.includes('node_modules')) {
|
|
50
68
|
return null;
|
|
51
69
|
}
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
|
|
70
|
+
const [_completePath, query] = id.split('?', 2); // 当前文件的绝对路径
|
|
71
|
+
let filePath = _completePath;
|
|
72
|
+
const params = new URLSearchParams(query);
|
|
73
|
+
let fileType = '';
|
|
74
|
+
if ((0, utils_1.isJsTypeFile)(filePath) || (filePath.endsWith('.vue') && (utils_1.jsxParamList.some(param => params.get(param) !== null) || params.get('lang') === 'tsx' || params.get('lang') === 'jsx'))) {
|
|
75
|
+
// jsx 代码
|
|
76
|
+
fileType = 'jsx';
|
|
77
|
+
}
|
|
78
|
+
else if (filePath.endsWith('.html') && params.get('type') === 'template' && params.has('vue')) {
|
|
79
|
+
// <template src="xxx.html"></template>
|
|
80
|
+
fileType = 'vue';
|
|
81
|
+
}
|
|
82
|
+
else if (filePath.endsWith('.vue') && params.get('type') !== 'style' && params.get('raw') === null) {
|
|
83
|
+
// vue 代码
|
|
84
|
+
fileType = 'vue';
|
|
85
|
+
}
|
|
86
|
+
// 如果是Vue文件但@vue/compiler-dom不可用,跳过处理
|
|
87
|
+
if (fileType === 'vue' && !vueCompilerAvailable) {
|
|
88
|
+
console.warn(`[vite-plugin-nocode-compiler] Skipping Vue file processing for ${filePath} due to missing @vue/compiler-dom`);
|
|
89
|
+
return code;
|
|
90
|
+
}
|
|
91
|
+
if (fileType) {
|
|
92
|
+
return codeTransformer.transformCode({
|
|
93
|
+
content: code,
|
|
94
|
+
filePath,
|
|
95
|
+
fileType,
|
|
96
|
+
});
|
|
59
97
|
}
|
|
60
|
-
return
|
|
98
|
+
return code;
|
|
61
99
|
},
|
|
62
100
|
};
|
|
63
101
|
}
|
|
102
|
+
// 添加默认导出,使 ESM 导入更方便
|
|
103
|
+
exports.default = NocodeCompiler;
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const JsFileExtList: string[];
|
|
2
|
+
export declare const jsxParamList: string[];
|
|
3
|
+
export declare function isJsTypeFile(file: string): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* 规范化路径,将反斜杠转换为正斜杠
|
|
6
|
+
* @param filePath 文件路径
|
|
7
|
+
* @returns 规范化后的路径
|
|
8
|
+
*/
|
|
9
|
+
export declare function normalizePath(filePath: string): string;
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.jsxParamList = exports.JsFileExtList = void 0;
|
|
4
|
+
exports.isJsTypeFile = isJsTypeFile;
|
|
5
|
+
exports.normalizePath = normalizePath;
|
|
6
|
+
exports.JsFileExtList = ['.js', '.ts', '.mjs', '.mts', '.jsx', '.tsx'];
|
|
7
|
+
exports.jsxParamList = ['isJsx', 'isTsx', 'lang.jsx', 'lang.tsx'];
|
|
8
|
+
// 是否为 JS 类型的文件
|
|
9
|
+
function isJsTypeFile(file) {
|
|
10
|
+
return exports.JsFileExtList.some(ext => file.endsWith(ext));
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 规范化路径,将反斜杠转换为正斜杠
|
|
14
|
+
* @param filePath 文件路径
|
|
15
|
+
* @returns 规范化后的路径
|
|
16
|
+
*/
|
|
17
|
+
function normalizePath(filePath) {
|
|
18
|
+
return filePath.replace(/\\/g, '/');
|
|
19
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meituan-nocode/vite-plugin-nocode-compiler",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
4
|
-
"description": "nocode
|
|
5
|
-
"
|
|
6
|
-
"
|
|
3
|
+
"version": "0.1.0-beta.20-z",
|
|
4
|
+
"description": "nocode compiler plugin",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.cjs.js",
|
|
7
|
+
"module": "dist/index.es.js",
|
|
7
8
|
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"require": "./dist/index.cjs.js",
|
|
12
|
+
"import": "./dist/index.es.js",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
8
16
|
"files": [
|
|
9
17
|
"dist"
|
|
10
18
|
],
|
|
@@ -13,18 +21,12 @@
|
|
|
13
21
|
"build": "tsc",
|
|
14
22
|
"prepublishOnly": "npm run build"
|
|
15
23
|
},
|
|
16
|
-
"peerDependencies": {
|
|
17
|
-
"vite": "^5.4.0"
|
|
18
|
-
},
|
|
19
24
|
"devDependencies": {
|
|
20
25
|
"@types/node": "^20.0.0",
|
|
21
26
|
"typescript": "^5.0.0",
|
|
22
|
-
"vite": "^5.
|
|
27
|
+
"vite": "^4.5.14"
|
|
23
28
|
},
|
|
24
29
|
"dependencies": {
|
|
25
|
-
"@
|
|
26
|
-
"@babel/types": "^7.23.0",
|
|
27
|
-
"magic-string": "^0.30.0",
|
|
28
|
-
"estree-walker": "^3.0.0"
|
|
30
|
+
"@meituan-nocode/nocode-compiler-core": "0.1.0-beta.20-z"
|
|
29
31
|
}
|
|
30
32
|
}
|
|
@@ -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,157 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.JSXCompiler = void 0;
|
|
40
|
-
const parser_1 = require("@babel/parser");
|
|
41
|
-
const magic_string_1 = __importDefault(require("magic-string"));
|
|
42
|
-
const path_1 = __importDefault(require("path"));
|
|
43
|
-
const utils_1 = require("../utils/utils");
|
|
44
|
-
/**
|
|
45
|
-
* JSX 编译器类
|
|
46
|
-
* 负责处理 JSX 文件的编译逻辑
|
|
47
|
-
*/
|
|
48
|
-
class JSXCompiler {
|
|
49
|
-
static supportedExtensions = ['.jsx'];
|
|
50
|
-
static name = 'jsx';
|
|
51
|
-
options;
|
|
52
|
-
logger;
|
|
53
|
-
cwd;
|
|
54
|
-
constructor(options) {
|
|
55
|
-
this.options = options;
|
|
56
|
-
this.logger = new utils_1.Logger(options.enableLogging);
|
|
57
|
-
this.cwd = process.cwd();
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* 编译 JSX 代码
|
|
61
|
-
*/
|
|
62
|
-
async compile(code, id) {
|
|
63
|
-
this.logger.log('\nProcessing file:', id);
|
|
64
|
-
if (!(0, utils_1.shouldProcessFile)(id, this.options.validExtensions)) {
|
|
65
|
-
this.logger.log('Skipping file (not .jsx or in node_modules):', id);
|
|
66
|
-
return null;
|
|
67
|
-
}
|
|
68
|
-
const relativePath = path_1.default.relative(this.cwd, id);
|
|
69
|
-
this.logger.log('Relative path:', relativePath);
|
|
70
|
-
try {
|
|
71
|
-
const parserOptions = {
|
|
72
|
-
sourceType: 'module',
|
|
73
|
-
plugins: ['jsx'],
|
|
74
|
-
};
|
|
75
|
-
const ast = (0, parser_1.parse)(code, parserOptions);
|
|
76
|
-
const magicString = new magic_string_1.default(code);
|
|
77
|
-
let changedElementsCount = 0;
|
|
78
|
-
let currentElement = null;
|
|
79
|
-
let arrayContext = null;
|
|
80
|
-
const { walk } = await Promise.resolve().then(() => __importStar(require('estree-walker')));
|
|
81
|
-
walk(ast, {
|
|
82
|
-
enter: (node) => {
|
|
83
|
-
// 检测数组的 map 调用
|
|
84
|
-
if (node.type === 'CallExpression' && node.callee?.type === 'MemberExpression' && node.callee.property?.name === 'map') {
|
|
85
|
-
this.logger.log('Found array map:', node);
|
|
86
|
-
const callee = node.callee;
|
|
87
|
-
const arrayName = callee.object.name || (callee.object.type === 'MemberExpression' ? `${callee.object.object.name}.${callee.object.property.name}` : null);
|
|
88
|
-
if (arrayName) {
|
|
89
|
-
const paramName = node.arguments[0].params?.[1]?.name || 'index';
|
|
90
|
-
arrayContext = { arrayName, paramName };
|
|
91
|
-
this.logger.log('Found array map:', { arrayName, paramName });
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if (node.type === 'JSXElement') {
|
|
95
|
-
currentElement = node;
|
|
96
|
-
}
|
|
97
|
-
if (node.type === 'JSXOpeningElement') {
|
|
98
|
-
const jsxNode = node;
|
|
99
|
-
let elementName;
|
|
100
|
-
if (jsxNode.name.type === 'JSXIdentifier') {
|
|
101
|
-
elementName = jsxNode.name.name;
|
|
102
|
-
}
|
|
103
|
-
else if (jsxNode.name.type === 'JSXMemberExpression') {
|
|
104
|
-
const memberExpr = jsxNode.name;
|
|
105
|
-
elementName = `${memberExpr.object.name}.${memberExpr.property.name}`;
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
if (elementName === 'Fragment' || elementName === 'React.Fragment') {
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
const shouldTag = (0, utils_1.shouldTagElement)(elementName, this.options.threeFiberElems, this.options.dreiElems);
|
|
114
|
-
this.logger.log('Found JSX element:', {
|
|
115
|
-
elementName,
|
|
116
|
-
shouldTag,
|
|
117
|
-
hasArrayContext: !!arrayContext,
|
|
118
|
-
});
|
|
119
|
-
if (shouldTag) {
|
|
120
|
-
const line = jsxNode.loc?.start?.line ?? 0;
|
|
121
|
-
const col = jsxNode.loc?.start?.column ?? 0;
|
|
122
|
-
const attributes = (0, utils_1.generateDataAttributes)(relativePath, line, col, elementName, arrayContext);
|
|
123
|
-
this.logger.log('Adding attributes:', attributes);
|
|
124
|
-
magicString.appendLeft(jsxNode.name.end ?? 0, attributes);
|
|
125
|
-
changedElementsCount++;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
},
|
|
129
|
-
leave: (node) => {
|
|
130
|
-
if (node.type === 'CallExpression' && node.callee?.type === 'MemberExpression' && node.callee.property?.name === 'map') {
|
|
131
|
-
if (arrayContext) {
|
|
132
|
-
this.logger.log('Leaving array map context:', arrayContext.arrayName);
|
|
133
|
-
}
|
|
134
|
-
arrayContext = null;
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
this.logger.log('File processing complete:', {
|
|
139
|
-
file: relativePath,
|
|
140
|
-
elementsChanged: changedElementsCount,
|
|
141
|
-
});
|
|
142
|
-
if (changedElementsCount > 0) {
|
|
143
|
-
this.logger.log('Modified code preview:', magicString.toString().slice(0, 500) + '...');
|
|
144
|
-
}
|
|
145
|
-
return {
|
|
146
|
-
code: magicString.toString(),
|
|
147
|
-
map: magicString.generateMap({ hires: true }),
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
catch (error) {
|
|
151
|
-
this.logger.error('Error processing file:', relativePath);
|
|
152
|
-
this.logger.error('Error', error);
|
|
153
|
-
return null;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
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}" data-nocode-index="\${${arrayContext.paramName}}"`;
|
|
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
|
-
}
|