2024-06-09 01:00:07 +08:00
|
|
|
|
# 开发者需知
|
|
|
|
|
|
2024-06-09 11:57:45 +08:00
|
|
|
|
未来将支持TS、TSX环境,提供Miao-Yunzai完全的类型声明及其开发文档。
|
2024-06-09 01:00:07 +08:00
|
|
|
|
|
2024-06-09 01:00:25 +08:00
|
|
|
|
- 提交
|
|
|
|
|
|
|
|
|
|
```ts
|
|
|
|
|
/**
|
|
|
|
|
* feature:新功能
|
|
|
|
|
* update:更新某功能
|
|
|
|
|
* fixbug:修补某功能的bug
|
|
|
|
|
* refactor:重构某个功能
|
|
|
|
|
* optimize: 优化构建工具或运行时性能
|
|
|
|
|
* style:仅样式改动
|
|
|
|
|
* docs:仅文档新增/改动
|
|
|
|
|
* chore:构建过程或辅助工具的变动
|
|
|
|
|
*/
|
|
|
|
|
```
|
|
|
|
|
|
2024-06-09 11:57:45 +08:00
|
|
|
|
- 注释风格
|
|
|
|
|
|
|
|
|
|
```ts
|
|
|
|
|
/**
|
|
|
|
|
* 返回false
|
|
|
|
|
* @param T 任意字符串
|
|
|
|
|
* @returns false
|
|
|
|
|
*/
|
2024-06-09 11:58:17 +08:00
|
|
|
|
function getTest(T: string) {
|
2024-06-09 11:57:45 +08:00
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
- 命名风格
|
|
|
|
|
|
|
|
|
|
```ts
|
|
|
|
|
// 获得test值
|
2024-06-09 11:58:17 +08:00
|
|
|
|
function getTest(T: string) {}
|
2024-06-09 11:57:45 +08:00
|
|
|
|
// 设置
|
2024-06-09 11:58:17 +08:00
|
|
|
|
function setTest(T: string) {}
|
2024-06-09 11:57:45 +08:00
|
|
|
|
// 删除
|
2024-06-09 11:58:17 +08:00
|
|
|
|
function delTest(T: string) {}
|
2024-06-09 11:57:45 +08:00
|
|
|
|
// 获取某数据依据为id
|
2024-06-09 11:58:17 +08:00
|
|
|
|
function getDataById(T: string) {}
|
2024-06-09 11:57:45 +08:00
|
|
|
|
|
|
|
|
|
// 系统常量
|
|
|
|
|
const ENV_TEST = 'dev'
|
|
|
|
|
|
|
|
|
|
// 局域常量
|
|
|
|
|
const MyName = 'yunzai'
|
|
|
|
|
|
|
|
|
|
// 可修改变量
|
|
|
|
|
let values = ''
|
|
|
|
|
|
|
|
|
|
// 禁止使用 var values = ''
|
|
|
|
|
|
|
|
|
|
// 声明数组
|
|
|
|
|
const Arr = []
|
|
|
|
|
|
|
|
|
|
// 不推荐 new
|
|
|
|
|
|
|
|
|
|
// 声明对象
|
|
|
|
|
const Obj = {}
|
|
|
|
|
|
|
|
|
|
// 不推荐new
|
|
|
|
|
```
|
|
|
|
|
|
2024-06-09 01:00:07 +08:00
|
|
|
|
## 关于lib目录
|
|
|
|
|
|
|
|
|
|
lib目录将在未来逐渐放弃,在版本发布后,开发者需要有意识的对此变化做出调整.
|
|
|
|
|
|
|
|
|
|
```ts
|
|
|
|
|
// 已废弃
|
2024-06-09 01:00:25 +08:00
|
|
|
|
--lib / puppeteer
|
2024-06-09 01:00:07 +08:00
|
|
|
|
// 无扩展性,计划废弃
|
2024-06-09 01:00:25 +08:00
|
|
|
|
--lib / renderer
|
2024-06-09 01:00:07 +08:00
|
|
|
|
// 非机器人框架的核心处理代码
|
|
|
|
|
// 消耗服务器内存,无扩展性,计划废弃
|
2024-06-09 01:00:25 +08:00
|
|
|
|
--lib / tools / web.js / test.js / log.js / ksr.js
|
2024-06-09 01:00:07 +08:00
|
|
|
|
// 计划废弃
|
2024-06-09 01:00:25 +08:00
|
|
|
|
--renderers
|
2024-06-09 11:57:45 +08:00
|
|
|
|
|
|
|
|
|
// 其他内容逐步优化。。。
|
2024-06-09 01:00:07 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 新版目录
|
|
|
|
|
|
|
|
|
|
- 核心源码
|
|
|
|
|
|
|
|
|
|
src/core
|
|
|
|
|
|
2024-06-09 11:57:45 +08:00
|
|
|
|
- 配置管理
|
|
|
|
|
|
|
|
|
|
src/config
|
|
|
|
|
|
2024-06-09 01:00:07 +08:00
|
|
|
|
- 数据管理
|
|
|
|
|
|
|
|
|
|
src/db
|
|
|
|
|
|
|
|
|
|
- 接口板块
|
|
|
|
|
|
|
|
|
|
src/mys
|
|
|
|
|
|
|
|
|
|
- 工具类
|
|
|
|
|
|
|
|
|
|
src/utils
|
|
|
|
|
|
2024-06-09 11:57:45 +08:00
|
|
|
|
## 新开发示例
|
2024-06-09 01:00:25 +08:00
|
|
|
|
|
2024-06-09 01:00:07 +08:00
|
|
|
|
- 图片组件
|
|
|
|
|
|
|
|
|
|
```tsx
|
|
|
|
|
import React from 'react'
|
|
|
|
|
export default function App() {
|
|
|
|
|
return (
|
|
|
|
|
<html>
|
|
|
|
|
<head>
|
|
|
|
|
<link rel="stylesheet" href="../css/output.css"></link>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
<div id="root">
|
|
|
|
|
<div className="text-red-500 p-2 text-xl">Hello, world!</div>
|
|
|
|
|
</div>
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```ts
|
|
|
|
|
import React from 'react'
|
|
|
|
|
import { renderToString } from 'react-dom/server'
|
|
|
|
|
import { mkdirSync, writeFileSync } from 'fs'
|
|
|
|
|
import { join } from 'path'
|
|
|
|
|
// puppeteer
|
|
|
|
|
import { Puppeteer } from './puppeteer.ts'
|
|
|
|
|
// component
|
2024-06-09 11:57:45 +08:00
|
|
|
|
import HelloComponent from './hello.tsx'
|
2024-06-09 01:00:07 +08:00
|
|
|
|
//
|
|
|
|
|
class Component {
|
|
|
|
|
puppeteer: typeof Puppeteer.prototype
|
|
|
|
|
#dir = ''
|
|
|
|
|
constructor(dir: string) {
|
|
|
|
|
this.puppeteer = new Puppeteer()
|
|
|
|
|
this.#dir = dir
|
|
|
|
|
mkdirSync(this.#dir, {
|
|
|
|
|
recursive: true
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 渲染字符串
|
|
|
|
|
* @param element
|
|
|
|
|
* @param name
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
create(element: React.ReactNode, dirs: string, name: string) {
|
|
|
|
|
const html = renderToString(element)
|
|
|
|
|
const dir = join(this.#dir, dirs)
|
|
|
|
|
mkdirSync(dir, {
|
|
|
|
|
recursive: true
|
|
|
|
|
})
|
|
|
|
|
const address = join(dir, name)
|
|
|
|
|
writeFileSync(address, `<!DOCTYPE html>${html}`)
|
|
|
|
|
return address
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* hello
|
|
|
|
|
* @param _
|
|
|
|
|
* @param name
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
|
|
|
|
hello() {
|
|
|
|
|
return this.puppeteer.render(
|
|
|
|
|
this.create(<HelloComponent />, 'hello', 'help.html')
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-06-09 11:58:17 +08:00
|
|
|
|
```
|