@@ -2,23 +2,84 @@ import { Controller } from "./Controller"
2
2
import { AtomicCommand , Subsystem } from "./Command"
3
3
import { v4 as uuidV4 } from "uuid"
4
4
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
+ }
5
17
6
18
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 [ ]
11
24
} ;
12
25
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
+
13
61
export const makeNewProject = ( ) : Project => {
14
- return {
62
+ const project : Project = {
15
63
name : "New Project" ,
16
64
controllers : [
17
65
{ name : "New Controller" , uuid : uuidV4 ( ) , type : "ps5" , className : "CommandPS5Controller" , fqn : "" , port : 1 , buttons : [ ] } ,
18
66
] ,
19
67
subsystems : [ ] ,
20
68
commands : [ ] ,
69
+ generatedFiles : makeDefaultGeneratedFiles ( ) ,
21
70
}
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
22
83
}
23
84
24
85
export function findCommand ( project : Project , commandOrId : AtomicCommand | IR . Group | string ) : AtomicCommand | IR . Group | null {
0 commit comments