diff options
| -rw-r--r-- | makefile | 4 | ||||
| -rw-r--r-- | serve.mk | 6 | ||||
| -rw-r--r-- | src/exe.zig | 3 | ||||
| -rw-r--r-- | src/main.zig | 18 |
4 files changed, 21 insertions, 10 deletions
diff --git a/makefile b/makefile index d7147ca..5433fbb 100644 --- a/makefile +++ b/makefile @@ -18,6 +18,9 @@ gen: $(rbl_BIN) watch: @ $(rbl_BIN) watch +serve: + @ $(rbl_BIN) serve + watch-and-serve: @ ${MAKE} -j2 watch serve @@ -26,6 +29,5 @@ dev: watch-and-serve .PHONY: all gen clean serve watch watch-and-serve was -include serve.mk include webdeploy.mk include edit.mk diff --git a/serve.mk b/serve.mk deleted file mode 100644 index 5817f63..0000000 --- a/serve.mk +++ /dev/null @@ -1,6 +0,0 @@ -CADDY_HTTP_PORT ?= 1414 -CADDY_HOST ?= localhost - -serve: - @ caddy fmt --overwrite - @ caddy run --watch diff --git a/src/exe.zig b/src/exe.zig index 56914b3..b246d56 100644 --- a/src/exe.zig +++ b/src/exe.zig @@ -138,7 +138,7 @@ pub fn captureStdout(ctx: *Context, argv: []const []const u8, env_map: ?*std.pro _ = result; } -pub fn shell(ctx: *Context, command: []const u8) !void { +pub fn shell(ctx: *Context, command: []const u8, env_map: ?*std.process.EnvMap) !void { const label = try std.fmt.allocPrint(ctx.allocator(), "running {s}", .{command}); defer ctx.allocator().free(label); @@ -152,6 +152,7 @@ pub fn shell(ctx: *Context, command: []const u8) !void { }, std.heap.page_allocator); p.progress_node = ctx.progress_nodes.getLast(); + p.env_map = env_map; try p.spawn(); const result = try p.wait(); diff --git a/src/main.zig b/src/main.zig index 8e0b27e..7199bce 100644 --- a/src/main.zig +++ b/src/main.zig @@ -162,6 +162,8 @@ const Cli = struct { try Cli.mdCmd(ctx); } else if (std.mem.eql(u8, arg, "watch")) { try Cli.watchCmd(ctx); + } else if (std.mem.eql(u8, arg, "serve")) { + try Cli.serveCmd(ctx); } else { Cli.helpCmd(ctx); } @@ -169,7 +171,7 @@ const Cli = struct { } fn helpCmd(_: *Context) void { - std.debug.print("usage: rbl [gen|md]\n\n", .{}); + std.debug.print("usage: rbl [gen|md|watch|serve]\n\n", .{}); } fn genCmd(ctx: *Context) !void { @@ -186,7 +188,19 @@ const Cli = struct { fn watchCmd(ctx: *Context) !void { try exe.shell(ctx, \\find ./src/inc/ -type f -print | entr -nc -dd -- rbl md gen - ); + , null); + } + + fn serveCmd(ctx: *Context) !void { + var env_map = try std.process.getEnvMap(ctx.allocator()); + defer env_map.deinit(); + + try env_map.put("CADDY_HTTP_PORT", "1414"); + try env_map.put("CADDY_HOST", "localhost"); + + try exe.shell(ctx, + \\caddy fmt --overwrite && caddy run --watch + , &env_map); } }; |