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
Adding option .directory for scaffolding templates #2985
Conversation
@santi-d we should document these additions here as well |
β¦ort `.directory` option
Was modified the file commented and also modified unit test that refers to scaffolding. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for adding this improvement @santi-d. One more thing that it'd be great to add to this PR is extending this fixture to include a directory, and adding an extra step to the acceptance test that uses that feature, to ensure that the directory is copied as expected. This will prevent future regressions in your implementation. You can read more about acceptance tests here
@all-contributors add @santi-d for code |
@pepibumur I've put up a pull request to add @santi-d! π |
Co-authored-by: Daniele Formichelli <df@bendingspoons.com>
@pepibumur was modified fixture adding new template case with copy folder tree and acceptance testing was increased with this approach. thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good π€ just some minor comments π
/// - path: Path where will be copied the folder | ||
/// - sourcePath: Path of folder which will be copied | ||
/// - Returns: `Template.File` that is `.file` | ||
static func directory(path: String, sourcePath: Path) -> Template.File { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the naming of Template.File
does not really make sense anymore. Maybe Template.Item
? I am open to other suggestions as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you think is ok change also the signatures from files
to items
too (in all app)??
eg:
let template = Template(
description: "",
attributes: [
.required("name"),
.optional("aName", default: "defaultName"),
.optional("bName", default: ""),
],
items: [
.string(path: "static.swift", contents: "content"),
.file(path: "generated.swift", templatePath: "generate.swift"),
.directory(path: "destinationFolder", sourcePath: "sourceFolder"),
]
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, but I'd also keep the current init and mark it deprecated, so this does not end up a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added new init and the tag for deprecation.
@@ -54,4 +58,6 @@ Since platform is an optional argument, we can also call the command without the | |||
|
|||
If `.string` and `.files` don't provide enough flexibility, you can leverage the [Stencil](https://github.com/stencilproject/Stencil) templating language via the `.file` case. Besides that, you can also use additional filters defined [here](https://github.com/SwiftGen/StencilSwiftKit#filters) | |||
|
|||
Additionally is given `.directory` which gives the possibility to copy entire folders from one path inside another. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additionally is given `.directory` which gives the possibility to copy entire folders from one path inside another. | |
You can also use `.directory` which gives the possibility to copy entire folders to a given path. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed, thanks :)
...s_app_with_templates/Tuist/Templates/custom_using_copy_folder/custom_using_copy_folder.swift
Show resolved
Hide resolved
@@ -107,11 +107,19 @@ public final class TemplateGenerator: TemplateGenerating { | |||
} else { | |||
renderedContents = fileContents | |||
} | |||
case let .directory(path): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd test this in TemplateGeneratorTests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added and tested :)
@@ -107,11 +107,19 @@ public final class TemplateGenerator: TemplateGenerating { | |||
} else { | |||
renderedContents = fileContents | |||
} | |||
case let .directory(path): | |||
let destinationContainerPath = destinationPath.appending(components: [$0.path.pathString, path.basename]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rename destinationContainerPath
to destinationDirectoryPath
.
Also nit: you can leverage the variadic arguments for appending()
and rewrite .appending(components: [x, y])
to .appending(components: x, y)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, thanks
add @santi-d for code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for this contribution! LGTM once the pipeline is green β
Short description π
Checklist β
CHANGELOG.md
has been updated to reflect the changes. In case of a breaking change, it's been flagged as such.