This repository has been archived by the owner on May 7, 2021. It is now read-only.
forked from pmuir/patternfly-sass
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
139 lines (117 loc) · 4.58 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
require 'rake'
require 'rspec/core/rake_task'
require 'bundler/gem_tasks'
def gem_asset_path(package, path)
File.join(Gem::Specification.find_by_name(package).gem_dir, path)
end
desc "Convert LESS to SCSS"
task :convert, [:branch] => [:deps] do |_, args|
require './tasks/converter'
branch = args.has_key?(:branch) ? args[:branch] : 'master'
Converter.new(:branch => branch).convert
end
desc "Compile patternfly-sass into CSS"
task :compile do
require 'sass'
require 'fileutils'
require 'term/ansicolor'
Sass.load_paths << File.join(gem_asset_path('bootstrap-sass', 'assets/stylesheets'))
Sass.load_paths << File.join(gem_asset_path('font-awesome-sass', 'assets/stylesheets'))
::Sass::Script::Value::Number.precision = [8, ::Sass::Script::Value::Number.precision].max
dst_dir = 'assets/css'
path = 'assets/stylesheets'
FileUtils.mkdir_p(dst_dir)
puts Term::ANSIColor.bold "Compiling SCSS in #{path} to #{dst_path}"
%w(patternfly.css patternfly.min.css).each do |out|
style = (out == "patternfly.min.css") ? :compressed : :nested
src_path = File.join(path, '_patternfly.scss')
dst_path = File.join(dst_dir, out)
engine = Sass::Engine.for_file(src_path, :filename => src_path, :syntax => :scss, :load_paths => [path], :style => style)
css = engine.render_with_sourcemap(dst_path + '.map')
css[0].gsub!(/(( )|(:))0((px)|(em)|(\%))/, '\10')
File.open(dst_path, 'w') { |f| f.write css[0] }
puts Term::ANSIColor.cyan(" #{dst_path}") + '...'
# write sourcemap to file
sourcemap_options = {
:css_path => dst_path,
:sourcemap_path => dst_path + '.map'
}
File.write(dst_path + '.map', css[1].to_json(sourcemap_options))
puts Term::ANSIColor.cyan(" #{dst_path}.map") + '...'
end
end
desc "Start a web server with both the less and the sass version"
task :serve => :compile do
require 'webrick'
server = WEBrick::HTTPServer.new :Port => 9000
{
'/' => 'spec/main.html',
'/less/dist/css' => 'spec/html/dist/css',
'/less/dist/fonts' => 'assets/fonts/patternfly',
'/less/dist/img' => 'assets/images/patternfly',
'/less/dist/js' => 'assets/javascripts',
'/less/pages/patternfly' => 'spec/html',
'/sass/dist/fonts' => 'assets/fonts',
'/sass/dist/fonts/bootstrap' => gem_asset_path('bootstrap-sass', 'assets/fonts/bootstrap'),
'/sass/dist/img' => 'assets/images/patternfly',
'/sass/dist/images' => 'assets/images',
'/sass/dist/js' => 'assets/javascripts',
'/sass/dist/css' => 'tmp',
'/sass/dist/fonts/font-awesome' => gem_asset_path('font-awesome-sass', 'assets/fonts/font-awesome'),
'/sass/pages/patternfly' => 'spec/html',
}.each { |http, local| server.mount http, WEBrick::HTTPServlet::FileHandler, local }
trap('INT') { server.stop }
server.start
end
desc "Install testing dependencies using bower"
task :deps do
system("bower update", out: $stdout, err: :out)
end
desc "Clean up the test results"
task :cleanup do
require 'fileutils'
FileUtils.rm_rf '.sass-cache'
FileUtils.rm_rf 'spec/results'
end
desc "Run the tests with a web server"
task :test => :compile do
pid = Process.fork do
puts "Starting web server on port 9000"
$stdout.reopen('/dev/null', 'w')
$stderr.reopen('/dev/null', 'w')
Rake::Task[:serve].invoke
puts "Stopping web server on port 9000"
end
puts "Starting the tests against the web server"
begin
Rake::Task[:spec].invoke
ensure
Process.kill('INT', pid)
end
end
desc "Run the tests without a web server"
RSpec::Core::RakeTask.new(:spec) do |t|
Rake::Task[:cleanup].invoke
FileUtils.mkdir_p 'spec/results/sass'
FileUtils.mkdir_p 'spec/results/less'
t.pattern = Dir.glob('spec/**/*_spec.rb')
end
task :upload do
require 'imgur'
require 'term/ansicolor'
# Travis only task, exit when the IMGUR_ID is not present
exit(0) if ENV['IMGUR_ID'].nil?
print Term::ANSIColor.bold "Uploading failure diffs to imgur "
client = Imgur.new ENV['IMGUR_ID']
images = Dir["spec/results/*.png"].map do |img|
print Term::ANSIColor.cyan '.'
client.upload Imgur::LocalImage.new(img, :title => img.sub('.png', '.html').sub('spec/results/', ''))
end
if images.empty?
puts Term::ANSIColor.cyan ' nothing to upload'
else
album = client.new_album(images, :title => "patternfly-sass CI results for build ##{ENV['TRAVIS_BUILD_NUMBER']}")
puts Term::ANSIColor.bold " available at: #{Term::ANSIColor.cyan album.link}"
end
end
task :default => :convert