Skip to content

Commit 63ece11

Browse files
authored
Add a tree view to navigate the generated file structure (#29)
Now regenerate Robot.java when subsystems and controllers change (instead of only when visiting the "Robot" tab)
1 parent 948c351 commit 63ece11

File tree

13 files changed

+596
-29
lines changed

13 files changed

+596
-29
lines changed

package-lock.json

Lines changed: 67 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"@mui/icons-material": "^5.11.11",
1010
"@mui/lab": "^5.0.0-alpha.121",
1111
"@mui/material": "^5.11.11",
12+
"@mui/x-tree-view": "^7.18.0",
1213
"@stylistic/eslint-plugin-plus": "^2.8.0",
1314
"@testing-library/jest-dom": "^5.16.5",
1415
"@testing-library/react": "^13.4.0",
@@ -20,6 +21,7 @@
2021
"prop-types": "^15.8.1",
2122
"react": "^18.2.0",
2223
"react-dom": "^18.2.0",
24+
"react-resizable-panels": "^2.1.3",
2325
"react-resize-detector": "^8.0.4",
2426
"react-svg": "^16.1.5",
2527
"react-syntax-highlighter": "^15.5.0",

src/App.scss

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,15 @@ html, body {
3737

3838
&.Mui-selected {
3939
color: white;
40-
border-color: white;
40+
border-top: white solid 2px;
41+
border-bottom: white solid 2px;
4142
}
4243
}
4344

45+
.MuiTabs-indicator {
46+
background-color: white;
47+
}
48+
4449
.project-name-input {
4550
margin-bottom: 5px;
4651
margin-left: 12px;
@@ -675,3 +680,8 @@ div.gutter {
675680
}
676681
}
677682
}
683+
684+
.code-panel-divider {
685+
width: 0.125em;
686+
background: #ccc;
687+
}

src/bindings/Project.ts

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,84 @@ import { Controller } from "./Controller"
22
import { AtomicCommand, Subsystem } from "./Command"
33
import { v4 as uuidV4 } from "uuid"
44
import * as IR from "../bindings/ir"
5+
import { BundledMain } from "../bundled_files/Main.java"
6+
import { BundledGitignore } from "../bundled_files/.gitignore"
7+
import { generateRobotClass } from "../codegen/java/RobotGenerator"
8+
import { BundledGradleBuild } from "../bundled_files/build.gradle"
9+
import { generateReadme } from "../bundled_files/README.md"
10+
11+
export type GeneratedFile = {
12+
name: string
13+
description: string
14+
contents?: string
15+
hidden?: boolean
16+
}
517

618
export type Project = {
7-
name: string;
8-
controllers: Controller[];
9-
subsystems: Subsystem[];
10-
commands: IR.Group[];
19+
name: string
20+
controllers: Controller[]
21+
subsystems: Subsystem[]
22+
commands: IR.Group[]
23+
generatedFiles: GeneratedFile[]
1124
};
1225

26+
const makeDefaultGeneratedFiles = (): GeneratedFile[] => {
27+
return [
28+
{
29+
name: ".gitignore",
30+
description: "",
31+
contents: BundledGitignore,
32+
},
33+
{
34+
name: "build.gradle",
35+
description: "The build file that controls how the program is compiled and deployed",
36+
contents: BundledGradleBuild,
37+
},
38+
{
39+
name: "README.md",
40+
description: "A readme file that gives some overview of the project",
41+
contents: `<!-- TODO: README.md template -->`,
42+
},
43+
{
44+
name: "src/main/java/frc/robot/subsystems/.gitkeep",
45+
description: "",
46+
hidden: true,
47+
},
48+
{
49+
name: "src/main/java/frc/robot/Main.java",
50+
description: "The Java main class used to start the program. Do not edit this file.",
51+
contents: BundledMain,
52+
},
53+
{
54+
name: "src/main/java/frc/robot/Robot.java",
55+
description: "The main robot class",
56+
contents: null,
57+
},
58+
]
59+
}
60+
1361
export const makeNewProject = (): Project => {
14-
return {
62+
const project: Project = {
1563
name: "New Project",
1664
controllers: [
1765
{ name: "New Controller", uuid: uuidV4(), type: "ps5", className: "CommandPS5Controller", fqn: "", port: 1 , buttons: [] },
1866
],
1967
subsystems: [],
2068
commands: [],
69+
generatedFiles: makeDefaultGeneratedFiles(),
2170
}
71+
72+
// Update the robot class contents
73+
project.generatedFiles.find(f => f.name === "src/main/java/frc/robot/Robot.java").contents = generateRobotClass(project)
74+
75+
// Update the readme
76+
project.generatedFiles.find(f => f.name === "README.md").contents = generateReadme(project)
77+
78+
return project
79+
}
80+
81+
export function updateFile(project: Project, path: string, contents: string): void {
82+
project.generatedFiles.find(f => f.name === path).contents = contents
2283
}
2384

2485
export function findCommand(project: Project, commandOrId: AtomicCommand | IR.Group | string): AtomicCommand | IR.Group | null {

0 commit comments

Comments
 (0)