const std = @import("std"); const args = @import("args"); const live = @import("live.zig").live; const helper = @import("helper.zig"); const Makko = @import("Makko.zig"); const Log = @import("Log.zig"); // TODO: Fix this. // depends on: https://github.com/ziglang/zig/issues/22775 // const Setup = @import("build.zig.zon"); // const VERSION_STRING = "2.1.0"; const Arguments = struct { help: bool = false, version: bool = false, live: bool = false, public: bool = false, port: u16 = 4040, pub const shorthands = .{ .h = "help", .v = "version", .l = "live", .p = "public", }; }; fn version(out: Log) !void { out.raw("Starlight Makko v{s}\n\n", .{VERSION_STRING}); } fn help(out: Log) !void { out.header("STARLIGHT MAKKO"); out.raw( \\ Makko is the simple static site generator that loves you back. \\ , .{}); out.header("USAGE"); out.raw( \\ makko [options] \\ \\ --help, -h: Displays this screen. \\ \\ --version, -v: Displays version information. (v{s}) \\ \\ --live, -l: Enables the live-development environment. \\ \\ --public, -p: Makes the live-environment visible to other \\ devices on the network. \\ \\ --port: Sets the port for the live-environment. \\ (Default is 4040.) \\ \\ : The folder that contains your Makko project. \\ , .{VERSION_STRING}); out.header("ABOUT PROJECTS"); out.raw( \\ If the project folder you specify does not have a 'makko.json' \\ file (which is a sort-of database for Makko), it will generate \\ one in the spot as necessary, you are advised to revise it. \\ \\ If any of the specified paths on the 'makko.json' file do not \\ exist, Makko will create and populate them with examples. \\ \\ If any template is unavailable, Makko will generate an \\ example template in its place. \\ , .{}); out.header("LEARN MORE"); out.raw( \\ Documentation: https://makko.starlightnet.work/ \\ GIT Repository: https://forge.starlightnet.work/Team/Makko/ \\ About us: https://starlightnet.work/ \\ \\ , .{}); } pub fn main() !void { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; defer _ = gpa.deinit(); const allocator = gpa.allocator(); const options = args.parseForCurrentProcess( Arguments, allocator, .print, ) catch return; defer options.deinit(); var log = Log.init(); if (options.options.version) return try version(log); if (options.options.help) return try help(log); const p = options.positionals.len; if (p != 1) { log.err("Expected 1 positional, got {}.", .{p}); if (p == 0) log.info("Hint: Pass a folder to Makko!", .{}); return try help(log); } const root = options.positionals[0]; if (!helper.isDir(std.fs.cwd(), root)) log.fatal("Path '{s}' is not a folder!", .{root}); var makko = Makko.open(root, allocator) catch |err| log.fatal("Could not open or set up Makko state! ({})\n", .{err}); defer makko.deinit(); makko.loadTemplates() catch |err| log.err("Could not load templates! ({})", .{err}); blk: { var pass = try makko.automaticPass(); defer pass.deinit(); makko.generateFeeds() catch |err| log.err("Could not generate feeds! ({})", .{err}); // No changes made! :O if (pass.changes.items.len == 0) { log.info("Nothing to do!", .{}); break :blk; } log.info("Starlight Makko v{s}", .{VERSION_STRING}); // I... don't know how this could fail! other than alloc/os stuff try makko.storeDatabase(); try pass.printChanges(); pass.runCallbacks() catch |err| log.err("Could not run callbacks! ({})", .{err}); } // Enable live mode if one happens to pass --live (-l) if (options.options.live) try live(options.options.public, options.options.port, &makko); }