Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli)!: use a URL id in the frontmatter #20

Merged
merged 1 commit into from
Apr 22, 2024

Conversation

aloisklink
Copy link
Contributor

@aloisklink aloisklink commented Apr 10, 2024

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.

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!

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.
@aloisklink aloisklink added the enhancement New feature or request label Apr 10, 2024
Copy link

vercel bot commented Apr 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Updated (UTC)
office-plugin-site ⬜️ Ignored (Inspect) Apr 10, 2024 6:14am

Comment on lines +21 to +27
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/**/*.md

We 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!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Purely a "nice-to-have" feature :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 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

@aloisklink aloisklink merged commit 0e3299b into main Apr 22, 2024
6 checks passed
@aloisklink aloisklink deleted the feat/use-a-url-id-for-frontmatter branch April 22, 2024 04:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants