@@ -2,12 +2,27 @@ import { resolve, join, dirname } from 'path';
22import { readFileSync , readdirSync , statSync , mkdirSync , existsSync , writeFileSync } from 'fs' ;
33import type { Plugin } from 'vite' ;
44
5- export interface robot8oPluginOptions {
5+ export interface coolbotPluginOptions {
6+ /**
7+ * Write the raw txt output to the converted directory
8+ * @default false
9+ */
10+ writeRawOutput ?: boolean ;
611 /**
712 * Directory containing markdown files to convert
813 * @default 'docs'
914 */
1015 docsDir ?: string ;
16+ /**
17+ * Webhook URL to send the file map to
18+ * @default '' || process.env.COOLBOT_WEBHOOK_URL
19+ */
20+ webhookUrl ?: string ;
21+ /**
22+ * Ignore files in the docs directory
23+ * @default []
24+ */
25+ ignoreFolders ?: string [ ] ;
1126}
1227
1328interface FileMap {
@@ -17,9 +32,9 @@ interface FileMap {
1732/**
1833 * Plugin to convert markdown files to text files, RAG chain.
1934 */
20- export default function robot8oPlugin ( options : robot8oPluginOptions = { } ) : Plugin {
35+ export default function coolbotPlugin ( options : coolbotPluginOptions = { } ) : Plugin {
2136 const docsDir = options . docsDir || 'docs' ;
22- const webhookUrl = 'https://n8n.darweb.io/webhook-test/kv ';
37+ const webhookUrl = process . env . COOLBOT_WEBHOOK_URL || ' ';
2338
2439 const ensureDirectoryExists = ( filePath : string ) => {
2540 const dir = dirname ( filePath ) ;
@@ -29,26 +44,26 @@ export default function robot8oPlugin(options: robot8oPluginOptions = {}): Plugi
2944 } ;
3045
3146 return {
32- name : 'vitepress-plugin-robo8o ' ,
47+ name : 'vitepress-plugin-CoolBot ' ,
3348
3449 async closeBundle ( ) {
3550 try {
3651 const docsPath = resolve ( process . cwd ( ) , docsDir ) ;
3752 const markdownFiles = getAllMarkdownFiles ( docsPath ) ;
38- const convertedDir = resolve ( docsPath , '.vitepress/dist/converted ' ) ;
53+ const convertedDir = resolve ( docsPath , '.vitepress/dist/' ) ;
3954 const fileMap : FileMap = { } ;
4055
4156 // Ensure converted directory exists
4257 if ( ! existsSync ( convertedDir ) ) {
4358 mkdirSync ( convertedDir , { recursive : true } ) ;
4459 }
4560
46- for ( const file of markdownFiles ) {
61+ for ( const file of markdownFiles ) {
4762 try {
4863 const relativePath = file . replace ( docsPath , '' ) ;
4964
5065 if ( ! relativePath . startsWith ( '\\' ) && ! relativePath . startsWith ( '/' ) ) {
51- console . warn ( `Skipping file with invalid path: ${ file } ` ) ;
66+ console . warn ( `CoolBot: Skipping file with invalid path: ${ file } ` ) ;
5267 continue ;
5368 }
5469
@@ -60,23 +75,27 @@ export default function robot8oPlugin(options: robot8oPluginOptions = {}): Plugi
6075 const normalizedPath = relativePath . slice ( 1 ) . replace ( '.md' , '' ) . replace ( / \\ / g, '/' ) ;
6176 fileMap [ normalizedPath ] = convertedContent ;
6277
63- // Write the converted file
64- ensureDirectoryExists ( outputPath ) ;
65- writeFileSync ( outputPath , convertedContent , 'utf-8' ) ;
78+ if ( options . writeRawOutput ) {
79+ // Write the converted file
80+ ensureDirectoryExists ( outputPath ) ;
81+ writeFileSync ( outputPath , convertedContent , 'utf-8' ) ;
82+ console . log ( `CoolBot: ${ relativePath } -> .vitepress/dist/${ relativePath . replace ( '.md' , '.txt' ) } ` ) ;
83+ }
6684
67- console . log ( `Converted: ${ relativePath } -> .vitepress/dist/converted${ relativePath . replace ( '.md' , '.txt' ) } ` ) ;
6885 } catch ( fileError ) {
69- console . error ( `Error processing file ${ file } :` , fileError ) ;
86+ console . error ( `CoolBot: Error processing file ${ file } :` , fileError ) ;
7087 }
7188 }
89+
7290
7391 // Write the file map
7492 const mapPath = resolve ( convertedDir , 'kvmap.json' ) ;
7593 writeFileSync ( mapPath , JSON . stringify ( fileMap , null , 2 ) , 'utf-8' ) ;
7694
77- // Send POST request to webhook
78- try {
79- const response = await fetch ( webhookUrl , {
95+ if ( webhookUrl ) {
96+ // Send POST request to webhook
97+ try {
98+ const response = await fetch ( webhookUrl , {
8099 method : 'POST' ,
81100 headers : {
82101 'Content-Type' : 'application/json' ,
@@ -88,15 +107,16 @@ export default function robot8oPlugin(options: robot8oPluginOptions = {}): Plugi
88107 throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
89108 }
90109
91- console . log ( '\nROBO8O: Successfully sent file map to webhook' ) ;
92- } catch ( webhookError ) {
93- console . error ( 'ROBO8O: Error sending file map to webhook:' , webhookError ) ;
110+ console . log ( '\nCoolBot: Successfully sent file map to webhook' ) ;
111+ } catch ( webhookError ) {
112+ console . error ( 'CoolBot: Error sending file map to webhook:' , webhookError ) ;
113+ }
94114 }
95115
96- console . log ( '\nROBO8O : Generated file map at .vitepress/dist/converted /kvmap.json' ) ;
97- console . log ( '\nROBO8O : Conversion complete' ) ;
116+ console . log ( '\nCoolBot : Generated file map at .vitepress/dist/public /kvmap.json' ) ;
117+ console . log ( '\nCoolBot : Conversion complete' ) ;
98118 } catch ( error ) {
99- console . error ( 'ROBO8O : Error during conversion:' , error ) ;
119+ console . error ( 'CoolBot : Error during conversion:' , error ) ;
100120 }
101121 }
102122 } ;
@@ -111,20 +131,24 @@ function getAllMarkdownFiles(dir: string): string[] {
111131 let results : string [ ] = [ ] ;
112132 try {
113133 const files = readdirSync ( dir ) ;
134+ const defaultIgnored = [ 'node_modules' , '.vitepress' , 'dist' , 'api-reference' ] ;
114135
115136 for ( const file of files ) {
116137 const filePath = join ( dir , file ) ;
117138 const stat = statSync ( filePath ) ;
118139
119- // Skip the .vitepress directory and node_modules
120- if ( stat . isDirectory ( ) && ! [ 'node_modules' , '.vitepress' , 'dist' , 'api-reference' ] . includes ( file ) ) {
140+ if ( defaultIgnored . includes ( file ) ) {
141+ continue ;
142+ }
143+
144+ if ( stat . isDirectory ( ) ) {
121145 results = results . concat ( getAllMarkdownFiles ( filePath ) ) ;
122146 } else if ( file . endsWith ( '.md' ) ) {
123147 results . push ( filePath ) ;
124148 }
125149 }
126150 } catch ( error ) {
127- console . error ( 'ROBO8O : Error reading directory:' , error ) ;
151+ console . error ( 'CoolBot : Error reading directory:' , error ) ;
128152 }
129153
130154 return results ;
0 commit comments