@meituan-nocode/vite-plugin-nocode-compiler 0.1.0-beta.7 → 0.1.0-beta.9-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.
@@ -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 });