GithubHelp home page GithubHelp logo

Comments (3)

mbmasuda avatar mbmasuda commented on June 3, 2024

This workaround worked for me: #59

from mermaid.cli.

tonytonyjan avatar tonytonyjan commented on June 3, 2024

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

from mermaid.cli.

aloisklink avatar aloisklink commented on June 3, 2024

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!

from mermaid.cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.