chore: 容器框架升级,修复项目命令行异常问题

This commit is contained in:
wangxuefeng
2025-03-11 10:05:28 +08:00
parent de679d4289
commit 3e1a1b4a66
1187 changed files with 95352 additions and 12509 deletions

View File

@@ -0,0 +1,17 @@
# 只在开发模式中被载入
VITE_NODE_ENV = 'development'
# 公共基础路径, 详见: https://cn.vitejs.dev/guide/build.html#public-base-path
VITE_BASE_URL = /
# 前端可见变量(必须以 VITE_ 开头)
VITE_PORT = 10012
# VITE_BASE_API_URL = 'https://custom-chart-pre-api.shiyue.com/'
VITE_BASE_API_URL = 'https://custom-chart-api.shiyuegame.com/'
VITE_DEBUG_MODE = true
VITE_PLATFORM_URL = 'https://localhost:10010/'
VITE_DESIGNER_URL = 'https://localhost:10011/'
VITE_RENDERER_URL = 'https://localhost:10012/'

View File

@@ -0,0 +1,11 @@
# 只在生产模式中被载入
VITE_NODE_ENV = 'production'
# 公共基础路径, 详见: https://cn.vitejs.dev/guide/build.html#public-base-path
VITE_BASE_URL = /
VITE_BASE_API_URL = 'https://custom-chart-api.shiyuegame.com/'
VITE_PLATFORM_URL = 'https://y-code-platform.shiyuegame.com/'
VITE_DESIGNER_URL = 'https://y-code-designer.shiyuegame.com/'
VITE_RENDERER_URL = 'https://y-code-renderer.shiyuegame.com/'

View File

@@ -0,0 +1,15 @@
# 只在预发布模式中被载入
VITE_NODE_ENV = 'staging'
# 公共基础路径, 详见: https://cn.vitejs.dev/guide/build.html#public-base-path
VITE_BASE_URL = /
# 端口
VITE_PORT = 10010
# base api url
VITE_BASE_API_URL = 'https://custom-chart-pre-api.shiyue.com/'
VITE_PLATFORM_URL = 'https://y-code-platform-pre.shiyue.com/'
VITE_DESIGNER_URL = 'https://y-code-designer-pre.shiyue.com/'
VITE_RENDERER_URL = 'https://y-code-renderer-pre.shiyue.com/'

22
apps/renderer/.gitignore vendored Normal file
View File

@@ -0,0 +1,22 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.sln
*.sw?

7
apps/renderer/.npmrc Normal file
View File

@@ -0,0 +1,7 @@
# 使用淘宝镜像源
registry = https://registry.npmmirror.com
@sy:registry=http://sy-registry.shiyue.com
enable-pre-post-scripts=true
engine-strict=true
package-manager-strict=false

37
apps/renderer/README.md Normal file
View File

@@ -0,0 +1,37 @@
# Farm + Vue
This template should help you start developing using Vue and TypeScript in Farm.
## Setup
Install the dependencies:
```bash
pnpm install
```
## Get Started
Start the dev server:
```bash
pnpm start
```
Build the app for production:
```bash
pnpm build
```
Preview the Production build product:
```bash
pnpm preview
```
Clear persistent cache local files
```bash
pnpm clean
```

8
apps/renderer/env.d.ts vendored Normal file
View File

@@ -0,0 +1,8 @@
/// <reference types="vite/client" />
interface ImportMeta {
readonly env: {
NODE_ENV: "development" | "production";
VITE_API_BASE?: string;
};
}

View File

@@ -0,0 +1,39 @@
import path from 'node:path';
import { defineConfig, loadEnv } from '@farmfe/core';
import vue from '@vitejs/plugin-vue';
import mkcert from 'vite-plugin-mkcert';
// @ts-ignore
export default defineConfig(({ mode }) => {
console.log('mode', mode);
const env = loadEnv(mode, process.cwd(), ['VITE_', 'Y_CODE_']);
return {
server: {
port: Number(env.VITE_PORT),
cors: true,
},
// @ts-ignore coding
vitePlugins: [vue(), mkcert({ source: 'coding' })],
compilation: {
resolve: {
alias: {
'@': path.resolve(process.cwd(), 'src'),
$vtj: path.resolve(process.cwd(), '.vtj'),
},
},
define: {
// 注入环境变量到客户端
'process.env': JSON.stringify(env),
},
// output: {
// path: path.resolve(process.cwd(), "../../dist/renderer"),
// clean: true,
// },
script: {
target: 'es2022',
},
},
};
});

14
apps/renderer/index.html Normal file
View File

@@ -0,0 +1,14 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
<title>Farm + Vue3 + TS</title>
</head>
<body>
<div id="y-code-renderer"></div>
<script src="./src/index.ts"></script>
</body>
</html>

View File

@@ -0,0 +1,43 @@
{
"name": "@sy/y-code-renderer",
"version": "1.0.0",
"type": "module",
"scripts": {
"dev": "farm dev --mode development",
"start": "farm start --mode production",
"build": "farm build --mode production",
"build:staging": "farm build --mode staging",
"preview": "farm preview",
"clean:lock": "rimraf pnpm-lock.yaml && rimraf package.lock.json",
"clean:lib": "rimraf node_modules",
"test": "echo 'test",
"clean": "rimraf node_modules"
},
"dependencies": {
"@iframe-resizer/child": "^5.3.3",
"@sy/web-vitals": "workspace:*",
"@tanstack/vue-query": "^5.66.9",
"@vtj/core": "^0.10.10",
"@vtj/icons": "0.10.10",
"@vtj/materials": "^0.10.10",
"@vtj/pro": "^0.10.10",
"@vtj/renderer": "^0.10.10",
"@vtj/ui": "^0.10.10",
"@vtj/utils": "^0.10.10",
"@vtj/web": "^0.10.10",
"axios": "catalog:",
"core-js": "^3.40.0",
"element-plus": "catalog:",
"licia-es": "^1.46.0",
"postmate": "catalog:",
"rrweb": "2.0.0-alpha.4",
"vue": "catalog:"
},
"devDependencies": {
"@farmfe/cli": "^1.0.4",
"@farmfe/core": "^1.6.6",
"@vitejs/plugin-vue": "^5.2.1",
"@vtj/cli": "^0.10.2",
"vite-plugin-mkcert": "catalog:"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

80
apps/renderer/src/App.vue Normal file
View File

@@ -0,0 +1,80 @@
<script setup lang="ts">
import { computed, watch, ref, getCurrentInstance } from 'vue'
import { ElLoading } from 'element-plus'
import Postmate from 'postmate'
import { createProvider } from '@vtj/web'
import { useQuery } from '@tanstack/vue-query'
import { LowCodeService } from './service'
import { getFile } from './io'
import { request, jsonp } from '@vtj/utils'
// import * as VtjUI from '@vtj/ui'
// 响应式状态
const renderer = ref()
const lowCodeService = new LowCodeService()
// Postmate 握手协议
const postmate = new Postmate.Model({
sayHi: (data: any) => {
console.log('sayHi',data)
}
})
// 数据模型
const model = {
name: '',
applicationId: -1,
projectId: -1,
fileId: '',
url: '',
accessToken: ''
}
// 数据查询
const { data: file, isFetching } = useQuery({
queryKey: ['getFile'],
queryFn: async () => {
await postmate.then((parent) => {
parent.emit('some-event', 'y-code-renderer is ready')
Object.assign(model, parent.model)
localStorage.setItem('y-code-access-token', model.accessToken || '')
})
return getFile(model.fileId).then(() => {
request.useRequest((req) => {
req.headers.set('Authorization', `Bearer ${model.accessToken}`)
return req
})
const { provider, onReady } = createProvider({
nodeEnv: import.meta.env.NODE_ENV,
service: lowCodeService,
project: { id: model.projectId },
adapter: {
request,
jsonp
}
})
onReady(async () => {
const instance = getCurrentInstance()
instance?.appContext.app.use(provider)
renderer.value = await provider.getRenderComponent(model.fileId)
})
})
}
})
// 加载状态监控
watch(isFetching, (newVal) => {
if (newVal) {
ElLoading.service({ text: '低代码文件加载中...' })
} else {
ElLoading.service().close()
}
})
</script>
<template>
<div style="padding: 20px;">
<component :is="renderer" v-if="renderer" />
</div>
</template>

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>

After

Width:  |  Height:  |  Size: 496 B

View File

@@ -0,0 +1,2 @@
// @ts-ignore
export const currentEnv = __APP_ENV__;

View File

@@ -0,0 +1 @@
export * from "./env";

2
apps/renderer/src/env.d.ts vendored Normal file
View File

@@ -0,0 +1,2 @@
declare module '*.vue';
declare module '*.svg';

View File

@@ -0,0 +1,25 @@
import { createApp } from 'vue';
import { VueQueryPlugin } from '@tanstack/vue-query';
import { IconsPlugin } from '@vtj/icons';
import * as VtjUI from '@vtj/ui';
import ElementPlus from 'element-plus';
import App from './App.vue';
import '@sy/web-vitals';
import 'element-plus/dist/index.css';
import '@vtj/ui/dist/style.css';
const app = createApp(App);
// 批量注册组件
Object.entries(VtjUI).forEach(([name, component]) => {
app.component(name, component);
});
app
.use(ElementPlus)
.use(IconsPlugin)
.use(VueQueryPlugin)
.mount('#y-code-renderer');

View File

@@ -0,0 +1,16 @@
import { BlockSchema } from "@vtj/core";
import instance from "./instance";
export type LowCodeFileSchema = {
project_id: number;
publish: boolean;
active: boolean;
dsl: BlockSchema;
file_path?: string;
file_id?: string;
};
export const getFile = async (id: string): Promise<LowCodeFileSchema> => {
const response = await instance.get(`/api/v1/files/${id}`);
return response.data;
};

View File

@@ -0,0 +1,2 @@
export * from "./file";
export * from "./project";

View File

@@ -0,0 +1,28 @@
import axios from "axios";
// 创建独立实例
const instance = axios.create({
baseURL: import.meta.env.VITE_BASE_API_URL, // 基础URL直接放在实例配置中
});
// 请求拦截器改为使用实例
instance.interceptors.request.use(
(config) => {
// 可在此处添加统一请求头等配置
return config;
},
(error) => {
return Promise.reject(error);
}
);
instance.interceptors.response.use(
(response) => {
return response.data;
},
(error) => {
return Promise.reject(error);
}
);
// 导出实例
export default instance;

View File

@@ -0,0 +1,6 @@
import instance from "./instance";
export const getProject = async (id: string) => {
const response = await instance.get(`/api/v1/projects/${id}`);
return response.data;
};

View File

@@ -0,0 +1,43 @@
import { type ProjectSchema, type BlockSchema, ProjectModel } from "@vtj/core";
import { BaseService } from "@vtj/renderer";
import { getProject, getFile as getLowCodeFile } from "@/io";
let initProject: ProjectModel = {};
export class LowCodeService extends BaseService {
public async init(project: ProjectSchema) {
console.log("init", project);
initProject = project;
const remoteProject = await getProject(project.id);
console.log("remoteProject", remoteProject);
const model = new ProjectModel(remoteProject);
const dsl = model.toDsl();
return Promise.resolve(dsl);
}
public saveProject(project: ProjectSchema): Promise<boolean> {
const newProject = {
...project,
...Object.fromEntries(
Object.entries(project)
.filter(([key]) => stringifyFields.includes(key))
.map(([key, value]) => [key, JSON.stringify(value)])
),
};
updateProject(initProject.id, newProject);
const model = new ProjectModel(newProject);
// storage.save(`project_${model.id}`, model.toDsl());
return Promise.resolve(true);
}
public async getFile(id: string): Promise<BlockSchema> {
console.log("service getFile", id);
return getLowCodeFile(id).then((lowCodeFile) => {
if (lowCodeFile.dsl) {
return Promise.resolve(lowCodeFile.dsl as BlockSchema);
} else {
return Promise.reject(null);
}
});
}
}

View File

View File

@@ -0,0 +1,21 @@
{
"extends": "./node_modules/@vtj/cli/config/tsconfig.web.json",
"compilerOptions": {
"module": "nodenext",
"lib": ["ESNext", "DOM"],
"moduleResolution": "nodenext",
"noUnusedLocals": false,
"noUnusedParameters": false,
"baseUrl": "./",
"paths": {
"@/*": ["src/*"]
}
},
"include": ["src"],
"exclude": [".vtj"],
"references": [
{
"path": "./tsconfig.node.json"
}
]
}

View File

@@ -0,0 +1,10 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}