1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
require "pathname"

$LOAD_PATH.unshift Pathname(__dir__).join("lib").to_s

require "minitest/test_task"

Minitest::TestTask.create

desc "Start dev server with auto-restart"
task :dev do
  # :memory: and a per-process session secret both reset on restart, so
  # use a file and a fixed secret (64+ bytes, Roda's minimum). db/*.db is
  # gitignored, so fd skips the file too.
  env = {
    "DATABASE_URL" => ENV.fetch("DATABASE_URL", "db/dev.db"),
    "SESSION_SECRET" => ENV.fetch("SESSION_SECRET", "dev-only-secret-" + "x" * 64),
  }
  sh(env, "fd | entr -r rackup -o localhost demo.ru")
end

desc "Type check lib against the RBS comments in it"
task :steep do
  sh "steep", "check"
end

task default: %i[ steep test ]

# Rank King inherits Gloss (https://github.com/kejadlen/gloss) as its
# design system. Gloss ships as plain CSS meant to be copied into a
# consuming project rather than pulled in as a dependency (see its
# install.md), so public/vendor/gloss is a vendored snapshot, and this
# task is how it gets refreshed.
namespace :gloss do
  desc "Refresh the vendored Gloss CSS and JS from a local checkout (GLOSS=path)"
  task :vendor do
    require "fileutils"
    require "pathname"

    checkout = Pathname.new(ENV.fetch("GLOSS") { abort "usage: rake gloss:vendor GLOSS=/path/to/gloss/checkout" })
    commit = `git -C #{checkout} rev-parse HEAD`.strip
    abort "#{checkout} is not a git checkout" unless $?.success?

    out = Pathname.new(__dir__) / "public" / "vendor" / "gloss"
    FileUtils.mkdir_p(out)

    header = <<~CSS
      /* Vendored from kejadlen/gloss @ #{commit}, #{Time.now.utc.strftime("%Y-%m-%d")}.
         Refresh with `rake gloss:vendor GLOSS=/path/to/gloss/checkout`. */

    CSS

    # Mirrors CSS_BUNDLES in Gloss' lib/build.rb.
    bundles = {
      "tokens.css" => %w[assets/css/tokens.css],
      "base.css" => %w[_sass/base/reset.css _sass/base/typography.css],
      "components.css" => %w[
        _sass/components/icon.css
        _sass/components/button.css
        _sass/components/field.css
        _sass/components/badge.css
        _sass/components/card.css
        _sass/components/feedback.css
        _sass/components/tabs.css
      ],
    }

    bundles.each do |name, sources|
      body = sources.map { |source| (checkout / source).read }.join("\n")
      (out / name).write(header + body)
      puts "wrote #{out / name}"
    end

    # The tab keyboard wiring; the theme toggle in it is unused here.
    js = out / "system.js"
    js.write(header + (checkout / "assets/js/system.js").read)
    puts "wrote #{js}"
  end
end