loreanvictor / tmplr

Automate Code Scaffolding
MIT License
26 stars 0 forks source link

Copy all files in a directory #6

Closed tommy-mitchell closed 1 year ago

tommy-mitchell commented 1 year ago

Similar to #1, is there a way to copy all files from one directory to another? Specifically, if all of my template files are in [ROOT]/template, is there a way to copy them into the root directory?

Related, does the remove command also remove directories?

loreanvictor commented 1 year ago

not atm. remove can be easily updated to work like update (i.e. handling glob patterns). as for copy, it would require some further thought: it could either work with glob patterns as well, which would require figuring out the destination address based on the pattern (perhaps the most intuitive would be to copy the last explicit folder in the source pattern, i.e. x/y/*.md -> z means x/y/t.md -> z/t.md), or it could just support copying folders outright, which would require further access to the underlying filesystem (right now the fs interface can't check whether a certain path is a folder or not, and can't copy folders or do recursive copies).

However, considering that both of these actions are relatively dangerous (imagine copying node_modules, for example), can you provide specific example use cases?

tommy-mitchell commented 1 year ago

I’d like to easily update and rename/move all template files. So either:

I think the latter could be safer if tmplr itself specifies that the "copy glob" style only works for a specific file naming scheme.

loreanvictor commented 1 year ago

Hmmm, ok so to remain consistent with how update works (and allow maximum flexibility), I feel enabling glob patterns on remove and copy would basically achieve this, providing a mechanism for the recipe author to ensure safety of the operation as well (like the example you provided). I would need to further investigate how copy would work with this in a way that doesn't become confusing, while also exploring further interactions (e.g. x/**/*.tmplr.js -> *.js).

loreanvictor commented 1 year ago

I'll create separate, subsequent issues for each. I think this issue should remain open until those are merged and shipped.