@@ -55,19 +55,32 @@ func NewSketch(ctx context.Context, req *rpc.NewSketchRequest) (*rpc.NewSketchRe
5555 return nil , err
5656 }
5757
58+ templateDir := configuration .Settings .GetString ("directories.template" )
5859 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 }
6783 }
68- }
69- if err := sketchMainFilePath .WriteFile (emptySketch ); err != nil {
70- return nil , & arduino.CantCreateSketchError {Cause : err }
7184 }
7285
7386 return & rpc.NewSketchResponse {MainFile : sketchMainFilePath .String ()}, nil
0 commit comments