yamori

有給休暇計算を主目的とした簡易勤怠管理システム

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
  88. 88
  89. 89
  90. 90
  91. 91
  92. 92
  93. 93
  94. 94
  95. 95
  96. 96
  97. 97
  98. 98
  99. 99
  100. 100
  101. 101
  102. 102
  103. 103
  104. 104
  105. 105
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright 2026 Shota FUJI
//
// This program is free software: you can redistribute it and/or modify it under the terms
// of the GNU Affero General Public License as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
// PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License along
// with this program.  If not, see <http://www.gnu.org/licenses/>.

const builtin = @import("builtin");
const std = @import("std");

const pages: []const []const u8 = @import("./pages.zon");
const diagrams: []const []const u8 = @import("./diagrams.zon");

pub fn build(b: *std.Build) !void {
    const pandoc_exe = pandoc_exe: {
        const dep = if (builtin.os.tag == .linux and builtin.cpu.arch == .x86_64)
            b.lazyDependency("pandoc_linux_amd64", .{}) orelse return
        else {
            @panic("このホスト用の pandoc が用意できません。 build.zig.zon と build.zig を編集してホストを追加してください。");
        };

        break :pandoc_exe dep.path("bin/pandoc");
    };

    const dist = dist: {
        const dir = b.addWriteFiles();

        for (pages) |page| {
            if (!std.mem.startsWith(u8, page, "src/")) {
                @panic(b.fmt("ページファイルは src/ 配下に置いてください: {s}", .{page}));
            }

            const ext = std.fs.path.extension(page);

            const format = format: {
                if (std.mem.eql(u8, ext, ".md")) {
                    break :format "gfm";
                }

                if (std.mem.eql(u8, ext, ".adoc")) {
                    break :format "asciidoc";
                }

                @panic(b.fmt("{s} ファイルは読み込めません: {s}", .{ ext, page }));
            };

            const pandoc = std.Build.Step.Run.create(b, "pandoc");
            pandoc.addFileArg(pandoc_exe);

            pandoc.addArgs(&.{ "--from", format });
            pandoc.addArg("--to=html");

            pandoc.addArg("--standalone");

            pandoc.addFileArg(b.path(page));

            const output = pandoc.addPrefixedOutputFileArg("--output=", "out.html");

            _ = dir.addCopyFile(output, b.fmt("{s}.html", .{page["src/".len .. page.len - ext.len]}));
        }

        for (diagrams) |diagram| {
            if (!std.mem.startsWith(u8, diagram, "src/")) {
                @panic(b.fmt("図形ファイルは src/ 配下に置いてください: {s}", .{diagram}));
            }

            const ext = std.fs.path.extension(diagram);
            if (!std.mem.eql(u8, ext, ".d2")) {
                @panic(b.fmt("図形ファイルは d2 形式のみ対応しています: {s}", .{diagram}));
            }

            const d2 = b.addSystemCommand(&.{ "d2", "--dark-theme", "200", "--layout", "elk" });

            // d2 は成功時でも stderr にメッセージを表示し、かつこの挙動を無効化することが
            // できない。 "expectStdErrMatch" を使うと、出力された stderr がビルド成果物に
            // なるのか zig build の結果に表示されなくなる。
            d2.expectStdErrMatch("success: successfully compiled");

            d2.addFileArg(b.path(diagram));

            const svg = d2.addOutputFileArg("out.svg");
            _ = dir.addCopyFile(svg, b.fmt("{s}.svg", .{diagram["src/".len .. diagram.len - ext.len]}));
        }

        break :dist dir;
    };

    // デフォルトインストール
    {
        const install = b.addInstallDirectory(.{
            .source_dir = dist.getDirectory(),
            .install_dir = .{ .custom = "" },
            .install_subdir = "",
        });

        b.default_step.dependOn(&install.step);
    }
}