-
-
Notifications
You must be signed in to change notification settings - Fork 511
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
Scaffold - tuist templating #813
Comments
Hey @fortmarek, first of all, thanks for coming up with such a detail proposal. Let me dump my thoughts on some of the points that you touch on:
Agree. In fact, I'd require users to include a description with their templates that we can show next to the identifier when listing them: The following templates are available for scaffolding:
identifier_a Use this template to create new projects that represent feature frameworks
identifier_b Use this template to create a watch application
That sounds a good idea!
Agree. We could bundle some templates with Tuist.
Would you then bundle those alongside the binaries and the project description framework?
I agree with the directory here. Inside that
I'd include a suite of acceptance tests that make sure that templates generate files that are valid. The experience of using generated code that does not work is very frustrating.
I wouldn't worry about this because we just have a
Scaffolding can have its own section in the documentation. We could explain why the feature is very useful to extend projects, how to use them, and some examples of templates that are vendored with Tuist.
We can start with
Rails uses |
I like the detailed proposal @fortmarek 👍 Something like this would be a great addition to Tuist. I wonder what the difference between Could the files currently generated via |
Thanks for the comments @kwridan and @pepibumur! I'll try to answer or expand on the points you have raised:
That sounds like a good idea, definitely something we should implement!
What kind of definition? As in
Agree!
Yep, probably better to wait for the use case to emerge before starting to implement it.
Implementation-wise I think it is very much possible to add it to So, as for the naming, I'd probably leave it with |
Agree with this one. Rails for instance uses |
Hey, I am trying to start work on this and I'd need some input. Is there a better solution to this that I am not thinking of - and if not, which of these solutions makes more sense to you? |
Hey @fortmarek, thanks for posting your concerns here. In regards to where the templates should be defined, I think they should be defined under the Then we have to decide for a format for the template. These are the 2 options that you mention:
The first one is clearly more flexible and if you enter a template directory you can see at a glance what's in it. What I'd do though is require every template to have a
Otherwise the command would fail. The format of the template model could be something along the lines of: // Template.swift
let template = Template(
attributes: [
.required("name", default: nil),
]
) This is just an idea, feel free to iterate until you find an API that is concise and readable. |
Thanks for the comment @pepibumur I definitely like the second option more and I have started to play with it, but I am still unsure how to actually then generate those files - as I have laid out in the previous comment, we can trigger a script that would be at the same place as // Template.swift
let template = Template(
attributes: [
.required("name", default: nil),
],
directories: ["MyDirectory", "\(.argument(for: "name"))Tests"],
files: [File(path: "MyDirectory/file.swift", contents: "Contents of this file")]
) where You can also easily declare all Am I missing some implementation hurdle? The only thing I can think of is that the arguments, as it stands, are limited to Strings - passing Bool would require some additional logic - but it might be possible. |
Couple of things that might be useful:
|
Thanks for the input! 🙂 As for the first point, you will be able to shared code using a similar pattern as project description helpers - right now I call it Ad 2) yes, something I definitely plan to implement, thanks for raising this up, I'll add it to the checklist in the pr |
I was going to say the same. Instead of having another type of helpers, I'd reuse func myTemplate(name: String, withUnitTests: Bool) -> Template {
// Initialize the template
} And then you can just do: // MyTemplateWithUnitTests.swift
import ProjectDescriptionHelpers
let template = myTemplate(name: "Bar", witUnitTests: true) That's the beauty of using Swift over YAML or JSON, that it enables this type of reusability by leveraging Swift modules. |
Right now I have Do you think it makes sense to merge |
I think so. The fewer of those, the easier it'll be to maintain them. In the end they expose models to describe things. Having them separated doesn't make that much difference for the user, but complicates the maintenance in our end. |
Already implemented |
Need/problem
Following up on swiftUI template PR from here, it makes sense to make something more generic, so adding such new templates is easy and can be read dynamic from one directory. It can also enable users to define their own templates, in addition to the basic ones offered by tuist.
Motivation
Improving upon projectDescription helpers, this is a logical next step to improve creating a new framework/project, etc. Not only can the users share the description throughout their project, users could with this feature share what the structure of a new component looks (i.e. pre-generated files, folders, you name it)
Detailed design
We will need to introduce a new command:
tuist scaffold name_of_template Name
This will create a new eg framework (depends on your template) of name
Name
.In addition to that, it will be useful to add
tuist scaffold list
, so users can immediately see what templates are available to them. These templates should be probably made available totuist init
, too, with added option such astuist init --template name_of_template
.Templates will be of two types, each type handled a bit differently - tuist templates and custom templates (but it should be possible to envoke both of these with the same
tuist scaffold
command)tuist scaffold
produces the same result for everyone in the team. For this reason, I think~/.tuist/Version/version_number/Templates/...
is an ideal place.ProjectDescriptionHelpers
in${PROJECT_FOLDER}/Tuist/Templates
. If there is a need to share these custom templates, we will need to think of how to port these easily to another project, or event make it possible to add custom system-wide templates - but we should focus on the core of this feature and leave this as a future possibility.As for the template files themselves, I'd like to keep them Swift-generated, but if they become more complicated, we should probably resort to Stencil that makes such a task much more manageable.
Drawbacks
Since this feature is optional, I think the current Tuist users should not be affected in any way. But it is something that we will need to maintain if eg there are breaking (or just deprecation) Swift changes - therefore, I'd try to keep our provided templates as simple as possible to make this task easier.
It will also make
.tuist
directory a little bit more complicated, but in my view it is worth it for this use case.Alternatives
I thought about keeping templates in the current project directory, but this approach makes the distinction between custom and tuist templates more clear. Also, changing local tuist version would mean changing the templates in the current dir, too, which would be a nightmare, so the current approach is much better.
How we teach this
As an extension of ProjectDescriptionHelpers, I think it can be incorporated into our documentation quite easy; it is something we should try to show off alongside each other to make a point of how easy it is to create a new feature, etc.
Unresolved questions
scaffold
name is the most memorable? Maybe something liketuist new framework Name
would read a little better? But on the other hand that could clash withtuist init
, but would love to know your thoughts.The text was updated successfully, but these errors were encountered: