@contractspec/integration.example-generator 1.48.1
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 +151 -0
- package/dist/index.d.mts +123 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +91 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +82 -0
package/README.md
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# @contractspec/integration.example-generator
|
|
2
|
+
|
|
3
|
+
Example plugin for ContractSpec that generates markdown documentation from ContractSpec specifications.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This plugin demonstrates how to create a ContractSpec generator plugin. It transforms structured spec definitions into human-readable markdown documentation that can be used for API docs, user guides, or technical specifications.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- ๐ **Spec-First Generation**: Converts ContractSpec specs to markdown automatically
|
|
12
|
+
- ๐ **Rich Formatting**: Supports tables, lists, and detail views
|
|
13
|
+
- ๐ง **Configurable Output**: Customize formatting, field selection, and styling
|
|
14
|
+
- ๐ **Data Integration**: Works with schema models and instance data
|
|
15
|
+
- ๐ฏ **Type Safe**: Full TypeScript support with proper type definitions
|
|
16
|
+
- ๐งช **Well Tested**: Comprehensive test suite included
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @contractspec/integration.example-generator
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### Basic Usage
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { ExampleGeneratorPlugin } from "@contractspec/integration.example-generator";
|
|
30
|
+
|
|
31
|
+
const generator = new ExampleGeneratorPlugin({
|
|
32
|
+
outputDir: "./docs",
|
|
33
|
+
format: "table", // or "list", "detail", "auto"
|
|
34
|
+
includeFields: ["id", "name", "description"],
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Generate markdown from specs
|
|
38
|
+
await generator.generateFromSpec(specPath, outputPath);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Advanced Configuration
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { ExampleGeneratorPlugin } from "@contractspec/integration.example-generator";
|
|
45
|
+
|
|
46
|
+
const generator = new ExampleGeneratorPlugin({
|
|
47
|
+
outputDir: "./docs",
|
|
48
|
+
format: "auto",
|
|
49
|
+
title: "API Documentation",
|
|
50
|
+
description: "Auto-generated API documentation",
|
|
51
|
+
maxItems: 100,
|
|
52
|
+
maxDepth: 3,
|
|
53
|
+
fieldLabels: {
|
|
54
|
+
id: "ID",
|
|
55
|
+
createdAt: "Created Date",
|
|
56
|
+
updatedAt: "Last Modified"
|
|
57
|
+
},
|
|
58
|
+
summaryFields: ["id", "name", "status"],
|
|
59
|
+
excludeFields: ["internalNotes", "metadata"]
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Configuration Options
|
|
64
|
+
|
|
65
|
+
| Option | Type | Default | Description |
|
|
66
|
+
| --------------- | ------------------------ | ---------- | -------------------------------------------------------- |
|
|
67
|
+
| `outputDir` | `string` | `"./docs"` | Directory for generated files |
|
|
68
|
+
| `format` | `string` | `"auto"` | Output format: `"table"`, `"list"`, `"detail"`, `"auto"` |
|
|
69
|
+
| `title` | `string` | undefined | Document title |
|
|
70
|
+
| `description` | `string` | undefined | Document description |
|
|
71
|
+
| `maxItems` | `number` | `100` | Maximum items to render in tables |
|
|
72
|
+
| `maxDepth` | `number` | `2` | Maximum nesting depth for objects |
|
|
73
|
+
| `includeFields` | `string[]` | undefined | Only include these fields |
|
|
74
|
+
| `excludeFields` | `string[]` | `[]` | Exclude these fields from output |
|
|
75
|
+
| `fieldLabels` | `Record<string, string>` | undefined | Custom field labels |
|
|
76
|
+
| `summaryFields` | `string[]` | undefined | Fields for list summaries |
|
|
77
|
+
|
|
78
|
+
## Plugin Interface
|
|
79
|
+
|
|
80
|
+
This plugin implements the ContractSpec generator interface:
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
interface GeneratorPlugin {
|
|
84
|
+
readonly id: string;
|
|
85
|
+
readonly name: string;
|
|
86
|
+
readonly version: string;
|
|
87
|
+
|
|
88
|
+
initialize(config: GeneratorConfig): Promise<void>;
|
|
89
|
+
generate(spec: SpecDefinition, context: GeneratorContext): Promise<GeneratorResult>;
|
|
90
|
+
cleanup(): Promise<void>;
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Development
|
|
95
|
+
|
|
96
|
+
### Setup
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
# Clone the repository
|
|
100
|
+
git clone https://github.com/lssm-tech/contractspec.git
|
|
101
|
+
cd contractspec/packages/libs/plugins/example-generator
|
|
102
|
+
|
|
103
|
+
# Install dependencies
|
|
104
|
+
bun install
|
|
105
|
+
|
|
106
|
+
# Run tests
|
|
107
|
+
bun test
|
|
108
|
+
|
|
109
|
+
# Build the plugin
|
|
110
|
+
bun run build
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Testing
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
# Run all tests
|
|
117
|
+
bun test
|
|
118
|
+
|
|
119
|
+
# Run tests in watch mode
|
|
120
|
+
bun test:watch
|
|
121
|
+
|
|
122
|
+
# Run tests with coverage
|
|
123
|
+
bun test:coverage
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Building
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
# Build the plugin
|
|
130
|
+
bun run build
|
|
131
|
+
|
|
132
|
+
# Build types only
|
|
133
|
+
bun run build:types
|
|
134
|
+
|
|
135
|
+
# Build bundle only
|
|
136
|
+
bun run build:bundle
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Contributing
|
|
140
|
+
|
|
141
|
+
We welcome contributions! Please see our [Contributing Guide](../../../CONTRIBUTING.md) for details.
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
MIT ยฉ ContractSpec Team
|
|
146
|
+
|
|
147
|
+
## Support
|
|
148
|
+
|
|
149
|
+
- ๐ [Documentation](https://contractspec.io/docs)
|
|
150
|
+
- ๐ [Issues](https://github.com/lssm-tech/contractspec/issues)
|
|
151
|
+
- ๐ฌ [Discussions](https://github.com/lssm-tech/contractspec/discussions)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { AnySchemaModel } from "@contractspec/lib.schema";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
type SpecDefinition = unknown;
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for the ExampleGeneratorPlugin
|
|
7
|
+
*/
|
|
8
|
+
interface ExampleGeneratorPluginConfig {
|
|
9
|
+
/** Directory where markdown files will be generated */
|
|
10
|
+
outputDir: string;
|
|
11
|
+
/** Output format: table, list, detail, or auto */
|
|
12
|
+
format?: 'table' | 'list' | 'detail' | 'auto';
|
|
13
|
+
/** Title for the generated documentation */
|
|
14
|
+
title?: string;
|
|
15
|
+
/** Description to include below the title */
|
|
16
|
+
description?: string;
|
|
17
|
+
/** Maximum number of items to render in tables */
|
|
18
|
+
maxItems?: number;
|
|
19
|
+
/** Maximum nesting depth for nested objects */
|
|
20
|
+
maxDepth?: number;
|
|
21
|
+
/** Only include these fields (if not specified, all fields are included) */
|
|
22
|
+
includeFields?: string[];
|
|
23
|
+
/** Exclude these fields from output */
|
|
24
|
+
excludeFields?: string[];
|
|
25
|
+
/** Custom field labels (field name -> display label) */
|
|
26
|
+
fieldLabels?: Record<string, string>;
|
|
27
|
+
/** Fields to use for summary in list format */
|
|
28
|
+
summaryFields?: string[];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Context provided during generation
|
|
32
|
+
*/
|
|
33
|
+
interface GeneratorContext {
|
|
34
|
+
/** The spec definition being processed */
|
|
35
|
+
spec: SpecDefinition;
|
|
36
|
+
/** Schema models from the spec */
|
|
37
|
+
schemas: Record<string, AnySchemaModel>;
|
|
38
|
+
/** Instance data (optional) */
|
|
39
|
+
data?: unknown;
|
|
40
|
+
/** Additional metadata */
|
|
41
|
+
metadata?: Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Result of generation
|
|
45
|
+
*/
|
|
46
|
+
interface GeneratorResult {
|
|
47
|
+
/** Path to the generated file */
|
|
48
|
+
outputPath: string;
|
|
49
|
+
/** Number of items processed */
|
|
50
|
+
itemCount: number;
|
|
51
|
+
/** Generation metadata */
|
|
52
|
+
metadata: {
|
|
53
|
+
specId: string;
|
|
54
|
+
generatedAt: Date;
|
|
55
|
+
format: string;
|
|
56
|
+
config: Partial<ExampleGeneratorPluginConfig>;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Plugin metadata
|
|
61
|
+
*/
|
|
62
|
+
interface PluginMetadata {
|
|
63
|
+
readonly id: string;
|
|
64
|
+
readonly name: string;
|
|
65
|
+
readonly version: string;
|
|
66
|
+
readonly description: string;
|
|
67
|
+
readonly author: string;
|
|
68
|
+
readonly homepage?: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Error types for the plugin
|
|
72
|
+
*/
|
|
73
|
+
declare class ExampleGeneratorError extends Error {
|
|
74
|
+
readonly code: string;
|
|
75
|
+
readonly details?: unknown | undefined;
|
|
76
|
+
constructor(message: string, code: string, details?: unknown | undefined);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Validation errors
|
|
80
|
+
*/
|
|
81
|
+
declare class ValidationError extends ExampleGeneratorError {
|
|
82
|
+
constructor(message: string, details?: unknown);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Configuration errors
|
|
86
|
+
*/
|
|
87
|
+
declare class ConfigurationError extends ExampleGeneratorError {
|
|
88
|
+
constructor(message: string, details?: unknown);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Generation errors
|
|
92
|
+
*/
|
|
93
|
+
declare class GenerationError extends ExampleGeneratorError {
|
|
94
|
+
constructor(message: string, details?: unknown);
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/generator.d.ts
|
|
98
|
+
declare class ExampleGeneratorPlugin {
|
|
99
|
+
private config;
|
|
100
|
+
private readonly metadata;
|
|
101
|
+
constructor(config?: Partial<ExampleGeneratorPluginConfig>);
|
|
102
|
+
getConfig(): ExampleGeneratorPluginConfig;
|
|
103
|
+
updateConfig(config: Partial<ExampleGeneratorPluginConfig>): void;
|
|
104
|
+
getMetadata(): PluginMetadata;
|
|
105
|
+
generate(context: GeneratorContext): Promise<GeneratorResult>;
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/config.d.ts
|
|
109
|
+
/**
|
|
110
|
+
* Default configuration for the ExampleGeneratorPlugin
|
|
111
|
+
*/
|
|
112
|
+
declare const defaultConfig: ExampleGeneratorPluginConfig;
|
|
113
|
+
/**
|
|
114
|
+
* Merge user config with defaults
|
|
115
|
+
*/
|
|
116
|
+
declare function mergeConfig(userConfig: Partial<ExampleGeneratorPluginConfig>): ExampleGeneratorPluginConfig;
|
|
117
|
+
/**
|
|
118
|
+
* Validate configuration
|
|
119
|
+
*/
|
|
120
|
+
declare function validateConfig(config: ExampleGeneratorPluginConfig): void;
|
|
121
|
+
//#endregion
|
|
122
|
+
export { type ConfigurationError, type ExampleGeneratorError, ExampleGeneratorPlugin, type ExampleGeneratorPluginConfig, type GenerationError, type GeneratorResult, type PluginMetadata, type ValidationError, defaultConfig, mergeConfig, validateConfig };
|
|
123
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/generator.ts","../src/config.ts"],"sourcesContent":[],"mappings":";;;KACY,cAAA;;AAAZ;AAKA;AA0BiB,UA1BA,4BAAA,CA0BgB;EAEzB;EAEkB,SAAA,EAAA,MAAA;EAAf;EAIE,MAAA,CAAA,EAAA,OAAA,GAAA,MAAA,GAAA,QAAA,GAAA,MAAA;EAAM;EAMF,KAAA,CAAA,EAAA,MAAA;EAQA;EAEG,WAAA,CAAA,EAAA,MAAA;EAAR;EAAO,QAAA,CAAA,EAAA,MAAA;EAOF;EAYJ,QAAA,CAAA,EAAA,MAAA;EAcA;EAUA,aAAA,CAAA,EAAA,MAAmB,EAAA;EAUnB;;;gBArFG;ECdH;EAIiB,aAAA,CAAA,EAAA,MAAA,EAAA;;;;;AAuBb,UDLA,gBAAA,CCKA;EAIS;EAA2B,IAAA,EDP7C,cCO6C;EAAR;EAAO,OAAA,EDLzC,MCKyC,CAAA,MAAA,EDL1B,cCK0B,CAAA;;;;ECpCvC,QAAA,CAAA,EFmCA,ME7BZ,CAAA,MAAA,EAAA,OAN2B,CAAA;AAW5B;;;;AAE+B,UF4Bd,eAAA,CE5Bc;EAUf;;;;;;;iBF0BC;;YAEL,QAAQ;;;;;;UAOH,cAAA;;;;;;;;;;;cAYJ,qBAAA,SAA8B,KAAA;;;;;;;;cAc9B,eAAA,SAAwB,qBAAA;;;;;;cAUxB,kBAAA,SAA2B,qBAAA;;;;;;cAU3B,eAAA,SAAwB,qBAAA;;;;;cCnGxB,sBAAA;;EDTD,iBAAc,QAAA;EAKT,WAAA,CAAA,MAkBK,CAlBL,ECQK,ODRL,CCQa,4BDUR,CAAA;EAQL,SAAA,CAAA,CAAA,ECLF,4BDKkB;EAEzB,YAAA,CAAA,MAAA,ECHe,ODGf,CCHuB,4BDGvB,CAAA,CAAA,EAAA,IAAA;EAEkB,WAAA,CAAA,CAAA,ECCT,cDDS;EAAf,QAAA,CAAA,OAAA,ECKe,gBDLf,CAAA,ECKkC,ODLlC,CCK0C,eDL1C,CAAA;;;;;;AAnCX;AAKiB,cEDJ,aFCI,EEDW,4BFmBN;AAQtB;;;AAIW,iBEpBK,WAAA,CFoBL,UAAA,EEnBG,OFmBH,CEnBW,4BFmBX,CAAA,CAAA,EElBR,4BFkBQ;;;AAUX;AAQiB,iBE1BD,cAAA,CF0BC,MAAA,EE1BsB,4BF0BtB,CAAA,EAAA,IAAA"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from "fs";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
|
|
4
|
+
//#region src/config.ts
|
|
5
|
+
/**
|
|
6
|
+
* Default configuration for the ExampleGeneratorPlugin
|
|
7
|
+
*/
|
|
8
|
+
const defaultConfig = {
|
|
9
|
+
outputDir: "./docs",
|
|
10
|
+
format: "auto",
|
|
11
|
+
maxItems: 100,
|
|
12
|
+
maxDepth: 2,
|
|
13
|
+
excludeFields: []
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Merge user config with defaults
|
|
17
|
+
*/
|
|
18
|
+
function mergeConfig(userConfig) {
|
|
19
|
+
return {
|
|
20
|
+
...defaultConfig,
|
|
21
|
+
...userConfig
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Validate configuration
|
|
26
|
+
*/
|
|
27
|
+
function validateConfig(config) {
|
|
28
|
+
if (!config.outputDir) throw new Error("outputDir is required");
|
|
29
|
+
if (config.format && ![
|
|
30
|
+
"table",
|
|
31
|
+
"list",
|
|
32
|
+
"detail",
|
|
33
|
+
"auto"
|
|
34
|
+
].includes(config.format)) throw new Error("format must be one of: table, list, detail, auto");
|
|
35
|
+
if (config.maxItems !== void 0 && config.maxItems < 1) throw new Error("maxItems must be greater than 0");
|
|
36
|
+
if (config.maxDepth !== void 0 && config.maxDepth < 1) throw new Error("maxDepth must be greater than 0");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/generator.ts
|
|
41
|
+
var ExampleGeneratorPlugin = class {
|
|
42
|
+
config;
|
|
43
|
+
metadata;
|
|
44
|
+
constructor(config = {}) {
|
|
45
|
+
const merged = mergeConfig(config);
|
|
46
|
+
validateConfig(merged);
|
|
47
|
+
this.config = merged;
|
|
48
|
+
this.metadata = {
|
|
49
|
+
id: "example-generator",
|
|
50
|
+
name: "@contractspec/integration.example-generator",
|
|
51
|
+
version: "1.0.0",
|
|
52
|
+
description: "Example markdown documentation generator",
|
|
53
|
+
author: "ContractSpec"
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
getConfig() {
|
|
57
|
+
return { ...this.config };
|
|
58
|
+
}
|
|
59
|
+
updateConfig(config) {
|
|
60
|
+
const merged = mergeConfig({
|
|
61
|
+
...this.config,
|
|
62
|
+
...config
|
|
63
|
+
});
|
|
64
|
+
validateConfig(merged);
|
|
65
|
+
this.config = merged;
|
|
66
|
+
}
|
|
67
|
+
getMetadata() {
|
|
68
|
+
return { ...this.metadata };
|
|
69
|
+
}
|
|
70
|
+
async generate(context) {
|
|
71
|
+
if (!context.spec) throw new Error("Spec is required to generate documentation");
|
|
72
|
+
const outputDir = this.config.outputDir;
|
|
73
|
+
mkdirSync(outputDir, { recursive: true });
|
|
74
|
+
const outputPath = join(outputDir, "spec-" + Date.now() + ".md");
|
|
75
|
+
writeFileSync(outputPath, `# Spec Documentation\n\nGenerated for spec: ${String(context.spec.id ?? "unknown")}`, "utf8");
|
|
76
|
+
return {
|
|
77
|
+
outputPath,
|
|
78
|
+
itemCount: 1,
|
|
79
|
+
metadata: {
|
|
80
|
+
specId: String(context.spec.id ?? "unknown"),
|
|
81
|
+
generatedAt: /* @__PURE__ */ new Date(),
|
|
82
|
+
format: this.config.format ?? "auto",
|
|
83
|
+
config: this.config
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
//#endregion
|
|
90
|
+
export { ExampleGeneratorPlugin, defaultConfig, mergeConfig, validateConfig };
|
|
91
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/config.ts","../src/generator.ts"],"sourcesContent":["import type { ExampleGeneratorPluginConfig } from './types.js';\n\n/**\n * Default configuration for the ExampleGeneratorPlugin\n */\nexport const defaultConfig: ExampleGeneratorPluginConfig = {\n outputDir: './docs',\n format: 'auto',\n maxItems: 100,\n maxDepth: 2,\n excludeFields: [],\n};\n\n/**\n * Merge user config with defaults\n */\nexport function mergeConfig(\n userConfig: Partial<ExampleGeneratorPluginConfig>\n): ExampleGeneratorPluginConfig {\n return {\n ...defaultConfig,\n ...userConfig,\n };\n}\n\n/**\n * Validate configuration\n */\nexport function validateConfig(config: ExampleGeneratorPluginConfig): void {\n if (!config.outputDir) {\n throw new Error('outputDir is required');\n }\n\n if (\n config.format &&\n !['table', 'list', 'detail', 'auto'].includes(config.format)\n ) {\n throw new Error('format must be one of: table, list, detail, auto');\n }\n\n if (config.maxItems !== undefined && config.maxItems < 1) {\n throw new Error('maxItems must be greater than 0');\n }\n\n if (config.maxDepth !== undefined && config.maxDepth < 1) {\n throw new Error('maxDepth must be greater than 0');\n }\n}\n","import { mkdirSync, writeFileSync } from 'fs';\nimport { join } from 'path';\nimport { mergeConfig, validateConfig } from './config.js';\nimport type {\n ExampleGeneratorPluginConfig,\n GeneratorContext,\n GeneratorResult,\n PluginMetadata,\n} from './types.js';\n\nexport class ExampleGeneratorPlugin {\n private config: ExampleGeneratorPluginConfig;\n private readonly metadata: PluginMetadata;\n\n constructor(config: Partial<ExampleGeneratorPluginConfig> = {}) {\n const merged = mergeConfig(config);\n validateConfig(merged);\n this.config = merged;\n this.metadata = {\n id: 'example-generator',\n name: '@contractspec/integration.example-generator',\n version: '1.0.0',\n description: 'Example markdown documentation generator',\n author: 'ContractSpec',\n };\n }\n\n getConfig(): ExampleGeneratorPluginConfig {\n return { ...this.config };\n }\n\n updateConfig(config: Partial<ExampleGeneratorPluginConfig>): void {\n const merged = mergeConfig({ ...this.config, ...config });\n validateConfig(merged);\n this.config = merged;\n }\n\n getMetadata(): PluginMetadata {\n return { ...this.metadata };\n }\n\n async generate(context: GeneratorContext): Promise<GeneratorResult> {\n if (!context.spec) {\n throw new Error('Spec is required to generate documentation');\n }\n\n const outputDir = this.config.outputDir;\n mkdirSync(outputDir, { recursive: true });\n\n const fileName = 'spec-' + Date.now() + '.md';\n const outputPath = join(outputDir, fileName);\n const content = `# Spec Documentation\\n\\nGenerated for spec: ${String(\n (context.spec as { id?: string }).id ?? 'unknown'\n )}`;\n\n writeFileSync(outputPath, content, 'utf8');\n\n return {\n outputPath,\n itemCount: 1,\n metadata: {\n specId: String((context.spec as { id?: string }).id ?? 'unknown'),\n generatedAt: new Date(),\n format: this.config.format ?? 'auto',\n config: this.config,\n },\n };\n }\n}\n"],"mappings":";;;;;;;AAKA,MAAa,gBAA8C;CACzD,WAAW;CACX,QAAQ;CACR,UAAU;CACV,UAAU;CACV,eAAe,EAAE;CAClB;;;;AAKD,SAAgB,YACd,YAC8B;AAC9B,QAAO;EACL,GAAG;EACH,GAAG;EACJ;;;;;AAMH,SAAgB,eAAe,QAA4C;AACzE,KAAI,CAAC,OAAO,UACV,OAAM,IAAI,MAAM,wBAAwB;AAG1C,KACE,OAAO,UACP,CAAC;EAAC;EAAS;EAAQ;EAAU;EAAO,CAAC,SAAS,OAAO,OAAO,CAE5D,OAAM,IAAI,MAAM,mDAAmD;AAGrE,KAAI,OAAO,aAAa,UAAa,OAAO,WAAW,EACrD,OAAM,IAAI,MAAM,kCAAkC;AAGpD,KAAI,OAAO,aAAa,UAAa,OAAO,WAAW,EACrD,OAAM,IAAI,MAAM,kCAAkC;;;;;ACnCtD,IAAa,yBAAb,MAAoC;CAClC,AAAQ;CACR,AAAiB;CAEjB,YAAY,SAAgD,EAAE,EAAE;EAC9D,MAAM,SAAS,YAAY,OAAO;AAClC,iBAAe,OAAO;AACtB,OAAK,SAAS;AACd,OAAK,WAAW;GACd,IAAI;GACJ,MAAM;GACN,SAAS;GACT,aAAa;GACb,QAAQ;GACT;;CAGH,YAA0C;AACxC,SAAO,EAAE,GAAG,KAAK,QAAQ;;CAG3B,aAAa,QAAqD;EAChE,MAAM,SAAS,YAAY;GAAE,GAAG,KAAK;GAAQ,GAAG;GAAQ,CAAC;AACzD,iBAAe,OAAO;AACtB,OAAK,SAAS;;CAGhB,cAA8B;AAC5B,SAAO,EAAE,GAAG,KAAK,UAAU;;CAG7B,MAAM,SAAS,SAAqD;AAClE,MAAI,CAAC,QAAQ,KACX,OAAM,IAAI,MAAM,6CAA6C;EAG/D,MAAM,YAAY,KAAK,OAAO;AAC9B,YAAU,WAAW,EAAE,WAAW,MAAM,CAAC;EAGzC,MAAM,aAAa,KAAK,WADP,UAAU,KAAK,KAAK,GAAG,MACI;AAK5C,gBAAc,YAJE,+CAA+C,OAC5D,QAAQ,KAAyB,MAAM,UACzC,IAEkC,OAAO;AAE1C,SAAO;GACL;GACA,WAAW;GACX,UAAU;IACR,QAAQ,OAAQ,QAAQ,KAAyB,MAAM,UAAU;IACjE,6BAAa,IAAI,MAAM;IACvB,QAAQ,KAAK,OAAO,UAAU;IAC9B,QAAQ,KAAK;IACd;GACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@contractspec/integration.example-generator",
|
|
3
|
+
"version": "1.48.1",
|
|
4
|
+
"description": "Example plugin: Markdown documentation generator for ContractSpec specs",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"contractspec",
|
|
7
|
+
"plugin",
|
|
8
|
+
"generator",
|
|
9
|
+
"markdown",
|
|
10
|
+
"documentation",
|
|
11
|
+
"typescript"
|
|
12
|
+
],
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": "./dist/index.js",
|
|
18
|
+
"./types": "./dist/types.js",
|
|
19
|
+
"./generator": "./dist/generator.js",
|
|
20
|
+
"./config": "./dist/config.js",
|
|
21
|
+
"./*": "./*"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"README.md",
|
|
26
|
+
"LICENSE"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
|
|
30
|
+
"publish:pkg:canary": "bun publish:pkg --tag canary",
|
|
31
|
+
"build": "bun build:types && bun build:bundle",
|
|
32
|
+
"build:bundle": "tsdown",
|
|
33
|
+
"build:types": "tsc --noEmit",
|
|
34
|
+
"dev": "bun build:bundle --watch",
|
|
35
|
+
"clean": "rimraf dist .turbo",
|
|
36
|
+
"lint": "bun lint:fix",
|
|
37
|
+
"lint:fix": "eslint src --fix",
|
|
38
|
+
"lint:check": "eslint src",
|
|
39
|
+
"test": "bun test",
|
|
40
|
+
"test:watch": "bun test --watch",
|
|
41
|
+
"test:coverage": "bun test --coverage"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@contractspec/lib.contracts": "1.48.1",
|
|
45
|
+
"@contractspec/lib.schema": "1.48.0",
|
|
46
|
+
"zod": "^4.3.5"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@contractspec/tool.tsdown": "1.48.0",
|
|
50
|
+
"@contractspec/tool.typescript": "1.48.0",
|
|
51
|
+
"tsdown": "^0.19.0",
|
|
52
|
+
"typescript": "^5.9.3",
|
|
53
|
+
"@types/node": "^22.0.0",
|
|
54
|
+
"rimraf": "^6.0.1"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"@contractspec/lib.contracts": "^1.0.0",
|
|
58
|
+
"@contractspec/lib.schema": "^1.0.0"
|
|
59
|
+
},
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"access": "public",
|
|
62
|
+
"registry": "https://registry.npmjs.org/"
|
|
63
|
+
},
|
|
64
|
+
"license": "MIT",
|
|
65
|
+
"repository": {
|
|
66
|
+
"type": "git",
|
|
67
|
+
"url": "https://github.com/lssm-tech/contractspec.git",
|
|
68
|
+
"directory": "packages/integrations/example-generator"
|
|
69
|
+
},
|
|
70
|
+
"homepage": "https://contractspec.io",
|
|
71
|
+
"bugs": {
|
|
72
|
+
"url": "https://github.com/lssm-tech/contractspec/issues"
|
|
73
|
+
},
|
|
74
|
+
"author": {
|
|
75
|
+
"name": "ContractSpec Team",
|
|
76
|
+
"email": "team@contractspec.io"
|
|
77
|
+
},
|
|
78
|
+
"engines": {
|
|
79
|
+
"node": ">=18.0.0",
|
|
80
|
+
"bun": ">=1.0.0"
|
|
81
|
+
}
|
|
82
|
+
}
|