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
81 changes: 0 additions & 81 deletions src/commands/build.ts

This file was deleted.

100 changes: 11 additions & 89 deletions src/commands/buildgraph/run.ts
Original file line number Diff line number Diff line change
@@ -1,94 +1,13 @@
import { Command } from '@cliffy/command'
import * as path from '@std/path'
import { readNdjson } from 'ndjson'
import { Config } from '../../lib/config.ts'
import type { GlobalOptions } from '../../lib/types.ts'
import { createEngine } from '../../lib/engine.ts'
import { createProject } from '../../lib/project.ts'
import { writeMarkdownReport } from '../../lib/report.ts'
import { logger } from '../../lib/logger.ts'

export type RunOptions = typeof run extends Command<void, void, infer Options, infer Argument, GlobalOptions> ? Options
: never

interface AutomationToolLogs {
time: string
level: string
message: string
format: string
properties: Record<string, any>
id?: number
line?: number
lineCount?: number
}

async function getAutomationToolLogs(enginePath: string) {
const logJson = path.join(enginePath, 'Engine', 'Programs', 'AutomationTool', 'Saved', 'Logs', 'Log.json')
let logs: AutomationToolLogs[] = []
try {
logs = await readNdjson(logJson) as unknown as AutomationToolLogs[]
} catch (e) {
// pass
}
return logs
}

function generateMarkdownReport(logs: AutomationToolLogs[]): string {
const errorLogs = logs.filter(({ level }) => level === 'Error')
if (errorLogs.length === 0) {
return '# Build Report\n\nNo errors found.'
}

let markdown = '# Build Error Report\n\n'

// Group errors by id
const errorGroups = new Map<number | string, AutomationToolLogs[]>()

for (const log of errorLogs) {
const groupId = log.id !== undefined ? log.id : 'ungrouped'
if (!errorGroups.has(groupId)) {
errorGroups.set(groupId, [])
}
errorGroups.get(groupId)!.push(log)
}

markdown += `## Errors (${errorLogs.length})\n\n`

// Process each group of errors
for (const [groupId, groupLogs] of errorGroups) {
if (groupId !== 'ungrouped') {
markdown += `### Group ID: ${groupId} (${groupLogs.length} errors)\n\n`
} else {
markdown += `### Ungrouped Errors (${groupLogs.length} errors)\n\n`
}

for (const log of groupLogs) {
markdown += `#### Error: ${log.message}\n`

if (log.properties?.file) {
const file = log.properties.file.$text
const line = log.properties.line?.$text || log.line
markdown += `- **File**: ${file}${line ? `:${line}` : ''}\n`
}

if (log.properties?.code) {
markdown += `- **Code**: ${log.properties.code.$text}\n`
}

if (log.properties?.severity) {
markdown += `- **Severity**: ${log.properties.severity.$text}\n`
}

markdown += '\n'
}
}

return markdown
}

async function writeMarkdownReport(logs: AutomationToolLogs[], outputPath: string): Promise<void> {
const markdown = generateMarkdownReport(logs)
await Deno.writeTextFile(outputPath, markdown)
console.log(`[BUILDGRAPH RUN] Error report generated: ${outputPath}`)
}

export const run = new Command<GlobalOptions>()
.description('run buildgraph script')
.arguments('<buildGraphScript:file> <buildGraphArgs...>')
Expand All @@ -100,14 +19,17 @@ export const run = new Command<GlobalOptions>()
.stopEarly()
.action(async (options, buildGraphScript: string, ...buildGraphArgs: Array<string>) => {
const config = Config.getInstance()
const { engine: { path: enginePath } } = config.mergeConfigCLIConfig({ cliOptions: options })
const engine = createEngine(enginePath)
const { success, code } = await engine.runBuildGraph(buildGraphScript, buildGraphArgs)
const { engine: { path: enginePath }, project: { path: projectPath } } = config.mergeConfigCLIConfig({
cliOptions: options,
})

const project = await createProject(enginePath, projectPath)
const { success, code } = await project.runBuildGraph(buildGraphScript, buildGraphArgs)
if (!success) {
const logs = await getAutomationToolLogs(enginePath)
const logs = await project.engine.getAutomationToolLogs(enginePath)

for (const log of logs.filter(({ level }) => level === 'Error')) {
console.log(`[BUILDGRAPH RUN] ${log.message}`)
logger.info(`[BUILDGRAPH RUN] ${log.message}`)
}

if (options.buildgraphReportErrors) {
Expand Down
9 changes: 0 additions & 9 deletions src/commands/clean.ts

This file was deleted.

41 changes: 0 additions & 41 deletions src/commands/gen.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/commands/list-targets.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Command } from '@cliffy/command'
import { createProject } from '../lib/project.ts'
import { createEngine } from '../lib/engine.ts'
import type { GlobalOptions } from '../lib/types.ts'
import { Config } from '../lib/config.ts'
Expand Down Expand Up @@ -29,9 +30,8 @@ export const listTargets = new Command<GlobalOptions>()
let projectTargets: string[] = []

if (projectPath) {
projectTargets = (await engine.parseProjectTargets(projectPath)).filter((target) =>
!engineTargets.includes(target)
)
const project = await createProject(enginePath, projectPath)
projectTargets = (await project.parseProjectTargets()).filter((target) => !engineTargets.includes(target))
}

if (engineOnly) {
Expand Down
125 changes: 0 additions & 125 deletions src/commands/pkg.ts

This file was deleted.

Loading