ash-project / ash-project/igniter
Proposal: adding `Igniter.copy`
- Dominant language
- Elixir
- Stars
- 404
- Forks
- 75
- Avg merge
- 9h 58m
- Merged PRs (30d)
- 3
Description
**Describe the solution you'd like**
`Igniter.copy` to copy file(s) or directories recursively.
**Describe alternatives you've considered**
I currently have this in a helper module used by my tasks, but thought it may make sense for it to be supported upstream:
```elixir
def igniter_copy(igniter, source, target, opts \\ [])
def igniter_copy(igniter, sources, target, opts) when is_list(sources) do
IO.puts("Batch copying #{inspect sources} to #{target}")
Enum.reduce(sources, igniter, fn source, igniter ->
igniter_copy(igniter, source, prepare_target_path(source, target), opts)
end)
end
def igniter_copy(igniter, source, target, opts) do
IO.puts("Copying #{source} to #{target}")
if File.dir?(source) do
sources = File.ls!(source)
|> Enum.map(fn file -> Path.join(source, file) end)
igniter_copy(igniter, sources, target, opts)
else
contents_to_copy = File.read!(source)
Igniter.create_or_update_file(igniter, target, contents_to_copy, fn source ->
Rewrite.Source.update(source, :content, contents_to_copy)
end)
end
end
defp prepare_target_path(source, target) do
# Remove the repeated part of source from target
if String.contains?(target, source) do
String.replace(target, source, "")
|> String.trim_leading("/")
|> (&Path.join(target, &1)).()
else
Path.join(target, Path.basename(source))
end
end
```
Contributor guide
Research direction
Start by locating Igniter.create_or_update_file and the existing Igniter file-operation APIs; the issue provides a helper implementation for the intended behavior. Verify that the new operation handles individual files, recursive directories, lists of sources, and target-path construction, with coverage for those cases when the repository's test location is identified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- elixir
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100