This repository has been archived by the owner on Dec 4, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Rakefile
114 lines (94 loc) · 2.79 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
#
# Copyright 2011-2013, Dell
# Copyright 2013-2015, SUSE Linux GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
begin
require "sprockets/standalone"
Sprockets::Standalone::RakeTask.new(:assets) do |task, sprockets|
task.assets = [
"**/application.js"
]
task.sources = [
"crowbar_framework/app/assets/javascripts"
]
task.output = "crowbar_framework/public/assets"
task.compress = true
task.digest = true
sprockets.js_compressor = :closure
sprockets.css_compressor = :sass
end
namespace :assets do
def available_assets
Pathname.glob(
File.expand_path(
"../crowbar_framework/public/assets/**/*",
__FILE__
)
)
end
def digested_regex
/(-{1}[a-z0-9]{32}*\.{1}){1}/
end
task :setup_logger do
@logger = Logger.new(STDOUT)
@logger.level = Logger::INFO
end
task non_digested: :setup_logger do
available_assets.each do |asset|
next if asset.directory?
next unless asset.to_s =~ digested_regex
simple = asset.dirname.join(
asset.basename.to_s.gsub(digested_regex, ".")
)
if simple.exist?
simple.delete
end
@logger.info "Symlinking #{simple}"
simple.make_symlink(asset.basename)
end
end
task clean_dangling: :setup_logger do
available_assets.each do |asset|
next if asset.directory?
next if asset.to_s =~ digested_regex
next unless asset.symlink?
# exist? is enough for checking the symlink target as it resolves the
# link target and checks if that really exists. The check for having a
# symlink is already done above.
unless asset.exist?
@logger.info "Removing #{asset}"
asset.delete
end
end
end
end
Rake::Task["assets:compile"].enhance do
Rake::Task["assets:non_digested"].invoke
Rake::Task["assets:clean_dangling"].invoke
end
rescue
end
unless ENV["PACKAGING"] && ENV["PACKAGING"] == "yes"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
task :syntaxcheck do
system("for f in `find -name \*.rb`; do echo -n \"Syntaxcheck $f: \"; ruby -c $f || exit $? ; done")
exit $?.exitstatus
end
task default: [
:spec,
:syntaxcheck
]
end