11import { Command } from '@cliffy/command'
2- import * as path from '@std/path'
3- import { readNdjson } from 'ndjson'
42import { Config } from '../../lib/config.ts'
53import type { GlobalOptions } from '../../lib/types.ts'
6- import { createEngine } from '../../lib/engine.ts'
4+ import { createProject } from '../../lib/project.ts'
5+ import { writeMarkdownReport } from '../../lib/report.ts'
6+ import { logger } from '../../lib/logger.ts'
77
88export type RunOptions = typeof run extends Command < void , void , infer Options , infer Argument , GlobalOptions > ? Options
99 : never
1010
11- interface AutomationToolLogs {
12- time : string
13- level : string
14- message : string
15- format : string
16- properties : Record < string , any >
17- id ?: number
18- line ?: number
19- lineCount ?: number
20- }
21-
22- async function getAutomationToolLogs ( enginePath : string ) {
23- const logJson = path . join ( enginePath , 'Engine' , 'Programs' , 'AutomationTool' , 'Saved' , 'Logs' , 'Log.json' )
24- let logs : AutomationToolLogs [ ] = [ ]
25- try {
26- logs = await readNdjson ( logJson ) as unknown as AutomationToolLogs [ ]
27- } catch ( e ) {
28- // pass
29- }
30- return logs
31- }
32-
33- function generateMarkdownReport ( logs : AutomationToolLogs [ ] ) : string {
34- const errorLogs = logs . filter ( ( { level } ) => level === 'Error' )
35- if ( errorLogs . length === 0 ) {
36- return '# Build Report\n\nNo errors found.'
37- }
38-
39- let markdown = '# Build Error Report\n\n'
40-
41- // Group errors by id
42- const errorGroups = new Map < number | string , AutomationToolLogs [ ] > ( )
43-
44- for ( const log of errorLogs ) {
45- const groupId = log . id !== undefined ? log . id : 'ungrouped'
46- if ( ! errorGroups . has ( groupId ) ) {
47- errorGroups . set ( groupId , [ ] )
48- }
49- errorGroups . get ( groupId ) ! . push ( log )
50- }
51-
52- markdown += `## Errors (${ errorLogs . length } )\n\n`
53-
54- // Process each group of errors
55- for ( const [ groupId , groupLogs ] of errorGroups ) {
56- if ( groupId !== 'ungrouped' ) {
57- markdown += `### Group ID: ${ groupId } (${ groupLogs . length } errors)\n\n`
58- } else {
59- markdown += `### Ungrouped Errors (${ groupLogs . length } errors)\n\n`
60- }
61-
62- for ( const log of groupLogs ) {
63- markdown += `#### Error: ${ log . message } \n`
64-
65- if ( log . properties ?. file ) {
66- const file = log . properties . file . $text
67- const line = log . properties . line ?. $text || log . line
68- markdown += `- **File**: ${ file } ${ line ? `:${ line } ` : '' } \n`
69- }
70-
71- if ( log . properties ?. code ) {
72- markdown += `- **Code**: ${ log . properties . code . $text } \n`
73- }
74-
75- if ( log . properties ?. severity ) {
76- markdown += `- **Severity**: ${ log . properties . severity . $text } \n`
77- }
78-
79- markdown += '\n'
80- }
81- }
82-
83- return markdown
84- }
85-
86- async function writeMarkdownReport ( logs : AutomationToolLogs [ ] , outputPath : string ) : Promise < void > {
87- const markdown = generateMarkdownReport ( logs )
88- await Deno . writeTextFile ( outputPath , markdown )
89- console . log ( `[BUILDGRAPH RUN] Error report generated: ${ outputPath } ` )
90- }
91-
9211export const run = new Command < GlobalOptions > ( )
9312 . description ( 'run buildgraph script' )
9413 . arguments ( '<buildGraphScript:file> <buildGraphArgs...>' )
@@ -100,14 +19,17 @@ export const run = new Command<GlobalOptions>()
10019 . stopEarly ( )
10120 . action ( async ( options , buildGraphScript : string , ...buildGraphArgs : Array < string > ) => {
10221 const config = Config . getInstance ( )
103- const { engine : { path : enginePath } } = config . mergeConfigCLIConfig ( { cliOptions : options } )
104- const engine = createEngine ( enginePath )
105- const { success, code } = await engine . runBuildGraph ( buildGraphScript , buildGraphArgs )
22+ const { engine : { path : enginePath } , project : { path : projectPath } } = config . mergeConfigCLIConfig ( {
23+ cliOptions : options ,
24+ } )
25+
26+ const project = await createProject ( enginePath , projectPath )
27+ const { success, code } = await project . runBuildGraph ( buildGraphScript , buildGraphArgs )
10628 if ( ! success ) {
107- const logs = await getAutomationToolLogs ( enginePath )
29+ const logs = await project . engine . getAutomationToolLogs ( enginePath )
10830
10931 for ( const log of logs . filter ( ( { level } ) => level === 'Error' ) ) {
110- console . log ( `[BUILDGRAPH RUN] ${ log . message } ` )
32+ logger . info ( `[BUILDGRAPH RUN] ${ log . message } ` )
11133 }
11234
11335 if ( options . buildgraphReportErrors ) {
0 commit comments