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

Scaffold init #1129

Merged
merged 8 commits into from
Mar 24, 2020
Merged

Scaffold init #1129

merged 8 commits into from
Mar 24, 2020

Conversation

fortmarek
Copy link
Member

Short description πŸ“

This PR does not bring any new user-facing features, but it should make it super easy to add tuist built-in templates. That way you will be soon able to call tuist scaffold --template swiftui and it will generate a SwiftUI-compatible project instead of using UIKit as it does now. This is made possible by scaffold command merged here.

Solution πŸ“¦

Tuist templates are defined in Templates. This directory then gets copied to ~/.tuist/Versions/version/Templates. When locating available templates, tuist will scan both user and tuist templates. When running tuist init, it will default to template called default, if the user provides --template option, it will try to use that.

Implementation πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

  • Define default Template
  • Run TemplateGenerator in InitCommand
  • Add tests

Questions ❓

To get the command running when running this tool via swift run or in Xcode, I had to make this ugly hack - the reason is that it is not possible to copy files to the build directory that are not libraries/executables. If you can think of a better solution, I'd love to hear it.

Another question is if there is a way how to test the whole flow of bundling the templates directory and then copying it?

@fortmarek fortmarek self-assigned this Mar 22, 2020
Rakefile Outdated
@@ -101,7 +101,8 @@ def package
system(
"zip", "-q", "-r", "--symlinks",
"tuist.zip", "tuist",
"ProjectDescription.swiftmodule", "ProjectDescription.swiftdoc", "libProjectDescription.dylib", "ProjectDescription.swiftinterface"
"ProjectDescription.swiftmodule", "ProjectDescription.swiftdoc", "libProjectDescription.dylib", "ProjectDescription.swiftinterface",
File.expand_path("Templates", __dir__)
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you double-check that the zipped directory copies its content recursively?

Copy link
Member Author

Choose a reason for hiding this comment

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

It did, but it was nested deeply in the expanded path, I have modified the copy method to fix it.

@@ -21,16 +23,38 @@ public final class TemplatesDirectoryLocator: TemplatesDirectoryLocating {

// MARK: - TemplatesDirectoryLocating

public func locateTuistTemplates() -> AbsolutePath? {
#if DEBUG
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's an ok hack because we are using the #DEBUG macro. I'd add a comment indicating what path bundlePath points to:

Copy link
Member Author

Choose a reason for hiding this comment

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

good point, added πŸ‘

Copy link
Contributor

@pepicrft pepicrft left a comment

Choose a reason for hiding this comment

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

@fortmarek when I use scaffold --list I get the following as an output:

default: Default template

What about adding a couple of improvements:

  • Make it grep parseable and presenting it as a table.
  • Add support for returning the list as a JSON.

@fortmarek
Copy link
Member Author

That's a good idea @pepibumur , I think it'd make sense to change --list and modify it, so it is a subcommand. Instead of running tuist scaffold --list, you'd run tuist scaffold list which seems a little bit better to me.

Would you mind if I did the recommended changes in a follow-up PR?

@fortmarek fortmarek merged commit 2d307f2 into master Mar 24, 2020
This was referenced Mar 24, 2020
@natanrolnik natanrolnik deleted the scaffold_init branch June 17, 2020 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants