Skip to content

Commit

Permalink
Merge pull request #43 from obsidian-confluence/load_mermaid_renderer…
Browse files Browse the repository at this point in the history
…_from_bundle
  • Loading branch information
andymac4182 committed Apr 6, 2023
2 parents 0372b01 + db7787a commit 9e57cbc
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 56 deletions.
48 changes: 0 additions & 48 deletions .github/workflows/release.yml

This file was deleted.

50 changes: 49 additions & 1 deletion esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,60 @@ if you want to view the source, please visit the github repository of this plugi
*/
`;


const mermaid_renderer_plugin = {
name: 'mermaid_renderer_plugin',
setup(build) {
build.onResolve({ filter: /mermaid_renderer\.esbuild$/ }, args => {
return {
path: args.path,
namespace: 'mermaid-binary',
}
});
build.onLoad({ filter: /mermaid_renderer\.esbuild$/, namespace: 'mermaid-binary' }, async (args) => {
const result = await esbuild.build({
entryPoints: ['src/mermaid_renderer.js'],
bundle: true,
format: 'cjs',
target: 'chrome106',
logLevel: 'info',
sourcemap: false,
treeShaking: true,
write: false,
mainFields: ['module', 'main']
}).catch(() => process.exit(1));

const fileContents = `
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Mermaid Chart</title>
</head>
<body>
<div id="graphDiv"></div>
<script type="text/javascript">
${result.outputFiles[0].text}
</script>
</body>
</html>
`;

return {
contents: fileContents,
loader: 'binary',
}
})
}
};

const prod = (process.argv[2] === 'production');

esbuild.build({
banner: {
js: banner,
},
entryPoints: ['src/main.ts', 'src/mermaid_renderer.js'],
entryPoints: ['src/main.ts'],
bundle: true,
external: [
'obsidian',
Expand All @@ -41,4 +88,5 @@ esbuild.build({
treeShaking: true,
outdir: prod ? 'dist' : 'dev-vault/.obsidian/plugins/obsidian-confluence',
mainFields: ['module', 'main'],
plugins: [mermaid_renderer_plugin],
}).catch(() => process.exit(1));
5 changes: 5 additions & 0 deletions src/custom.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ declare module "*.json" {
const content: any;
export default content;
}

declare module "mermaid_renderer.esbuild" {
const content: Buffer;
export default content;
}
14 changes: 7 additions & 7 deletions src/mermaid_renderers/electron.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import * as path from "path";
import { BrowserWindow } from "@electron/remote";
import { ChartData, MermaidRenderer } from "./types";
import MermaidRendererClient from "mermaid_renderer.esbuild";

const mermaid_render_html = URL.createObjectURL(
new Blob([MermaidRendererClient], { type: "text/html" })
);

export class ElectronMermaidRenderer implements MermaidRenderer {
async captureMermaidCharts(
Expand All @@ -18,13 +23,8 @@ export class ElectronMermaidRenderer implements MermaidRenderer {
frame: false,
});

// Load the HTML file with the Mermaid.js chart
await chartWindow.loadFile(
path.join(
"/Users/andrewmcclenaghan/dev/obsidian-confluence/obsidian-confluence/dev-vault/.obsidian/plugins/obsidian-confluence",
"mermaid_renderer.html"
)
);
console.log({ mermaid_render_html });
await chartWindow.loadURL(mermaid_render_html);

const mermaidConfig = {
theme: "base",
Expand Down

0 comments on commit 9e57cbc

Please sign in to comment.