Skip to content

Commit

Permalink
Add a tree view to navigate the generated file structure (#29)
Browse files Browse the repository at this point in the history
Now regenerate Robot.java when subsystems and controllers change (instead of only when visiting the "Robot" tab)
  • Loading branch information
SamCarlberg authored Sep 26, 2024
1 parent 948c351 commit 63ece11
Show file tree
Hide file tree
Showing 13 changed files with 596 additions and 29 deletions.
67 changes: 67 additions & 0 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"@mui/icons-material": "^5.11.11",
"@mui/lab": "^5.0.0-alpha.121",
"@mui/material": "^5.11.11",
"@mui/x-tree-view": "^7.18.0",
"@stylistic/eslint-plugin-plus": "^2.8.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
Expand All @@ -20,6 +21,7 @@
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-resizable-panels": "^2.1.3",
"react-resize-detector": "^8.0.4",
"react-svg": "^16.1.5",
"react-syntax-highlighter": "^15.5.0",
Expand Down
12 changes: 11 additions & 1 deletion src/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ html, body {

&.Mui-selected {
color: white;
border-color: white;
border-top: white solid 2px;
border-bottom: white solid 2px;
}
}

.MuiTabs-indicator {
background-color: white;
}

.project-name-input {
margin-bottom: 5px;
margin-left: 12px;
Expand Down Expand Up @@ -675,3 +680,8 @@ div.gutter {
}
}
}

.code-panel-divider {
width: 0.125em;
background: #ccc;
}
71 changes: 66 additions & 5 deletions src/bindings/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,84 @@ import { Controller } from "./Controller"
import { AtomicCommand, Subsystem } from "./Command"
import { v4 as uuidV4 } from "uuid"
import * as IR from "../bindings/ir"
import { BundledMain } from "../bundled_files/Main.java"
import { BundledGitignore } from "../bundled_files/.gitignore"
import { generateRobotClass } from "../codegen/java/RobotGenerator"
import { BundledGradleBuild } from "../bundled_files/build.gradle"
import { generateReadme } from "../bundled_files/README.md"

export type GeneratedFile = {
name: string
description: string
contents?: string
hidden?: boolean
}

export type Project = {
name: string;
controllers: Controller[];
subsystems: Subsystem[];
commands: IR.Group[];
name: string
controllers: Controller[]
subsystems: Subsystem[]
commands: IR.Group[]
generatedFiles: GeneratedFile[]
};

const makeDefaultGeneratedFiles = (): GeneratedFile[] => {
return [
{
name: ".gitignore",
description: "",
contents: BundledGitignore,
},
{
name: "build.gradle",
description: "The build file that controls how the program is compiled and deployed",
contents: BundledGradleBuild,
},
{
name: "README.md",
description: "A readme file that gives some overview of the project",
contents: `<!-- TODO: README.md template -->`,
},
{
name: "src/main/java/frc/robot/subsystems/.gitkeep",
description: "",
hidden: true,
},
{
name: "src/main/java/frc/robot/Main.java",
description: "The Java main class used to start the program. Do not edit this file.",
contents: BundledMain,
},
{
name: "src/main/java/frc/robot/Robot.java",
description: "The main robot class",
contents: null,
},
]
}

export const makeNewProject = (): Project => {
return {
const project: Project = {
name: "New Project",
controllers: [
{ name: "New Controller", uuid: uuidV4(), type: "ps5", className: "CommandPS5Controller", fqn: "", port: 1 , buttons: [] },
],
subsystems: [],
commands: [],
generatedFiles: makeDefaultGeneratedFiles(),
}

// Update the robot class contents
project.generatedFiles.find(f => f.name === "src/main/java/frc/robot/Robot.java").contents = generateRobotClass(project)

// Update the readme
project.generatedFiles.find(f => f.name === "README.md").contents = generateReadme(project)

return project
}

export function updateFile(project: Project, path: string, contents: string): void {
project.generatedFiles.find(f => f.name === path).contents = contents
}

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

0 comments on commit 63ece11

Please sign in to comment.