barodoc 0.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Barocss
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,140 @@
1
+ // src/runtime/project.ts
2
+ import fs from "fs-extra";
3
+ import path from "path";
4
+ import pc from "picocolors";
5
+ var BARODOC_DIR = ".barodoc";
6
+ function isCustomProject(dir) {
7
+ return fs.existsSync(path.join(dir, "astro.config.mjs")) || fs.existsSync(path.join(dir, "astro.config.ts")) || fs.existsSync(path.join(dir, "astro.config.js"));
8
+ }
9
+ async function loadProjectConfig(dir, configFile) {
10
+ const configPath = configFile ? path.resolve(dir, configFile) : path.join(dir, "barodoc.config.json");
11
+ if (fs.existsSync(configPath)) {
12
+ const content = await fs.readFile(configPath, "utf-8");
13
+ return {
14
+ config: JSON.parse(content),
15
+ configPath
16
+ };
17
+ }
18
+ return {
19
+ config: getDefaultConfig(),
20
+ configPath: null
21
+ };
22
+ }
23
+ function getDefaultConfig() {
24
+ return {
25
+ name: "Documentation",
26
+ navigation: [],
27
+ i18n: {
28
+ defaultLocale: "en",
29
+ locales: ["en"]
30
+ },
31
+ search: {
32
+ enabled: true
33
+ }
34
+ };
35
+ }
36
+ async function createProject(options) {
37
+ const { root, docsDir, config, configPath } = options;
38
+ const projectDir = path.join(root, BARODOC_DIR);
39
+ console.log(pc.dim(`Creating temporary project in ${BARODOC_DIR}/`));
40
+ await fs.remove(projectDir);
41
+ await fs.ensureDir(projectDir);
42
+ await fs.writeJSON(
43
+ path.join(projectDir, "package.json"),
44
+ {
45
+ name: "barodoc-temp",
46
+ type: "module",
47
+ private: true
48
+ },
49
+ { spaces: 2 }
50
+ );
51
+ const astroConfig = generateAstroConfig(config, configPath || null, docsDir);
52
+ await fs.writeFile(path.join(projectDir, "astro.config.mjs"), astroConfig);
53
+ await fs.writeJSON(
54
+ path.join(projectDir, "tsconfig.json"),
55
+ {
56
+ extends: "astro/tsconfigs/strict",
57
+ compilerOptions: {
58
+ jsx: "react-jsx",
59
+ jsxImportSource: "react"
60
+ }
61
+ },
62
+ { spaces: 2 }
63
+ );
64
+ const tempConfigPath = path.join(projectDir, "barodoc.config.json");
65
+ await fs.writeJSON(tempConfigPath, config, { spaces: 2 });
66
+ const contentDir = path.join(projectDir, "src/content");
67
+ await fs.ensureDir(contentDir);
68
+ await fs.writeFile(
69
+ path.join(contentDir, "config.ts"),
70
+ generateContentConfig()
71
+ );
72
+ const docsAbsolute = path.resolve(root, docsDir);
73
+ const docsLink = path.join(contentDir, "docs");
74
+ if (fs.existsSync(docsAbsolute)) {
75
+ await fs.symlink(docsAbsolute, docsLink, "dir");
76
+ } else {
77
+ await fs.ensureDir(docsLink);
78
+ }
79
+ const publicDir = path.join(root, "public");
80
+ const publicLink = path.join(projectDir, "public");
81
+ if (fs.existsSync(publicDir)) {
82
+ await fs.symlink(publicDir, publicLink, "dir");
83
+ } else {
84
+ await fs.ensureDir(publicLink);
85
+ }
86
+ return projectDir;
87
+ }
88
+ async function cleanupProject(root) {
89
+ const projectDir = path.join(root, BARODOC_DIR);
90
+ await fs.remove(projectDir);
91
+ }
92
+ function generateAstroConfig(config, configPath, docsDir) {
93
+ return `import { defineConfig } from "astro/config";
94
+ import barodoc from "@barodoc/core";
95
+ import docsTheme from "@barodoc/theme-docs";
96
+
97
+ export default defineConfig({
98
+ integrations: [
99
+ barodoc({
100
+ config: "./barodoc.config.json",
101
+ theme: docsTheme(),
102
+ }),
103
+ ],
104
+ });
105
+ `;
106
+ }
107
+ function generateContentConfig() {
108
+ return `import { defineCollection, z } from "astro:content";
109
+
110
+ const docsCollection = defineCollection({
111
+ type: "content",
112
+ schema: z.object({
113
+ title: z.string(),
114
+ description: z.string().optional(),
115
+ }),
116
+ });
117
+
118
+ export const collections = {
119
+ docs: docsCollection,
120
+ };
121
+ `;
122
+ }
123
+ function findDocsDir(root) {
124
+ const candidates = ["docs", "content", "src/content/docs"];
125
+ for (const candidate of candidates) {
126
+ const fullPath = path.join(root, candidate);
127
+ if (fs.existsSync(fullPath)) {
128
+ return candidate;
129
+ }
130
+ }
131
+ return "docs";
132
+ }
133
+
134
+ export {
135
+ isCustomProject,
136
+ loadProjectConfig,
137
+ createProject,
138
+ cleanupProject,
139
+ findDocsDir
140
+ };
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/dist/cli.js ADDED
@@ -0,0 +1,305 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ cleanupProject,
4
+ createProject,
5
+ findDocsDir,
6
+ isCustomProject,
7
+ loadProjectConfig
8
+ } from "./chunk-KI3NAGJ3.js";
9
+
10
+ // src/cli.ts
11
+ import cac from "cac";
12
+ import pc5 from "picocolors";
13
+
14
+ // package.json
15
+ var version = "0.0.1";
16
+
17
+ // src/commands/serve.ts
18
+ import path from "path";
19
+ import pc from "picocolors";
20
+ import { execa } from "execa";
21
+ async function serve(dir, options) {
22
+ const root = path.resolve(process.cwd(), dir);
23
+ console.log();
24
+ console.log(pc.bold(pc.cyan(" barodoc serve")));
25
+ console.log();
26
+ if (isCustomProject(root)) {
27
+ console.log(pc.dim("Detected custom Astro project"));
28
+ console.log(pc.dim("Running astro dev..."));
29
+ console.log();
30
+ await runAstroDev(root, options);
31
+ return;
32
+ }
33
+ console.log(pc.dim("Quick mode - creating temporary project..."));
34
+ const docsDir = findDocsDir(root);
35
+ const { config } = await loadProjectConfig(root, options.config);
36
+ const projectDir = await createProject({
37
+ root,
38
+ docsDir,
39
+ config,
40
+ configPath: options.config
41
+ });
42
+ console.log(pc.green("\u2713 Project created"));
43
+ console.log();
44
+ await runAstroDev(projectDir, options);
45
+ }
46
+ async function runAstroDev(projectDir, options) {
47
+ const args = ["astro", "dev"];
48
+ if (options.port) {
49
+ args.push("--port", String(options.port));
50
+ }
51
+ if (options.host) {
52
+ args.push("--host");
53
+ }
54
+ try {
55
+ await execa("npx", args, {
56
+ cwd: projectDir,
57
+ stdio: "inherit"
58
+ });
59
+ } catch (error) {
60
+ if (error.signal === "SIGINT") {
61
+ console.log();
62
+ console.log(pc.dim("Shutting down..."));
63
+ } else {
64
+ throw error;
65
+ }
66
+ }
67
+ }
68
+
69
+ // src/commands/build.ts
70
+ import path2 from "path";
71
+ import pc2 from "picocolors";
72
+ import fs from "fs-extra";
73
+ import { execa as execa2 } from "execa";
74
+ async function build(dir, options) {
75
+ const root = path2.resolve(process.cwd(), dir);
76
+ const outputDir = path2.resolve(process.cwd(), options.output);
77
+ console.log();
78
+ console.log(pc2.bold(pc2.cyan(" barodoc build")));
79
+ console.log();
80
+ if (isCustomProject(root)) {
81
+ console.log(pc2.dim("Detected custom Astro project"));
82
+ console.log(pc2.dim("Running astro build..."));
83
+ console.log();
84
+ await runAstroBuild(root, outputDir);
85
+ return;
86
+ }
87
+ console.log(pc2.dim("Quick mode - creating temporary project..."));
88
+ const docsDir = findDocsDir(root);
89
+ const { config } = await loadProjectConfig(root, options.config);
90
+ const projectDir = await createProject({
91
+ root,
92
+ docsDir,
93
+ config,
94
+ configPath: options.config
95
+ });
96
+ console.log(pc2.green("\u2713 Project created"));
97
+ console.log();
98
+ try {
99
+ await runAstroBuild(projectDir, path2.join(projectDir, "dist"));
100
+ const tempDist = path2.join(projectDir, "dist");
101
+ if (await fs.pathExists(tempDist)) {
102
+ await fs.ensureDir(outputDir);
103
+ await fs.copy(tempDist, outputDir);
104
+ console.log();
105
+ console.log(pc2.green(`\u2713 Build output copied to ${options.output}/`));
106
+ }
107
+ } finally {
108
+ console.log(pc2.dim("Cleaning up..."));
109
+ await cleanupProject(root);
110
+ }
111
+ console.log();
112
+ console.log(pc2.green("Build complete!"));
113
+ console.log();
114
+ console.log(` ${pc2.dim("Output:")} ${outputDir}`);
115
+ console.log(` ${pc2.dim("Preview:")} barodoc preview ${dir}`);
116
+ console.log();
117
+ }
118
+ async function runAstroBuild(projectDir, outputDir) {
119
+ console.log(pc2.dim("Building site..."));
120
+ await execa2("npx", ["astro", "build"], {
121
+ cwd: projectDir,
122
+ stdio: "inherit"
123
+ });
124
+ console.log();
125
+ console.log(pc2.dim("Generating search index..."));
126
+ try {
127
+ await execa2("npx", ["pagefind", "--site", "dist"], {
128
+ cwd: projectDir,
129
+ stdio: "inherit"
130
+ });
131
+ } catch {
132
+ console.log(pc2.yellow("\u26A0 Pagefind not available, skipping search index"));
133
+ }
134
+ }
135
+
136
+ // src/commands/create.ts
137
+ import path3 from "path";
138
+ import pc3 from "picocolors";
139
+ import fs2 from "fs-extra";
140
+ async function create(name) {
141
+ const targetDir = path3.resolve(process.cwd(), name);
142
+ console.log();
143
+ console.log(pc3.bold(pc3.cyan(" barodoc create")));
144
+ console.log();
145
+ if (await fs2.pathExists(targetDir)) {
146
+ console.log(pc3.red(`Error: Directory "${name}" already exists.`));
147
+ process.exit(1);
148
+ }
149
+ console.log(pc3.dim(`Creating project in ${name}/`));
150
+ await fs2.ensureDir(path3.join(targetDir, "docs/en"));
151
+ await fs2.ensureDir(path3.join(targetDir, "public"));
152
+ await fs2.writeJSON(
153
+ path3.join(targetDir, "barodoc.config.json"),
154
+ {
155
+ name,
156
+ logo: "/logo.svg",
157
+ navigation: [
158
+ {
159
+ group: "Getting Started",
160
+ pages: ["introduction", "quickstart"]
161
+ }
162
+ ],
163
+ i18n: {
164
+ defaultLocale: "en",
165
+ locales: ["en"]
166
+ },
167
+ topbar: {
168
+ github: ""
169
+ }
170
+ },
171
+ { spaces: 2 }
172
+ );
173
+ await fs2.writeFile(
174
+ path3.join(targetDir, "docs/en/introduction.md"),
175
+ `# Introduction
176
+
177
+ Welcome to your documentation site!
178
+
179
+ ## Getting Started
180
+
181
+ Edit this file at \`docs/en/introduction.md\` to customize your documentation.
182
+
183
+ ## Features
184
+
185
+ - Write documentation in Markdown
186
+ - Dark mode support
187
+ - Full-text search
188
+ - i18n support
189
+ `
190
+ );
191
+ await fs2.writeFile(
192
+ path3.join(targetDir, "docs/en/quickstart.md"),
193
+ `# Quick Start
194
+
195
+ ## Development
196
+
197
+ \`\`\`bash
198
+ barodoc serve
199
+ \`\`\`
200
+
201
+ ## Build
202
+
203
+ \`\`\`bash
204
+ barodoc build
205
+ \`\`\`
206
+
207
+ ## Preview
208
+
209
+ \`\`\`bash
210
+ barodoc preview
211
+ \`\`\`
212
+ `
213
+ );
214
+ await fs2.writeFile(
215
+ path3.join(targetDir, "public/logo.svg"),
216
+ `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="32" height="32">
217
+ <rect x="10" y="20" width="80" height="60" rx="8" fill="currentColor" opacity="0.1"/>
218
+ <rect x="18" y="32" width="40" height="4" rx="2" fill="currentColor"/>
219
+ <rect x="18" y="42" width="64" height="3" rx="1.5" fill="currentColor" opacity="0.5"/>
220
+ <rect x="18" y="50" width="56" height="3" rx="1.5" fill="currentColor" opacity="0.5"/>
221
+ <rect x="18" y="58" width="48" height="3" rx="1.5" fill="currentColor" opacity="0.5"/>
222
+ </svg>
223
+ `
224
+ );
225
+ await fs2.writeFile(
226
+ path3.join(targetDir, ".gitignore"),
227
+ `.barodoc/
228
+ dist/
229
+ node_modules/
230
+ .DS_Store
231
+ `
232
+ );
233
+ console.log(pc3.green("\u2713 Project created!"));
234
+ console.log();
235
+ console.log("Next steps:");
236
+ console.log();
237
+ console.log(` ${pc3.cyan(`cd ${name}`)}`);
238
+ console.log(` ${pc3.cyan("barodoc serve")}`);
239
+ console.log();
240
+ }
241
+
242
+ // src/commands/preview.ts
243
+ import path4 from "path";
244
+ import pc4 from "picocolors";
245
+ import fs3 from "fs-extra";
246
+ import { execa as execa3 } from "execa";
247
+ async function preview(dir, options) {
248
+ const root = path4.resolve(process.cwd(), dir);
249
+ const distDir = path4.resolve(root, options.output);
250
+ console.log();
251
+ console.log(pc4.bold(pc4.cyan(" barodoc preview")));
252
+ console.log();
253
+ if (!await fs3.pathExists(distDir)) {
254
+ console.log(
255
+ pc4.red(`Error: Build directory not found: ${options.output}/`)
256
+ );
257
+ console.log();
258
+ console.log(`Run ${pc4.cyan("barodoc build")} first to create a build.`);
259
+ console.log();
260
+ process.exit(1);
261
+ }
262
+ console.log(pc4.dim(`Serving from ${options.output}/`));
263
+ console.log();
264
+ try {
265
+ await execa3(
266
+ "npx",
267
+ ["serve", distDir, "-l", String(options.port)],
268
+ {
269
+ stdio: "inherit"
270
+ }
271
+ );
272
+ } catch (error) {
273
+ if (error.signal === "SIGINT") {
274
+ console.log();
275
+ console.log(pc4.dim("Shutting down..."));
276
+ } else {
277
+ throw error;
278
+ }
279
+ }
280
+ }
281
+
282
+ // src/cli.ts
283
+ var cli = cac("barodoc");
284
+ cli.command("serve [dir]", "Start development server").option("-p, --port <port>", "Port to listen on", { default: 4321 }).option("-h, --host", "Expose to network").option("-c, --config <file>", "Config file path").action(async (dir = ".", options) => {
285
+ await serve(dir, options);
286
+ });
287
+ cli.command("build [dir]", "Build for production").option("-o, --output <dir>", "Output directory", { default: "dist" }).option("-c, --config <file>", "Config file path").action(async (dir = ".", options) => {
288
+ await build(dir, options);
289
+ });
290
+ cli.command("preview [dir]", "Preview production build").option("-p, --port <port>", "Port to listen on", { default: 4321 }).option("-o, --output <dir>", "Build output directory", { default: "dist" }).action(async (dir = ".", options) => {
291
+ await preview(dir, options);
292
+ });
293
+ cli.command("create <name>", "Create a new Barodoc project").action(async (name) => {
294
+ await create(name);
295
+ });
296
+ cli.help();
297
+ cli.version(version);
298
+ cli.parse();
299
+ if (!process.argv.slice(2).length) {
300
+ console.log();
301
+ console.log(pc5.bold(pc5.cyan(" barodoc")));
302
+ console.log(pc5.dim(" Documentation framework powered by Astro"));
303
+ console.log();
304
+ cli.outputHelp();
305
+ }
@@ -0,0 +1,40 @@
1
+ import { BarodocConfig } from '@barodoc/core';
2
+ export * from '@barodoc/core';
3
+
4
+ interface ProjectOptions {
5
+ root: string;
6
+ docsDir: string;
7
+ config: BarodocConfig;
8
+ configPath?: string;
9
+ }
10
+ /**
11
+ * Create temporary Astro project for quick mode
12
+ */
13
+ declare function createProject(options: ProjectOptions): Promise<string>;
14
+ /**
15
+ * Clean up temporary project
16
+ */
17
+ declare function cleanupProject(root: string): Promise<void>;
18
+
19
+ interface ExtractedFrontmatter {
20
+ title: string;
21
+ description?: string;
22
+ [key: string]: unknown;
23
+ }
24
+ /**
25
+ * Extract frontmatter from markdown content
26
+ * If no frontmatter exists, extract title from first heading
27
+ */
28
+ declare function extractFrontmatter(content: string): {
29
+ data: ExtractedFrontmatter;
30
+ content: string;
31
+ };
32
+ /**
33
+ * Process markdown file for content collection
34
+ */
35
+ declare function processMarkdown(filePath: string, content: string): {
36
+ frontmatter: ExtractedFrontmatter;
37
+ body: string;
38
+ };
39
+
40
+ export { cleanupProject, createProject, extractFrontmatter, processMarkdown };
package/dist/index.js ADDED
@@ -0,0 +1,62 @@
1
+ import {
2
+ cleanupProject,
3
+ createProject
4
+ } from "./chunk-KI3NAGJ3.js";
5
+
6
+ // src/index.ts
7
+ export * from "@barodoc/core";
8
+
9
+ // src/runtime/content.ts
10
+ import matter from "gray-matter";
11
+ function extractFrontmatter(content) {
12
+ const { data, content: body } = matter(content);
13
+ if (data.title) {
14
+ return {
15
+ data,
16
+ content: body
17
+ };
18
+ }
19
+ const titleMatch = body.match(/^#\s+(.+)$/m);
20
+ const title = titleMatch?.[1] || "Untitled";
21
+ const description = extractFirstParagraph(body);
22
+ return {
23
+ data: {
24
+ ...data,
25
+ title,
26
+ description
27
+ },
28
+ content: body
29
+ };
30
+ }
31
+ function extractFirstParagraph(content) {
32
+ const lines = content.split("\n");
33
+ let inParagraph = false;
34
+ let paragraph = "";
35
+ for (const line of lines) {
36
+ const trimmed = line.trim();
37
+ if (trimmed.startsWith("#")) continue;
38
+ if (trimmed.startsWith("```")) break;
39
+ if (trimmed.startsWith("-") || trimmed.startsWith("*")) continue;
40
+ if (trimmed.startsWith(">")) continue;
41
+ if (trimmed === "") {
42
+ if (inParagraph) break;
43
+ continue;
44
+ }
45
+ inParagraph = true;
46
+ paragraph += (paragraph ? " " : "") + trimmed;
47
+ }
48
+ return paragraph || void 0;
49
+ }
50
+ function processMarkdown(filePath, content) {
51
+ const { data, content: body } = extractFrontmatter(content);
52
+ return {
53
+ frontmatter: data,
54
+ body
55
+ };
56
+ }
57
+ export {
58
+ cleanupProject,
59
+ createProject,
60
+ extractFrontmatter,
61
+ processMarkdown
62
+ };
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "barodoc",
3
+ "version": "0.0.1",
4
+ "description": "Documentation framework powered by Astro",
5
+ "type": "module",
6
+ "bin": {
7
+ "barodoc": "./dist/cli.js"
8
+ },
9
+ "main": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "types": "./dist/index.d.ts",
14
+ "import": "./dist/index.js"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "dependencies": {
21
+ "cac": "^6.7.14",
22
+ "chokidar": "^4.0.0",
23
+ "execa": "^9.5.0",
24
+ "fs-extra": "^11.2.0",
25
+ "gray-matter": "^4.0.3",
26
+ "picocolors": "^1.1.1",
27
+ "@barodoc/core": "0.0.1",
28
+ "@barodoc/theme-docs": "0.0.1"
29
+ },
30
+ "devDependencies": {
31
+ "@types/fs-extra": "^11.0.4",
32
+ "@types/node": "^22.0.0",
33
+ "tsup": "^8.3.0",
34
+ "typescript": "^5.7.0"
35
+ },
36
+ "keywords": [
37
+ "documentation",
38
+ "astro",
39
+ "mdx",
40
+ "cli",
41
+ "barodoc"
42
+ ],
43
+ "license": "MIT",
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "https://github.com/barocss/barodoc.git",
47
+ "directory": "packages/barodoc"
48
+ },
49
+ "scripts": {
50
+ "build": "tsup",
51
+ "dev": "tsup --watch"
52
+ }
53
+ }