sveld 0.26.2 → 0.28.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/README.md +68 -5
- package/cli.js +1 -7
- package/lib/ComponentParser.d.ts +1 -1
- package/lib/index.js +184 -14
- package/package.json +10 -9
- package/lib/ComponentParser.js +0 -2657
- package/lib/cli.js +0 -48
- package/lib/create-exports.js +0 -170
- package/lib/element-tag-map.js +0 -158
- package/lib/get-svelte-entry.js +0 -39
- package/lib/parse-exports.js +0 -112
- package/lib/path.js +0 -12
- package/lib/plugin.js +0 -269
- package/lib/resolve-alias.js +0 -198
- package/lib/sveld.js +0 -33
- package/lib/writer/MarkdownWriterBase.js +0 -70
- package/lib/writer/Writer.js +0 -104
- package/lib/writer/WriterMarkdown.js +0 -65
- package/lib/writer/markdown-format-utils.js +0 -158
- package/lib/writer/markdown-render-utils.js +0 -89
- package/lib/writer/writer-json.js +0 -119
- package/lib/writer/writer-markdown-core.js +0 -44
- package/lib/writer/writer-markdown.js +0 -46
- package/lib/writer/writer-ts-definitions-core.js +0 -753
- package/lib/writer/writer-ts-definitions.js +0 -64
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const MarkdownWriterBase_1 = require("./MarkdownWriterBase");
|
|
7
|
-
const Writer_1 = __importDefault(require("./Writer"));
|
|
8
|
-
/**
|
|
9
|
-
* Markdown writer that extends Writer for file operations.
|
|
10
|
-
*
|
|
11
|
-
* Combines file writing capabilities from Writer with markdown
|
|
12
|
-
* generation capabilities from MarkdownWriterBaseImpl. Supports
|
|
13
|
-
* callbacks for monitoring document construction.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```ts
|
|
17
|
-
* const writer = new WriterMarkdown({
|
|
18
|
-
* onAppend: (type, doc) => {
|
|
19
|
-
* console.log(`Appended ${type} to markdown`);
|
|
20
|
-
* }
|
|
21
|
-
* });
|
|
22
|
-
* writer.append("h1", "Title");
|
|
23
|
-
* await writer.write("./docs.md", writer.end());
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
class WriterMarkdown extends Writer_1.default {
|
|
27
|
-
onAppend;
|
|
28
|
-
markdownBase;
|
|
29
|
-
/**
|
|
30
|
-
* Creates a new WriterMarkdown instance.
|
|
31
|
-
*
|
|
32
|
-
* @param options - Markdown writer options including append callback
|
|
33
|
-
*/
|
|
34
|
-
constructor(options) {
|
|
35
|
-
super({ parser: "markdown", printWidth: 80 });
|
|
36
|
-
this.onAppend = options.onAppend;
|
|
37
|
-
this.markdownBase = new MarkdownWriterBase_1.MarkdownWriterBaseImpl();
|
|
38
|
-
}
|
|
39
|
-
get source() {
|
|
40
|
-
return this.markdownBase.source;
|
|
41
|
-
}
|
|
42
|
-
get hasToC() {
|
|
43
|
-
return this.markdownBase.hasToC;
|
|
44
|
-
}
|
|
45
|
-
get toc() {
|
|
46
|
-
return this.markdownBase.toc;
|
|
47
|
-
}
|
|
48
|
-
appendLineBreaks() {
|
|
49
|
-
this.markdownBase.appendLineBreaks();
|
|
50
|
-
return this;
|
|
51
|
-
}
|
|
52
|
-
append(type, raw) {
|
|
53
|
-
this.markdownBase.append(type, raw);
|
|
54
|
-
this.onAppend?.call(this, type, this);
|
|
55
|
-
return this;
|
|
56
|
-
}
|
|
57
|
-
tableOfContents() {
|
|
58
|
-
this.markdownBase.tableOfContents();
|
|
59
|
-
return this;
|
|
60
|
-
}
|
|
61
|
-
end() {
|
|
62
|
-
return this.markdownBase.end();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
exports.default = WriterMarkdown;
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EVENT_TABLE_HEADER = exports.SLOT_TABLE_HEADER = exports.PROP_TABLE_HEADER = exports.MD_TYPE_UNDEFINED = exports.WHITESPACE_REGEX = exports.BACKTICK_REGEX = void 0;
|
|
4
|
-
exports.formatPropType = formatPropType;
|
|
5
|
-
exports.escapeHtml = escapeHtml;
|
|
6
|
-
exports.formatPropValue = formatPropValue;
|
|
7
|
-
exports.formatPropDescription = formatPropDescription;
|
|
8
|
-
exports.formatSlotProps = formatSlotProps;
|
|
9
|
-
exports.formatSlotFallback = formatSlotFallback;
|
|
10
|
-
exports.formatEventDetail = formatEventDetail;
|
|
11
|
-
const writer_ts_definitions_core_1 = require("./writer-ts-definitions-core");
|
|
12
|
-
exports.BACKTICK_REGEX = /`/g;
|
|
13
|
-
exports.WHITESPACE_REGEX = /\s+/g;
|
|
14
|
-
exports.MD_TYPE_UNDEFINED = "--";
|
|
15
|
-
exports.PROP_TABLE_HEADER = "| Prop name | Required | Kind | Reactive | Type | Default value | Description |\n| :- | :- | :- | :- |\n";
|
|
16
|
-
exports.SLOT_TABLE_HEADER = "| Slot name | Default | Props | Fallback |\n| :- | :- | :- | :- |\n";
|
|
17
|
-
exports.EVENT_TABLE_HEADER = "| Event name | Type | Detail | Description |\n| :- | :- | :- | :- |\n";
|
|
18
|
-
const PIPE_REGEX = /\|/g;
|
|
19
|
-
const LT_REGEX = /</g;
|
|
20
|
-
const GT_REGEX = />/g;
|
|
21
|
-
const NEWLINE_REGEX = /\n/g;
|
|
22
|
-
/**
|
|
23
|
-
* Formats a prop type for display in markdown tables.
|
|
24
|
-
*
|
|
25
|
-
* Escapes pipe characters to prevent breaking markdown table syntax
|
|
26
|
-
* and wraps the type in a code block.
|
|
27
|
-
*
|
|
28
|
-
* @param type - The type string to format
|
|
29
|
-
* @returns Formatted type string or MD_TYPE_UNDEFINED if type is undefined
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```ts
|
|
33
|
-
* formatPropType("string | number") // Returns: "<code>string | number</code>"
|
|
34
|
-
* formatPropType(undefined) // Returns: "--"
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
function formatPropType(type) {
|
|
38
|
-
if (type === undefined)
|
|
39
|
-
return exports.MD_TYPE_UNDEFINED;
|
|
40
|
-
return `<code>${type.replace(PIPE_REGEX, "|")}</code>`;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Escapes HTML special characters in text.
|
|
44
|
-
*
|
|
45
|
-
* Converts `<` to `<` and `>` to `>` to prevent HTML injection
|
|
46
|
-
* and ensure proper rendering in markdown.
|
|
47
|
-
*
|
|
48
|
-
* @param text - The text to escape
|
|
49
|
-
* @returns The escaped text
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```ts
|
|
53
|
-
* escapeHtml("<div>") // Returns: "<div>"
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
function escapeHtml(text) {
|
|
57
|
-
return text.replace(LT_REGEX, "<").replace(GT_REGEX, ">");
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Formats a prop default value for display in markdown tables.
|
|
61
|
-
*
|
|
62
|
-
* Escapes backticks and pipe characters, and wraps the value in a code block.
|
|
63
|
-
*
|
|
64
|
-
* @param value - The default value string to format
|
|
65
|
-
* @returns Formatted value string or MD_TYPE_UNDEFINED if value is undefined
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```ts
|
|
69
|
-
* formatPropValue("'hello'") // Returns: "<code>'hello'</code>"
|
|
70
|
-
* formatPropValue("`test`") // Returns: "<code>\\`test\\`</code>"
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
function formatPropValue(value) {
|
|
74
|
-
if (value === undefined)
|
|
75
|
-
return exports.MD_TYPE_UNDEFINED;
|
|
76
|
-
return `<code>${value.replace(exports.BACKTICK_REGEX, "\\`").replace(PIPE_REGEX, "|")}</code>`;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Formats a prop description for display in markdown tables.
|
|
80
|
-
*
|
|
81
|
-
* Escapes HTML characters and converts newlines to `<br />` tags
|
|
82
|
-
* for proper rendering in markdown tables.
|
|
83
|
-
*
|
|
84
|
-
* @param description - The description string to format
|
|
85
|
-
* @returns Formatted description or MD_TYPE_UNDEFINED if description is empty
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* ```ts
|
|
89
|
-
* formatPropDescription("Line 1\nLine 2")
|
|
90
|
-
* // Returns: "Line 1<br />Line 2"
|
|
91
|
-
* ```
|
|
92
|
-
*/
|
|
93
|
-
function formatPropDescription(description) {
|
|
94
|
-
if (description === undefined || description.trim().length === 0)
|
|
95
|
-
return exports.MD_TYPE_UNDEFINED;
|
|
96
|
-
return escapeHtml(description).replace(NEWLINE_REGEX, "<br />");
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Formats slot props for display in markdown tables.
|
|
100
|
-
*
|
|
101
|
-
* Converts TypeScript type definitions to a single-line format
|
|
102
|
-
* and wraps them in a code block. Returns MD_TYPE_UNDEFINED for
|
|
103
|
-
* empty or undefined props.
|
|
104
|
-
*
|
|
105
|
-
* @param props - The slot props type string
|
|
106
|
-
* @returns Formatted props string or MD_TYPE_UNDEFINED
|
|
107
|
-
*
|
|
108
|
-
* @example
|
|
109
|
-
* ```ts
|
|
110
|
-
* formatSlotProps("{ title: string }") // Returns: "<code>{ title: string }</code>"
|
|
111
|
-
* formatSlotProps("{}") // Returns: "--"
|
|
112
|
-
* ```
|
|
113
|
-
*/
|
|
114
|
-
function formatSlotProps(props) {
|
|
115
|
-
if (props === undefined || props === "{}")
|
|
116
|
-
return exports.MD_TYPE_UNDEFINED;
|
|
117
|
-
return formatPropType((0, writer_ts_definitions_core_1.formatTsProps)(props).replace(NEWLINE_REGEX, " "));
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Formats slot fallback content for display in markdown tables.
|
|
121
|
-
*
|
|
122
|
-
* Escapes HTML and converts newlines to `<br />` tags, then wraps
|
|
123
|
-
* in a code block.
|
|
124
|
-
*
|
|
125
|
-
* @param fallback - The fallback content string
|
|
126
|
-
* @returns Formatted fallback string or MD_TYPE_UNDEFINED if undefined
|
|
127
|
-
*
|
|
128
|
-
* @example
|
|
129
|
-
* ```ts
|
|
130
|
-
* formatSlotFallback("<p>Default</p>")
|
|
131
|
-
* // Returns: "<code><p>Default</p></code>"
|
|
132
|
-
* ```
|
|
133
|
-
*/
|
|
134
|
-
function formatSlotFallback(fallback) {
|
|
135
|
-
if (fallback === undefined)
|
|
136
|
-
return exports.MD_TYPE_UNDEFINED;
|
|
137
|
-
return formatPropType(escapeHtml(fallback).replace(NEWLINE_REGEX, "<br />"));
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Formats event detail type for display in markdown tables.
|
|
141
|
-
*
|
|
142
|
-
* Converts the detail type to a single-line format and wraps it
|
|
143
|
-
* in a code block.
|
|
144
|
-
*
|
|
145
|
-
* @param detail - The event detail type string
|
|
146
|
-
* @returns Formatted detail string or MD_TYPE_UNDEFINED if undefined
|
|
147
|
-
*
|
|
148
|
-
* @example
|
|
149
|
-
* ```ts
|
|
150
|
-
* formatEventDetail("{ value: string }")
|
|
151
|
-
* // Returns: "<code>{ value: string }</code>"
|
|
152
|
-
* ```
|
|
153
|
-
*/
|
|
154
|
-
function formatEventDetail(detail) {
|
|
155
|
-
if (detail === undefined)
|
|
156
|
-
return exports.MD_TYPE_UNDEFINED;
|
|
157
|
-
return formatPropType(detail.replace(NEWLINE_REGEX, " "));
|
|
158
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.renderComponentsToMarkdown = renderComponentsToMarkdown;
|
|
4
|
-
const markdown_format_utils_1 = require("./markdown-format-utils");
|
|
5
|
-
const writer_ts_definitions_core_1 = require("./writer-ts-definitions-core");
|
|
6
|
-
/**
|
|
7
|
-
* Renders component documentation to a markdown document.
|
|
8
|
-
* This shared function is used by both writeMarkdown and writeMarkdownCore.
|
|
9
|
-
*/
|
|
10
|
-
function renderComponentsToMarkdown(document, components) {
|
|
11
|
-
document.append("h1", "Component Index");
|
|
12
|
-
document.append("h2", "Components").tableOfContents();
|
|
13
|
-
document.append("divider");
|
|
14
|
-
const keys = Array.from(components.keys()).sort();
|
|
15
|
-
for (const key of keys) {
|
|
16
|
-
const component = components.get(key);
|
|
17
|
-
if (!component)
|
|
18
|
-
continue;
|
|
19
|
-
renderComponent(document, component);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Renders a section conditionally - if items exist, calls renderFn, otherwise renders "None."
|
|
24
|
-
*/
|
|
25
|
-
function renderSectionIfNotEmpty(document, items, renderFn, emptyMessage) {
|
|
26
|
-
if (items.length > 0) {
|
|
27
|
-
renderFn();
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
document.append("p", emptyMessage ?? "None.");
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Renders a single component's documentation to the markdown document.
|
|
35
|
-
*
|
|
36
|
-
* @param document - The markdown document to append to
|
|
37
|
-
* @param component - The component documentation to render
|
|
38
|
-
*/
|
|
39
|
-
function renderComponent(document, component) {
|
|
40
|
-
document.append("h2", `\`${component.moduleName}\``);
|
|
41
|
-
/**
|
|
42
|
-
* Render typedefs section if the component has any type definitions.
|
|
43
|
-
*/
|
|
44
|
-
if (component.typedefs.length > 0) {
|
|
45
|
-
document.append("h3", "Types").append("raw", `\`\`\`ts\n${(0, writer_ts_definitions_core_1.getTypeDefs)({
|
|
46
|
-
typedefs: component.typedefs,
|
|
47
|
-
})}\n\`\`\`\n\n`);
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Render props section with a table of all component props.
|
|
51
|
-
* Props are sorted with reactive props first, then constants last.
|
|
52
|
-
*/
|
|
53
|
-
document.append("h3", "Props");
|
|
54
|
-
renderSectionIfNotEmpty(document, component.props, () => {
|
|
55
|
-
document.append("raw", markdown_format_utils_1.PROP_TABLE_HEADER);
|
|
56
|
-
const sortedProps = [...component.props].sort((a) => {
|
|
57
|
-
if (a.reactive)
|
|
58
|
-
return -1;
|
|
59
|
-
if (a.constant)
|
|
60
|
-
return 1;
|
|
61
|
-
return 0;
|
|
62
|
-
});
|
|
63
|
-
for (const prop of sortedProps) {
|
|
64
|
-
document.append("raw", `| ${prop.name} | ${prop.isRequired ? "Yes" : "No"} | ${`<code>${prop.kind}</code>`} | ${prop.reactive ? "Yes" : "No"} | ${(0, markdown_format_utils_1.formatPropType)(prop.type)} | ${(0, markdown_format_utils_1.formatPropValue)(prop.value)} | ${(0, markdown_format_utils_1.formatPropDescription)(prop.description)} |\n`);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
/**
|
|
68
|
-
* Render slots section with a table of all component slots.
|
|
69
|
-
* Includes slot name, default status, props, and fallback content.
|
|
70
|
-
*/
|
|
71
|
-
document.append("h3", "Slots");
|
|
72
|
-
renderSectionIfNotEmpty(document, component.slots, () => {
|
|
73
|
-
document.append("raw", markdown_format_utils_1.SLOT_TABLE_HEADER);
|
|
74
|
-
for (const slot of component.slots) {
|
|
75
|
-
document.append("raw", `| ${slot.default ? markdown_format_utils_1.MD_TYPE_UNDEFINED : slot.name} | ${slot.default ? "Yes" : "No"} | ${(0, markdown_format_utils_1.formatSlotProps)(slot.slot_props)} | ${(0, markdown_format_utils_1.formatSlotFallback)(slot.fallback)} |\n`);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
/**
|
|
79
|
-
* Render events section with a table of all component events.
|
|
80
|
-
* Includes event name, type (dispatched/forwarded), detail type, and description.
|
|
81
|
-
*/
|
|
82
|
-
document.append("h3", "Events");
|
|
83
|
-
renderSectionIfNotEmpty(document, component.events, () => {
|
|
84
|
-
document.append("raw", markdown_format_utils_1.EVENT_TABLE_HEADER);
|
|
85
|
-
for (const event of component.events) {
|
|
86
|
-
document.append("raw", `| ${event.name} | ${event.type} | ${event.type === "dispatched" ? (0, markdown_format_utils_1.formatEventDetail)(event.detail) : markdown_format_utils_1.MD_TYPE_UNDEFINED} | ${(0, markdown_format_utils_1.formatPropDescription)(event.description)} |\n`);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.default = writeJson;
|
|
7
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
-
const path_1 = require("../path");
|
|
9
|
-
const Writer_1 = require("./Writer");
|
|
10
|
-
/**
|
|
11
|
-
* Transforms and sorts component documentation for JSON output.
|
|
12
|
-
*
|
|
13
|
-
* Normalizes file paths and sorts components alphabetically by module name.
|
|
14
|
-
*
|
|
15
|
-
* @param components - Map of component documentation
|
|
16
|
-
* @param inputDir - The input directory for normalizing paths
|
|
17
|
-
* @returns Sorted array of component documentation with normalized paths
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```ts
|
|
21
|
-
* // Input: components with relative paths
|
|
22
|
-
* // Output: components with normalized absolute paths, sorted by name
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
function transformAndSortComponents(components, inputDir) {
|
|
26
|
-
return Array.from(components, ([_moduleName, component]) => ({
|
|
27
|
-
...component,
|
|
28
|
-
filePath: (0, path_1.normalizeSeparators)(node_path_1.default.join(inputDir, node_path_1.default.normalize(component.filePath))),
|
|
29
|
-
})).sort((a, b) => a.moduleName.localeCompare(b.moduleName));
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Writes individual JSON files for each component.
|
|
33
|
-
*
|
|
34
|
-
* Creates a separate `.api.json` file for each component in the
|
|
35
|
-
* specified output directory. Used when `outDir` is specified.
|
|
36
|
-
*
|
|
37
|
-
* @param components - Map of component documentation
|
|
38
|
-
* @param options - Write options including output directory
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```ts
|
|
42
|
-
* await writeJsonComponents(components, {
|
|
43
|
-
* inputDir: "./src",
|
|
44
|
-
* outDir: "./dist"
|
|
45
|
-
* });
|
|
46
|
-
* // Creates: dist/Button.api.json, dist/Input.api.json, etc.
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
async function writeJsonComponents(components, options) {
|
|
50
|
-
const output = transformAndSortComponents(components, options.inputDir);
|
|
51
|
-
await Promise.all(output.map((c) => {
|
|
52
|
-
const outFile = node_path_1.default.resolve(node_path_1.default.join(options.outDir || "", `${c.moduleName}.api.json`));
|
|
53
|
-
const writer = (0, Writer_1.createJsonWriter)();
|
|
54
|
-
console.log(`created ${outFile}"\n`);
|
|
55
|
-
return writer.write(outFile, JSON.stringify(c));
|
|
56
|
-
}));
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Writes component documentation to a single JSON file.
|
|
60
|
-
*
|
|
61
|
-
* Creates a JSON file containing all components with metadata.
|
|
62
|
-
* Used when `outDir` is not specified.
|
|
63
|
-
*
|
|
64
|
-
* @param components - Map of component documentation
|
|
65
|
-
* @param options - Write options including output file path
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```ts
|
|
69
|
-
* await writeJsonLocal(components, {
|
|
70
|
-
* inputDir: "./src",
|
|
71
|
-
* outFile: "components.api.json"
|
|
72
|
-
* });
|
|
73
|
-
* // Creates: components.api.json with all component docs
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
async function writeJsonLocal(components, options) {
|
|
77
|
-
const output = {
|
|
78
|
-
total: components.size,
|
|
79
|
-
components: transformAndSortComponents(components, options.inputDir),
|
|
80
|
-
};
|
|
81
|
-
const output_path = node_path_1.default.join(process.cwd(), options.outFile);
|
|
82
|
-
const writer = (0, Writer_1.createJsonWriter)();
|
|
83
|
-
await writer.write(output_path, JSON.stringify(output));
|
|
84
|
-
console.log(`created "${options.outFile}".\n`);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Writes component documentation to JSON format.
|
|
88
|
-
*
|
|
89
|
-
* Can write either:
|
|
90
|
-
* - Individual JSON files per component (when `outDir` is specified)
|
|
91
|
-
* - A single combined JSON file (when only `outFile` is specified)
|
|
92
|
-
*
|
|
93
|
-
* @param components - Map of component documentation to write
|
|
94
|
-
* @param options - Write options including output directory or file
|
|
95
|
-
* @returns A promise that resolves when all files have been written
|
|
96
|
-
*
|
|
97
|
-
* @example
|
|
98
|
-
* ```ts
|
|
99
|
-
* // Write individual files:
|
|
100
|
-
* await writeJson(components, {
|
|
101
|
-
* inputDir: "./src",
|
|
102
|
-
* outDir: "./dist"
|
|
103
|
-
* });
|
|
104
|
-
*
|
|
105
|
-
* // Write single file:
|
|
106
|
-
* await writeJson(components, {
|
|
107
|
-
* inputDir: "./src",
|
|
108
|
-
* outFile: "components.api.json"
|
|
109
|
-
* });
|
|
110
|
-
* ```
|
|
111
|
-
*/
|
|
112
|
-
async function writeJson(components, options) {
|
|
113
|
-
if (options.outDir) {
|
|
114
|
-
await writeJsonComponents(components, options);
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
await writeJsonLocal(components, options);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BrowserWriterMarkdown = void 0;
|
|
4
|
-
exports.writeMarkdownCore = writeMarkdownCore;
|
|
5
|
-
const MarkdownWriterBase_1 = require("./MarkdownWriterBase");
|
|
6
|
-
const markdown_render_utils_1 = require("./markdown-render-utils");
|
|
7
|
-
/**
|
|
8
|
-
* Browser-compatible WriterMarkdown that doesn't extend Writer.
|
|
9
|
-
*
|
|
10
|
-
* This class is designed for browser environments where file system operations
|
|
11
|
-
* are not available. It extends MarkdownWriterBaseImpl directly instead of
|
|
12
|
-
* Writer to avoid Node.js dependencies.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* const writer = new BrowserWriterMarkdown({
|
|
17
|
-
* onAppend: (type, doc) => {
|
|
18
|
-
* console.log(`Appended ${type} to document`);
|
|
19
|
-
* }
|
|
20
|
-
* });
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
class BrowserWriterMarkdown extends MarkdownWriterBase_1.MarkdownWriterBaseImpl {
|
|
24
|
-
onAppend;
|
|
25
|
-
constructor(options) {
|
|
26
|
-
super();
|
|
27
|
-
this.onAppend = options.onAppend;
|
|
28
|
-
}
|
|
29
|
-
append(type, raw) {
|
|
30
|
-
super.append(type, raw);
|
|
31
|
-
this.onAppend?.call(this, type, this);
|
|
32
|
-
return this;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.BrowserWriterMarkdown = BrowserWriterMarkdown;
|
|
36
|
-
function writeMarkdownCore(components, options) {
|
|
37
|
-
const document = new BrowserWriterMarkdown({
|
|
38
|
-
onAppend: (type, document) => {
|
|
39
|
-
options?.onAppend?.call(null, type, document, components);
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
(0, markdown_render_utils_1.renderComponentsToMarkdown)(document, components);
|
|
43
|
-
return document.end();
|
|
44
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.default = writeMarkdown;
|
|
7
|
-
const node_path_1 = require("node:path");
|
|
8
|
-
const markdown_render_utils_1 = require("./markdown-render-utils");
|
|
9
|
-
const WriterMarkdown_1 = __importDefault(require("./WriterMarkdown"));
|
|
10
|
-
/**
|
|
11
|
-
* Writes component documentation to a markdown file.
|
|
12
|
-
*
|
|
13
|
-
* Renders all components to markdown format and optionally writes
|
|
14
|
-
* the result to a file. Returns the markdown string regardless of
|
|
15
|
-
* whether it was written to disk.
|
|
16
|
-
*
|
|
17
|
-
* @param components - Map of component documentation to render
|
|
18
|
-
* @param options - Write options including output file and callbacks
|
|
19
|
-
* @returns A promise that resolves to the generated markdown string
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* const markdown = await writeMarkdown(components, {
|
|
24
|
-
* outFile: "COMPONENTS.md",
|
|
25
|
-
* write: true,
|
|
26
|
-
* onAppend: (type, doc) => {
|
|
27
|
-
* console.log(`Appended ${type}`);
|
|
28
|
-
* }
|
|
29
|
-
* });
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
async function writeMarkdown(components, options) {
|
|
33
|
-
const write = options?.write !== false;
|
|
34
|
-
const document = new WriterMarkdown_1.default({
|
|
35
|
-
onAppend: (type, document) => {
|
|
36
|
-
options.onAppend?.call(null, type, document, components);
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
(0, markdown_render_utils_1.renderComponentsToMarkdown)(document, components);
|
|
40
|
-
if (write) {
|
|
41
|
-
const outFile = (0, node_path_1.join)(process.cwd(), options.outFile);
|
|
42
|
-
await document.write(outFile, document.end());
|
|
43
|
-
console.log(`created "${options.outFile}".`);
|
|
44
|
-
}
|
|
45
|
-
return document.end();
|
|
46
|
-
}
|