Spaces:
Sleeping
Sleeping
File size: 9,253 Bytes
07c3cdd | 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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | require 'rubygems'
desc "Generate JS libraries"
task :buildjs do
begin
require 'json'
rescue LoadError
puts "JSON not found.\nInstall it by running 'gem install json'"
exit
end
puts "Starting libraries generation..."
#system "rm -rf gulliver/js-min/"
#system "rm -rf gulliver/css-min/"
#Dir.mkdir('gulliver/css-min') unless File.exists?('gulliver/css-min')
#Dir.mkdir('gulliver/js-min') unless File.exists?('gulliver/js-min')
lib_file = File.read 'workflow/engine/bin/tasks/libraries.json'
libraries = JSON.parse(lib_file);
libraries.each do |library|
build = library['build']
if build
begin
require 'closure-compiler'
rescue LoadError
puts "closure-compiler not found.\nInstall it by running 'gem install closure-compiler'"
exit
end
buffer_full = ""
buffer_mini = ""
buffer_css = ""
lib_name = library['name']
files = library['libraries']
js_path = library['build_js_to']
css_path = library['build_css_to']
puts "Processing #{lib_name} file."
files.each do |lbry|
puts "Processing library: " + lbry['name']
buffer_full += File.read lbry['full']
buffer_mini += File.read lbry['mini']
if lbry['css']
buffer_css += File.read lbry['css']
end
if lbry['css_images']
Dir.mkdir(lbry['copy_css_images_to']) unless File.exists?(lbry['copy_css_images_to'])
system "cp -r " + lbry['css_images'] + " " + lbry['copy_css_images_to'] + "."
end
end
fileName = lib_name + "-" + getVersion
#File.open(js_path + fileName + ".js", 'w+') do |file_full|
# file_full.write buffer_full
#end
#puts "File '#{js_path}#{fileName}.js' has been generated correctly."
File.open(js_path + lib_name + '.js', 'w+') do |file_mini|
file_mini.write Closure::Compiler.new.compress(buffer_mini)
end
puts "File '#{js_path}#{fileName}.js' has been generated correctly."
#puts "File '#{js_path}#{fileName}.min.js' has been generated correctly."
#File.open(css_path + fileName + '.css', 'w+') do |file_css|
# file_css.write buffer_css
#end
#puts "File '#{css_path}#{fileName}.css' has been generated correctly."
end
end
#puts "Copying VERSION.txt"
#system "cp workflow/engine/bin/tasks/VERSION.js.txt gulliver/js-min/VERSION.txt"
puts "Libraries generation DONE"
end
desc "Run Jasmine BDD tests"
task :jasmine do
system "jasmine-node --matchall --verbose spec"
end
desc "Create skeleton pages"
task :skeleton do
begin
require 'json'
rescue LoadError
puts "JSON not found.\nInstall it by running 'gem install json'"
exit
end
version = getVersion
template = "<!DOCTYPE html>\n<html>\n<head>\n"
template += "<title>jCore #{version}</title>\n"
template += "<link type=\"text/css\" href=\"css/jcore.utils-#{version}.css\" rel=\"stylesheet\" />\n"
template += "<script type=\"text/javascript\" src=\"js/jcore.utils-#{version}.min.js\" ></script>\n"
build_file = File.read 'src/build.json'
sources = JSON.parse(build_file)
sources.each do |source|
if source['css']
template += "<link type=\"text/css\" href=\"css/" + source['name'] + "-#{version}.css\" rel=\"stylesheet\" />\n"
end
template += "<script type=\"text/javascript\" src=\"js/" + source['name'] + "-#{version}.min.js\" ></script>\n"
end
template += "</head>\n<body>\n"
template += "<h1>Welcome to jCore FE #{version}</h1>\n"
template += "</body>\n</html>"
File.open('index.html', 'w+') do |file|
file.write template
end
puts "File 'index.html' has been generated correctly."
template = "<!DOCTYPE html>\n<html>\n<head>\n"
template += "<title>jCore #{version}</title>\n"
lib_file = File.read 'lib/libraries.json'
libraries = JSON.parse(lib_file)
libraries.each do |library|
if library['build']
template += "<!--Including " + library['name'] + " files -->\n"
buffer_js = ""
buffer_css = ""
files = library['libraries']
files.each do |lbry|
if lbry['full']
buffer_js += "<script type=\"text/javascript\" src=\"" + lbry['full'] + "\" ></script>\n"
end
if lbry['css']
buffer_css += "<link type=\"text/css\" href=\"" + lbry['css'] + "\" rel=\"stylesheet\" />\n"
end
end
template += buffer_css
template += buffer_js
end
end
src_file = File.read 'src/build.json'
sources = JSON.parse(src_file)
sources.each do |source|
if source['build']
template += "<!--Including " + source['name'] + " files -->\n"
styles = source['css']
styles.each do |style|
template += "<link type=\"text/css\" href=\"" + style + "\" rel=\"stylesheet\" />\n"
end
files = source['files']
files.each do |file|
template += "<script type=\"text/javascript\" src=\"" + file + "\" ></script>\n"
end
end
end
template += "</head>\n<body>\n"
template += "<h1>Welcome to jCore FE #{version}</h1>\n"
template += "</body>\n</html>"
File.open('devel.html', 'w+') do |file|
file.write template
end
puts "File 'devel.html' has been generated correctly."
end
desc "Set the library's version"
task :version, :version do |t,args|
if (args['version'])
File.open('VERSION.txt', 'w+') do |file|
file.write args['version']
end
end
end
desc "Create a package for distribution"
task :package do
begin
require 'zip/zip'
require 'zip/zipfilesystem'
rescue LoadError
puts "Zip Tools not found.\nInstall it by running 'gem install rubyzip'"
exit
end
begin
require 'json'
rescue LoadError
puts "JSON not found.\nInstall it by running 'gem install json'"
exit
end
system "rm -rf dist/"
Dir.mkdir('dist') unless File.exists?('dist')
zip_config = File.read 'dist.json'
zips = JSON.parse(zip_config)
zips.each do |zip|
zip_path = zip['copy_to']
fileName = zip['fileName']
type = zip['type']
version = getVersion
archive = zip_path + fileName + "-" + version + "-" + type + ".zip";
FileUtils.rm archive, :force=>true
Zip::ZipFile.open(archive, 'w') do |zipfile|
files = zip['files']
files.each do |file|
add_files = FileList.new(file)
add_files.each do |afile|
zipfile.add(afile,afile)
end
end
puts "File: " + archive + " has been created correctly!"
end
end
end
desc "Run JSHint Javascript sniffer"
task :sniffer do
system "find src/ -name \"*.js\" -print0 | xargs -0 jslint --sloppy"
system "jshint src/"
end
desc "Run JSLint tests"
task :jslint, :file do |t, args|
if args['file']
system "find src/ -name \"" + args['file'] + "\" -print0 | xargs -0 jslint --sloppy"
else
system "find src/ -name \"*.js\" -print0 | xargs -0 jslint --sloppy"
end
end
desc "Run JSHint tests"
task :jshint, :file do |t, args|
if args['file']
system "find src/ -name \"" + args['file'] + "\" -print0 | xargs -0 jshint"
else
system "jshint src/"
end
end
desc "Run JSLint for CI Server"
task :jslint_ci do
puts "Starting JSLINT test for CI Server"
failed_files = []
Dir['src/**/*.js'].each do |name|
cmd = "jslint --sloppy #{name}"
results = %x{#{cmd}}
unless results == name + " is OK"
failed_files << name
else
puts "File: " + name + " ...OK"
end
end
if failed_files.size > 0
exit 0
else
puts "JSLINT testing...DONE"
end
end
desc "Run Jasmine Test for CI Server"
task :jasmine_ci do
puts "Starting JASMINE testing..."
system "jasmine-node spec/ --junitreport"
puts "JASMINE testing...DONE"
end
desc "Compile Documentation with JSDoc 3"
task :docs do
begin
require 'json'
rescue LoadError
puts "JSON not found.\nInstall it by running 'gem install json'"
exit
end
doc_config = File.read 'docs.json'
docs = JSON.parse(doc_config)
docs.each do |doc_file|
doc_list = ""
doc_target = doc_file['build_dir']
files = doc_file['files']
files.each do |file|
doc_list += " " + file
end
system "jsduck -o " + doc_target + doc_list
end
end
desc "Build jCore library"
task :build, :version do |t, args|
if args['version']
Rake::Task['version'].invoke(args['version'])
end
Rake::Task['buildjs'].execute
#Rake::Task['skeleton'].execute
#Rake::Task['docs'].execute
#Rake::Task['package'].execute
puts "jCore " + getVersion + " has been build correctly."
end
desc "Default Task - Build Library"
task :default do
Rake::Task['build'].execute
end
desc "Run Violations Test for CI Server"
task :violations do
Dir.mkdir('violations') unless File.exists?('violations')
Dir.mkdir('violations/js') unless File.exists?('violations/js')
Dir.mkdir('violations/css') unless File.exists?('violations/css')
system "nodelint src --config config/jslint.js --reporter=xml > violations/js/jslint.xml"
system "csslint src --format=checkstyle-xml > violations/css/checkstyle.xml"
system "csslint src --format=lint-xml > violations/css/csslint.xml"
end
def getVersion
version = File.read 'workflow/engine/bin/tasks/VERSION.js.txt'
return version
exit
end
|