@opensyntaxhq/autodocs-plugin-markdown 1.0.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,10 @@
1
+ import { Plugin } from '@opensyntaxhq/autodocs-core';
2
+
3
+ interface MarkdownPluginOptions {
4
+ sourceDir: string;
5
+ patterns?: string[];
6
+ frontMatter?: boolean;
7
+ }
8
+ declare function markdownPlugin(options: MarkdownPluginOptions): Plugin;
9
+
10
+ export { type MarkdownPluginOptions, markdownPlugin as default, markdownPlugin };
@@ -0,0 +1,10 @@
1
+ import { Plugin } from '@opensyntaxhq/autodocs-core';
2
+
3
+ interface MarkdownPluginOptions {
4
+ sourceDir: string;
5
+ patterns?: string[];
6
+ frontMatter?: boolean;
7
+ }
8
+ declare function markdownPlugin(options: MarkdownPluginOptions): Plugin;
9
+
10
+ export { type MarkdownPluginOptions, markdownPlugin as default, markdownPlugin };
package/dist/index.js ADDED
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ default: () => markdownPlugin,
34
+ markdownPlugin: () => markdownPlugin
35
+ });
36
+ module.exports = __toCommonJS(index_exports);
37
+ var import_promises6 = __toESM(require("fs/promises"));
38
+ var import_path10 = __toESM(require("path"));
39
+ var import_gray_matter = __toESM(require("gray-matter"));
40
+ var import_marked = require("marked");
41
+ var import_glob = require("glob");
42
+
43
+ // ../../core/src/parser/index.ts
44
+ var import_typescript = __toESM(require("typescript"));
45
+ var import_path = __toESM(require("path"));
46
+ var import_fs = __toESM(require("fs"));
47
+
48
+ // ../../core/src/extractor/index.ts
49
+ var import_typescript5 = __toESM(require("typescript"));
50
+ var import_path3 = __toESM(require("path"));
51
+
52
+ // ../../core/src/parser/utils.ts
53
+ var import_typescript2 = __toESM(require("typescript"));
54
+
55
+ // ../../core/src/extractor/serializers.ts
56
+ var import_typescript4 = __toESM(require("typescript"));
57
+ var import_crypto = __toESM(require("crypto"));
58
+ var import_path2 = __toESM(require("path"));
59
+
60
+ // ../../core/src/extractor/utils.ts
61
+ var import_typescript3 = __toESM(require("typescript"));
62
+
63
+ // ../../core/src/generators/json/index.ts
64
+ var import_promises = __toESM(require("fs/promises"));
65
+ var import_path4 = __toESM(require("path"));
66
+
67
+ // ../../core/src/version.ts
68
+ var VERSION = "1.0.0";
69
+
70
+ // ../../core/src/generators/markdown/index.ts
71
+ var import_promises2 = __toESM(require("fs/promises"));
72
+ var import_path5 = __toESM(require("path"));
73
+
74
+ // ../../core/src/generators/html/index.ts
75
+ var import_promises3 = __toESM(require("fs/promises"));
76
+ var import_path6 = __toESM(require("path"));
77
+
78
+ // ../../core/src/cache/FileCache.ts
79
+ var import_promises4 = __toESM(require("fs/promises"));
80
+ var import_path7 = __toESM(require("path"));
81
+ var import_crypto2 = __toESM(require("crypto"));
82
+
83
+ // ../../core/src/cache/incremental.ts
84
+ var import_typescript6 = __toESM(require("typescript"));
85
+ var import_path8 = __toESM(require("path"));
86
+ var import_fs2 = __toESM(require("fs"));
87
+
88
+ // ../../core/src/deploy/static.ts
89
+ var import_promises5 = __toESM(require("fs/promises"));
90
+ var import_path9 = __toESM(require("path"));
91
+
92
+ // src/index.ts
93
+ function markdownPlugin(options) {
94
+ const files = [];
95
+ return {
96
+ name: "@opensyntaxhq/autodocs-plugin-markdown",
97
+ version: VERSION,
98
+ async initialize(context) {
99
+ context.logger.info("Initializing markdown plugin");
100
+ const patterns = options.patterns || ["**/*.md"];
101
+ const foundFiles = await (0, import_glob.glob)(patterns, {
102
+ cwd: options.sourceDir,
103
+ absolute: true,
104
+ nodir: true
105
+ });
106
+ for (const file of foundFiles) {
107
+ const content = await import_promises6.default.readFile(file, "utf-8");
108
+ let frontMatter = {};
109
+ let markdown = content;
110
+ if (options.frontMatter !== false) {
111
+ const parsed = (0, import_gray_matter.default)(content);
112
+ frontMatter = parsed.data;
113
+ markdown = parsed.content;
114
+ }
115
+ const rendered = import_marked.marked.parse(markdown);
116
+ const html = typeof rendered === "string" ? rendered : await rendered;
117
+ files.push({
118
+ path: file,
119
+ frontMatter,
120
+ markdown,
121
+ html
122
+ });
123
+ }
124
+ context.logger.info(`Found ${files.length.toString()} markdown files`);
125
+ context.cache.set("markdown:files", files);
126
+ },
127
+ afterExtract(docs) {
128
+ const guideDocs = files.map((file) => {
129
+ const fileName = import_path10.default.basename(file.path, import_path10.default.extname(file.path));
130
+ const title = typeof file.frontMatter.title === "string" ? file.frontMatter.title : fileName;
131
+ const description = typeof file.frontMatter.description === "string" ? file.frontMatter.description : "";
132
+ return {
133
+ id: `guide:${file.path}`,
134
+ name: title,
135
+ kind: "guide",
136
+ fileName: file.path,
137
+ source: { file: file.path, line: 1, column: 0 },
138
+ position: { line: 1, column: 0 },
139
+ signature: "",
140
+ documentation: {
141
+ summary: description,
142
+ tags: []
143
+ },
144
+ metadata: {
145
+ markdown: file.markdown,
146
+ html: file.html,
147
+ frontMatter: file.frontMatter
148
+ }
149
+ };
150
+ });
151
+ return [...docs, ...guideDocs];
152
+ }
153
+ };
154
+ }
155
+ // Annotate the CommonJS export names for ESM import in node:
156
+ 0 && (module.exports = {
157
+ markdownPlugin
158
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,123 @@
1
+ // src/index.ts
2
+ import fs8 from "fs/promises";
3
+ import path10 from "path";
4
+ import matter from "gray-matter";
5
+ import { marked } from "marked";
6
+ import { glob } from "glob";
7
+
8
+ // ../../core/src/parser/index.ts
9
+ import ts from "typescript";
10
+ import path from "path";
11
+ import fs from "fs";
12
+
13
+ // ../../core/src/extractor/index.ts
14
+ import ts5 from "typescript";
15
+ import path3 from "path";
16
+
17
+ // ../../core/src/parser/utils.ts
18
+ import ts2 from "typescript";
19
+
20
+ // ../../core/src/extractor/serializers.ts
21
+ import ts4 from "typescript";
22
+ import crypto from "crypto";
23
+ import path2 from "path";
24
+
25
+ // ../../core/src/extractor/utils.ts
26
+ import ts3 from "typescript";
27
+
28
+ // ../../core/src/generators/json/index.ts
29
+ import fs2 from "fs/promises";
30
+ import path4 from "path";
31
+
32
+ // ../../core/src/version.ts
33
+ var VERSION = "1.0.0";
34
+
35
+ // ../../core/src/generators/markdown/index.ts
36
+ import fs3 from "fs/promises";
37
+ import path5 from "path";
38
+
39
+ // ../../core/src/generators/html/index.ts
40
+ import fs4 from "fs/promises";
41
+ import path6 from "path";
42
+
43
+ // ../../core/src/cache/FileCache.ts
44
+ import fs5 from "fs/promises";
45
+ import path7 from "path";
46
+ import crypto2 from "crypto";
47
+
48
+ // ../../core/src/cache/incremental.ts
49
+ import ts6 from "typescript";
50
+ import path8 from "path";
51
+ import fs6 from "fs";
52
+
53
+ // ../../core/src/deploy/static.ts
54
+ import fs7 from "fs/promises";
55
+ import path9 from "path";
56
+
57
+ // src/index.ts
58
+ function markdownPlugin(options) {
59
+ const files = [];
60
+ return {
61
+ name: "@opensyntaxhq/autodocs-plugin-markdown",
62
+ version: VERSION,
63
+ async initialize(context) {
64
+ context.logger.info("Initializing markdown plugin");
65
+ const patterns = options.patterns || ["**/*.md"];
66
+ const foundFiles = await glob(patterns, {
67
+ cwd: options.sourceDir,
68
+ absolute: true,
69
+ nodir: true
70
+ });
71
+ for (const file of foundFiles) {
72
+ const content = await fs8.readFile(file, "utf-8");
73
+ let frontMatter = {};
74
+ let markdown = content;
75
+ if (options.frontMatter !== false) {
76
+ const parsed = matter(content);
77
+ frontMatter = parsed.data;
78
+ markdown = parsed.content;
79
+ }
80
+ const rendered = marked.parse(markdown);
81
+ const html = typeof rendered === "string" ? rendered : await rendered;
82
+ files.push({
83
+ path: file,
84
+ frontMatter,
85
+ markdown,
86
+ html
87
+ });
88
+ }
89
+ context.logger.info(`Found ${files.length.toString()} markdown files`);
90
+ context.cache.set("markdown:files", files);
91
+ },
92
+ afterExtract(docs) {
93
+ const guideDocs = files.map((file) => {
94
+ const fileName = path10.basename(file.path, path10.extname(file.path));
95
+ const title = typeof file.frontMatter.title === "string" ? file.frontMatter.title : fileName;
96
+ const description = typeof file.frontMatter.description === "string" ? file.frontMatter.description : "";
97
+ return {
98
+ id: `guide:${file.path}`,
99
+ name: title,
100
+ kind: "guide",
101
+ fileName: file.path,
102
+ source: { file: file.path, line: 1, column: 0 },
103
+ position: { line: 1, column: 0 },
104
+ signature: "",
105
+ documentation: {
106
+ summary: description,
107
+ tags: []
108
+ },
109
+ metadata: {
110
+ markdown: file.markdown,
111
+ html: file.html,
112
+ frontMatter: file.frontMatter
113
+ }
114
+ };
115
+ });
116
+ return [...docs, ...guideDocs];
117
+ }
118
+ };
119
+ }
120
+ export {
121
+ markdownPlugin as default,
122
+ markdownPlugin
123
+ };
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@opensyntaxhq/autodocs-plugin-markdown",
3
+ "version": "1.0.0",
4
+ "license": "Apache-2.0",
5
+ "description": "Markdown guide plugin for Autodocs",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/OpenSyntaxHQ/autodocs.git",
9
+ "directory": "packages/plugins/markdown"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/OpenSyntaxHQ/autodocs/issues"
13
+ },
14
+ "homepage": "https://github.com/OpenSyntaxHQ/autodocs",
15
+ "keywords": [
16
+ "autodocs",
17
+ "plugin",
18
+ "markdown",
19
+ "documentation"
20
+ ],
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "main": "./dist/index.js",
25
+ "module": "./dist/index.mjs",
26
+ "types": "./dist/index.d.ts",
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.mjs",
34
+ "require": "./dist/index.js"
35
+ }
36
+ },
37
+ "scripts": {
38
+ "build": "tsup",
39
+ "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
40
+ "lint": "eslint .",
41
+ "type-check": "tsc --noEmit",
42
+ "clean": "rm -rf dist"
43
+ },
44
+ "dependencies": {
45
+ "glob": "^13.0.1",
46
+ "gray-matter": "^4.0.3",
47
+ "marked": "^17.0.1"
48
+ },
49
+ "peerDependencies": {
50
+ "@opensyntaxhq/autodocs-core": "^1.0.0"
51
+ },
52
+ "devDependencies": {
53
+ "@opensyntaxhq/autodocs-core": "^1.0.0",
54
+ "@types/node": "^22.0.0",
55
+ "tsup": "^8.3.0",
56
+ "typescript": "^5.9.0"
57
+ }
58
+ }