-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrakefile.rb
119 lines (95 loc) · 2.76 KB
/
rakefile.rb
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
require "uri"
def curl(args, dest)
sh "curl -fsSL '#{args}' > #{dest}"
end
task :init do
sh "npm install"
sh "bundle install"
end
directory "tmp"
{ text: "Noto Sans", code: "Roboto Mono" }.each do |kind, family|
file "tmp/#{kind}.css" => "tmp" do |t|
query = URI.encode_www_form(
family: family,
text: (" ".."~").to_a.join,
)
curl "https://fonts.googleapis.com/css?#{query}", t.name
end
end
rule "-font.css" => ".css" do |t|
File.write(t.name, File.read(t.source)
.sub(/font-family:[^;]*;/,
"font-family: #{t.source.pathmap("%n").capitalize}Font;
font-display: swap;")
.sub(/url\([^)]*\)/, t.source.pathmap('url("%n.woff2")'))
.sub(/format\([^)]*\)/, 'format("woff2")'))
end
rule ".ttf" => ".css" do |t|
curl(/url\(([^)]+)\)/.match(File.read(t.source))[1], t.name)
end
rule %r{tmp/.*\.woff2} => ->(f) { f.pathmap("tmp/%n.ttf") } do |t|
sh "npx ttf2woff2 < #{t.source} > #{t.name}"
end
file "tmp/webpack/index.js" => %w[
tmp/text-font.css
tmp/code-font.css
tmp/text.woff2
tmp/code.woff2] do
sh "npx webpack-cli"
end
file "tmp/webpack/main.css" => "tmp/webpack/index.js"
file "_includes/index.css" => "tmp/webpack/main.css" do |t|
cp t.source.ext(".css"), t.name
end
file "_includes/icon.svg" do |t|
curl "https://github.com/cloe-lang/icon/raw/master/icon.svg", t.name
end
file "_includes/x.svg" do |t|
curl(
"https://github.com/simple-icons/simple-icons/raw/master/icons/x.svg",
t.name
)
end
directory "tmp/cloe" do |t|
sh "git clone https://github.com/cloe-lang/cloe #{t.name}"
end
directory "examples" => "tmp/cloe" do |t|
sh "go run github.com/raviqqe/gherkin2markdown #{File.join t.source, "examples"} #{t.name}"
File.write(File.join(t.name, "index.md"),
"# Examples\n\n" \
"Code examples which describes usage of the language features " \
"and built-in functions and modules.")
end
directory "_site" => %w[
_includes/index.css
_includes/icon.svg
_includes/x.svg
examples
] do
sh "bundle exec jekyll build"
end
file "_site/index.js" => "tmp/webpack/index.js" do |t|
cp t.source, t.name
end
file "_site/icon.svg" => "_includes/icon.svg" do |t|
cp t.source, t.name
end
task build: %w[_site _site/index.js _site/icon.svg] do
sh "npx tsx bin/modify-html.ts #{Dir.glob("_site/**/*.html").join " "}"
sh "npx workbox generateSW workbox-cli-config.cjs"
cp Dir.glob("tmp/webpack/*.woff2"), "_site"
end
task :deploy do
sh "npx firebase deploy"
end
task default: %w[build deploy]
task run: :build do
sh "npx superstatic --debug"
end
task :lint do
sh "rufo -c *.rb"
sh "npx stylelint **/*.scss"
end
task :clean do
sh %w[git clean -dfx --exclude node_modules].join " "
end