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