forked from thechangelog/nightly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
127 lines (104 loc) · 3.36 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
require "rubygems"
require "bundler/setup"
require "date"
require "json"
require "dotenv/tasks"
require "createsend"
require "pry"
require_relative "lib/core_ext/date"
require_relative "lib/bq_client"
require_relative "lib/template"
require_relative "lib/repo"
DATE = Date.parse(ENV["DATE"]) rescue Date.today
DIST_DIR = "dist"
ISSUE_DIR = "#{DIST_DIR}/#{DATE.path}"
ISSUE_URL = "http://nightly.changelog.com/#{DATE.path}"
DATA_FILE = "#{ISSUE_DIR}/data.json"
THEMES = %w(night day)
desc "Launches local HTTP server on DIST_DIR"
task :preview do
system "cd #{DIST_DIR} && python -m SimpleHTTPServer"
end
desc "Performs all operations for DATE except delivering the email"
task generate: [:sass, :images, :issue, :index]
task :dist do
FileUtils.mkdir_p DIST_DIR
end
desc "Takes dat scss and makes it dat css"
task sass: [:dist] do
Dir["styles/*.scss"].each do |infile|
outfile = File.basename(infile).gsub ".scss", ".css"
next if outfile.start_with? "_"
system "sass --sourcemap=none #{infile} #{DIST_DIR}/#{outfile}"
end
end
desc "Copies the images directory to DIST_DIR"
task images: [:dist] do
FileUtils.cp_r "images", "dist", preserve: false
FileUtils.cp_r "#{Emoji.images_path}/emoji", "dist/images"
end
desc "Processes the site's index w/ current linked list"
task index: [:dist] do
File.write "#{DIST_DIR}/index.html", Template.new("index").render
end
desc "Runs all tasks to generate DATE's issue"
task issue: ["issue:data", "issue:html"]
namespace :issue do
task dir: [:dist] do
FileUtils.mkdir_p ISSUE_DIR
end
desc "Generates DATA_FILE file for DATE. No-op if file exists"
task data: [:dotenv, :dir] do
if File.exist? DATA_FILE
next
end
bq = BqClient.new DATE
data = {
top_new: bq.top_new,
top_all: bq.top_all
}
File.write DATA_FILE, JSON.dump(data)
end
desc "Generates index.html file for DATE"
task html: [:data] do
template = Template.new "issue"
data = Repo.new JSON.parse File.read DATA_FILE
File.write "#{ISSUE_DIR}/index.html", template.render({
top_new: data.top_new,
top_all: data.top_all,
web_version: true,
theme: "night"
})
THEMES.each do |theme|
File.write "#{ISSUE_DIR}/email-#{theme}.html", template.render({
top_new: data.top_new,
top_all: data.top_all,
web_version: false,
theme: theme
})
end
end
desc "Delivers DATE's email to Campaign Monitor"
task deliver: [:dotenv] do
auth = {api_key: ENV["CAMPAIGN_MONITOR_KEY"]}
CreateSend::List.new(auth, ENV["CAMPAIGN_MONITOR_LIST"]).segments.each do |segment|
theme_name = segment.Title.downcase
theme_id = segment.SegmentID
next unless THEMES.include? theme_name
campaign_id = CreateSend::Campaign.create(
auth,
ENV["CAMPAIGN_MONITOR_ID"], # client id
"The Hottest Repos on GitHub - #{DATE.day_month_abbrev}", # subject
"Nightly – #{DATE} (#{theme_name} theme)", # campaign name
"Changelog Nightly", # from name
"[email protected]", # from email
"[email protected]", # reply to
"#{ISSUE_URL}/email-#{theme_name}.html", # html url
nil, # text url
[], # list ids
[theme_id] # segment ids
)
CreateSend::Campaign.new(auth, campaign_id).send "[email protected]" # send + confirmation email
end
end
end