forked from home-assistant/home-assistant.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
129 lines (106 loc) · 4.53 KB
/
Rakefile
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
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
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 "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 "compass compile --css-dir #{source_dir}/stylesheets"
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 blueprint_exchange_data"
abort("Generating blueprint exchange data failed") 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 Compass."
system "compass compile --css-dir #{source_dir}/stylesheets" unless File.exist?("#{source_dir}/stylesheets/screen.css")
jekyllPid = Process.spawn({"OCTOPRESS_ENV"=>"preview"}, "jekyll build --watch --incremental")
compassPid = Process.spawn("compass watch")
trap("INT") {
[jekyllPid, compassPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
exit 0
}
[jekyllPid, compassPid].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 Compass."
puts "Now listening on http://localhost:#{server_port}"
system "compass compile --css-dir #{source_dir}/stylesheets" unless File.exist?("#{source_dir}/stylesheets/screen.css")
system "rake analytics_data"
system "rake version_data"
system "rake alerts_data"
system "rake blueprint_exchange_data"
jekyllPid = Process.spawn({"OCTOPRESS_ENV"=>"preview"}, "jekyll build -t --watch --incremental")
compassPid = Process.spawn("compass watch")
rackupPid = Process.spawn("rackup --port #{server_port} --host #{listen_addr}")
trap("INT") {
[jekyllPid, compassPid, rackupPid].each { |pid| Process.kill(9, pid) rescue Errno::ESRCH }
exit 0
}
[jekyllPid, compassPid, 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 data from the blueprint exchange @ community.home-assistant.io"
task :blueprint_exchange_data do
uri = URI('https://community.home-assistant.io/c/blueprints-exchange/53/l/top.json?period=all')
remote_data = JSON.parse(Net::HTTP.get(uri))
File.open("#{source_dir}/_data/blueprint_exchange_data.json", "w") do |file|
file.write(JSON.generate(remote_data['topic_list']['topics']))
end
end