Enable creating new sketches from a template directory#2359
Enable creating new sketches from a template directory#2359gsingh93 wants to merge 4 commits intoarduino:masterfrom
Conversation
cmaglie
left a comment
There was a problem hiding this comment.
One question how to handle setting sketchMainFilePath. Should we rename some file in the template directory to MySketch.ino? Or just pick a .ino from the directory (ideally there's only one) and return that from the RPC call?
mmmhh... It's a bit more convoluted than expected, we should consider these factors:
- A sketch may be composed of many files
- The main sketch file is the .ino file that is named exactly as the containing folder
- We should copy the entire "template" sketch folder into the new user-requested sketch folder
- In the new folder we must rename the template-main-sketch file to match the new folder name.
So let's recap with an example:
Suppose we configure the sketch template to point to /path/to/sketch/template, that has the following content:
/path/to/sketch/template/another_file.ino
/path/to/sketch/template/template.ino <--- MAIN FILE
/path/to/sketch/template/passwords.h
if we run arduino-cli sketch new mysketchbook/newsketch, the expected result is:
./mysketchbook/newsketch/another_file.ino
./mysketchbook/newsketch/newsketch.ino <--- MAIN FILE
./mysketchbook/newsketch/passwords.h
The most notable part here is that template.ino has been renamed newsketch.ino because it's the main file.
|
@cmaglie thanks for the feedback! I've addressed your comments and rebased. If the template directory is If this general approach looks correct to you, I'll start working on the tests/docs when I get some time. |
|
Looks good, thanks, go on! |
|
Hello @gsingh93 did you had time to continue? 😄 |
|
Sorry, I haven't had time to work on this in a while. Someone else can pick it up from here, or it could be closed for now and I'll reopen if I ever come back to it. Either way is fine. |
Please check if the PR fulfills these requirements
See how to contribute
before creating one)
our contributing guidelines
UPGRADING.mdhas been updated with a migration guide (for breaking changes)configuration.schema.jsonupdated if new parameters are added.What kind of change does this PR introduce?
Implements feature request in #2239, although instead of implementing a single "blueprint" file, allows for an entire template directory.
What is the current behavior?
Running
arduino-cli sketch new MySketchwill create aMySketch/MySketch.inofile.What is the new behavior?
If
directories.templateis not set, the behavior is the same as before.If it is set, running
arduino-cli sketch new MySketchwill copy thedirectories.templatedirectory to create theMySketchdirectory.Does this PR introduce a breaking change, and is titled accordingly?
This isn't a breaking change.
Other Information
Tests/docs haven't been written. Putting this up as a draft to get initial feedback before putting in more effort. One question how to handle setting
sketchMainFilePath. Should we rename some file in the template directory toMySketch.ino? Or just pick a .ino from the directory (ideally there's only one) and return that from the RPC call?