Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
dist/
coverage/

# Generated reports
report/

# Dependencies
node_modules/

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Analyze source code and generate interactive dependency graphs",
"type": "module",
"bin": {
"codeviz": "./dist/cli.js"
"codeviz": "./dist/cli.cjs"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
24 changes: 17 additions & 7 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Command } from 'commander'
import { VERSION } from './index.js'
import { analyze } from './analyze.js'
import { renderToTerminal } from './renderer.js'
import { generateHtmlReport } from './html-report.js'

const program = new Command()

Expand All @@ -11,19 +12,28 @@ program
.description('Analyze source code and generate interactive dependency graphs')
.version(VERSION)
.argument('[directory]', 'source directory to analyze', '.')
.option('--html', 'generate an interactive HTML report (coming in Phase 2)')
.option('--html', 'generate an interactive HTML report in the report/ directory')
.option('--out-dir <dir>', 'output directory for the HTML report', 'report')
.option('--show-external', 'include external npm packages in the output')
.option('--ignore <dirs>', 'comma-separated list of directory names to ignore', '')
.action(async (directory: string, options: { html?: boolean; showExternal?: boolean; ignore?: string }) => {
if (options.html) {
console.warn('--html report generation is not yet implemented (Phase 2).')
}

.action(async (
directory: string,
options: { html?: boolean; outDir?: string; showExternal?: boolean; ignore?: string },
) => {
const ignore = options.ignore ? options.ignore.split(',').map((d) => d.trim()).filter(Boolean) : []

try {
const graph = await analyze(directory, { ignore })
renderToTerminal(graph, { showExternal: options.showExternal })

if (options.html) {
const { htmlFile, jsonFile } = await generateHtmlReport(graph, { outDir: options.outDir })
console.log(`\n HTML report generated:`)
console.log(` ${htmlFile}`)
console.log(` ${jsonFile}`)
console.log(`\n Open in browser: file://${htmlFile}\n`)
} else {
renderToTerminal(graph, { showExternal: options.showExternal })
}
} catch (err) {
const message = err instanceof Error ? err.message : String(err)
console.error(`\nError: ${message}\n`)
Expand Down
Loading
Loading