Skip to content

Commit 0e97f69

Browse files
feat: new editor and project commands (#66)
1 parent e6a5cdd commit 0e97f69

File tree

19 files changed

+733
-444
lines changed

19 files changed

+733
-444
lines changed

src/commands/build.ts

Lines changed: 0 additions & 81 deletions
This file was deleted.

src/commands/buildgraph/run.ts

Lines changed: 11 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,13 @@
11
import { Command } from '@cliffy/command'
2-
import * as path from '@std/path'
3-
import { readNdjson } from 'ndjson'
42
import { Config } from '../../lib/config.ts'
53
import 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

88
export 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-
9211
export 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) {

src/commands/clean.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/commands/gen.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/commands/list-targets.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Command } from '@cliffy/command'
2+
import { createProject } from '../lib/project.ts'
23
import { createEngine } from '../lib/engine.ts'
34
import type { GlobalOptions } from '../lib/types.ts'
45
import { Config } from '../lib/config.ts'
@@ -29,9 +30,8 @@ export const listTargets = new Command<GlobalOptions>()
2930
let projectTargets: string[] = []
3031

3132
if (projectPath) {
32-
projectTargets = (await engine.parseProjectTargets(projectPath)).filter((target) =>
33-
!engineTargets.includes(target)
34-
)
33+
const project = await createProject(enginePath, projectPath)
34+
projectTargets = (await project.parseProjectTargets()).filter((target) => !engineTargets.includes(target))
3535
}
3636

3737
if (engineOnly) {

src/commands/pkg.ts

Lines changed: 0 additions & 125 deletions
This file was deleted.

0 commit comments

Comments
 (0)