From 6abe3bb5b1389f72c6388d990a2e5a68b6f2c111 Mon Sep 17 00:00:00 2001 From: ningmengchongshui <916415899@qq.com> Date: Mon, 10 Jun 2024 10:05:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E6=88=AA=E5=9B=BE?= =?UTF-8?q?=E5=A4=84=E7=90=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/apps.ts | 7 +++++++ {src => example}/hello.tsx | 0 example/index.tsx | 25 +++++++++++++++++++++++++ src/utils/component.ts | 9 +++++---- 4 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 example/apps.ts rename {src => example}/hello.tsx (100%) create mode 100644 example/index.tsx diff --git a/example/apps.ts b/example/apps.ts new file mode 100644 index 0000000..5101381 --- /dev/null +++ b/example/apps.ts @@ -0,0 +1,7 @@ +import { Messages } from '../src/core/index.js' +const message = new Messages({ + priority: 9000 +}) +message.response(/^你好/, async e => { + e.reply('你好') +}) diff --git a/src/hello.tsx b/example/hello.tsx similarity index 100% rename from src/hello.tsx rename to example/hello.tsx diff --git a/example/index.tsx b/example/index.tsx new file mode 100644 index 0000000..af1d4d0 --- /dev/null +++ b/example/index.tsx @@ -0,0 +1,25 @@ +import React from 'react' +import { Component, Puppeteer } from '../src/utils/index.js' +import Hello from './hello.tsx' +const Com = new Component() +const Pup = new Puppeteer() +export class Image { + constructor() { + // 启动 + Pup.start() + } + /** + * + * @returns + */ + async getHelloComponent() { + // 生成 html 地址 + const Address = Com.create(, { + html_head: ``, + html_name: 'hello.html' + }) + // + const img = await Pup.render(Address) + return img + } +} diff --git a/src/utils/component.ts b/src/utils/component.ts index e1b8ced..fdc4ffa 100644 --- a/src/utils/component.ts +++ b/src/utils/component.ts @@ -31,12 +31,13 @@ export class Component { */ create(element: React.ReactNode, options: ComponentCreateOpsionType) { const str = renderToString(element) - const dir = join(this.#dir, options.join_dir) + const dir = join(this.#dir, options?.join_dir ?? '') mkdirSync(dir, { recursive: true }) - const address = join(dir, options.html_name) + const address = join(dir, options?.html_name ?? 'hello.html') const DOCTYPE = '' - const head = `${options.html_head}` - const body = `${str}${options.html_body}` + const Link = `` + const head = `${options?.html_head ?? Link}` + const body = ` ${str} ${options?.html_body ?? ''}` const html = `${DOCTYPE}${head}${body}` writeFileSync(address, html) return address