dev: ensure .git* files are standardized across subprojects
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
parent
e43695f8ff
commit
60220cbe4f
1 changed files with 27 additions and 5 deletions
|
|
@ -1,8 +1,11 @@
|
||||||
|
//! Ensures that standard files in subprojects, like LICENSE files, .gitattributes, etc.
|
||||||
|
//! are present and in-sync with the version in dev/template.
|
||||||
|
//!
|
||||||
//! Usage: zig run ./dev/ensure-standard-files.zig
|
//! Usage: zig run ./dev/ensure-standard-files.zig
|
||||||
|
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
|
|
||||||
const dirs = [_][]const u8{
|
const projects = [_][]const u8{
|
||||||
".",
|
".",
|
||||||
"basisu",
|
"basisu",
|
||||||
"ecs",
|
"ecs",
|
||||||
|
|
@ -16,13 +19,32 @@ const dirs = [_][]const u8{
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn main() !void {
|
pub fn main() !void {
|
||||||
inline for (dirs) |dir| {
|
inline for (projects) |project| {
|
||||||
copyFile("dev/template/LICENSE", dir ++ "/LICENSE");
|
copyFile("dev/template/LICENSE", project ++ "/LICENSE");
|
||||||
copyFile("dev/template/LICENSE-MIT", dir ++ "/LICENSE-MIT");
|
copyFile("dev/template/LICENSE-MIT", project ++ "/LICENSE-MIT");
|
||||||
copyFile("dev/template/LICENSE-APACHE", dir ++ "/LICENSE-APACHE");
|
copyFile("dev/template/LICENSE-APACHE", project ++ "/LICENSE-APACHE");
|
||||||
|
copyFile("dev/template/.gitattributes", project ++ "/.gitattributes");
|
||||||
|
copyFile("dev/template/.gitignore", project ++ "/.gitignore");
|
||||||
|
|
||||||
|
if (!std.mem.eql(u8, project, ".")) {
|
||||||
|
copyFile(
|
||||||
|
"dev/template/.github/pull_request_template.md",
|
||||||
|
project ++ "/.github/pull_request_template.md",
|
||||||
|
);
|
||||||
|
replaceInFile(project ++ "/.github/pull_request_template.md", "foobar", project);
|
||||||
|
}
|
||||||
|
copyFile("dev/template/.github/FUNDING.yml", project ++ "/.github/FUNDING.yml");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn copyFile(src_path: []const u8, dst_path: []const u8) void {
|
pub fn copyFile(src_path: []const u8, dst_path: []const u8) void {
|
||||||
|
std.fs.cwd().makePath(std.fs.path.dirname(dst_path).?) catch unreachable;
|
||||||
std.fs.cwd().copyFile(src_path, std.fs.cwd(), dst_path, .{}) catch unreachable;
|
std.fs.cwd().copyFile(src_path, std.fs.cwd(), dst_path, .{}) catch unreachable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn replaceInFile(file_path: []const u8, needle: []const u8, replacement: []const u8) void {
|
||||||
|
const allocator = std.heap.page_allocator;
|
||||||
|
const data = std.fs.cwd().readFileAlloc(allocator, file_path, std.math.maxInt(usize)) catch unreachable;
|
||||||
|
const new_data = std.mem.replaceOwned(u8, allocator, data, needle, replacement) catch unreachable;
|
||||||
|
std.fs.cwd().writeFile(file_path, new_data) catch unreachable;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue