citty-test-utils
Version:
A comprehensive testing framework for CLI applications built with Citty, featuring Docker cleanroom support, fluent assertions, advanced scenario DSL, and noun-verb CLI structure with template generation.
157 lines (131 loc) âĸ 4.05 kB
JavaScript
/**
* @fileoverview PlantUML Diagram Generator for CTU Analysis Verbs Architecture
* @description Generates all innovative architecture diagrams from PlantUML source files
*/
import { execSync } from 'child_process'
import { existsSync, readdirSync, statSync } from 'fs'
import { join, basename, extname } from 'path'
const ARCHITECTURE_DIR = 'docs/architecture'
const OUTPUT_DIR = 'docs/architecture/generated'
/**
* Check if PlantUML is installed
* @returns {boolean} True if PlantUML is available
*/
function checkPlantUML() {
try {
execSync('plantuml -version', { stdio: 'pipe' })
return true
} catch (error) {
return false
}
}
/**
* Install PlantUML via npm
*/
function installPlantUML() {
console.log('đĻ Installing PlantUML...')
try {
execSync('npm install -g plantuml', { stdio: 'inherit' })
console.log('â
PlantUML installed successfully')
return true
} catch (error) {
console.error('â Failed to install PlantUML:', error.message)
return false
}
}
/**
* Generate diagrams from PlantUML source files
* @param {string} format - Output format (png, svg, pdf)
*/
function generateDiagrams(format = 'png') {
if (!existsSync(ARCHITECTURE_DIR)) {
console.error(`â Architecture directory not found: ${ARCHITECTURE_DIR}`)
return
}
const pumlFiles = readdirSync(ARCHITECTURE_DIR)
.filter((file) => extname(file) === '.puml')
.map((file) => join(ARCHITECTURE_DIR, file))
if (pumlFiles.length === 0) {
console.log('âšī¸ No PlantUML files found')
return
}
console.log(`đ Generating ${format.toUpperCase()} diagrams from ${pumlFiles.length} files...`)
// Create output directory
if (!existsSync(OUTPUT_DIR)) {
execSync(`mkdir -p ${OUTPUT_DIR}`, { stdio: 'pipe' })
}
for (const pumlFile of pumlFiles) {
const fileName = basename(pumlFile, '.puml')
const outputFile = join(OUTPUT_DIR, `${fileName}.${format}`)
try {
console.log(`đ Generating: ${fileName}.${format}`)
execSync(`plantuml -t${format} -o ${OUTPUT_DIR} ${pumlFile}`, { stdio: 'pipe' })
console.log(`â
Generated: ${outputFile}`)
} catch (error) {
console.error(`â Failed to generate ${fileName}:`, error.message)
}
}
console.log(`đ Diagram generation complete! Check ${OUTPUT_DIR}/`)
}
/**
* List available PlantUML files
*/
function listDiagrams() {
if (!existsSync(ARCHITECTURE_DIR)) {
console.log('â Architecture directory not found')
return
}
const pumlFiles = readdirSync(ARCHITECTURE_DIR)
.filter((file) => extname(file) === '.puml')
.map((file) => basename(file, '.puml'))
if (pumlFiles.length === 0) {
console.log('âšī¸ No PlantUML files found')
return
}
console.log('đ Available PlantUML Diagrams:')
pumlFiles.forEach((file, index) => {
console.log(` ${index + 1}. ${file}`)
})
}
/**
* Main function
*/
function main() {
const args = process.argv.slice(2)
const command = args[0] || 'generate'
const format = args[1] || 'png'
console.log('đ CTU Analysis Verbs - Innovative Architecture Diagram Generator')
console.log('='.repeat(60))
switch (command) {
case 'list':
listDiagrams()
break
case 'install':
if (checkPlantUML()) {
console.log('â
PlantUML is already installed')
} else {
installPlantUML()
}
break
case 'generate':
default:
if (!checkPlantUML()) {
console.log('â PlantUML not found. Please install it first:')
console.log(' npm install -g plantuml')
console.log(' or run: node generate-diagrams.mjs install')
return
}
if (!['png', 'svg', 'pdf'].includes(format)) {
console.error('â Invalid format. Use: png, svg, or pdf')
return
}
generateDiagrams(format)
break
}
}
// Run if called directly
if (import.meta.url === `file://${process.argv[1]}`) {
main()
}
export { checkPlantUML, generateDiagrams, listDiagrams }