Closed ppg closed 1 year ago
This workaround worked for me: https://github.com/mermaidjs/mermaid.cli/issues/59
My workaround is making an executable file at bin/mmd
in my project:
package.json
:
{
"dependencies": {
"mermaid": "^8.4.4",
"puppeteer": "^2.0.0"
}
}
bin/mmd
:
#!/usr/bin/env node
const puppeteer = require("puppeteer");
const fs = require("fs");
const input = fs.readFileSync(process.argv[2], "utf8");
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.addScriptTag({ path: "node_modules/mermaid/dist/mermaid.min.js" });
const result = await page.evaluate(
async ({ input }) => {
const element = document.createElement("div");
element.id = "root";
document.body.appendChild(element);
return await new Promise(resolve =>
mermaid.mermaidAPI.render("root", input, resolve)
);
},
{ input }
);
console.log(result);
await browser.close();
})();
chmod +x bin/mmd
bin/mmd UML.mmd > UML.svg
Development has moved to the https://github.com/mermaid-js/mermaid-cli repo, please re-open your issue there if it's still relevant.
The package has also been renamed on NPM to @mermaid-js/mermaid-cli
, so you may need to run npm uninstall mermaid.cli && npm install @mermaid-js/mermaid-cli
to get the latest version of this package.
Instead of copying in a static version of mermaid is it not possible to move mermaid to a normal (non-dev) dependency and have the JS code pull in the package version? Or perhaps better yet make it a peer dependency and then the installer can pick the version they want?
FYI, since Mermaid v10.0.0 this isn't very easy to do. Now that Mermaid is ESM only, you need https://
to import ESM scripts, and that doesn't work without running a local server and getting certificates set up. The way @mermaid-js/mermaid-cli
currently works is by bundling and transpiling the ESM code into one massive HTML file, which does work, but it can take a few minutes on a weak computer.
If you do want to use your own version of mermaid, you can do something like npm install git+https://github.com/mermaid-js/mermaid-cli.git
and then your package manager will automatically pick a suitable version of mermaid
to use with @mermaid-js/mermaid-cli
!
Instead of copying in a static version of mermaid is it not possible to move mermaid to a normal (non-dev) dependency and have the JS code pull in the package version? Or perhaps better yet make it a peer dependency and then the installer can pick the version they want?