-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for automatically gitignoring generated files
Add a light `gitignore` abstraction allowing to define a set of gitignore patterns from Nickel, and plug that in to the file generation interface so that a generated file can also be git ignored by simply setting `files.foo.gitignore = true`
- Loading branch information
Théophane Hufschmitt
committed
Oct 17, 2023
1 parent
98b4641
commit 2b7ebe9
Showing
4 changed files
with
73 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
########## | ||
# This file is autogenerated by Organist, don't edit | ||
########## | ||
.editorconfig | ||
/examples/*/result | ||
/result | ||
/result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# let nix = import "./nix-interop/nix.ncl" in | ||
let filegen = import "./files.ncl" in | ||
let Gitignorable = { | ||
gitignore | ||
: Bool | ||
| doc "Whether to gitignore the file" | ||
| default | ||
= false, | ||
.. | ||
} | ||
in | ||
let header : String = m%" | ||
########## | ||
# This file is autogenerated by Organist, don't edit | ||
########## | ||
|
||
"% | ||
in | ||
let ignored_files | { _ : Gitignorable } -> { _ : Bool } = fun files => | ||
files | ||
|> std.record.to_array | ||
|> std.array.filter (fun { value = { gitignore, .. }, .. } => gitignore) | ||
|> std.array.map (fun { value = { target, .. }, .. } => { field = target, value = true }) | ||
|> std.record.from_array | ||
in | ||
let gitignore_content | { _ : Bool } -> String = fun ignores => | ||
ignores | ||
|> std.record.map | ||
( | ||
fun pattern is_ignored => | ||
"%{if is_ignored then "" else "!"}%{pattern}" | ||
) | ||
|> std.record.values | ||
|> std.string.join "\n" | ||
|> (fun c => header ++ c ++ "\n") | ||
in | ||
{ | ||
Schema = | ||
filegen.Schema | ||
& { | ||
|
||
files | filegen.Files, | ||
files | { _ : Gitignorable }, | ||
|
||
git.ignore | ||
| { _ : Bool } | ||
= ignored_files files, | ||
|
||
files.".gitignore".materialisation_method = 'Copy, | ||
files.".gitignore".content = gitignore_content git.ignore, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters