Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable creating new sketches from a template directory #2359

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

gsingh93
Copy link

@gsingh93 gsingh93 commented Oct 8, 2023

Please check if the PR fulfills these requirements

See how to contribute

  • The PR has no duplicates (please search among the Pull Requests
    before creating one)
  • The PR follows
    our contributing guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • UPGRADING.md has been updated with a migration guide (for breaking changes)
  • configuration.schema.json updated 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 MySketch will create a MySketch/MySketch.ino file.

What is the new behavior?

If directories.template is not set, the behavior is the same as before.

If it is set, running arduino-cli sketch new MySketch will copy the directories.template directory to create the MySketch directory.

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 to MySketch.ino? Or just pick a .ino from the directory (ideally there's only one) and return that from the RPC call?

@per1234 per1234 added type: enhancement Proposed improvement topic: code Related to content of the project itself labels Oct 8, 2023
Copy link
Member

@cmaglie cmaglie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. A sketch may be composed of many files
  2. The main sketch file is the .ino file that is named exactly as the containing folder
  3. We should copy the entire "template" sketch folder into the new user-requested sketch folder
  4. 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.

commands/sketch/new.go Outdated Show resolved Hide resolved
commands/sketch/new.go Outdated Show resolved Hide resolved
@gsingh93
Copy link
Author

@cmaglie thanks for the feedback! I've addressed your comments and rebased. If the template directory is /path/to/template, it's now required that /path/to/template.ino exists, and it will be renamed to the actual main sketch file.

If this general approach looks correct to you, I'll start working on the tests/docs when I get some time.

@cmaglie
Copy link
Member

cmaglie commented Oct 23, 2023

Looks good, thanks, go on!

@umbynos umbynos linked an issue Nov 14, 2023 that may be closed by this pull request
3 tasks
@umbynos
Copy link
Contributor

umbynos commented Jan 23, 2024

Hello @gsingh93 did you had time to continue? 😄

@umbynos umbynos added the status: waiting for information More information must be provided before work can proceed label Jan 23, 2024
@gsingh93
Copy link
Author

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.

@umbynos umbynos removed the status: waiting for information More information must be provided before work can proceed label Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: code Related to content of the project itself type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow customizing the new sketch template
4 participants