diagrams-js 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1593,4 +1593,4 @@ declare namespace index_d_exports {
1593
1593
  export { ChangeKind, Cluster, ClusterDiff, ClusterOptions, CreatePlugin, Custom, DependencyError, Diagram, DiagramClusterJSON, DiagramDiffResult, DiagramEdgeJSON, DiagramJSON, DiagramNodeJSON, DiagramOptions, DiagramsPlugin, DiffMeta, DiffOptions, DiffSummary, Edge, EdgeDiff, EdgeOptions, ExportContext, ExporterCapability, FromJSONOptions, HookCapability, HookContext, HookEvent, HookHandler, Iconify, ImportContext, ImporterCapability, MetadataCapability, MetadataContext, Node, NodeDiff, NodeMetadata, NodeOptions, PluginCapability, PluginContext, PluginError, PluginRegistry, ProviderModule, RenderContext, RenderDiffOptions, RendererCapability, RuntimeError, RuntimeSupport, ThemeConfig, ThemeName, Yaml, computeDiff, createJSONPlugin, createPluginRegistry, createSVGPlugin, jsonPlugin, renderDiff, svgPlugin };
1594
1594
  }
1595
1595
  //#endregion
1596
- export { type ChangeKind, Cluster, type ClusterDiff, type ClusterOptions, type CreatePlugin, Custom, DependencyError, Diagram, type DiagramClusterJSON, type DiagramDiffResult, type DiagramEdgeJSON, type DiagramJSON, type DiagramNodeJSON, type DiagramOptions, type DiagramsPlugin, type DiffMeta, type DiffOptions, type DiffSummary, Edge, type EdgeDiff, type EdgeOptions, type ExportContext, type ExporterCapability, type FromJSONOptions, type HookCapability, type HookContext, HookEvent, type HookHandler, Iconify, type ImportContext, type ImporterCapability, type MetadataCapability, type MetadataContext, type Node, type NodeDiff, type NodeMetadata, type NodeOptions, type PluginCapability, type PluginContext, PluginError, type PluginRegistry, type ProviderModule, type RenderContext, type RenderDiffOptions, type RendererCapability, RuntimeError, type RuntimeSupport, type ThemeConfig, type ThemeName, type Yaml, computeDiff, createJSONPlugin, createPluginRegistry, createSVGPlugin, jsonPlugin, renderDiff, svgPlugin };
1596
+ export { type ChangeKind, Cluster, type ClusterDiff, type ClusterOptions, type CreatePlugin, Custom, DependencyError, Diagram, type DiagramClusterJSON, type DiagramDiffResult, type DiagramEdgeJSON, type DiagramJSON, type DiagramNodeJSON, type DiagramOptions, type DiagramsPlugin, type DiffMeta, type DiffOptions, type DiffSummary, Edge, type EdgeDiff, type EdgeOptions, type ExportContext, type ExporterCapability, type FromJSONOptions, type HookCapability, type HookContext, HookEvent, type HookHandler, Iconify, type ImportContext, type ImporterCapability, type MetadataCapability, type MetadataContext, Node, type NodeDiff, type NodeMetadata, type NodeOptions, type PluginCapability, type PluginContext, PluginError, type PluginRegistry, type ProviderModule, type RenderContext, type RenderDiffOptions, type RendererCapability, RuntimeError, type RuntimeSupport, type ThemeConfig, type ThemeName, type Yaml, computeDiff, createJSONPlugin, createPluginRegistry, createSVGPlugin, jsonPlugin, renderDiff, svgPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "diagrams-js",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "A TypeScript port of the diagrams Python library for drawing cloud system architecture diagrams as code",
5
5
  "keywords": [
6
6
  "architecture",
@@ -0,0 +1,220 @@
1
+ ---
2
+ name: diagrams-js/cli
3
+ description: >
4
+ Command-line interface for diagrams-js. Install @diagrams-js/cli and use
5
+ diagrams <command> to render, export, diff, init, watch, and manage
6
+ plugins. Cross-platform CLI with programmatic API. Supports file and stdin
7
+ input.
8
+ type: tooling
9
+ library: diagrams-js
10
+ library_version: "0.5.0"
11
+ requires:
12
+ - diagrams-js/getting-started
13
+ sources:
14
+ - "hatemhosny/diagrams-js:docs/docs/guides/cli.mdx"
15
+ - "hatemhosny/diagrams-js:cli/src/cli.ts"
16
+ ---
17
+
18
+ This skill builds on diagrams-js/getting-started. Read it first for foundational concepts.
19
+
20
+ # diagrams-js CLI
21
+
22
+ Command-line interface for diagrams-js. Render diagrams, import via plugins, export, generate diffs, scaffold new files, and watch for changes. Supports file and stdin input.
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ npm install -g @diagrams-js/cli
28
+ ```
29
+
30
+ Or use with `npx`:
31
+
32
+ ```bash
33
+ npx @diagrams-js/cli render diagram.ts -o out.svg
34
+ ```
35
+
36
+ ## Commands
37
+
38
+ ### render — Render diagrams and import via plugins
39
+
40
+ ```bash
41
+ # Render diagram source to SVG (default: same-name.svg)
42
+ diagrams render diagram.ts
43
+
44
+ # Render to PNG
45
+ diagrams render diagram.ts -o diagram.png
46
+
47
+ # Render with options
48
+ diagrams render diagram.ts -f svg -t dark -d LR -o out.svg
49
+
50
+ # Import Docker Compose via plugin and render to SVG
51
+ diagrams render docker-compose.yml
52
+
53
+ # Import Kubernetes via plugin
54
+ diagrams render k8s.yaml -p kubernetes -o architecture.svg
55
+
56
+ # Output to stdout
57
+ diagrams render diagram.ts --stdout
58
+
59
+ # Write to file AND stdout
60
+ diagrams render diagram.ts -o out.svg --stdout
61
+
62
+ # Render from stdin
63
+ cat diagram.json | diagrams render - -f json -o out.svg
64
+
65
+ ```
66
+
67
+ **Input sources:** file (`.ts`, `.js`, `.mjs`, `.json`, `.svg`, `.yaml`, `.yml`), stdin (`-`)
68
+
69
+ **Output formats:** `svg`, `png`, `jpg`, `dot`, `json`
70
+
71
+ Plugin auto-detection for `.yaml`/`.yml`:
72
+
73
+ - Files with `services:` → docker-compose
74
+ - Files with `apiVersion:` and `kind:` → kubernetes
75
+
76
+ ### export — Export to plugin formats
77
+
78
+ ```bash
79
+ # Export to Docker Compose (default: same-name.yml)
80
+ diagrams export diagram.json -f docker-compose
81
+
82
+ # Export to Kubernetes
83
+ diagrams export diagram.ts -f kubernetes -o manifest.yaml
84
+
85
+ # Export from stdin
86
+ cat diagram.json | diagrams export - -f docker-compose
87
+
88
+ # Export to stdout
89
+ diagrams export diagram.json -f docker-compose --stdout
90
+ ```
91
+
92
+ ### diff — Visual diffs in git
93
+
94
+ ```bash
95
+ # Diff against HEAD (default: diagram-diff.html)
96
+ diagrams diff show HEAD diagram.ts
97
+
98
+ # Diff with explicit output
99
+ diagrams diff show HEAD diagram.ts -o diff.html
100
+
101
+ # Diff to stdout
102
+ diagrams diff show HEAD diagram.ts --stdout
103
+
104
+ # Diff between branches
105
+ diagrams diff show main...feature diagram.json -F html
106
+
107
+ # List changed files
108
+ diagrams diff list HEAD
109
+
110
+ # Batch diff all changes
111
+ diagrams diff batch main...feature -o ./diffs
112
+ ```
113
+
114
+ ### init — Scaffold new diagrams
115
+
116
+ ```bash
117
+ # Basic diagram
118
+ diagrams init "My Architecture"
119
+
120
+ # AWS template
121
+ diagrams init "AWS Stack" -t aws -o aws.ts
122
+
123
+ # Kubernetes template
124
+ diagrams init "K8s Cluster" -t k8s -o k8s.ts
125
+ ```
126
+
127
+ **Templates:** `basic`, `aws`, `k8s`
128
+
129
+ ### watch — Watch and auto-render
130
+
131
+ ```bash
132
+ # Watch file and re-render on changes (default: same-name.svg)
133
+ diagrams watch diagram.ts
134
+
135
+ # Watch with explicit output
136
+ diagrams watch diagram.ts -o out.svg
137
+
138
+ # Watch with PNG output
139
+ diagrams watch diagram.ts -f png --scale 2 -o out.png
140
+ ```
141
+
142
+ ### plugins — Discover plugins
143
+
144
+ ```bash
145
+ # List installed plugins
146
+ diagrams plugins list
147
+
148
+ # Show plugin details
149
+ diagrams plugins info docker-compose
150
+ ```
151
+
152
+ ## Configuration
153
+
154
+ Create `.diagramsrc.json`:
155
+
156
+ ```json
157
+ {
158
+ "format": "svg",
159
+ "theme": "light",
160
+ "direction": "TB",
161
+ "curveStyle": "ortho",
162
+ "scale": 2,
163
+ "diff": {
164
+ "layout": "side-by-side",
165
+ "showUnchanged": "show",
166
+ "ignorePosition": true
167
+ }
168
+ }
169
+ ```
170
+
171
+ ## Common Mistakes
172
+
173
+ ### HIGH Wrong input file format
174
+
175
+ Wrong:
176
+
177
+ ```bash
178
+ diagrams render diagram.txt # .txt not supported
179
+ ```
180
+
181
+ Correct:
182
+
183
+ ```bash
184
+ diagrams render diagram.ts # .ts, .js, .json, .svg, .yaml, .yml supported
185
+ ```
186
+
187
+ ### MEDIUM Forgetting output format for PNG/JPG
188
+
189
+ Wrong:
190
+
191
+ ```bash
192
+ diagrams render diagram.ts -o out.jpg # Missing -f jpg
193
+ ```
194
+
195
+ Correct:
196
+
197
+ ```bash
198
+ diagrams render diagram.ts -f jpg -o out.jpg
199
+ ```
200
+
201
+ ### CRITICAL Wrong diff command syntax
202
+
203
+ Wrong:
204
+
205
+ ```bash
206
+ diagrams diff HEAD diagram.ts # Missing subcommand
207
+ ```
208
+
209
+ Correct:
210
+
211
+ ```bash
212
+ diagrams diff show HEAD diagram.ts
213
+ ```
214
+
215
+ ## See Also
216
+
217
+ - diagrams-js/getting-started — Basic diagram creation
218
+ - diagrams-js/diagram-diff — Visual diff details
219
+ - diagrams-js-plugin-system — Creating custom plugins
220
+ - diagrams-js/github-action — CI/CD integration
@@ -443,13 +443,31 @@ export const myPlugin = () => ({
443
443
  3. **Version**: `npm version patch|minor|major`
444
444
  4. **Publish**: `npm publish --access public`
445
445
 
446
+ ### Naming Convention
447
+
448
+ Name your plugin with the `diagrams-js-plugin-` prefix so the CLI and users can find it:
449
+
450
+ ```json
451
+ {
452
+ "name": "diagrams-js-plugin-terraform"
453
+ }
454
+ ```
455
+
456
+ Or with a scope:
457
+
458
+ ```json
459
+ {
460
+ "name": "@myorg/diagrams-js-plugin-terraform"
461
+ }
462
+ ```
463
+
446
464
  ### NPM Keywords for Discoverability
447
465
 
448
466
  Add `diagrams-js` to your `package.json` keywords to make your plugin discoverable:
449
467
 
450
468
  ```json
451
469
  {
452
- "name": "@diagrams-js/plugin-my-format",
470
+ "name": "diagrams-js-plugin-my-format",
453
471
  "keywords": ["diagrams-js", "diagrams", "architecture", "plugin", "import", "export"]
454
472
  }
455
473
  ```
@@ -191,20 +191,29 @@ These appear in the HTML output under "Diagram Options Changed".
191
191
 
192
192
  ## CLI Tool
193
193
 
194
- Use `diagrams-diff-cli` for git workflows:
194
+ Use `@diagrams-js/cli` for git workflows:
195
195
 
196
196
  ```bash
197
197
  # Install globally
198
- npm install -g diagrams-diff-cli
198
+ npm install -g @diagrams-js/cli
199
199
 
200
- # Compare with HEAD
201
- diagrams-diff HEAD diagram.json -o diff.html
200
+ # Compare with HEAD (default: diagram-diff.html)
201
+ diagrams diff show HEAD diagram.json
202
+
203
+ # Compare with explicit output
204
+ diagrams diff show HEAD diagram.json -o diff.html
205
+
206
+ # Output to stdout
207
+ diagrams diff show HEAD diagram.json --stdout
202
208
 
203
209
  # Compare branches
204
- diagrams-diff main...feature diagram.json -o diff.html
210
+ diagrams diff show main...feature diagram.json -F html -o diff.html
211
+
212
+ # List changed files
213
+ diagrams diff list HEAD
205
214
 
206
- # Terminal preview
207
- diagrams-diff HEAD diagram.json --format terminal
215
+ # Batch diff all changed files
216
+ diagrams diff batch main...feature -o ./diffs
208
217
  ```
209
218
 
210
219
  ## Common Mistakes
@@ -0,0 +1,318 @@
1
+ ---
2
+ name: diagrams-js/github-action
3
+ description: >
4
+ GitHub Action for diagrams-js. Use diagrams-js/action@v1 in CI/CD workflows
5
+ to render, diff, import, and validate architecture diagrams. Supports PR
6
+ comments, artifact uploads, and plugin integration.
7
+ type: tooling
8
+ library: diagrams-js
9
+ library_version: "0.5.0"
10
+ requires:
11
+ - diagrams-js/getting-started
12
+ - diagrams-js/cli
13
+ sources:
14
+ - "hatemhosny/diagrams-js:docs/docs/guides/github-action.mdx"
15
+ - "hatemhosny/diagrams-js:action/action.yml"
16
+ ---
17
+
18
+ This skill builds on diagrams-js/getting-started and diagrams-js/cli. Read them first for foundational concepts.
19
+
20
+ # diagrams-js GitHub Action
21
+
22
+ Use diagrams-js in GitHub Actions for CI/CD. Render diagrams on push, generate visual diffs in PRs, validate diagrams, and auto-render from Docker Compose or Kubernetes files.
23
+
24
+ ## Quick Start
25
+
26
+ ```yaml
27
+ - uses: diagrams-js/action@v1
28
+ with:
29
+ command: render
30
+ args: architecture.ts
31
+ output: architecture.svg
32
+ ```
33
+
34
+ ## Inputs
35
+
36
+ | Input | Description | Default |
37
+ | ------------------- | ------------------------------------------------- | ----------------- |
38
+ | `command` | CLI command: `render`, `import`, `export`, `diff` | `render` |
39
+ | `args` | Arguments for the command | `""` |
40
+ | `format` | Output format | `svg` |
41
+ | `output` | Output file path | `""` |
42
+ | `theme` | Color theme | `""` |
43
+ | `direction` | Layout direction | `""` |
44
+ | `plugin` | Plugin name | `""` |
45
+ | `comment-pr` | Comment on PR | `false` |
46
+ | `upload-artifact` | Upload artifact | `true` |
47
+ | `artifact-name` | Artifact name | `diagrams-output` |
48
+ | `working-directory` | Working directory | `""` |
49
+ | `node-version` | Node.js version | `22` |
50
+ | `cli-version` | CLI version | `latest` |
51
+
52
+ ## Outputs
53
+
54
+ | Output | Description |
55
+ | --------------- | ------------------- |
56
+ | `output-path` | Generated file path |
57
+ | `output-format` | Output format |
58
+
59
+ ## Core Patterns
60
+
61
+ ### Render on push
62
+
63
+ ```yaml
64
+ name: Render Diagrams
65
+ on:
66
+ push:
67
+ branches: [main]
68
+ paths:
69
+ - "diagrams/**"
70
+
71
+ jobs:
72
+ render:
73
+ runs-on: ubuntu-latest
74
+ steps:
75
+ - uses: actions/checkout@v4
76
+ - uses: diagrams-js/action@v1
77
+ with:
78
+ command: render
79
+ args: diagrams/architecture.ts
80
+ output: architecture.svg
81
+ - uses: actions/upload-artifact@v4
82
+ with:
83
+ name: diagrams
84
+ path: architecture.svg
85
+ ```
86
+
87
+ ### Diff in PR
88
+
89
+ ```yaml
90
+ name: Diagram Diff
91
+ on:
92
+ pull_request:
93
+ paths:
94
+ - "**/*.ts"
95
+ - "**/*.json"
96
+ - "**/*.svg"
97
+
98
+ jobs:
99
+ diff:
100
+ runs-on: ubuntu-latest
101
+ steps:
102
+ - uses: actions/checkout@v4
103
+ with:
104
+ fetch-depth: 0
105
+ - uses: diagrams-js/action@v1
106
+ with:
107
+ command: diff
108
+ args: show origin/${{ github.base_ref }} architecture.ts
109
+ output: diff.html
110
+ format: html
111
+ comment-pr: true
112
+ ```
113
+
114
+ ### Validate diagrams
115
+
116
+ ```yaml
117
+ name: Validate Diagrams
118
+ on: [pull_request]
119
+
120
+ jobs:
121
+ validate:
122
+ runs-on: ubuntu-latest
123
+ steps:
124
+ - uses: actions/checkout@v4
125
+ - uses: diagrams-js/action@v1
126
+ with:
127
+ command: render
128
+ args: diagram.ts
129
+ format: svg
130
+ ```
131
+
132
+ ### Import from Docker Compose
133
+
134
+ ```yaml
135
+ - uses: diagrams-js/action@v1
136
+ with:
137
+ command: import
138
+ args: docker-compose.yml
139
+ output: architecture.svg
140
+ plugin: docker-compose
141
+ ```
142
+
143
+ ### Import from Kubernetes
144
+
145
+ ```yaml
146
+ - uses: diagrams-js/action@v1
147
+ with:
148
+ command: import
149
+ args: k8s/manifest.yaml
150
+ output: k8s-architecture.svg
151
+ plugin: kubernetes
152
+ ```
153
+
154
+ ## PR Comments
155
+
156
+ Enable `comment-pr: true` to post results on pull requests:
157
+
158
+ ```yaml
159
+ - uses: diagrams-js/action@v1
160
+ with:
161
+ command: diff
162
+ args: show HEAD diagram.ts
163
+ output: diff.html
164
+ format: html
165
+ comment-pr: true
166
+ ```
167
+
168
+ ## Artifacts
169
+
170
+ Outputs auto-upload as artifacts. Disable with `upload-artifact: false`:
171
+
172
+ ```yaml
173
+ - uses: diagrams-js/action@v1
174
+ with:
175
+ command: render
176
+ args: diagram.ts
177
+ output: diagram.svg
178
+ artifact-name: my-diagram
179
+ ```
180
+
181
+ ## Version Pinning
182
+
183
+ Pin CLI version for reproducible builds:
184
+
185
+ ```yaml
186
+ - uses: diagrams-js/action@v1
187
+ with:
188
+ command: render
189
+ args: diagram.ts
190
+ cli-version: "0.1.0"
191
+ ```
192
+
193
+ ## Working Directory
194
+
195
+ Run in a subdirectory:
196
+
197
+ ```yaml
198
+ - uses: diagrams-js/action@v1
199
+ with:
200
+ command: render
201
+ args: diagram.ts
202
+ working-directory: ./projects/my-app
203
+ ```
204
+
205
+ ## Common Mistakes
206
+
207
+ ### CRITICAL Missing fetch-depth for diffs
208
+
209
+ Wrong:
210
+
211
+ ```yaml
212
+ - uses: actions/checkout@v4
213
+ - uses: diagrams-js/action@v1
214
+ with:
215
+ command: diff
216
+ args: show origin/main diagram.ts
217
+ ```
218
+
219
+ Correct:
220
+
221
+ ```yaml
222
+ - uses: actions/checkout@v4
223
+ with:
224
+ fetch-depth: 0
225
+ - uses: diagrams-js/action@v1
226
+ with:
227
+ command: diff
228
+ args: show origin/main diagram.ts
229
+ ```
230
+
231
+ Git diff requires full history. Always set `fetch-depth: 0`.
232
+
233
+ ### HIGH Wrong command for diff
234
+
235
+ Wrong:
236
+
237
+ ```yaml
238
+ with:
239
+ command: diff
240
+ args: HEAD diagram.ts
241
+ ```
242
+
243
+ Correct:
244
+
245
+ ```yaml
246
+ with:
247
+ command: diff
248
+ args: show HEAD diagram.ts
249
+ ```
250
+
251
+ Diff requires subcommand: `show`, `list`, or `batch`.
252
+
253
+ ### MEDIUM Forgetting output path
254
+
255
+ Without `output`, the action generates default filenames. Always specify `output` for clarity:
256
+
257
+ ```yaml
258
+ with:
259
+ command: render
260
+ args: diagram.ts
261
+ output: diagram.svg
262
+ ```
263
+
264
+ ## Best Practices
265
+
266
+ ### 1. Trigger on relevant paths
267
+
268
+ Only run when diagram files change:
269
+
270
+ ```yaml
271
+ on:
272
+ push:
273
+ paths:
274
+ - "diagrams/**"
275
+ - "**/*.diagram.ts"
276
+ ```
277
+
278
+ ### 2. Use matrix for multiple diagrams
279
+
280
+ ```yaml
281
+ strategy:
282
+ matrix:
283
+ diagram: [architecture.ts, infrastructure.ts]
284
+ steps:
285
+ - uses: diagrams-js/action@v1
286
+ with:
287
+ command: render
288
+ args: diagrams/${{ matrix.diagram }}
289
+ output: ${{ matrix.diagram }}.svg
290
+ ```
291
+
292
+ ### 3. Combine with artifact upload
293
+
294
+ ```yaml
295
+ - uses: diagrams-js/action@v1
296
+ with:
297
+ command: render
298
+ args: diagram.ts
299
+ output: diagram.svg
300
+ - uses: actions/upload-artifact@v4
301
+ with:
302
+ name: diagrams
303
+ path: diagram.svg
304
+ ```
305
+
306
+ ### 4. Pin versions in production
307
+
308
+ ```yaml
309
+ - uses: diagrams-js/action@v1
310
+ with:
311
+ cli-version: "0.1.0"
312
+ ```
313
+
314
+ ## See Also
315
+
316
+ - diagrams-js/cli — Command-line interface
317
+ - diagrams-js/diagram-diff — Visual diff details
318
+ - diagrams-js-plugin-system — Creating custom plugins