Don't convert dotfiles to ZON, which may include editor configurations. (#734)

* Don't convert dotfiles, which may include editor configurations.
This means that configurations specific to this workspace in editors
don't get overwritten, which prevents accidental formatting errors
whenever the game is tested.

* Fix accidental formatting change

* Use the syntax sugar

* Update main.zig
This commit is contained in:
Zachary Hall 2024-10-01 11:00:27 -07:00 committed by GitHub
parent 6ed0800b4a
commit 1f1cc286ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -403,7 +403,26 @@ fn isValidIdentifierName(str: []const u8) bool { // TODO: Remove after #480
return true;
}
fn isHiddenOrParentHiddenPosix(path: []const u8) bool {
var iter = std.fs.path.componentIterator(path) catch |err| {
std.log.err("Cannot iterate on path {s}: {s}!", .{path, @errorName(err)});
return false;
};
while (iter.next()) |component| {
if (std.mem.eql(u8, component.name, ".") or std.mem.eql(u8, component.name, "..")) {
continue;
}
if (component.name.len > 0 and component.name[0] == '.') {
return true;
}
}
return false;
}
pub fn convertJsonToZon(jsonPath: []const u8) void { // TODO: Remove after #480
if (isHiddenOrParentHiddenPosix(jsonPath)) {
std.log.info("NOT converting {s}.", .{jsonPath});
return;
}
std.log.info("Converting {s}:", .{jsonPath});
const jsonString = files.read(stackAllocator, jsonPath) catch |err| {
std.log.err("Could convert file {s}: {s}", .{jsonPath, @errorName(err)});