Skip to content

Commit b282fbe

Browse files
committed
Added functions to load and save sketch project files
1 parent d12e330 commit b282fbe

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

Diff for: arduino/sketch/profiles.go

+6
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,9 @@ func LoadProjectFile(file *paths.Path) (*Project, error) {
262262
}
263263
return res, nil
264264
}
265+
266+
// SaveProjectFile save the sketch project to a file
267+
func (s *Sketch) SaveProjectFile() error {
268+
projectFile := s.GetProjectPath()
269+
return projectFile.WriteFile([]byte(s.Project.AsYaml()))
270+
}

Diff for: arduino/sketch/sketch.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,10 @@ func New(path *paths.Path) (*Sketch, error) {
101101
AdditionalFiles: paths.PathList{},
102102
RootFolderFiles: paths.PathList{},
103103
Metadata: new(Metadata),
104+
Project: &Project{},
104105
}
105106

106-
projectFile := path.Join("sketch.yaml")
107-
if !projectFile.Exist() {
108-
projectFile = path.Join("sketch.yml")
109-
}
110-
if projectFile.Exist() {
107+
if projectFile := sketch.GetProjectPath(); projectFile.Exist() {
111108
prj, err := LoadProjectFile(projectFile)
112109
if err != nil {
113110
return nil, fmt.Errorf("%s %w", tr("error loading sketch project file:"), err)
@@ -287,6 +284,18 @@ func (s *Sketch) checkSketchCasing() error {
287284
return nil
288285
}
289286

287+
// GetProjectPath returns the path to the sketch project file (sketch.yaml or sketch.yml)
288+
func (s *Sketch) GetProjectPath() *paths.Path {
289+
projectFile := s.FullPath.Join("sketch.yaml")
290+
if !projectFile.Exist() {
291+
alternateProjectFile := s.FullPath.Join("sketch.yml")
292+
if alternateProjectFile.Exist() {
293+
return alternateProjectFile
294+
}
295+
}
296+
return projectFile
297+
}
298+
290299
// InvalidSketchFolderNameError is returned when the sketch directory doesn't match the sketch name
291300
type InvalidSketchFolderNameError struct {
292301
SketchFolder *paths.Path

0 commit comments

Comments
 (0)