From 10b9af578a87c221981dae4dd00bf8a8003e0a6d Mon Sep 17 00:00:00 2001 From: Mahmoud-Emad Date: Tue, 4 Nov 2025 16:49:00 +0200 Subject: [PATCH] feat: Add Docusaurus dev server integration - Add 'dev' flag to run Docusaurus server - Import docusaurus library - Enable scan and export if 'dev' flag is set - Handle export errors more gracefully - Start Docusaurus dev server after export --- lib/core/herocmds/atlas.v | 50 +++++++++++++++++++++++++++++++++++++-- lib/data/atlas/export.v | 4 +--- lib/data/atlas/play.v | 7 ++---- 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/lib/core/herocmds/atlas.v b/lib/core/herocmds/atlas.v index 86c3a7db..81b0b953 100644 --- a/lib/core/herocmds/atlas.v +++ b/lib/core/herocmds/atlas.v @@ -4,6 +4,7 @@ import incubaid.herolib.ui.console import incubaid.herolib.data.atlas import incubaid.herolib.core.playcmds import incubaid.herolib.develop.gittools +import incubaid.herolib.web.docusaurus import os import cli { Command, Flag } @@ -59,7 +60,6 @@ pub fn cmd_atlas(mut cmdroot Command) Command { flag: .string required: false name: 'destination' - abbrev: 'd' description: 'Export destination path.' }) @@ -71,6 +71,14 @@ pub fn cmd_atlas(mut cmdroot Command) Command { description: 'Scan directories for collections.' }) + cmd_run.add_flag(Flag{ + flag: .bool + required: false + name: 'dev' + abbrev: 'd' + description: 'Run development server after export.' + }) + cmd_run.add_flag(Flag{ flag: .bool required: false @@ -110,6 +118,7 @@ fn cmd_atlas_execute(cmd Command) ! { mut update := cmd.flags.get_bool('update') or { false } mut scan := cmd.flags.get_bool('scan') or { false } mut export := cmd.flags.get_bool('export') or { false } + mut dev := cmd.flags.get_bool('dev') or { false } // Include and redis default to true unless explicitly disabled mut no_include := cmd.flags.get_bool('no-include') or { false } @@ -138,9 +147,12 @@ fn cmd_atlas_execute(cmd Command) ! { console.print_header('Running Atlas for: ${atlas_path.path}') // Run HeroScript if exists + // Note: emptycheck is false because !!include actions in markdown files + // are processed internally by atlas during export, not through the playbook system playcmds.run( heroscript_path: atlas_path.path reset: false + emptycheck: false )! // Create or get atlas instance @@ -151,11 +163,18 @@ fn cmd_atlas_execute(cmd Command) ! { } // Default behavior: scan and export if no flags specified + // Also enable scan and export if dev is requested if !scan && !export { scan = true export = true } + // If dev server is requested, ensure we scan and export first + if dev { + scan = true + export = true + } + // Execute operations if scan { console.print_header('Scanning collections...') @@ -172,12 +191,13 @@ fn cmd_atlas_execute(cmd Command) ! { console.print_item('Include processing: ${include}') console.print_item('Redis metadata: ${redis}') + // Export even if there are errors - we want to export what we can a.export( destination: destination reset: reset include: include redis: redis - )! + ) or { console.print_item('Export completed with errors: ${err}') } console.print_green('✓ Export complete to ${destination}') @@ -188,4 +208,30 @@ fn cmd_atlas_execute(cmd Command) ! { } } } + + // Run development server if requested - always run even if there were export errors + if dev { + if destination == '' { + return error('Cannot run dev server: no destination specified. Use -destination flag.') + } + + console.print_header('Starting Docusaurus development server') + console.print_item('Atlas content exported to: ${destination}') + + // Get the docusaurus site that was configured via heroscript + // The heroscript should have been processed by playcmds.run() above + mut dsite := docusaurus.dsite_get('') or { + console.print_item('Warning: No Docusaurus site configured') + console.print_item('Make sure your atlas source directory contains a heroscript file with Docusaurus configuration') + return error('Cannot start dev server: ${err}') + } + + // Run the docusaurus dev server - this will block until Ctrl+C + dsite.dev( + host: 'localhost' + port: 3000 + open: true + watch_changes: false + )! + } } diff --git a/lib/data/atlas/export.v b/lib/data/atlas/export.v index c4356462..f9125395 100644 --- a/lib/data/atlas/export.v +++ b/lib/data/atlas/export.v @@ -65,7 +65,7 @@ pub fn (mut c Collection) export(args CollectionExportArgs) ! { path: '${dir_meta.path}/${c.name}.json' create: true )! - json_file.write(meta)! + json_file.write(meta)! for _, mut page in c.pages { content := page.content(include: args.include)! @@ -82,8 +82,6 @@ pub fn (mut c Collection) export(args CollectionExportArgs) ! { mut redis := context.redis()! redis.hset('atlas:${c.name}', page.name, page.path)! } - - } // // Export files diff --git a/lib/data/atlas/play.v b/lib/data/atlas/play.v index b672ebdc..d925ccee 100644 --- a/lib/data/atlas/play.v +++ b/lib/data/atlas/play.v @@ -12,7 +12,7 @@ pub fn play(mut plbook PlayBook) ! { mut atlases := map[string]&Atlas{} - mut name := "" + mut name := '' // Process scan actions - scan directories for collections mut scan_actions := plbook.find(filter: 'atlas.scan')! @@ -52,13 +52,10 @@ pub fn play(mut plbook PlayBook) ! { mut atlas_instance_post := atlases[name] or { return error("Atlas '${name}' not found. Use !!atlas.scan first.") - } + } - atlas_instance_post.init_post()! - println(atlas_instance_post) - // Process export actions - export collections to destination mut export_actions := plbook.find(filter: 'atlas.export')!