feat(cli)!: use a URL id in the frontmatter#20
Conversation
Currently, we're using just an UUID for the id in the frontmatter of a link mermaid diagram, e.g.: ```mermaid --- id: 00000000-0000-0000-0000-000000000000 --- info ``` Instead, we can use a URL for an ID, e.g.: ```mermaid --- id: https://test.mermaidchart.invalid/d/00000000-0000-0000-0000-000000000000 --- info ``` This has the benefits of: 1. The MermaidChart server is part of the URL, which improves cases where users are using different instances of the MermaidChart app. 2. Users can click on the URL to instantly see their diagram on the Mermaid Chart app. BREAKING-CHANGE: Frontmatter `id`s are now URLs instead of just UUIDs.
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
| const { baseURL, documentID } = match.groups as { baseURL: string; documentID: string }; | ||
| if (baseURL !== expectedbaseURL) { | ||
| throw new Error( | ||
| `Your @mermaidchart/cli is configured to use ${expectedbaseURL}, but your diagram is using ${baseURL}`, | ||
| ); | ||
| } | ||
| return documentID; |
There was a problem hiding this comment.
What if they have a private and public instance, and they're linking a diagram manually?
Might be better to print a warning than throw an error.
In future release, we might have to go the git route and support multiple origins.
There was a problem hiding this comment.
IMO, you mean printing a warning, then ignoring the diagram?
Hmmmm, I still think we should return a non-zero exit code in this case. I'm guessing if somebody has two different instances, they'd currently have to do something like:
npx @mermaidchart/cli xxxx ./public/**/*.md
MERMAID_CHART_AUTH_TOKEN='private-token' MERMAID_CHART_BASE_URL='https://private-domain.example' npx @mermaidchart/cli xxxx ./private/**/*.mdWe could print out a different exit code for this case, but it seems like a lot of work, when most people will probably just a single domain for all their uploads, e.g. https://mermaidchart.com!
There was a problem hiding this comment.
What I had in mind was, we allow users to login to multiple domains (with OAuth), and save the sites and tokens in our config file. Then when we come across those, use the corresponding tokens and proceed.
So the flow would be
# OneTime
npx @mermaidchart/cli login # Browser opens, user logs in, we save to config file.
npx @mermaidchart/cli login https://private-domain.example # Browser opens, user logs in, we append to config file.
# Regular use
npx @mermaidchart/cli <other commands> # Uses corresponding auth for each diagram automatically based on the URL.There was a problem hiding this comment.
Purely a "nice-to-have" feature :)
There was a problem hiding this comment.
👍 Definitely!
NPM has this feature, so we should also have it!
Although, it would mean I need to think about the config file format a bit more. Maybe there's an open-source CLI tool we can take inspiration from, like NPM/Pip
Note
This PR is stacked on top of:
pull/push/linkon multiple mermaid files at once #15, which is stacked on top of@mermaidchart/cliCLI tool for accessing Mermaid Chart #12Currently, we're using just an UUID for the id in the frontmatter of a link mermaid diagram, e.g.:
Instead, we can use a URL for an ID, e.g.:
This has the benefits of:
This is technically a breaking change to the
@mermaidchart/cli, but since we haven't made a release yet to NPM, it's not a big deal!