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 load #1092

Merged
merged 24 commits into from
Mar 21, 2020
Merged

Scaffold load #1092

merged 24 commits into from
Mar 21, 2020

Conversation

fortmarek
Copy link
Member

Short description πŸ“

Follow-up PR to models - note it will have to be merged first

This PR adds the functionality of defining custom templates in Tuist/Templates + loading the template and parsing it. Generation logic will be added in a follow-up PR.

Solution πŸ“¦

Custom templates are defined in Tuist/Templates in Template.swift. Model has already been defined in a previous PR. When running tuist scaffold template --name hello we need to find the template in custom templates directory and then dynamically add its parsed options (--name hello is not defined in ScaffoldCommand itself)

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

There are several things that needed to be added to make loading of templates work:

  • Add templates to ProjectEditor to be able to edit the templates conveniently in Xcode project
  • TemplatesLoader to be able to load the template manifest
  • Add custom parse to Command -> this enables every Command to inject additional logic before running parse. In ScaffoldCommand we leverage this to add options from template manifest and thus being able to run tuist scaffold template --name hello where --name hello is dynamically parsed
  • Find custom templates in TemplatesDirectoryLocator that leverages already implemented RootDirectoryLocator
  • Add tests

@codecov
Copy link

codecov bot commented Mar 15, 2020

Codecov Report

Merging #1092 into master will decrease coverage by 0.63%.
The diff coverage is 64.21%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #1092      +/-   ##
=========================================
- Coverage   75.14%   74.5%   -0.64%     
=========================================
  Files         257     262       +5     
  Lines       11934    9164    -2770     
=========================================
- Hits         8968    6828    -2140     
+ Misses       2966    2336     -630
Impacted Files Coverage Ξ”
...es/TuistLoader/Utils/HelpersDirectoryLocator.swift 100% <ΓΈ> (ΓΈ) ⬆️
Sources/TuistLoader/Models/GeneratorPaths.swift 95.83% <ΓΈ> (-1.23%) ⬇️
Sources/TuistKit/Commands/CommandRegistry.swift 2.73% <0%> (-0.84%) ⬇️
Sources/TuistLoader/Loaders/TemplateLoader.swift 0% <0%> (ΓΈ)
Sources/TuistSupport/Commands/Command.swift 0% <0%> (ΓΈ)
Sources/TuistLoader/Loaders/ManifestLoader.swift 86.17% <100%> (-2.36%) ⬇️
Sources/TuistLoader/Models/Manifest.swift 100% <100%> (ΓΈ) ⬆️
Sources/TuistSupport/Utils/FileHandler.swift 76.57% <100%> (+2.66%) ⬆️
Sources/TuistCore/Utils/RootDirectoryLocator.swift 100% <100%> (ΓΈ)
Sources/ProjectDescription/Template/Template.swift 92.98% <100%> (+1.2%) ⬆️
... and 267 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Ξ” = absolute <relative> (impact), ΓΈ = not affected, ? = missing data
Powered by Codecov. Last update fac7058...79867ad. Read the comment docs.

Package.swift Outdated Show resolved Hide resolved
Package.swift Outdated Show resolved Hide resolved
@fortmarek fortmarek changed the title Scaffold load WIP: Scaffold load Mar 16, 2020
@fortmarek fortmarek changed the title WIP: Scaffold load Scaffold load Mar 16, 2020
@fortmarek fortmarek requested a review from pepicrft March 18, 2020 09:31
@@ -75,7 +76,10 @@ public final class CommandRegistry {

// Normal command
} else {
let parsedArguments = try parse()
guard let parsedArguments = try parse() else {
parser.printUsage(on: stdoutStream)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a good idea. We should do the same with other commands. Not as part of this PR though.

Copy link
Member Author

@fortmarek fortmarek Mar 18, 2020

Choose a reason for hiding this comment

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

This change is necessitated by this PR. parse() now returns optional ArgumentParser.Result if this does not include a command name. I can probably change this implementation back to its original signature.

/// - parser: Default parser
/// - argumets: List of arguments that the user passed to the CLI
/// - Returns: Result of parsing the arguments that the user passed to the CLI.
func parse(with parser: ArgumentParser, arguments: [String]) throws -> ArgumentParser.Result
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it need to be part of the protocol?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, otherwise I'd need to rewrite this

@fortmarek
Copy link
Member Author

I have addressed your comments, thanks for the review @pepibumur! Next up is generating, will start to work on that now πŸ™‚

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.

Amazing job @fortmarek πŸ‘ πŸ‘ πŸ‘

@pepicrft pepicrft merged commit 912356a into master Mar 21, 2020
@pepicrft pepicrft deleted the scaffold_load branch March 21, 2020 08:23
@fortmarek fortmarek mentioned this pull request Mar 21, 2020
4 tasks
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