@polagram/cli 0.0.2
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 +56 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.js +22 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +92 -0
- package/dist/index.js.map +1 -0
- package/package.json +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# @polagram/cli
|
|
2
|
+
|
|
3
|
+
The official CLI for Polagram, enabling CI/CD integration for sequence diagram transformations.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add -D @polagram/cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Configuration
|
|
14
|
+
|
|
15
|
+
Create a `polagram.yml` in your project root:
|
|
16
|
+
|
|
17
|
+
```yaml
|
|
18
|
+
version: 1
|
|
19
|
+
targets:
|
|
20
|
+
- input: ["docs/design/**/*.mmd"]
|
|
21
|
+
outputDir: "docs/generated"
|
|
22
|
+
ignore: ["**/_*.mmd"]
|
|
23
|
+
lenses:
|
|
24
|
+
- name: "success"
|
|
25
|
+
suffix: ".success"
|
|
26
|
+
layers:
|
|
27
|
+
# Resolve "Success" alt blocks (Show only the success case)
|
|
28
|
+
- action: resolve
|
|
29
|
+
selector: { kind: "fragment", condition: "Success" }
|
|
30
|
+
|
|
31
|
+
# Remove infrastructure details (Logger, Metrics)
|
|
32
|
+
- action: remove
|
|
33
|
+
selector: { kind: "participant", stereotype: "infra" }
|
|
34
|
+
|
|
35
|
+
# Focus on specific interactions
|
|
36
|
+
- action: focus
|
|
37
|
+
selector: { kind: "participant", name: { pattern: "Client.*" } }
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Running
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pnpm polagram run
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Or with a specific config:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pnpm polagram run --config my-config.yml
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Features
|
|
53
|
+
|
|
54
|
+
- **Glob Support**: Use standard glob patterns to find input files.
|
|
55
|
+
- **Directory Mirroring**: Output files preserve their directory structure relative to the project root (or execution directory) to prevent collisions.
|
|
56
|
+
- **Strict Validation**: Validates `polagram.yml` against the Core schema to prevent errors.
|
package/dist/config.d.ts
ADDED
package/dist/config.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { validateConfig } from '@polagram/core';
|
|
2
|
+
import { promises as fs } from 'fs';
|
|
3
|
+
import yaml from 'js-yaml';
|
|
4
|
+
export async function loadConfig(path) {
|
|
5
|
+
try {
|
|
6
|
+
const content = await fs.readFile(path, 'utf-8');
|
|
7
|
+
const raw = yaml.load(content);
|
|
8
|
+
return validateConfig(raw);
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
|
|
12
|
+
throw new Error(`Configuration file not found at: ${path}`);
|
|
13
|
+
}
|
|
14
|
+
if (error instanceof Error) {
|
|
15
|
+
// If it's a validation error from Core, it will have a nice message already.
|
|
16
|
+
// If it's a YAML syntax error, js-yaml throws formatted errors too.
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
throw new Error(`Unknown error loading config: ${String(error)}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,IAAI,CAAC;AACpC,OAAO,IAAI,MAAM,SAAS,CAAC;AAE3B,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,IAAY;IACzC,IAAI,CAAC;QACD,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACjD,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC/B,OAAO,cAAc,CAAC,GAAG,CAAC,CAAC;IAC/B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,IAAI,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACvE,MAAM,IAAI,KAAK,CAAC,oCAAoC,IAAI,EAAE,CAAC,CAAC;QAChE,CAAC;QACD,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YACzB,6EAA6E;YAC7E,oEAAoE;YACpE,MAAM,KAAK,CAAC;QAChB,CAAC;QACD,MAAM,IAAI,KAAK,CAAC,iCAAiC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACtE,CAAC;AACL,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Polagram } from '@polagram/core';
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
import { promises as fs } from 'fs';
|
|
5
|
+
import { glob } from 'glob';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { loadConfig } from './config.js';
|
|
8
|
+
const program = new Command();
|
|
9
|
+
program
|
|
10
|
+
.name('polagram')
|
|
11
|
+
.description('CLI tool for Polagram - Sequence Diagram CI/CD')
|
|
12
|
+
.version('0.0.1');
|
|
13
|
+
program
|
|
14
|
+
.command('run')
|
|
15
|
+
.description('Run transformations based on polagram.yml')
|
|
16
|
+
.option('-c, --config <path>', 'Path to config file', process.env.POLAGRAPH_CONFIG || 'polagram.yml')
|
|
17
|
+
.action(async (options) => {
|
|
18
|
+
try {
|
|
19
|
+
console.log(`Loading config from ${options.config}...`);
|
|
20
|
+
// Resolve config path to absolute to determine the base directory
|
|
21
|
+
const configPath = path.resolve(process.cwd(), options.config);
|
|
22
|
+
const configDir = path.dirname(configPath);
|
|
23
|
+
const config = await loadConfig(configPath);
|
|
24
|
+
console.log(`Found ${config.targets.length} targets.`);
|
|
25
|
+
for (const target of config.targets) {
|
|
26
|
+
const ignores = [
|
|
27
|
+
'**/node_modules/**',
|
|
28
|
+
'**/dist/**',
|
|
29
|
+
...(target.ignore || [])
|
|
30
|
+
];
|
|
31
|
+
// Search for files relative to the config file directory
|
|
32
|
+
const files = await glob(target.input, {
|
|
33
|
+
ignore: ignores,
|
|
34
|
+
cwd: configDir,
|
|
35
|
+
absolute: true
|
|
36
|
+
});
|
|
37
|
+
if (files.length === 0) {
|
|
38
|
+
console.warn(`No files found for input: ${target.input}`);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
console.log(`Processing ${files.length} files...`);
|
|
42
|
+
for (const file of files) {
|
|
43
|
+
const content = await fs.readFile(file, 'utf-8');
|
|
44
|
+
// Calculate relative path from the config directory to the input file
|
|
45
|
+
const relativePath = path.relative(configDir, file);
|
|
46
|
+
try {
|
|
47
|
+
// 1. Initialize Pipeline (Just parsing check essentially)
|
|
48
|
+
Polagram.init(content);
|
|
49
|
+
// 2. Apply Lenses
|
|
50
|
+
for (const lens of target.lenses) {
|
|
51
|
+
const lensPipeline = Polagram.init(content);
|
|
52
|
+
// core expects strict discriminated union, Zod inferred type is loose.
|
|
53
|
+
// Validation guarantees structure.
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
|
+
lensPipeline.applyLens(lens);
|
|
56
|
+
// 3. Generate
|
|
57
|
+
const result = lensPipeline.toMermaid();
|
|
58
|
+
// 4. Output
|
|
59
|
+
const originalExt = path.extname(file);
|
|
60
|
+
const basename = path.basename(file, originalExt);
|
|
61
|
+
const suffix = lens.suffix || `.${lens.name}`;
|
|
62
|
+
const newFilename = `${basename}${suffix}.mmd`;
|
|
63
|
+
// Mirroring Logic:
|
|
64
|
+
// input: src/foo/bar.mmd -> relativePath: src/foo/bar.mmd (relative to configDir)
|
|
65
|
+
// outputDir is resolved relative to configDir
|
|
66
|
+
const fileDir = path.dirname(relativePath); // src/foo
|
|
67
|
+
// target.outputDir is relative to configDir, so we join them: configDir + target.outputDir + fileDir
|
|
68
|
+
const absOutputDir = path.resolve(configDir, target.outputDir);
|
|
69
|
+
const finalOutputDir = path.join(absOutputDir, fileDir); // /path/to/config/generated/src/foo
|
|
70
|
+
await fs.mkdir(finalOutputDir, { recursive: true });
|
|
71
|
+
const outputPath = path.join(finalOutputDir, newFilename);
|
|
72
|
+
await fs.writeFile(outputPath, result);
|
|
73
|
+
console.log(` Derived: ${relativePath} -> ${path.relative(configDir, outputPath)}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
console.error(` Error processing ${relativePath}: ${err instanceof Error ? err.message : String(err)}`);
|
|
78
|
+
// Continue with next file? Yes, usually CI tools shouldn't crash fully on one file unless strict.
|
|
79
|
+
// But maybe we want to track errors and exit non-zero at end.
|
|
80
|
+
process.exitCode = 1;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
console.log('Done.');
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
console.error('Fatal error:', error instanceof Error ? error.message : String(error));
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
program.parse();
|
|
92
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC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K,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACtF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACL,CAAC,CAAC,CAAC;AAEP,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@polagram/cli",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/Jun-T-git/polagram.git"
|
|
11
|
+
},
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"polagram",
|
|
15
|
+
"cli"
|
|
16
|
+
],
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"description": "CLI tool for Polagram",
|
|
22
|
+
"main": "dist/index.js",
|
|
23
|
+
"bin": {
|
|
24
|
+
"polagram": "dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"commander": "^13.0.0",
|
|
28
|
+
"glob": "^11.0.0",
|
|
29
|
+
"js-yaml": "^4.1.0",
|
|
30
|
+
"@polagram/core": "0.0.2"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/glob": "^8.1.0",
|
|
34
|
+
"@types/js-yaml": "^4.0.9",
|
|
35
|
+
"@types/node": "^22.10.2",
|
|
36
|
+
"typescript": "^5.7.2",
|
|
37
|
+
"vitest": "^2.1.8"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "tsc -b",
|
|
41
|
+
"dev": "tsc -w",
|
|
42
|
+
"start": "node dist/index.js"
|
|
43
|
+
}
|
|
44
|
+
}
|