@zpress/templates 0.1.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.
@@ -0,0 +1,153 @@
1
+ /**
2
+ * Create a template registry, optionally pre-loaded with the given templates.
3
+ *
4
+ * When called with no arguments, the registry is populated with all built-in
5
+ * templates. Pass an explicit array to provide a custom set, or an empty array
6
+ * to start from scratch.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { createRegistry } from '@zpress/templates'
11
+ *
12
+ * // Use built-in templates as-is
13
+ * const registry = createRegistry()
14
+ * const guide = registry.get('guide')
15
+ * ```
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * // Start with an empty registry
20
+ * const registry = createRegistry([])
21
+ * .add(defineTemplate({
22
+ * type: 'adr',
23
+ * label: 'ADR',
24
+ * hint: 'Architecture decision record',
25
+ * body: '# {{title}}\n\n## Context\n\n## Decision\n\n## Consequences\n',
26
+ * }))
27
+ * ```
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * // Extend a built-in template
32
+ * const registry = createRegistry()
33
+ * .extend('guide', {
34
+ * body: (base) => base + '\n## Internal Notes\n',
35
+ * })
36
+ * ```
37
+ *
38
+ * @param templates - Optional array of templates to seed the registry with.
39
+ * Defaults to built-in templates when omitted.
40
+ * @returns Template registry
41
+ */
42
+ export declare function createRegistry(templates?: readonly Template[]): TemplateRegistry;
43
+
44
+ /**
45
+ * Define a new documentation template.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * import { defineTemplate, createRegistry } from '@zpress/templates'
50
+ *
51
+ * const adr = defineTemplate({
52
+ * type: 'adr',
53
+ * label: 'ADR',
54
+ * hint: 'Architecture decision record',
55
+ * body: '# {{title}}\n\n## Context\n\n## Decision\n\n## Consequences\n',
56
+ * })
57
+ *
58
+ * const registry = createRegistry().add(adr)
59
+ * ```
60
+ *
61
+ * @param options - Template definition including type, label, hint, and body
62
+ * @returns A new template object
63
+ */
64
+ export declare function defineTemplate(options: Template): Template;
65
+
66
+ /**
67
+ * Options for extending an existing template.
68
+ */
69
+ export declare interface ExtendTemplateOptions {
70
+ readonly label?: string;
71
+ readonly hint?: string;
72
+ readonly body?: string | ((base: string) => string);
73
+ }
74
+
75
+ /**
76
+ * Get all built-in documentation templates keyed by type.
77
+ *
78
+ * @returns Record of all built-in templates keyed by type
79
+ */
80
+ export declare function getBuiltInTemplates(): Record<TemplateType, Template>;
81
+
82
+ /**
83
+ * Render a template by replacing all `{{key}}` placeholders with
84
+ * the corresponding values from the variables map.
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * const output = render(template, { title: 'Authentication' })
89
+ * ```
90
+ *
91
+ * @param template - The template whose body contains `{{key}}` placeholders
92
+ * @param variables - Key/value map used to replace each placeholder
93
+ * @returns The rendered string with all placeholders substituted
94
+ */
95
+ export declare function render(template: Template, variables: TemplateVariables): string;
96
+
97
+ /**
98
+ * A documentation template definition.
99
+ */
100
+ export declare interface Template {
101
+ readonly type: string;
102
+ readonly label: string;
103
+ readonly hint: string;
104
+ readonly body: string;
105
+ }
106
+
107
+ /**
108
+ * Built-in template type identifiers.
109
+ */
110
+ export declare const TEMPLATE_TYPES: readonly ["tutorial", "guide", "quickstart", "explanation", "reference", "standard", "troubleshooting", "runbook"];
111
+
112
+ /**
113
+ * An immutable registry of templates.
114
+ */
115
+ export declare interface TemplateRegistry {
116
+ readonly templates: ReadonlyMap<string, Template>;
117
+ readonly get: (type: string) => Template | undefined;
118
+ readonly has: (type: string) => boolean;
119
+ readonly list: () => readonly Template[];
120
+ readonly types: () => readonly string[];
121
+ readonly add: (template: Template) => TemplateRegistry;
122
+ readonly extend: (type: string, options: ExtendTemplateOptions) => TemplateRegistry;
123
+ readonly merge: (other: TemplateRegistry) => TemplateRegistry;
124
+ }
125
+
126
+ /**
127
+ * A built-in template type identifier.
128
+ */
129
+ export declare type TemplateType = (typeof TEMPLATE_TYPES)[number];
130
+
131
+ /**
132
+ * Variables available for template rendering.
133
+ * `title` is always required; additional custom variables are allowed.
134
+ */
135
+ export declare interface TemplateVariables {
136
+ readonly title: string;
137
+ readonly [key: string]: string;
138
+ }
139
+
140
+ /**
141
+ * Convert a title string to a kebab-case filename slug.
142
+ *
143
+ * @example
144
+ * ```ts
145
+ * toSlug('Deploy to Vercel') // 'deploy-to-vercel'
146
+ * ```
147
+ *
148
+ * @param title - The human-readable title to convert
149
+ * @returns A kebab-case slug suitable for use as a filename
150
+ */
151
+ export declare function toSlug(title: string): string;
152
+
153
+ export { }
package/dist/index.mjs ADDED
@@ -0,0 +1,141 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { isFunction, kebabCase } from "es-toolkit";
4
+ const TEMPLATE_TYPES = [
5
+ 'tutorial',
6
+ 'guide',
7
+ 'quickstart',
8
+ 'explanation',
9
+ 'reference',
10
+ 'standard',
11
+ 'troubleshooting',
12
+ 'runbook'
13
+ ];
14
+ const BUILT_IN_TEMPLATE_RECORD = {
15
+ tutorial: {
16
+ type: 'tutorial',
17
+ label: 'Tutorial',
18
+ hint: 'Guided learning experience',
19
+ body: readTemplate('tutorial.liquid')
20
+ },
21
+ guide: {
22
+ type: 'guide',
23
+ label: 'Guide',
24
+ hint: 'Step-by-step task instructions',
25
+ body: readTemplate('guide.liquid')
26
+ },
27
+ quickstart: {
28
+ type: 'quickstart',
29
+ label: 'Quickstart',
30
+ hint: 'Fast-track to working result',
31
+ body: readTemplate('quickstart.liquid')
32
+ },
33
+ explanation: {
34
+ type: 'explanation',
35
+ label: 'Explanation',
36
+ hint: 'Conceptual background',
37
+ body: readTemplate('explanation.liquid')
38
+ },
39
+ reference: {
40
+ type: 'reference',
41
+ label: 'Reference',
42
+ hint: "Technical descriptions",
43
+ body: readTemplate('reference.liquid')
44
+ },
45
+ standard: {
46
+ type: 'standard',
47
+ label: 'Standard',
48
+ hint: 'Rules and conventions',
49
+ body: readTemplate('standard.liquid')
50
+ },
51
+ troubleshooting: {
52
+ type: 'troubleshooting',
53
+ label: 'Troubleshooting',
54
+ hint: 'Common problems and fixes',
55
+ body: readTemplate('troubleshooting.liquid')
56
+ },
57
+ runbook: {
58
+ type: 'runbook',
59
+ label: 'Runbook',
60
+ hint: 'Operational procedures',
61
+ body: readTemplate('runbook.liquid')
62
+ }
63
+ };
64
+ function getBuiltInTemplates() {
65
+ return BUILT_IN_TEMPLATE_RECORD;
66
+ }
67
+ function readTemplate(filename) {
68
+ return readFileSync(join(import.meta.dirname, '..', 'templates', filename), 'utf8');
69
+ }
70
+ function createRegistry(templates) {
71
+ const entries = resolveEntries(templates);
72
+ return createFromMap(entries);
73
+ }
74
+ function resolveEntries(templates) {
75
+ if (void 0 === templates) return new Map(Object.entries(getBuiltInTemplates()));
76
+ return new Map(templates.map((t)=>[
77
+ t.type,
78
+ t
79
+ ]));
80
+ }
81
+ function resolveBody(base, override) {
82
+ if (void 0 === override) return base;
83
+ if (isFunction(override)) return override(base);
84
+ return override;
85
+ }
86
+ function applyExtension(base, options) {
87
+ return {
88
+ type: base.type,
89
+ label: options.label ?? base.label,
90
+ hint: options.hint ?? base.hint,
91
+ body: resolveBody(base.body, options.body)
92
+ };
93
+ }
94
+ function createFromMap(templates) {
95
+ return {
96
+ templates,
97
+ get: (type)=>templates.get(type),
98
+ has: (type)=>templates.has(type),
99
+ list: ()=>[
100
+ ...templates.values()
101
+ ],
102
+ types: ()=>[
103
+ ...templates.keys()
104
+ ],
105
+ add: (template)=>createFromMap(new Map([
106
+ ...templates,
107
+ [
108
+ template.type,
109
+ template
110
+ ]
111
+ ])),
112
+ extend: (type, options)=>{
113
+ const base = templates.get(type);
114
+ if (!base) return createFromMap(templates);
115
+ const extended = applyExtension(base, options);
116
+ return createFromMap(new Map([
117
+ ...templates,
118
+ [
119
+ type,
120
+ extended
121
+ ]
122
+ ]));
123
+ },
124
+ merge: (other)=>createFromMap(new Map([
125
+ ...templates,
126
+ ...other.templates
127
+ ]))
128
+ };
129
+ }
130
+ function defineTemplate(options) {
131
+ return {
132
+ ...options
133
+ };
134
+ }
135
+ function render(template, variables) {
136
+ return Object.entries(variables).reduce((result, [key, value])=>result.replaceAll(`{{${key}}}`, value), template.body);
137
+ }
138
+ function toSlug(title) {
139
+ return kebabCase(title);
140
+ }
141
+ export { TEMPLATE_TYPES, createRegistry, defineTemplate, getBuiltInTemplates, render, toSlug };
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@zpress/templates",
3
+ "version": "0.1.0",
4
+ "description": "Documentation templates SDK for zpress — use built-in templates, extend them, or register custom ones",
5
+ "keywords": [
6
+ "docs",
7
+ "documentation",
8
+ "scaffold",
9
+ "templates",
10
+ "zpress"
11
+ ],
12
+ "homepage": "https://github.com/joggrdocs/zpress/tree/main/packages/templates#readme",
13
+ "bugs": "https://github.com/joggrdocs/zpress/issues",
14
+ "license": "MIT",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/joggrdocs/zpress.git",
18
+ "directory": "packages/templates"
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "templates"
23
+ ],
24
+ "type": "module",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.mjs"
29
+ }
30
+ },
31
+ "publishConfig": {
32
+ "access": "public",
33
+ "provenance": true
34
+ },
35
+ "scripts": {
36
+ "build": "rslib build",
37
+ "dev": "rslib build --watch --no-clean",
38
+ "test": "vitest run",
39
+ "typecheck": "tsc --noEmit"
40
+ },
41
+ "dependencies": {
42
+ "es-toolkit": "catalog:"
43
+ },
44
+ "devDependencies": {
45
+ "@rslib/core": "catalog:",
46
+ "typescript": "catalog:",
47
+ "vitest": "catalog:"
48
+ },
49
+ "engines": {
50
+ "node": ">=24.0.0"
51
+ }
52
+ }
@@ -0,0 +1,34 @@
1
+ # {{title}}
2
+
3
+ <!-- One sentence: what this topic is and why it matters. -->
4
+
5
+ ## Architecture
6
+
7
+ <!-- Optional: include a diagram if it clarifies the design. -->
8
+
9
+ ## Key Concepts
10
+
11
+ ### Concept 1
12
+
13
+ Explanation with minimal example.
14
+
15
+ ### Concept 2
16
+
17
+ Explanation with minimal example.
18
+
19
+ ## Usage
20
+
21
+ ### Basic Usage
22
+
23
+ ```ts
24
+ // Focused example
25
+ ```
26
+
27
+ ### Advanced Usage
28
+
29
+ <!-- Optional: more complex example. -->
30
+
31
+ ## References
32
+
33
+ - [Related Guide](../guides/related.md)
34
+ - [Related Reference](../reference/related.md)
@@ -0,0 +1,58 @@
1
+ # {{title}}
2
+
3
+ <!-- One sentence: what this guide accomplishes. -->
4
+
5
+ ## Prerequisites
6
+
7
+ - Requirement 1
8
+ - Requirement 2
9
+
10
+ ## Steps
11
+
12
+ ### 1. First Step
13
+
14
+ Brief explanation.
15
+
16
+ ```bash
17
+ command here
18
+ ```
19
+
20
+ ### 2. Second Step
21
+
22
+ Brief explanation.
23
+
24
+ ```ts
25
+ // Code example if needed
26
+ ```
27
+
28
+ ### 3. Third Step
29
+
30
+ <!-- Continue as needed. -->
31
+
32
+ ## Verification
33
+
34
+ How to verify the task completed successfully:
35
+
36
+ ```bash
37
+ verification-command
38
+ ```
39
+
40
+ Expected output or behavior.
41
+
42
+ ## Troubleshooting
43
+
44
+ <!-- Optional: include if there are known failure modes. -->
45
+
46
+ ### Common Issue Name
47
+
48
+ **Symptom:** Brief description of problem.
49
+
50
+ **Fix:**
51
+
52
+ ```bash
53
+ solution-command
54
+ ```
55
+
56
+ ## References
57
+
58
+ - [Related Doc](../path/to/doc.md)
@@ -0,0 +1,51 @@
1
+ # Get Started with {{title}}
2
+
3
+ <!-- One sentence: what the reader will have working by the end. -->
4
+
5
+ ## What You Will Build
6
+
7
+ A working implementation that does something useful.
8
+
9
+ ## Prerequisites
10
+
11
+ - Prerequisite 1
12
+ - Prerequisite 2
13
+
14
+ ## Steps
15
+
16
+ ### 1. First Step
17
+
18
+ ```bash
19
+ command here
20
+ ```
21
+
22
+ ### 2. Second Step
23
+
24
+ ```bash
25
+ command here
26
+ ```
27
+
28
+ ### 3. Third Step
29
+
30
+ ```ts
31
+ // Code example if needed
32
+ ```
33
+
34
+ <!-- Max 5 steps. No explanations. Fastest path. -->
35
+
36
+ ## Result
37
+
38
+ ```bash
39
+ verification-command
40
+ ```
41
+
42
+ You should see:
43
+
44
+ ```
45
+ expected output
46
+ ```
47
+
48
+ ## Next Steps
49
+
50
+ - [Full tutorial](../tutorials/related.md) — learn the concepts
51
+ - [Guide title](../guides/related.md) — apply to a real task
@@ -0,0 +1,20 @@
1
+ # {{title}}
2
+
3
+ <!-- One sentence: what this reference covers. -->
4
+
5
+ ## Options
6
+
7
+ | Option | Type | Default | Description |
8
+ | --------- | --------- | ----------- | ---------------- |
9
+ | `option1` | `string` | `"default"` | What it does |
10
+ | `option2` | `boolean` | `false` | What it controls |
11
+
12
+ ## Examples
13
+
14
+ ```ts
15
+ // Minimal usage example
16
+ ```
17
+
18
+ ## References
19
+
20
+ - [Related Guide](../guides/related.md)
@@ -0,0 +1,65 @@
1
+ # {{title}}
2
+
3
+ <!-- One sentence: what this procedure accomplishes. -->
4
+
5
+ ## When to Use
6
+
7
+ - Condition A occurs
8
+ - Condition B is met
9
+
10
+ ## Prerequisites
11
+
12
+ - Required access
13
+ - Required permissions
14
+
15
+ ## Procedure
16
+
17
+ ### 1. Assess
18
+
19
+ ```bash
20
+ status-command
21
+ ```
22
+
23
+ Expected output:
24
+
25
+ ```
26
+ normal state
27
+ ```
28
+
29
+ ### 2. Execute
30
+
31
+ ```bash
32
+ operation-command
33
+ ```
34
+
35
+ **Verify:**
36
+
37
+ ```bash
38
+ verification-command
39
+ ```
40
+
41
+ ### 3. Confirm
42
+
43
+ ```bash
44
+ health-check-command
45
+ ```
46
+
47
+ ## Rollback
48
+
49
+ ### 1. Revert
50
+
51
+ ```bash
52
+ rollback-command
53
+ ```
54
+
55
+ ### 2. Verify
56
+
57
+ ```bash
58
+ verification-command
59
+ ```
60
+
61
+ ## Escalation
62
+
63
+ | Condition | Contact | Channel |
64
+ | --------------- | ---------------- | ---------- |
65
+ | Procedure fails | On-call engineer | #incidents |
@@ -0,0 +1,41 @@
1
+ # {{title}}
2
+
3
+ <!-- One sentence: what this standard covers. -->
4
+
5
+ ## Overview
6
+
7
+ Why this standard exists and what it applies to.
8
+
9
+ ## Rules
10
+
11
+ ### Rule Category
12
+
13
+ | Rule | Description | Example |
14
+ | ------ | ------------- | ------------- |
15
+ | Rule A | What it means | Example usage |
16
+ | Rule B | What it means | Example usage |
17
+
18
+ ## Examples
19
+
20
+ ### Good
21
+
22
+ ```ts
23
+ // Following the standard
24
+ ```
25
+
26
+ ### Bad
27
+
28
+ ```ts
29
+ // Violating the standard
30
+ ```
31
+
32
+ ## Enforcement
33
+
34
+ | Rule | Enforced By | Severity |
35
+ | ------ | ------------- | -------- |
36
+ | Rule A | Linter / CI | Error |
37
+ | Rule B | Code review | Warning |
38
+
39
+ ## References
40
+
41
+ - [Related Standard](./related.md)
@@ -0,0 +1,34 @@
1
+ # {{title}} Troubleshooting
2
+
3
+ Common issues and fixes for {{title}}.
4
+
5
+ ## Issue Name
6
+
7
+ **Symptom:** Brief description (1 line).
8
+
9
+ **Fix:**
10
+
11
+ ```bash
12
+ solution-command
13
+ ```
14
+
15
+ ## Another Issue
16
+
17
+ **Symptom:** Brief description.
18
+
19
+ **Cause:** Why this happens.
20
+
21
+ **Fix:**
22
+
23
+ 1. First step
24
+ 2. Second step
25
+
26
+ ## Error: Specific Error Message
27
+
28
+ **Symptom:** When you see this error:
29
+
30
+ ```
31
+ Error: Something went wrong
32
+ ```
33
+
34
+ **Fix:** Explanation or command.
@@ -0,0 +1,58 @@
1
+ # Build Your First {{title}}
2
+
3
+ <!-- One sentence: what the reader will learn and build. -->
4
+
5
+ ## What You Will Learn
6
+
7
+ - Learning objective 1
8
+ - Learning objective 2
9
+ - Learning objective 3
10
+
11
+ ## What You Will Build
12
+
13
+ A working {{title}} that demonstrates concepts A, B, and C.
14
+
15
+ ## Prerequisites
16
+
17
+ - Prerequisite 1
18
+ - Prerequisite 2
19
+
20
+ ## Steps
21
+
22
+ ### 1. First Step
23
+
24
+ Brief explanation of what this step does.
25
+
26
+ ```bash
27
+ command here
28
+ ```
29
+
30
+ You should see:
31
+
32
+ ```
33
+ expected output
34
+ ```
35
+
36
+ ### 2. Second Step
37
+
38
+ Brief explanation.
39
+
40
+ ```ts
41
+ // Complete, runnable code
42
+ ```
43
+
44
+ ### 3. Third Step
45
+
46
+ <!-- Continue as needed. Max 7 steps. -->
47
+
48
+ ## Summary
49
+
50
+ In this tutorial, you learned:
51
+
52
+ - **Concept A** — what it is and how it works
53
+ - **Concept B** — how to apply it
54
+
55
+ ## Next Steps
56
+
57
+ - [Guide title](../guides/related.md) — apply what you learned
58
+ - [Concept title](../concepts/related.md) — deeper understanding