forked from unpoly/unpoly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
154 lines (132 loc) · 4.23 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
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
require "bundler/gem_tasks"
require 'sass/util'
require 'sass/script'
require 'sprockets/standalone'
require 'unpoly/rails/version'
require 'json'
module Unpoly
module Tasks
SPROCKETS_MANIFESTS = %w(
unpoly.js
unpoly.css
unpoly-bootstrap3.js
unpoly-bootstrap3.css
)
SPROCKETS_SOURCES = %w(lib/assets/javascripts lib/assets/stylesheets)
SPROCKETS_OUTPUT_FOLDER = 'dist'
NPM_MANIFEST = 'package.json'
VISIBLE_TASKS = %w(publish:build publish:commit publish:release publish:all)
end
end
Sprockets::Standalone::RakeTask.new(:source_assets) do |task, sprockets|
task.assets = Unpoly::Tasks::SPROCKETS_MANIFESTS
task.sources = Unpoly::Tasks::SPROCKETS_SOURCES
task.output = Unpoly::Tasks::SPROCKETS_OUTPUT_FOLDER
task.compress = false
task.digest = false
sprockets.js_compressor = nil
sprockets.css_compressor = nil
end
Sprockets::Standalone::RakeTask.new(:minified_assets) do |task, sprockets|
task.assets = Unpoly::Tasks::SPROCKETS_MANIFESTS
task.sources = Unpoly::Tasks::SPROCKETS_SOURCES
task.output = Unpoly::Tasks::SPROCKETS_OUTPUT_FOLDER
task.compress = false
task.digest = false
sprockets.js_compressor = :uglifier
sprockets.css_compressor = :sass
end
namespace :publish do
task :confirm do
puts "Before publishing new Unpoly version:"
puts "- Bump the version in version.rb"
puts "- Update the CHANGELOG"
puts "Ready to publish to all release channels? [y/N] "
reply = STDIN.gets.strip.downcase
unless reply == 'y'
puts "Aborted"
exit
end
end
desc 'Build release artifacts'
task :build do
ENV['JS_KNIFE'] = nil
Rake::Task['minified_assets:compile'].invoke
Unpoly::Tasks::SPROCKETS_MANIFESTS.each do |manifest|
source = "dist/#{manifest}"
target = "dist/#{manifest.sub(/\.([^\.]+)$/, '.min.\\1')}"
File.rename(source, target)
end
Rake::Task['source_assets:compile'].invoke
Rake::Task['publish:validate_dist'].invoke
Rake::Task['npm:bump_version'].invoke
end
desc 'Validate build files in dist folder'
task :validate_dist do
script_paths = Dir['dist/*.js']
script_paths.each do |script_path|
content = File.read(script_path)
if content.size == 0
raise "Zero-byte build file: #{script_path}"
end
if content =~ /\beval\b/
raise "`eval` found in build file: #{script_path}"
end
end
end
desc 'Commit and push build release artifacts'
task :commit do
commands = [
"git add #{Unpoly::Tasks::SPROCKETS_OUTPUT_FOLDER}",
"git add #{Unpoly::Tasks::NPM_MANIFEST}",
"git commit -m 'Release artifacts for version #{Unpoly::Rails::VERSION}'",
"git push"
]
commands.each do |command|
system(command) or raise "Error running command: #{command}"
end
end
desc 'Release new version to all package managers'
task :release do
Rake::Task['rubygems:publish'].invoke
Rake::Task['npm:publish'].invoke
end
desc 'Remind user to update unpoly.com'
task :remind_to_update_site do
puts "Now remember to:"
puts "- update unpoly.com so user see the updated CHANGELOG and CDN link"
puts "- send a message to the e-mail group announcing the new release"
puts "- tweet a link to the CHANGELOG as @unpolyjs"
end
desc 'Build artifacts, push to git and release to package managers'
task :all => [:confirm, :build, :commit, :release, :remind_to_update_site] do
end
end
namespace :rubygems do
task :publish do
puts 'Publishing to rubygems.org. If this seems to hang, enter your 2FA token.'
Rake::Task['release'].invoke
end
end
namespace :npm do
task :bump_version do
data = File.read(Unpoly::Tasks::NPM_MANIFEST)
json = JSON.load(data)
# Sanity-check the parsed JSON
json['version'] or raise 'No "version" key found in package.json'
json['version'] = Unpoly::Rails::VERSION
data = JSON.pretty_generate(json)
File.open(Unpoly::Tasks::NPM_MANIFEST, 'w') do |file|
file.write data
end
end
task :publish do
system('npm publish') or raise 'Could not publish npm module'
end
end
# Clean up task list in `rake -T`
Rake::Task.tasks.each do |task|
unless Unpoly::Tasks::VISIBLE_TASKS.include?(task.name)
task.clear_comments
end
end