Skip to content

Commit

Permalink
allow one to skip_files with a list of regex (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
the-mikedavis authored Feb 17, 2021
1 parent 571bf9b commit 9c22c90
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ The format is based on [Keep a
Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.3.0 - 2021-02-17

### Added

- Added a `:skip_files` key to the configuration of a manifest, allowing one
to provide a list of regex which will be checked against while sourcing files.
Any files found to match any of the regex will be excluded from generation.
- this allows a service author to 'take the reins' for that file

## 0.2.9 - 2020-11-02

### Fixed
Expand Down
6 changes: 5 additions & 1 deletion lib/harness/manifest.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ defmodule Harness.Manifest do
"manifest version is not compatible with the installed harness " <>
"archive. Please update the manifest or the harness archive."

defstruct generators: [], pkg_config: [], deps: [], manifest_version: nil
defstruct generators: [],
pkg_config: [],
deps: [],
skip_files: [],
manifest_version: nil

@doc false
def version, do: "~> 2.0"
Expand Down
1 change: 1 addition & 0 deletions lib/harness/renderer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ defmodule Harness.Renderer do
|> Enum.map(&Run.source(&1, manifest.pkg_config, path))
|> Enum.map(&Run.source_files/1)
|> Enum.map(&Run.expand_paths/1)
|> Enum.map(&Run.skip_files(&1, manifest.skip_files))
|> Enum.each(&render/1)
end

Expand Down
10 changes: 10 additions & 0 deletions lib/harness/renderer/run.ex
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ defmodule Harness.Renderer.Run do
%{run | files: expanded_files}
end

def skip_files(%__MODULE__{} = run, patterns) do
files =
run.files
|> Enum.reject(fn file ->
Enum.any?(patterns, &Regex.match?(&1, file.output_path))
end)

%{run | files: files}
end

defp substitute_vars(path, flat_config) do
Enum.reduce(flat_config, path, fn {config_key, config_val}, acc ->
if String.contains?(path, "$#{config_key}$") do
Expand Down

0 comments on commit 9c22c90

Please sign in to comment.