@polagram/cli 0.0.5 → 0.0.7
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/README.md +51 -4
- package/dist/index.js +48 -7
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -10,6 +10,10 @@ The official CLI for Polagram, enabling CI/CD integration for sequence diagram t
|
|
|
10
10
|
pnpm add -D @polagram/cli
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
+
## Supported Formats
|
|
14
|
+
- **Mermaid**: `.mmd`, `.mermaid`
|
|
15
|
+
- **PlantUML**: `.puml`, `.plantuml`, `.pu`
|
|
16
|
+
|
|
13
17
|
## Usage
|
|
14
18
|
|
|
15
19
|
### Configuration
|
|
@@ -22,6 +26,8 @@ targets:
|
|
|
22
26
|
- input: ["docs/design/**/*.mmd"]
|
|
23
27
|
outputDir: "docs/generated"
|
|
24
28
|
ignore: ["**/_*.mmd"]
|
|
29
|
+
# format: mermaid # Optional: auto-detected from file extension/content
|
|
30
|
+
# outputFormat: plantuml # Optional: defaults to input format
|
|
25
31
|
lenses:
|
|
26
32
|
- name: "success"
|
|
27
33
|
suffix: ".success"
|
|
@@ -32,7 +38,7 @@ targets:
|
|
|
32
38
|
|
|
33
39
|
# Remove infrastructure details (Logger, Metrics)
|
|
34
40
|
- action: remove
|
|
35
|
-
selector: { kind: "participant",
|
|
41
|
+
selector: { kind: "participant", name: { pattern: ".*(Logger|Metrics).*" } }
|
|
36
42
|
|
|
37
43
|
# Focus on specific interactions
|
|
38
44
|
- action: focus
|
|
@@ -53,6 +59,47 @@ pnpm polagram generate --config my-config.yml
|
|
|
53
59
|
|
|
54
60
|
## Features
|
|
55
61
|
|
|
56
|
-
- **
|
|
57
|
-
- **
|
|
58
|
-
- **
|
|
62
|
+
- **Multi-Format Support**: Works with both Mermaid and PlantUML sequence diagrams
|
|
63
|
+
- **Auto-Detection**: Automatically detects diagram format from file extension or content
|
|
64
|
+
- **Format Conversion**: Convert between Mermaid and PlantUML formats
|
|
65
|
+
- **Glob Support**: Use standard glob patterns to find input files
|
|
66
|
+
- **Directory Mirroring**: Output files preserve their directory structure relative to the project root
|
|
67
|
+
- **Strict Validation**: Validates `polagram.yml` against the Core schema to prevent errors
|
|
68
|
+
|
|
69
|
+
## Supported Formats
|
|
70
|
+
|
|
71
|
+
| Format | Extensions | Auto-Detection |
|
|
72
|
+
|--------|-----------|----------------|
|
|
73
|
+
| Mermaid | `.mmd`, `.mermaid` | `sequenceDiagram` keyword |
|
|
74
|
+
| PlantUML | `.puml`, `.plantuml`, `.pu` | `@startuml` keyword |
|
|
75
|
+
|
|
76
|
+
## Examples
|
|
77
|
+
|
|
78
|
+
### PlantUML to PlantUML
|
|
79
|
+
|
|
80
|
+
```yaml
|
|
81
|
+
version: 1
|
|
82
|
+
targets:
|
|
83
|
+
- input: ["diagrams/**/*.puml"]
|
|
84
|
+
outputDir: "generated"
|
|
85
|
+
lenses:
|
|
86
|
+
- name: "clean"
|
|
87
|
+
layers:
|
|
88
|
+
- action: remove
|
|
89
|
+
selector: { kind: "participant", name: "Logger" }
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Cross-Format Conversion (PlantUML to Mermaid)
|
|
93
|
+
|
|
94
|
+
```yaml
|
|
95
|
+
version: 1
|
|
96
|
+
targets:
|
|
97
|
+
- input: ["diagrams/**/*.puml"]
|
|
98
|
+
outputDir: "generated"
|
|
99
|
+
outputFormat: mermaid # Convert to Mermaid format
|
|
100
|
+
lenses:
|
|
101
|
+
- name: "converted"
|
|
102
|
+
layers:
|
|
103
|
+
- action: focus
|
|
104
|
+
selector: { kind: "participant", name: { pattern: "API.*" } }
|
|
105
|
+
```
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { Polagram } from '@polagram/core';
|
|
2
|
+
import { FormatDetector, Polagram } from '@polagram/core';
|
|
3
3
|
import { Command } from 'commander';
|
|
4
4
|
import { promises as fs } from 'fs';
|
|
5
5
|
import { glob } from 'glob';
|
|
@@ -44,22 +44,34 @@ program
|
|
|
44
44
|
// Calculate relative path from the config directory to the input file
|
|
45
45
|
const relativePath = path.relative(configDir, file);
|
|
46
46
|
try {
|
|
47
|
-
//
|
|
48
|
-
|
|
47
|
+
// Determine input format
|
|
48
|
+
const inputFormat = target.format || FormatDetector.detect(file, content);
|
|
49
|
+
if (!inputFormat) {
|
|
50
|
+
console.error(` Cannot detect format for ${relativePath}. Please specify 'format' in config.`);
|
|
51
|
+
process.exitCode = 1;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
// Determine output format (defaults to input format)
|
|
55
|
+
const outputFormat = target.outputFormat || inputFormat;
|
|
56
|
+
// 1. Initialize Pipeline with detected format (parsing check)
|
|
57
|
+
Polagram.init(content, inputFormat);
|
|
49
58
|
// 2. Apply Lenses
|
|
50
59
|
for (const lens of target.lenses) {
|
|
51
|
-
const lensPipeline = Polagram.init(content);
|
|
60
|
+
const lensPipeline = Polagram.init(content, inputFormat);
|
|
52
61
|
// core expects strict discriminated union, Zod inferred type is loose.
|
|
53
62
|
// Validation guarantees structure.
|
|
54
63
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
64
|
lensPipeline.applyLens(lens);
|
|
56
|
-
// 3. Generate
|
|
57
|
-
const result =
|
|
65
|
+
// 3. Generate based on output format
|
|
66
|
+
const result = outputFormat === 'plantuml'
|
|
67
|
+
? lensPipeline.toPlantUML()
|
|
68
|
+
: lensPipeline.toMermaid();
|
|
58
69
|
// 4. Output
|
|
59
70
|
const originalExt = path.extname(file);
|
|
60
71
|
const basename = path.basename(file, originalExt);
|
|
61
72
|
const suffix = lens.suffix || `.${lens.name}`;
|
|
62
|
-
const
|
|
73
|
+
const outputExt = FormatDetector.getDefaultExtension(outputFormat);
|
|
74
|
+
const newFilename = `${basename}${suffix}${outputExt}`;
|
|
63
75
|
// Mirroring Logic:
|
|
64
76
|
// input: src/foo/bar.mmd -> relativePath: src/foo/bar.mmd (relative to configDir)
|
|
65
77
|
// outputDir is resolved relative to configDir
|
|
@@ -88,5 +100,34 @@ program
|
|
|
88
100
|
process.exit(1);
|
|
89
101
|
}
|
|
90
102
|
});
|
|
103
|
+
program
|
|
104
|
+
.command('preview')
|
|
105
|
+
.description('Build or serve static spec viewer for diagrams')
|
|
106
|
+
.argument('[action]', 'Action to perform: build or serve', 'build')
|
|
107
|
+
.option('-c, --config <path>', 'Path to config file', 'polagram.yml')
|
|
108
|
+
.option('-o, --outDir <path>', 'Output directory for build', 'polagram-preview')
|
|
109
|
+
.option('-p, --port <number>', 'Port for serve', '4173')
|
|
110
|
+
.action(async (action, options) => {
|
|
111
|
+
try {
|
|
112
|
+
// Dynamic import to avoid loading preview package when not needed
|
|
113
|
+
const { build, serve } = await import('@polagram/preview');
|
|
114
|
+
if (action === 'serve') {
|
|
115
|
+
await serve({
|
|
116
|
+
config: options.config,
|
|
117
|
+
port: parseInt(options.port, 10)
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
await build({
|
|
122
|
+
config: options.config,
|
|
123
|
+
outDir: options.outDir
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
console.error('Preview error:', error instanceof Error ? error.message : String(error));
|
|
129
|
+
process.exit(1);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
91
132
|
program.parse();
|
|
92
133
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAsB,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,O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AM,CAAC,mBAAmB,CAAC,CAAC;QAE3D,IAAI,MAAM,KAAK,OAAO,EAAE,CAAC;YACrB,MAAM,KAAK,CAAC;gBACR,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;aACnC,CAAC,CAAC;QACP,CAAC;aAAM,CAAC;YACJ,MAAM,KAAK,CAAC;gBACR,MAAM,EAAE,OAAO,CAAC,MAAM;gBACtB,MAAM,EAAE,OAAO,CAAC,MAAM;aACzB,CAAC,CAAC;QACP,CAAC;IACL,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACtB,OAAO,CAAC,KAAK,CAAC,gBAAgB,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACxF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACL,CAAC,CAAC,CAAC;AAEP,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polagram/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"commander": "^13.0.0",
|
|
29
29
|
"glob": "^11.0.0",
|
|
30
30
|
"js-yaml": "^4.1.0",
|
|
31
|
-
"@polagram/
|
|
31
|
+
"@polagram/preview": "0.0.1",
|
|
32
|
+
"@polagram/core": "0.0.4"
|
|
32
33
|
},
|
|
33
34
|
"devDependencies": {
|
|
34
35
|
"@types/glob": "^8.1.0",
|
|
@@ -40,6 +41,7 @@
|
|
|
40
41
|
"scripts": {
|
|
41
42
|
"build": "tsc -b",
|
|
42
43
|
"dev": "tsc -w",
|
|
44
|
+
"test": "vitest run",
|
|
43
45
|
"start": "node dist/index.js"
|
|
44
46
|
}
|
|
45
47
|
}
|