@@ 5,8 5,13 @@ const mem = std.mem;
pub const Options = struct {
target: []const u8 = "src/embed.zig",
dir: []const u8,
+ filter: ?fn ([]const u8) anyerror!bool = default_filter,
};
+fn default_filter(_: []const u8) !bool {
+ return true;
+}
+
pub fn writeZig(caller_allocator: *mem.Allocator, options: Options) !void {
var zig_source = try fs.cwd().createFile(options.target, .{});
defer zig_source.close();
@@ 30,8 35,14 @@ pub fn writeZig(caller_allocator: *mem.A
const entry = i.?;
if (entry.kind != .File) continue;
+ const path = try mem.dupe(allocator, u8, entry.path[options.dir.len + "/".len ..]);
+
+ if (options.filter) |filter| {
+ if (!try filter(path)) continue;
+ }
+
try entries.append(.{
- .path = try mem.dupe(allocator, u8, entry.path[options.dir.len + "/".len ..]),
+ .path = path,
.target_path = try fs.path.relative(allocator, target_dir, entry.path),
});
}