bunki 0.3.1 → 0.3.3

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/dist/cli.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env bun
2
+ export {};
package/dist/cli.js CHANGED
@@ -28481,6 +28481,7 @@ var import_nunjucks = __toESM(require_nunjucks(), 1);
28481
28481
  var import_slugify = __toESM(require_slugify(), 1);
28482
28482
  import path6 from "path";
28483
28483
  var {Glob: Glob2 } = globalThis.Bun;
28484
+ import fs2 from "fs";
28484
28485
 
28485
28486
  // src/utils/markdown-utils.ts
28486
28487
  var import_gray_matter = __toESM(require_gray_matter(), 1);
@@ -32512,8 +32513,16 @@ class SiteGenerator {
32512
32513
  async copyStaticAssets() {
32513
32514
  const assetsDir = path6.join(this.options.templatesDir, "assets");
32514
32515
  const publicDir = path6.join(process.cwd(), "public");
32516
+ async function dirExists(p) {
32517
+ try {
32518
+ const stat = await fs2.promises.stat(p);
32519
+ return stat.isDirectory();
32520
+ } catch {
32521
+ return false;
32522
+ }
32523
+ }
32515
32524
  const assetsDirFile = Bun.file(assetsDir);
32516
- if (await assetsDirFile.exists()) {
32525
+ if (await assetsDirFile.exists() && await dirExists(assetsDir)) {
32517
32526
  const assetGlob = new Glob2("**/*.*");
32518
32527
  const assetsOutputDir = path6.join(this.options.outputDir, "assets");
32519
32528
  await ensureDir(assetsOutputDir);
@@ -32528,23 +32537,30 @@ class SiteGenerator {
32528
32537
  await copyFile(file, targetPath);
32529
32538
  }
32530
32539
  }
32531
- const publicDirFile = Bun.file(publicDir);
32532
- if (await publicDirFile.exists()) {
32533
- const publicGlob = new Glob2("**/*.*");
32534
- for await (const file of publicGlob.scan({
32535
- cwd: publicDir,
32536
- absolute: true
32537
- })) {
32538
- const relativePath = path6.relative(publicDir, file);
32539
- const targetPath = path6.join(this.options.outputDir, relativePath);
32540
- const targetDir = path6.dirname(targetPath);
32541
- await ensureDir(targetDir);
32542
- const targetFile = Bun.file(targetPath);
32543
- if (!await targetFile.exists()) {
32544
- await copyFile(file, targetPath);
32540
+ if (await dirExists(publicDir)) {
32541
+ const copyRecursive = async (srcDir) => {
32542
+ const entries = await fs2.promises.readdir(srcDir, { withFileTypes: true });
32543
+ for (const entry of entries) {
32544
+ const srcPath = path6.join(srcDir, entry.name);
32545
+ const relativePath = path6.relative(publicDir, srcPath);
32546
+ const destPath = path6.join(this.options.outputDir, relativePath);
32547
+ if (!relativePath)
32548
+ continue;
32549
+ if (entry.isDirectory()) {
32550
+ await ensureDir(destPath);
32551
+ await copyRecursive(srcPath);
32552
+ } else if (entry.isFile()) {
32553
+ const targetFile = Bun.file(destPath);
32554
+ if (!await targetFile.exists()) {
32555
+ const targetDir = path6.dirname(destPath);
32556
+ await ensureDir(targetDir);
32557
+ await copyFile(srcPath, destPath);
32558
+ }
32559
+ }
32545
32560
  }
32546
- }
32547
- console.log("Copied public files to site");
32561
+ };
32562
+ await copyRecursive(publicDir);
32563
+ console.log("Copied public files to site (including extensionless & dotfiles)");
32548
32564
  }
32549
32565
  }
32550
32566
  async generateRSSFeed() {
@@ -32679,10 +32695,10 @@ ${rssItems}
32679
32695
 
32680
32696
  // src/server.ts
32681
32697
  import path7 from "path";
32682
- import fs2 from "fs";
32698
+ import fs3 from "fs";
32683
32699
  async function startServer(outputDir = DEFAULT_OUTPUT_DIR, port = 3000) {
32684
32700
  try {
32685
- const stats = await fs2.promises.stat(outputDir);
32701
+ const stats = await fs3.promises.stat(outputDir);
32686
32702
  if (!stats.isDirectory()) {
32687
32703
  const msg = `Error: Output directory ${outputDir} does not exist or is not accessible.`;
32688
32704
  console.error(msg);
@@ -0,0 +1,11 @@
1
+ import { SiteConfig } from "./types";
2
+ export declare const DEFAULT_CONTENT_DIR: string;
3
+ export declare const DEFAULT_OUTPUT_DIR: string;
4
+ export declare const DEFAULT_TEMPLATES_DIR: string;
5
+ export declare const DEFAULT_CONFIG_TS: string;
6
+ export declare const DEFAULT_CONFIG_FILE: string;
7
+ export declare function configExists(configPath?: string): Promise<boolean>;
8
+ export declare function loadConfig(configPath?: string): Promise<SiteConfig>;
9
+ export declare function getDefaultConfig(): SiteConfig;
10
+ export declare function createDefaultConfig(configPath?: string): Promise<boolean>;
11
+ export declare function saveConfig(config: SiteConfig, configPath?: string): Promise<boolean>;
@@ -0,0 +1,9 @@
1
+ export * from "./types";
2
+ export { SiteGenerator } from "./site-generator";
3
+ export { parseMarkdownDirectory } from "./parser";
4
+ export { startServer } from "./server";
5
+ export { DEFAULT_CONTENT_DIR, DEFAULT_OUTPUT_DIR, DEFAULT_TEMPLATES_DIR, DEFAULT_CONFIG_FILE, loadConfig, createDefaultConfig, configExists, saveConfig, } from "./config";
6
+ export { extractExcerpt, convertMarkdownToHtml, parseMarkdownFile, } from "./utils/markdown-utils";
7
+ export { findFilesByPattern, fileExists, readFileAsText, getBaseFilename, ensureDir, copyFile, } from "./utils/file-utils";
8
+ export { uploadImages, DEFAULT_IMAGES_DIR } from "./utils/image-uploader";
9
+ export { createUploader } from "./utils/s3-uploader";
package/dist/index.js CHANGED
@@ -26002,6 +26002,7 @@ var import_nunjucks = __toESM(require_nunjucks(), 1);
26002
26002
  var import_slugify = __toESM(require_slugify(), 1);
26003
26003
  import path3 from "path";
26004
26004
  var {Glob: Glob2 } = globalThis.Bun;
26005
+ import fs2 from "fs";
26005
26006
 
26006
26007
  // src/utils/file-utils.ts
26007
26008
  var {Glob } = globalThis.Bun;
@@ -30052,8 +30053,16 @@ class SiteGenerator {
30052
30053
  async copyStaticAssets() {
30053
30054
  const assetsDir = path3.join(this.options.templatesDir, "assets");
30054
30055
  const publicDir = path3.join(process.cwd(), "public");
30056
+ async function dirExists(p) {
30057
+ try {
30058
+ const stat = await fs2.promises.stat(p);
30059
+ return stat.isDirectory();
30060
+ } catch {
30061
+ return false;
30062
+ }
30063
+ }
30055
30064
  const assetsDirFile = Bun.file(assetsDir);
30056
- if (await assetsDirFile.exists()) {
30065
+ if (await assetsDirFile.exists() && await dirExists(assetsDir)) {
30057
30066
  const assetGlob = new Glob2("**/*.*");
30058
30067
  const assetsOutputDir = path3.join(this.options.outputDir, "assets");
30059
30068
  await ensureDir(assetsOutputDir);
@@ -30068,23 +30077,30 @@ class SiteGenerator {
30068
30077
  await copyFile(file, targetPath);
30069
30078
  }
30070
30079
  }
30071
- const publicDirFile = Bun.file(publicDir);
30072
- if (await publicDirFile.exists()) {
30073
- const publicGlob = new Glob2("**/*.*");
30074
- for await (const file of publicGlob.scan({
30075
- cwd: publicDir,
30076
- absolute: true
30077
- })) {
30078
- const relativePath = path3.relative(publicDir, file);
30079
- const targetPath = path3.join(this.options.outputDir, relativePath);
30080
- const targetDir = path3.dirname(targetPath);
30081
- await ensureDir(targetDir);
30082
- const targetFile = Bun.file(targetPath);
30083
- if (!await targetFile.exists()) {
30084
- await copyFile(file, targetPath);
30080
+ if (await dirExists(publicDir)) {
30081
+ const copyRecursive = async (srcDir) => {
30082
+ const entries = await fs2.promises.readdir(srcDir, { withFileTypes: true });
30083
+ for (const entry of entries) {
30084
+ const srcPath = path3.join(srcDir, entry.name);
30085
+ const relativePath = path3.relative(publicDir, srcPath);
30086
+ const destPath = path3.join(this.options.outputDir, relativePath);
30087
+ if (!relativePath)
30088
+ continue;
30089
+ if (entry.isDirectory()) {
30090
+ await ensureDir(destPath);
30091
+ await copyRecursive(srcPath);
30092
+ } else if (entry.isFile()) {
30093
+ const targetFile = Bun.file(destPath);
30094
+ if (!await targetFile.exists()) {
30095
+ const targetDir = path3.dirname(destPath);
30096
+ await ensureDir(targetDir);
30097
+ await copyFile(srcPath, destPath);
30098
+ }
30099
+ }
30085
30100
  }
30086
- }
30087
- console.log("Copied public files to site");
30101
+ };
30102
+ await copyRecursive(publicDir);
30103
+ console.log("Copied public files to site (including extensionless & dotfiles)");
30088
30104
  }
30089
30105
  }
30090
30106
  async generateRSSFeed() {
@@ -30218,7 +30234,7 @@ ${rssItems}
30218
30234
  }
30219
30235
  // src/server.ts
30220
30236
  import path5 from "path";
30221
- import fs2 from "fs";
30237
+ import fs3 from "fs";
30222
30238
 
30223
30239
  // src/config.ts
30224
30240
  import path4 from "path";
@@ -30350,7 +30366,7 @@ export default function(): SiteConfig {
30350
30366
  // src/server.ts
30351
30367
  async function startServer(outputDir = DEFAULT_OUTPUT_DIR, port = 3000) {
30352
30368
  try {
30353
- const stats = await fs2.promises.stat(outputDir);
30369
+ const stats = await fs3.promises.stat(outputDir);
30354
30370
  if (!stats.isDirectory()) {
30355
30371
  const msg = `Error: Output directory ${outputDir} does not exist or is not accessible.`;
30356
30372
  console.error(msg);
@@ -0,0 +1,2 @@
1
+ import { Post } from "./types";
2
+ export declare function parseMarkdownDirectory(contentDir: string): Promise<Post[]>;
@@ -0,0 +1 @@
1
+ export declare function startServer(outputDir?: string, port?: number): Promise<Bun.Server>;
@@ -0,0 +1,20 @@
1
+ import { GeneratorOptions } from "./types";
2
+ export declare class SiteGenerator {
3
+ private options;
4
+ private site;
5
+ private formatRSSDate;
6
+ private getPacificDate;
7
+ private createPagination;
8
+ constructor(options: GeneratorOptions);
9
+ initialize(): Promise<void>;
10
+ generate(): Promise<void>;
11
+ private generateYearArchives;
12
+ private generateIndexPage;
13
+ private generatePostPages;
14
+ private generateTagPages;
15
+ private generateStylesheet;
16
+ private fallbackCSSGeneration;
17
+ private copyStaticAssets;
18
+ private generateRSSFeed;
19
+ private generateSitemap;
20
+ }
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Post object representing a single markdown file
3
+ */
4
+ export interface Post {
5
+ /** Title of the post */
6
+ title: string;
7
+ /** Date of the post in ISO format */
8
+ date: string;
9
+ /** Array of tags associated with the post */
10
+ tags: string[];
11
+ /** Map of tag names to their slugs */
12
+ tagSlugs: Record<string, string>;
13
+ /** Raw markdown content */
14
+ content: string;
15
+ /** Slug used in the URL */
16
+ slug: string;
17
+ /** URL path for this post */
18
+ url: string;
19
+ /** Brief excerpt from the post content */
20
+ excerpt: string;
21
+ /** Rendered HTML content */
22
+ html: string;
23
+ }
24
+ /**
25
+ * Configuration for CSS processing
26
+ */
27
+ export interface CSSConfig {
28
+ /** Input CSS file path (relative to project root) */
29
+ input: string;
30
+ /** Output CSS file path (relative to output directory) */
31
+ output: string;
32
+ /** PostCSS config file path (relative to project root) */
33
+ postcssConfig?: string;
34
+ /** Whether to enable CSS processing */
35
+ enabled: boolean;
36
+ /** Whether to watch for changes in development */
37
+ watch?: boolean;
38
+ }
39
+ /**
40
+ * Configuration for the site
41
+ */
42
+ export interface SiteConfig {
43
+ /** Site title */
44
+ title: string;
45
+ /** Site description */
46
+ description: string;
47
+ /** Base URL for the site (e.g., https://example.com) */
48
+ baseUrl: string;
49
+ /** Site identifier (used for metadata) */
50
+ domain: string;
51
+ /** Optional public URL for the bucket */
52
+ publicUrl?: string;
53
+ /** Optional S3 client configuration (accessKeyId, secretAccessKey, bucket, etc.) */
54
+ s3?: S3Config;
55
+ /** CSS processing configuration */
56
+ css?: CSSConfig;
57
+ /** Additional custom configuration options */
58
+ [key: string]: any;
59
+ }
60
+ /**
61
+ * Options for initializing the site generator
62
+ */
63
+ export interface GeneratorOptions {
64
+ /** Directory containing markdown content */
65
+ contentDir: string;
66
+ /** Directory where generated files will be output */
67
+ outputDir: string;
68
+ /** Directory containing template files */
69
+ templatesDir: string;
70
+ /** Site configuration */
71
+ config: SiteConfig;
72
+ }
73
+ /**
74
+ * Data structure for tag information
75
+ */
76
+ export interface TagData {
77
+ /** Name of the tag */
78
+ name: string;
79
+ /** URL-friendly slug version of the tag name */
80
+ slug: string;
81
+ /** Number of posts with this tag */
82
+ count: number;
83
+ /** Array of posts with this tag */
84
+ posts: Post[];
85
+ /** Optional description of the tag */
86
+ description?: string;
87
+ }
88
+ /**
89
+ * Pagination information for archives and tag pages
90
+ */
91
+ export interface PaginationData {
92
+ /** Current page number */
93
+ currentPage: number;
94
+ /** Total number of pages */
95
+ totalPages: number;
96
+ /** Whether there is a next page */
97
+ hasNextPage: boolean;
98
+ /** Whether there is a previous page */
99
+ hasPrevPage: boolean;
100
+ /** Next page number or null if no next page */
101
+ nextPage: number | null;
102
+ /** Previous page number or null if no previous page */
103
+ prevPage: number | null;
104
+ /** Number of items per page */
105
+ pageSize: number;
106
+ /** Total number of items across all pages */
107
+ totalItems: number;
108
+ /** Base path for pagination URLs */
109
+ pagePath: string;
110
+ }
111
+ /**
112
+ * Data structure for blog information
113
+ */
114
+ export interface Site {
115
+ /** Site identifier */
116
+ name: string;
117
+ /** Array of posts for the site */
118
+ posts: Post[];
119
+ /** Map of tag names to tag data */
120
+ tags: Record<string, TagData>;
121
+ }
122
+ /**
123
+ * Interface for uploaders (different services can implement this)
124
+ */
125
+ export interface Uploader {
126
+ upload(sourcePath: string, config: SiteConfig): Promise<void>;
127
+ }
128
+ /**
129
+ * Interface for image uploaders
130
+ */
131
+ export interface ImageUploader {
132
+ /**
133
+ * Upload all images from a directory
134
+ * @param imagesDir Directory containing images to upload
135
+ * @returns Record of image filenames to their public URLs
136
+ */
137
+ uploadImages(imagesDir: string): Promise<Record<string, string>>;
138
+ }
139
+ /**
140
+ * S3 configuration type
141
+ */
142
+ export interface S3Config {
143
+ accessKeyId: string;
144
+ secretAccessKey: string;
145
+ bucket: string;
146
+ publicUrl: string;
147
+ /** S3 client options */
148
+ endpoint?: string;
149
+ region?: string;
150
+ }
151
+ /**
152
+ * Options for image upload
153
+ */
154
+ export interface ImageUploadOptions {
155
+ domain?: string;
156
+ images?: string;
157
+ outputJson?: string;
158
+ }
@@ -0,0 +1,27 @@
1
+ import { CSSConfig } from "../types";
2
+ export interface CSSProcessorOptions {
3
+ /** CSS configuration */
4
+ css: CSSConfig;
5
+ /** Project root directory */
6
+ projectRoot: string;
7
+ /** Output directory for the site */
8
+ outputDir: string;
9
+ /** Whether to run in verbose mode */
10
+ verbose?: boolean;
11
+ }
12
+ /**
13
+ * Process CSS using PostCSS
14
+ */
15
+ export declare function processCSS(options: CSSProcessorOptions): Promise<void>;
16
+ /**
17
+ * Watch CSS files for changes and reprocess
18
+ */
19
+ export declare function watchCSS(options: CSSProcessorOptions): Promise<void>;
20
+ /**
21
+ * Get default CSS configuration
22
+ */
23
+ export declare function getDefaultCSSConfig(): CSSConfig;
24
+ /**
25
+ * Validate CSS configuration
26
+ */
27
+ export declare function validateCSSConfig(css: CSSConfig): string[];
@@ -0,0 +1,6 @@
1
+ export declare function findFilesByPattern(pattern: string, directory: string, absolute?: boolean): Promise<string[]>;
2
+ export declare function fileExists(filePath: string): Promise<boolean>;
3
+ export declare function readFileAsText(filePath: string): Promise<string | null>;
4
+ export declare function getBaseFilename(filePath: string, extension?: string): string;
5
+ export declare function ensureDir(dirPath: string): Promise<void>;
6
+ export declare function copyFile(sourcePath: string, targetPath: string): Promise<void>;
@@ -0,0 +1,3 @@
1
+ import { ImageUploadOptions } from "../types";
2
+ export declare const DEFAULT_IMAGES_DIR: string;
3
+ export declare function uploadImages(options?: ImageUploadOptions): Promise<Record<string, string>>;
@@ -0,0 +1,4 @@
1
+ import { Post } from "../types";
2
+ export declare function extractExcerpt(content: string, maxLength?: number): string;
3
+ export declare function convertMarkdownToHtml(markdownContent: string): string;
4
+ export declare function parseMarkdownFile(filePath: string): Promise<Post | null>;
@@ -0,0 +1,23 @@
1
+ import { ImageUploader, S3Config, SiteConfig, Uploader } from "../types";
2
+ /**
3
+ * Bun-native S3 uploader implementation
4
+ */
5
+ export declare class S3Uploader implements Uploader, ImageUploader {
6
+ private s3Config;
7
+ private client;
8
+ constructor(s3Config: S3Config);
9
+ upload(sourcePath: string, config: SiteConfig): Promise<void>;
10
+ /**
11
+ * Get the public URL for a file in S3
12
+ * @param s3Path Path to the file within the bucket
13
+ * @returns The public URL for the file
14
+ */
15
+ private getPublicUrl;
16
+ uploadImages(imagesDir: string): Promise<Record<string, string>>;
17
+ }
18
+ /**
19
+ * Create an S3 uploader
20
+ * @param config The configuration for the uploader
21
+ * @returns An uploader instance
22
+ */
23
+ export declare function createUploader(config: S3Config): Uploader & ImageUploader;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bunki",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "An opinionated static site generator built with Bun featuring PostCSS integration and modern web development workflows",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",