@meituan-nocode/vite-plugin-nocode-compiler 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +5 -2
- package/package.json +1 -4
- package/dist/framework-detector.d.ts +0 -13
- package/dist/framework-detector.js +0 -85
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import type { Plugin } from 'vite';
|
|
2
1
|
export interface NocodeCompilerOptions {
|
|
3
2
|
enableLogging?: boolean;
|
|
4
3
|
rootPath?: string;
|
|
5
4
|
}
|
|
6
|
-
export declare function componentCompiler(options?: NocodeCompilerOptions):
|
|
5
|
+
export declare function componentCompiler(options?: NocodeCompilerOptions): {
|
|
6
|
+
name: string;
|
|
7
|
+
enforce: "pre";
|
|
8
|
+
transform(code: string, id: string): Promise<string | null>;
|
|
9
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meituan-nocode/vite-plugin-nocode-compiler",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Vite plugin for nocode compiler",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -13,9 +13,6 @@
|
|
|
13
13
|
"build": "tsc",
|
|
14
14
|
"prepublishOnly": "npm run build"
|
|
15
15
|
},
|
|
16
|
-
"peerDependencies": {
|
|
17
|
-
"vite": "^5.4.0"
|
|
18
|
-
},
|
|
19
16
|
"devDependencies": {
|
|
20
17
|
"@types/node": "^20.0.0",
|
|
21
18
|
"typescript": "^5.0.0",
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export type FrameworkType = 'vue' | 'react';
|
|
2
|
-
/**
|
|
3
|
-
* 框架检测器
|
|
4
|
-
* 按优先级检测项目使用的前端框架
|
|
5
|
-
* 1. 首先检查是否强制指定了框架
|
|
6
|
-
* 2. 然后检查package.json中的依赖(React依赖优先于Vue依赖)
|
|
7
|
-
* 3. 接着检查src目录下是否有框架特定文件(JSX/TSX文件优先于Vue文件)
|
|
8
|
-
* 4. 如果以上都没有检测到,默认返回React
|
|
9
|
-
*/
|
|
10
|
-
export declare function detectFramework(options?: {
|
|
11
|
-
forceFramework?: FrameworkType;
|
|
12
|
-
enableLogging?: boolean;
|
|
13
|
-
}): FrameworkType;
|
|
@@ -1,85 +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.detectFramework = detectFramework;
|
|
7
|
-
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
/**
|
|
10
|
-
* 框架检测器
|
|
11
|
-
* 按优先级检测项目使用的前端框架
|
|
12
|
-
* 1. 首先检查是否强制指定了框架
|
|
13
|
-
* 2. 然后检查package.json中的依赖(React依赖优先于Vue依赖)
|
|
14
|
-
* 3. 接着检查src目录下是否有框架特定文件(JSX/TSX文件优先于Vue文件)
|
|
15
|
-
* 4. 如果以上都没有检测到,默认返回React
|
|
16
|
-
*/
|
|
17
|
-
function detectFramework(options) {
|
|
18
|
-
const log = (message, ...args) => {
|
|
19
|
-
if (options?.enableLogging) {
|
|
20
|
-
console.log(`[vite-nocode-compiler] ${message}`, ...args);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
// 1. 如果强制指定了框架,直接返回
|
|
24
|
-
if (options?.forceFramework) {
|
|
25
|
-
log('Using forced framework:', options.forceFramework);
|
|
26
|
-
return options.forceFramework;
|
|
27
|
-
}
|
|
28
|
-
try {
|
|
29
|
-
// 2. 检查package.json
|
|
30
|
-
const packagePath = path_1.default.resolve(process.cwd(), 'package.json');
|
|
31
|
-
log('Checking package.json:', packagePath);
|
|
32
|
-
if (fs_1.default.existsSync(packagePath)) {
|
|
33
|
-
try {
|
|
34
|
-
const pkg = JSON.parse(fs_1.default.readFileSync(packagePath, 'utf8'));
|
|
35
|
-
const deps = { ...(pkg.dependencies || {}), ...(pkg.devDependencies || {}) };
|
|
36
|
-
log('Package dependencies:', deps);
|
|
37
|
-
// React相关依赖(优先检查React,因为Vue项目可能也会依赖React组件)
|
|
38
|
-
if (deps.react || deps['react-dom']) {
|
|
39
|
-
log('React dependency detected');
|
|
40
|
-
return 'react';
|
|
41
|
-
}
|
|
42
|
-
// Vue相关依赖
|
|
43
|
-
if (deps.vue || deps['@vue/cli-service'] || deps.nuxt || deps['@vitejs/plugin-vue']) {
|
|
44
|
-
log('Vue dependency detected');
|
|
45
|
-
return 'vue';
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
catch (e) {
|
|
49
|
-
log('Failed to parse package.json:', e);
|
|
50
|
-
// 解析package.json失败,继续下一步检测
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
// 3. 快速检查src目录下是否有框架特定文件(不递归)
|
|
54
|
-
const srcDir = path_1.default.resolve(process.cwd(), 'src');
|
|
55
|
-
log('Checking src directory:', srcDir);
|
|
56
|
-
if (fs_1.default.existsSync(srcDir)) {
|
|
57
|
-
try {
|
|
58
|
-
const files = fs_1.default.readdirSync(srcDir);
|
|
59
|
-
log('Files in src directory:', files);
|
|
60
|
-
// 检查是否有.jsx/.tsx文件(优先检查React文件)
|
|
61
|
-
if (files.some(file => file.endsWith('.jsx') || file.endsWith('.tsx'))) {
|
|
62
|
-
log('JSX/TSX file detected');
|
|
63
|
-
return 'react';
|
|
64
|
-
}
|
|
65
|
-
// 检查是否有.vue文件
|
|
66
|
-
if (files.some(file => file.endsWith('.vue'))) {
|
|
67
|
-
log('Vue file detected');
|
|
68
|
-
return 'vue';
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
catch (e) {
|
|
72
|
-
log('Failed to read src directory:', e);
|
|
73
|
-
// 读取目录失败,继续使用默认值
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
// 4. 默认返回React
|
|
77
|
-
log('No framework detected, using default: react');
|
|
78
|
-
return 'react';
|
|
79
|
-
}
|
|
80
|
-
catch (e) {
|
|
81
|
-
log('Error in detectFramework:', e);
|
|
82
|
-
// 出现任何错误,默认使用React
|
|
83
|
-
return 'react';
|
|
84
|
-
}
|
|
85
|
-
}
|