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

Add a @mermaidchart/cli CLI tool for accessing Mermaid Chart #12

Merged
merged 9 commits into from
Apr 16, 2024

Conversation

aloisklink
Copy link
Contributor

@aloisklink aloisklink commented Nov 27, 2023

📖 Description

Add a @mermaidchart/cli package that can link/pull/push diagrams, e.g.

me@pc:~$ npx mermaid-chart link ./my-diagram.mmd 
? Select a project to upload your document to personal
me@pc:~$ npx mermaid-chart push ./my-diagram.mmd
✅ - ./my-diagram.mmd  was pushed
me@pc:~$ npx mermaid-chart pull ./my-diagram.mmd  
✅ - ./my-diagram.mmd  is up to date
me@pc:~$ npx @mermaidchart/cli --help
Usage: mermaid-cli [options] [command]

CLI for interacting with https://MermaidChart.com, the platform that makes
collaborating with Mermaid diagrams easy.

Options:
  -V, --version               output the version number
  -c, --config <config_file>  The path to the config file to use. (default:
                              "/home/me/.config/mermaid-chart.toml")
  -h, --help                  display help for command

Commands:
  whoami                      Display Mermaid Chart username
  login                       Login to a Mermaid Chart account
  logout                      Log out of a Mermaid Chart account
  link <path>                 Link the given Mermaid diagram to Mermaid Chart
  pull [options] <path>       Pulls a document from from Mermaid Chart
  push <path>                 Push a local diagram to Mermaid Chart
  help [command]              display help for command

Configuration file

The configuration file is a TOML file that's stored in:

  • Linux: ~/.config/mermaid-config.toml
  • MacOS: ~/Library/Application Support/mermaid-config.toml
  • Windows: %AppData%\mermaid-config.toml

Currently, the allowed fields are:

# TOML config file for mermaid-chart
[mermaid-chart]
base_url = "https://test.mermaidchart.com" # optional, defaults to https://mermaidchart.com
auth_token = "xxxxxx-xxxxxxx-xxxxxxxx" # set by `mermaid-chart login`.

Todo

@aloisklink aloisklink added the enhancement New feature or request label Nov 27, 2023
Copy link

vercel bot commented Nov 27, 2023

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

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
office-plugin-site ⬜️ Ignored (Inspect) Visit Preview Apr 16, 2024 6:38am

Comment on lines +29 to +34
"//2": "TODO: decide on a license once this code is finished",
"license": "UNLICENSED",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@knsv, what do you want the license for this package to be?

MIT is the license in the root of the repo, so we could use that: https://github.com/Mermaid-Chart/plugins/blob/main/LICENSE

@aloisklink aloisklink force-pushed the feat/add-mermaid-chart-cli branch 2 times, most recently from 7210e5b to 08f9cf9 Compare November 28, 2023 14:40
@aloisklink aloisklink force-pushed the feat/add-mermaid-chart-cli branch from c56defb to 849112d Compare December 1, 2023 13:42
Base automatically changed from feat/add-setDocument-to-sdk to main December 4, 2023 08:54
@aloisklink aloisklink marked this pull request as ready for review December 4, 2023 09:28
@aloisklink aloisklink requested a review from jgreywolf December 4, 2023 09:28
Comment on lines +13 to +15
```bash
npx @mermaidchart/cli --help
```
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can't test this until we've published this package to NPM, but it should work!

Add an initial @mermaidchart/cli package that can `link`/`pull`/`push`
diagrams.
Move the implementation of `push`/`pull`/`link` into their own
functions, so that we can reuse them to add the feature for sync Mermaid
diagrams from within markdown files.
Add a `pnpm run dev` command to make testing/development easier.
Recommend using [npx][] to automatically install, cache, and run
@mermaidchart/cli, e.g. with `npx @mermaidchart/cli`, as npx comes with
most Node.JS installations.

This doesn't currently work since we haven't published this package to
NPM, however.

[npx]: https://docs.npmjs.com/cli/v10/commands/npx
@aloisklink aloisklink force-pushed the feat/add-mermaid-chart-cli branch from c7b84c0 to 3211343 Compare March 6, 2024 16:12
@aloisklink aloisklink changed the base branch from main to fix/setDocument-specify-that-projectID-is-required March 6, 2024 16:14
Base automatically changed from fix/setDocument-specify-that-projectID-is-required to main April 10, 2024 14:16
Comment on lines +32 to +39
### `login`

Firstly, go to https://www.mermaidchart.com/app/user/settings and generate an
API key, which you can then setup by running:

```bash
npx @mermaidchart/cli login
```
Copy link
Member

Choose a reason for hiding this comment

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

Can we use OAuth before releasing?

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, since it's not a mandatory feature that's block the v0.1.0 release, I think it can wait for a future minor release (e.g. v0.1.1)!

But yep, we should definitely add it to make it easier for users to sign-in!


export function createCommanderCommand() {
const program = createCommand('mermaid-cli')
.version('0.1.0-alpha.0') // TODO: how can we keep this synced with package.json
Copy link
Member

Choose a reason for hiding this comment

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

Can't we import it from the json file? That's how we do in mermaid.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed by 480df29

I think in a previous version of this library, I had the file in src/index.ts, but I compiled the output into ./index.js. So require("../package.json"); would have had to have switched to require("./package.json");. But now I'm using a dist/ folder, so the import path to package.json is the same!

* If set, the user has said to use the projectId to create all documents
* in.
*/
selectedProjectId?: string;
Copy link
Member

Choose a reason for hiding this comment

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

nit: Consistency

Suggested change
selectedProjectId?: string;
selectedProjectID?: string;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

I'll look into fixing all of these before we make the first release, but after #22 is merged, to avoid causing merge conflicts.

Currently, this value is hard coded, which isn't great, since it means
we need to update the value in two places each time we make a new
release. This is a bit slower than the old version, but it shouldn't be
too much slower, unless the user is still using a HDD.
@aloisklink aloisklink merged commit 354b144 into main Apr 16, 2024
6 checks passed
@aloisklink aloisklink deleted the feat/add-mermaid-chart-cli branch April 16, 2024 08:45
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