Skip to content

Commit aae6376

Browse files
committed
feat(cli): initial @mermaidchart/cli package
Add an initial @mermaidchart/cli package that can `link`/`pull`/`push` diagrams.
1 parent c995911 commit aae6376

17 files changed

+1836
-33
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
matrix:
1111
node: ['18.18.x']
12-
pkg: ['sdk']
12+
pkg: ['sdk', 'cli']
1313
runs-on:
1414
labels: ubuntu-latest
1515
steps:

cSpell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"Cataa",
66
"colour",
77
"Cookiebot",
8+
"gantt",
89
"jsnext",
910
"lintstagedrc",
1011
"mermaidchart",

packages/cli/.eslintrc.cjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = /** @type {import("eslint").Linter.Config} */ ({
2+
root: false, // mono-repo
3+
parser: '@typescript-eslint/parser',
4+
ignorePatterns: ['*.cjs'],
5+
parserOptions: {
6+
ecmaVersion: 2022, // support node v18 features
7+
allowAutomaticSingleRunInference: true,
8+
sourceType: 'module',
9+
project: ['./tsconfig.json'],
10+
tsconfigRootDir: __dirname,
11+
parser: '@typescript-eslint/parser',
12+
},
13+
rules: {
14+
"no-console": ["warn"], // TODO: fix all of these
15+
}
16+
});

packages/cli/README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# @mermaidchart/cli
2+
3+
CLI for interacting with https://MermaidChart.com, the platform that makes collaborating with Mermaid diagrams easy!
4+
5+
## Usage
6+
7+
```bash
8+
mermaid-chart <command>
9+
```
10+
11+
Use `--help` to see options!
12+
13+
```bash
14+
mermaid-chart --help
15+
```
16+
17+
`@mermaidchart/cli` allows you to easily sync local diagrams with your diagrams
18+
on https://mermaidchart.com.
19+
20+
### `login`
21+
22+
Firstly, go to https://www.mermaidchart.com/app/user/settings and generate an
23+
API key, which you can then setup by running:
24+
25+
```bash
26+
mermaid-chart login
27+
```
28+
29+
### `link` an existing Mermaid diagram to MermaidChart.com
30+
31+
You can link a local Mermaid diagram to MermaidChart using:
32+
33+
```bash
34+
mermaid-chart link ./path/to/my/mermaid-digram.mmd
35+
```
36+
37+
This will add an `id: xxxx-xxxxx-xxxxx` field to your diagram's YAML frontmatter,
38+
which points to the diagram on MermaidChart.com:
39+
40+
````markdown
41+
```mermaid
42+
---
43+
title: My diagram
44+
id: xxxx-xxxxx-xxxxx # this field is created by @mermaidchart/cli
45+
---
46+
flowchart
47+
x[My Diagram]
48+
```
49+
````
50+
51+
### `push` local changes to MermaidChart.com
52+
53+
Once you've made some local changes, you can `push` your changes to MermaidChart.com
54+
55+
```console
56+
$ mermaid-chart push ./path/to/my/mermaid-digram.mmd
57+
✅ - ./path/to/my/mermaid-digram.mmd was pushed
58+
```
59+
60+
### `pull` changes from MermaidChart.com
61+
62+
You can use `pull` to pull down changes from MermaidChart.com.
63+
64+
```console
65+
$ mermaid-chart pull ./path/to/my/mermaid-digram.mmd
66+
✅ - ./path/to/my/mermaid-digram.mmd was updated
67+
```
68+
69+
Or use the `--check` flag to throw an error if your local file would have been
70+
updated:
71+
72+
```console
73+
$ mermaid-chart pull ./path/to/my/mermaid-digram.mmd
74+
❌ - ./path/to/my/mermaid-digram.mmd would be updated
75+
```

packages/cli/package.json

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"name": "@mermaidchart/cli",
3+
"version": "0.1.0-alpha.0",
4+
"description": "CLI for interacting with https://MermaidChart.com, the platform that makes collaborating with Mermaid diagrams easy",
5+
"main": "index.js",
6+
"bin": {
7+
"mermaid-chart": "dist/cli.js"
8+
},
9+
"//1": "temporarily disable pushing until we finish progress on this",
10+
"private": true,
11+
"engines": {
12+
"node": "^18.18.0 || ^20.0.0"
13+
},
14+
"scripts": {
15+
"lint": "eslint src/ && prettier --check src/",
16+
"lint:fix": "eslint --fix src/ && prettier --write src/",
17+
"prepare": "tsc --build tsconfig.json",
18+
"test": "vitest"
19+
},
20+
"type": "module",
21+
"repository": {
22+
"type": "git",
23+
"directory": "packages/cli",
24+
"url": "git+https://github.com/Mermaid-Chart/plugins.git"
25+
},
26+
"keywords": [
27+
"mermaid",
28+
"mermaidchart",
29+
"cli"
30+
],
31+
"author": "Alois Klink <[email protected]> (https://github.com/aloisklink)",
32+
"//2": "TODO: decide on a license once this code is finished",
33+
"license": "UNLICENSED",
34+
"bugs": {
35+
"url": "https://github.com/Mermaid-Chart/plugins/issues"
36+
},
37+
"homepage": "https://github.com/Mermaid-Chart/plugins/tree/main/packages/cli#readme",
38+
"devDependencies": {
39+
"@cspell/eslint-plugin": "^8.0.0",
40+
"@tsconfig/node18": "^18.2.2",
41+
"@tsconfig/strictest": "^2.0.2",
42+
"@types/iarna__toml": "^2.0.5",
43+
"@types/js-yaml": "^4.0.9",
44+
"@types/node": "^18.18.11",
45+
"@typescript-eslint/eslint-plugin": "^6.11.0",
46+
"@typescript-eslint/parser": "^6.11.0",
47+
"eslint": "^8.54.0",
48+
"typescript": "^5.2.2",
49+
"vitest": "^0.34.6"
50+
},
51+
"dependencies": {
52+
"@commander-js/extra-typings": "^11.1.0",
53+
"@iarna/toml": "^2.2.5",
54+
"@inquirer/input": "^1.2.14",
55+
"@inquirer/select": "^1.3.1",
56+
"@mermaidchart/sdk": "workspace:^",
57+
"commander": "^11.1.0",
58+
"js-yaml": "^4.1.0"
59+
}
60+
}

packages/cli/src/cli.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env node
2+
3+
import { createCommanderCommand } from './commander.js';
4+
5+
createCommanderCommand()
6+
.parseAsync()
7+
.catch((error) => {
8+
console.error(error); // eslint-disable-line no-console
9+
process.exitCode = 1;
10+
});

0 commit comments

Comments
 (0)