#!/usr/bin/env -S v -n -w -cg -gc none -cc tcc -d use_openssl -enable-globals run import os abs_dir_of_script := dir(@FILE) // Format code println('Formatting code...') // v fmt returns: // - 0: all files already formatted (no changes) // - 5: files were formatted (changes made) - this is SUCCESS // - other: actual errors (syntax errors, file access issues, etc.) fmt_examples_result := os.system('v fmt -w ${abs_dir_of_script}/examples') if fmt_examples_result != 0 && fmt_examples_result != 5 { eprintln('Error: Failed to format examples (exit code: ${fmt_examples_result})') exit(1) } fmt_lib_result := os.system('v fmt -w ${abs_dir_of_script}/lib') if fmt_lib_result != 0 && fmt_lib_result != 5 { eprintln('Error: Failed to format herolib (exit code: ${fmt_lib_result})') exit(1) } println('✓ Code formatting completed') // Clean existing docs println('Cleaning existing documentation...') os.rmdir_all('_docs') or {} os.rmdir_all('docs') or {} os.rmdir_all('vdocs') or {} herolib_path := os.join_path(abs_dir_of_script, 'lib') os.chdir(herolib_path) or { panic('Failed to change directory to herolib: ${err}') } os.mkdir_all('_docs') or {} os.mkdir_all('docs') or {} os.mkdir_all('vdocs') or {} // Generate HTML documentation println('Generating HTML documentation...') if os.system('v doc -m -f html . -readme -comments -no-timestamp -o ../docs') != 0 { panic('Failed to generate HTML documentation') } if os.system('v doc -m -f md . -no-color -o ../vdocs/') != 0 { panic('Failed to generate Hero markdown documentation') } os.chdir(abs_dir_of_script) or { panic('Failed to change directory to abs_dir_of_script: ${err}') } // Generate Markdown documentation println('Generating Markdown documentation...') // if os.system('v doc -m -no-color -f md -o ../vdocs/v/') != 0 { // panic('Failed to generate V markdown documentation') // } // if os.system('v doc -m -no-color -f md . -o vdocs/') != 0 { // panic('Failed to generate Hero markdown documentation') // } // Open documentation in browser on non-Linux systems $if !linux { os.chdir(abs_dir_of_script) or { panic('Failed to change directory: ${err}') } if os.system('open docs/index.html') != 0 { eprintln('Warning: Failed to open documentation in browser') } } // Create Jekyll required files println('Creating Jekyll files...') os.mkdir_all('docs/assets/css') or {} // Create style.scss style_content := '---\n---\n\n@import "{{ site.theme }}";' os.write_file('docs/assets/css/style.scss', style_content) or { panic('Failed to create style.scss: ${err}') } // Create _config.yml config_content := 'title: HeroLib Documentation description: Documentation for the HeroLib project theme: jekyll-theme-primer baseurl: /herolib exclude: - Gemfile - Gemfile.lock - node_modules - vendor/bundle/ - vendor/cache/ - vendor/gems/ - vendor/ruby/' os.write_file('docs/_config.yml', config_content) or { panic('Failed to create _config.yml: ${err}') } println('Documentation generation completed successfully!')