Skip to content

Commit

Permalink
fix: release
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-cn committed Jun 20, 2024
1 parent cffbba3 commit fd5c109
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
2 changes: 2 additions & 0 deletions packages/services/screenshot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"dependencies": {
"zhin": "workspace:^",
"vue": "^3.4.29",
"sass": "latest",
"less": "latest",
"esbuild": "^0.14.8",
"cheerio": "^1.0.0-rc.12",
"esbuild-plugin-vue3": "^0.4.2"
Expand Down
5 changes: 5 additions & 0 deletions packages/services/screenshot/src/adapters/vueRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export class VueRenderer extends Renderer {
// 6 生成入口html
let entryHTMLContent = await readFile(path.join(templatePath, 'index.html'), 'utf8');
const outputJS = await readFile(path.join(templatePath, 'app.js'), 'utf8');
if (existsSync(path.join(templatePath, 'app.css'))) {
const cssFile = path.join(templatePath, 'app.css');
entryHTMLContent = entryHTMLContent.replace('{{STYLE}}', await readFile(cssFile, 'utf8'));
needRemoveFiles.push(cssFile);
}
entryHTMLContent = entryHTMLContent.replace('{{SCRIPT}}', outputJS);
// 7. 渲染
const result = await htmlRenderer.rendering(entryHTMLContent, options);
Expand Down
3 changes: 3 additions & 0 deletions packages/services/screenshot/template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
{{STYLE}}
</style>
</head>
<body>
<div id="app"></div>
Expand Down
15 changes: 11 additions & 4 deletions test/plugins/Test.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<script setup lang="ts"></script>
<script setup lang="ts">
defineProps<{
who: string;
}>();
</script>

<template>
<div>hello world</div>
<div>hello {{ who }}</div>
</template>

<style scoped lang="less"></style>
<style lang="scss">
div {
color: red;
}
</style>
8 changes: 6 additions & 2 deletions test/plugins/screenshot-test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { Plugin } from 'zhin';
import fs from 'fs';
import '@zhinjs/plugin-screenshot';
import path from 'path';
const screenshotTest = new Plugin('screenshot');
screenshotTest.required('renderVue');
screenshotTest.mounted(async () => {
const result = await screenshotTest.renderVue(path.join(__dirname, 'Test.vue'), {
encoding: 'base64',
props: {
who: '张三',
},
encoding: 'binary',
});
console.log(result);
fs.writeFileSync(path.join(__dirname, 'test.jpg'), result);
});
export default screenshotTest;

0 comments on commit fd5c109

Please sign in to comment.