@@ -55,19 +55,32 @@ func NewSketch(ctx context.Context, req *rpc.NewSketchRequest) (*rpc.NewSketchRe
55
55
return nil , err
56
56
}
57
57
58
+ templateDir := configuration .Settings .GetString ("directories.template" )
58
59
sketchDirPath := paths .New (sketchesDir ).Join (req .SketchName )
59
- if err := sketchDirPath .MkdirAll (); err != nil {
60
- return nil , & arduino.CantCreateSketchError {Cause : err }
61
- }
62
- sketchName := sketchDirPath .Base ()
63
- sketchMainFilePath := sketchDirPath .Join (sketchName + globals .MainFileValidExtension )
64
- if ! req .Overwrite {
65
- if sketchMainFilePath .Exist () {
66
- return nil , & arduino.CantCreateSketchError {Cause : errors .New (tr (".ino file already exists" ))}
60
+
61
+ var sketchMainFilePath * paths.Path
62
+ if templateDir != "" {
63
+ templateDirPath := paths .New (templateDir )
64
+ if err := templateDirPath .CopyDirTo (sketchDirPath ); err != nil {
65
+ return nil , & arduino.CantCreateSketchError {Cause : err }
66
+ }
67
+ // TODO: Make this customizable?
68
+ sketchMainFilePath = sketchDirPath .Join ("main.ino" )
69
+ } else {
70
+ if err := sketchDirPath .MkdirAll (); err != nil {
71
+ return nil , & arduino.CantCreateSketchError {Cause : err }
72
+ }
73
+ sketchName := sketchDirPath .Base ()
74
+ sketchMainFilePath = sketchDirPath .Join (sketchName + globals .MainFileValidExtension )
75
+ if ! req .Overwrite {
76
+ if sketchMainFilePath .Exist () {
77
+ return nil , & arduino.CantCreateSketchError {Cause : errors .New (tr (".ino file already exists" ))}
78
+ }
79
+ }
80
+
81
+ if err := sketchMainFilePath .WriteFile (emptySketch ); err != nil {
82
+ return nil , & arduino.CantCreateSketchError {Cause : err }
67
83
}
68
- }
69
- if err := sketchMainFilePath .WriteFile (emptySketch ); err != nil {
70
- return nil , & arduino.CantCreateSketchError {Cause : err }
71
84
}
72
85
73
86
return & rpc.NewSketchResponse {MainFile : sketchMainFilePath .String ()}, nil
0 commit comments