Skip to content
This repository has been archived by the owner on Jul 22, 2023. It is now read-only.

Use installed mermaid package #71

Closed
ppg opened this issue Nov 14, 2019 · 3 comments
Closed

Use installed mermaid package #71

ppg opened this issue Nov 14, 2019 · 3 comments

Comments

@ppg
Copy link

ppg commented Nov 14, 2019

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?

@mbmasuda
Copy link

mbmasuda commented Dec 5, 2019

This workaround worked for me: #59

@tonytonyjan
Copy link

tonytonyjan commented Jan 8, 2020

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

Usage

bin/mmd UML.mmd > UML.svg

@aloisklink
Copy link
Collaborator

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!

@aloisklink aloisklink closed this as not planned Won't fix, can't repro, duplicate, stale Jul 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants