refactor: 悦码项目重构

This commit is contained in:
wangxuefeng
2025-02-19 13:42:56 +08:00
parent c8c9406fd5
commit eab709f94f
494 changed files with 50986 additions and 27639 deletions

22
packages/render-adapter/.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?

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
```

View File

@@ -0,0 +1,12 @@
import { defineConfig } from "@farmfe/core";
import vue from "@vitejs/plugin-vue";
export default defineConfig({
compilation: {
// 只构建组件
input: {
index: "./src/components/index.ts",
},
},
vitePlugins: [vue()],
});

View File

@@ -0,0 +1,16 @@
<!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="app"></div>
<script src="./src/index.ts"></script>
</body>
</html>

View File

@@ -0,0 +1,24 @@
{
"name": "@sy/low-code-render-adapter",
"version": "1.0.0",
"scripts": {
"dev": "farm start",
"start": "farm start",
"build": "farm build",
"preview": "farm preview",
"clean": "farm clean",
"clean:lock": "rimraf pnpm-lock.yaml && rimraf package.lock.json",
"clean:lib": "rimraf node_modules"
},
"dependencies": {
"@sy/low-code-shared": "workspace:*",
"vue": "^3.5.13",
"wujie-vue3": "^1.0.24"
},
"devDependencies": {
"@farmfe/cli": "^1.0.4",
"@farmfe/core": "^1.6.6",
"@vitejs/plugin-vue": "^5.2.1",
"core-js": "^3.40.0"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

@@ -0,0 +1,8 @@
<!-- 仅用于本地调试时预览 -->
<script setup lang="ts">
import Adapter from './components/adapter.vue'
</script>
<template>
<Adapter url="http://localhost:9000/" name="vue3" :plugins="[]" />
</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,66 @@
<script setup lang="ts">
import WujieVue from "wujie-vue3";
type lifecycle = (appWindow: Window) => any;
type loadErrorHandler = (url: string, e: Error) => any;
type startOption = {
/** 唯一性用户必须保证 */
name: string;
/** 需要渲染的url */
url: string;
/** 需要渲染的html, 如果用户已有则无需从url请求 */
html?: string;
/** 渲染的容器 */
// el: HTMLElement | string;
/** 子应用加载时loading元素 */
loading?: HTMLElement;
/** 路由同步开关, false刷新无效但是前进后退依然有效 */
sync?: boolean;
/** 子应用短路径替换,路由同步时生效 */
prefix?: { [key: string]: string };
/** 子应用保活模式state不会丢失 */
alive?: boolean;
/** 注入给子应用的数据 */
props?: { [key: string]: any };
/** js采用fiber模式执行 */
fiber?: boolean;
/** 子应用采用降级iframe方案 */
degrade?: boolean;
/** 自定义运行iframe的属性 */
attrs?: { [key: string]: any };
/** 自定义降级渲染iframe的属性 */
degradeAttrs?: { [key: string]: any };
/** 代码替换钩子 */
replace?: (codeText: string) => string;
/** 自定义fetch资源和接口 */
fetch?: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
/** 子应插件 */
plugins: Array<Plugin>;
/** 子应用生命周期 */
beforeLoad?: lifecycle;
/** 没有做生命周期改造的子应用不会调用 */
beforeMount?: lifecycle;
afterMount?: lifecycle;
beforeUnmount?: lifecycle;
afterUnmount?: lifecycle;
/** 非保活应用不会调用 */
activated?: lifecycle;
deactivated?: lifecycle;
/** 子应用资源加载失败后调用 */
loadError?: loadErrorHandler
};
const containerId = "low-code-render-adapter";
const props = defineProps<startOption>();
</script>
<template>
<div :id="containerId">
<WujieVue v-bind="props" :el="containerId" />
</div>
</template>
<style scoped></style>

View File

@@ -0,0 +1 @@
export { default as Adapter } from "./adapter.vue";

2
packages/render-adapter/src/env.d.ts vendored Normal file
View File

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

View File

@@ -0,0 +1,4 @@
import { createApp } from "vue";
import App from "./App.vue";
createApp(App).mount("#app");

View File

@@ -0,0 +1,31 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"src/index.js",
"src/index.js"
],
"references": [{ "path": "./tsconfig.node.json" }]
}

View File

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

View File

@@ -0,0 +1 @@
export const PORT = 8080;

View File

@@ -0,0 +1,21 @@
{
"name": "@sy/low-code-shared",
"version": "0.0.1",
"private": true,
"main": "./dist/src/index.js",
"types": "./dist/src/index.d.ts",
"exports": {
".": "./dist/src/index.js",
"./constants": "./dist/src/constants/index.js",
"./styles/reset.css": "./src/styles/reset.css"
},
"scripts": {
"build": "rimraf dist && tsc",
"clean:lock": "rimraf pnpm-lock.yaml && rimraf package.lock.json",
"clean:lib": "rimraf node_modules"
},
"devDependencies": {
"rimraf": "^6.0.1",
"typescript": "^5.7.3"
}
}

View File

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

View File

@@ -0,0 +1,51 @@
/* 现代 CSS 重置方案(推荐最佳实践) */
*,
*::before,
*::after {
box-sizing: border-box; /* 1. 使用更直观的盒模型 */
margin: 0; /* 2. 清除默认外边距 */
padding: 0; /* 3. 清除默认内边距 */
}
html {
scroll-behavior: smooth; /* 4. 平滑滚动 */
-webkit-text-size-adjust: 100%; /* 5. 防止字体缩放 */
-webkit-font-smoothing: antialiased; /* 6. 字体抗锯齿 */
}
body {
min-height: 100vh;
line-height: 1.5;
text-rendering: optimizeSpeed; /* 7. 优化文本渲染 */
}
ul[role="list"],
ol[role="list"] {
list-style: none; /* 8. 清除列表样式(保留语义) */
}
a:not([class]) {
text-decoration-skip-ink: auto; /* 9. 链接下划线优化 */
}
img {
max-width: 100%;
display: block; /* 10. 消除图片底部间隙 */
}
button,
input,
select,
textarea {
font: inherit; /* 11. 表单元素字体继承 */
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
animation-duration: 0.01ms !important;
transition-duration: 0.01ms !important;
scroll-behavior: auto !important;
}
}

View File

@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "ESNext",
"moduleResolution": "Node",
"module": "ESNext",
"outDir": "dist",
"declaration": true,
"strict": true,
"skipLibCheck": true,
"useUnknownInCatchVariables": false
}
}

View File

@@ -0,0 +1,21 @@
{
"name": "@sy/vite-plugin-http2-proxy",
"version": "0.0.2",
"type": "module",
"description": "",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": "./dist/index.js",
"scripts": {
"build": "tsc",
"clean:lock": "rimraf pnpm-lock.yaml && rimraf package.lock.json",
"clean:lib": "rimraf node_modules"
},
"license": "MIT",
"dependencies": {
"http2-proxy": "^5.0.53"
},
"devDependencies": {
"vite": "6.1.0"
}
}

View File

@@ -0,0 +1,138 @@
import http2Proxy from "http2-proxy";
import type { Plugin, PluginOption, ProxyOptions } from "vite";
const error = (message: string): never => {
throw new Error(message);
};
export default (options?: Record<string, ProxyOptions>): PluginOption => {
let routes: Record<string, ProxyOptions>;
const configure: Plugin["configureServer"] = ({
middlewares,
httpServer,
}) => {
const proxyOptions = options || routes;
for (const [regexp, serverOptions] of Object.entries(proxyOptions)) {
const {
target,
rewrite,
headers,
ws,
secure = true,
timeout = 30_000,
} = serverOptions;
if (!target) {
continue;
}
const re = new RegExp(regexp);
const urlObj = new URL(target.toString());
if (!urlObj.pathname.endsWith("/")) {
urlObj.pathname += "/";
}
const protocol = /^(http|ws)s?:$/.test(urlObj.protocol)
? (urlObj.protocol as "https" | "http")
: error(`Invalid protocol: ${urlObj.href}`);
const port =
urlObj.port === ""
? { https: 443, http: 80 }[protocol]
: /^\d+$/.test(urlObj.port)
? Number(urlObj.port)
: error(`Invalid port: ${urlObj.href}`);
// TODO unfinished
if (ws && httpServer) {
httpServer?.on("upgrade", (req, socket, head) => {
if (req.url && re.test(req.url)) {
const url = (rewrite?.(req.url) ?? req.url).replace(/^\/+/, "");
const { pathname, search } = new URL(url, urlObj);
http2Proxy.ws(
req,
socket,
head,
{
port: 443,
path: pathname + search,
proxyTimeout: timeout,
hostname: urlObj.hostname,
["rejectUnauthorized" as never]: secure,
...serverOptions,
},
(err) => {
if (err) {
console.error("proxy error", err);
socket.destroy();
}
}
);
}
});
} else {
middlewares.use((req, res, next) => {
if (req.url && re.test(req.url)) {
const url = (rewrite?.(req.url) ?? req.url).replace(/^\/+/, "");
const { pathname, search } = new URL(url, urlObj);
http2Proxy.web(
req,
res,
{
protocol,
port,
hostname: urlObj.hostname,
path: pathname + search,
proxyTimeout: timeout,
onReq: async (_, options) => {
options.headers = {
...options.headers,
...headers,
};
},
["rejectUnauthorized" as never]: secure,
...serverOptions,
},
(err) => err && next(err)
);
} else {
next();
}
});
}
}
};
// @ts-ignore
return {
name: "@sy/vite-plugin-http2-proxy",
config: (config) => {
const { server } = config;
routes = Object.entries(server?.proxy ?? {}).reduce(
(prev, [key, value]) => {
if (typeof value === "string") {
prev[key] = {
target: value,
};
} else {
prev[key] = value;
}
return prev;
},
{} as Record<string, ProxyOptions>
);
if (server) {
// https://cn.vitejs.dev/config/server-options#server-https
Reflect.deleteProperty(server, "proxy");
}
return config;
},
configureServer: configure,
// @ts-ignore
configurePreviewServer: configure,
};
};

View File

@@ -0,0 +1,13 @@
{
"compilerOptions": {
"target": "ESNext",
"moduleResolution": "Node",
"module": "ESNext",
"outDir": "dist",
"declaration": true,
"strict": true,
"skipLibCheck": true,
"useUnknownInCatchVariables": false,
"allowSyntheticDefaultImports": true
}
}

View File

@@ -0,0 +1,9 @@
import { defineConfig } from "@farmfe/core";
export default defineConfig({
compilation: {
input: {
index: "./src/index.ts",
},
},
});

View File

@@ -0,0 +1,29 @@
{
"name": "@sy/web-vitals",
"description": "web vitals",
"version": "0.0.1",
"private": true,
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.js",
"types": "./dist/index.d.ts"
}
},
"scripts": {
"build": "farm build",
"clean": "farm clean",
"clean:lock": "rimraf pnpm-lock.yaml && rimraf package.lock.json",
"clean:lib": "rimraf node_modules"
},
"dependencies": {
"firebase": "^11.3.1",
"web-vitals": "^4.2.4"
},
"devDependencies": {
"@farmfe/cli": "^1.0.4",
"@farmfe/core": "^1.6.6"
}
}

View File

@@ -0,0 +1,19 @@
import { onLCP, onINP, onCLS } from "web-vitals";
// import { initializeApp } from "firebase/app";
// import { getAnalytics } from "firebase/analytics";
// // TODO: Replace the following with your app's Firebase project configuration
// // See: https://firebase.google.com/docs/web/learn-more#config-object
// const firebaseConfig = {
// // ...
// };
// // Initialize Firebase
// const app = initializeApp(firebaseConfig);
// // Initialize Analytics and get a reference to the service
// const analytics = getAnalytics(app);
onCLS(console.log);
onINP(console.log);
onLCP(console.log);

View File

@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "ESNext",
"moduleResolution": "Node",
"module": "ESNext",
"outDir": "dist",
"declaration": true,
"strict": true,
"skipLibCheck": true,
"useUnknownInCatchVariables": false
}
}