forked from home-assistant/home-assistant.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
163 lines (136 loc) · 5.32 KB
/
Rakefile
File metadata and controls
163 lines (136 loc) · 5.32 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
require "rubygems"
require "bundler/setup"
require "stringex"
require 'net/http'
require 'json'
## -- Misc Configs -- ##
public_dir = "public/" # compiled site directory
source_dir = "source" # source file directory
server_port = "4000" # port for preview server eg. localhost:4000
sass_dir = "sass"
sass_compile = "sass #{sass_dir}/:#{source_dir}/stylesheets/ --style=compressed --no-source-map --load-path=#{sass_dir} --quiet-deps"
if (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
puts '## Set the codepage to 65001 for Windows machines'
`chcp 65001`
end
#######################
# Working with Jekyll #
#######################
desc "Compile SCSS files to CSS"
task :compile_sass do
success = system sass_compile
abort("Compiling SCSS failed") unless success
end
desc "Generate jekyll site"
task :generate do
raise "### You haven't set anything up yet. First run `rake install`." unless File.directory?(source_dir)
puts "## Generating Site with Jekyll"
success = system sass_compile
abort("Generating CSS failed") unless success
success = system "rake analytics_data"
abort("Generating analytics data failed") unless success
success = system "rake alerts_data"
abort("Generating alerts data failed") unless success
success = system "rake version_data"
abort("Generating version data failed") unless success
success = system "rake language_scores_data"
abort("Generating language scores data failed") unless success
success = system "rake codeowners_data"
abort("Extracting codeowners") unless success
success = system "jekyll build"
abort("Generating site failed") unless success
if ENV["CONTEXT"] != 'production'
File.open("#{public_dir}robots.txt", 'w') do |f|
f.write "User-agent: *\n"
f.write "Disallow: /\n"
end
end
public_dir
end
desc "Watch the site and regenerate when it changes"
task :watch do
raise "### You haven't set anything up yet. First run `rake install`." unless File.directory?(source_dir)
puts "Starting to watch source with Jekyll and Sass."
system sass_compile unless File.exist?("#{source_dir}/stylesheets/screen.css")
jekyllPid = Process.spawn({"OCTOPRESS_ENV"=>"preview"}, "jekyll build --watch --incremental")
sassPid = Process.spawn("#{sass_compile} --watch")
trap("INT") {
[jekyllPid, sassPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
exit 0
}
[jekyllPid, sassPid].each { |pid| Process.wait(pid) }
end
desc "preview the site in a web browser"
task :preview, :listen do |t, args|
listen_addr = args[:listen] || '127.0.0.1'
listen_addr = '0.0.0.0' unless ENV['DEVCONTAINER'].nil?
raise "### You haven't set anything up yet. First run `rake install`." unless File.directory?(source_dir)
puts "Starting to watch source with Jekyll and Sass."
puts "Now listening on http://localhost:#{server_port}"
# Always compile all SCSS files before starting Jekyll
system sass_compile
system "rake analytics_data"
system "rake version_data"
system "rake language_scores_data"
system "rake codeowners_data"
system "rake alerts_data"
jekyllPid = Process.spawn({"OCTOPRESS_ENV"=>"preview"}, "jekyll build -t --watch --incremental")
sassPid = Process.spawn("#{sass_compile} --watch")
rackupPid = Process.spawn("rackup --port #{server_port} --host #{listen_addr}")
trap("INT") {
[jekyllPid, sassPid, rackupPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
exit 0
}
[jekyllPid, sassPid, rackupPid].each { |pid| Process.wait(pid) }
end
desc "Download data from analytics.home-assistant.io"
task :analytics_data do
uri = URI('https://analytics.home-assistant.io/data.json')
remote_data = JSON.parse(Net::HTTP.get(uri))
File.open("#{source_dir}/_data/analytics_data.json", "w") do |file|
file.write(JSON.generate(remote_data['current']))
end
end
desc "Download data from alerts.home-assistant.io"
task :alerts_data do
uri = URI('https://alerts.home-assistant.io/alerts.json')
remote_data = JSON.parse(Net::HTTP.get(uri))
File.open("#{source_dir}/_data/alerts_data.json", "w") do |file|
file.write(JSON.generate(remote_data))
end
end
desc "Download version data from version.home-assistant.io"
task :version_data do
uri = URI('https://version.home-assistant.io/stable.json')
remote_data = JSON.parse(Net::HTTP.get(uri))
File.open("#{source_dir}/_data/version_data.json", "w") do |file|
file.write(JSON.generate(remote_data))
end
end
desc "Download supported language data from ohf-voice.github.io"
task :language_scores_data do
uri = URI('https://ohf-voice.github.io/intents/language_scores.json')
remote_data = JSON.parse(Net::HTTP.get(uri))
File.open("#{source_dir}/_data/language_scores.json", "w") do |file|
file.write(JSON.generate(remote_data))
end
end
desc "Extract CODEOWNERS and output to _data/codeowners.json"
task :codeowners_data do
codeowners = []
File.readlines("CODEOWNERS").each do |line|
next if line.start_with?("#") || line.strip.empty?
parts = line.split
next if parts.length < 2
owners = parts[1..-1]
owners.each do |owner|
owner = owner.delete_prefix('@')
next if owner.include?('/')
codeowners << owner unless codeowners.include?(owner)
end
end
codeowners.sort!
File.open("#{source_dir}/_data/codeowners.json", "w") do |file|
file.write(JSON.generate(codeowners))
end
end