Files
luos/Rakefile
Roly Rudy Gutierrez Pinto 928f691d9d change implementation pmdynaform
2014-07-02 10:37:51 -04:00

360 lines
14 KiB
Ruby

require 'rubygems'
desc "Default Task - Build Library"
task :default => [:required] do
Rake::Task['build'].execute
end
task :required do
begin
require 'json'
rescue LoadError
puts "JSON gem not found.\nInstall it by running 'gem install json'"
exit(1)
end
end
desc "Copy Files to ProcessMaker"
task :build => [:required] do
mode = "production"
#argv1 = ARGV.last
publicDir = Dir.pwd + "/workflow/public_html"
# validate
unless File.exists?(publicDir)
puts "Seems it is not a ProcessMaker installation"
exit(1)
end
if mode == "production"
targetDir = publicDir + "/lib"
pmUIFontsDir = targetDir + "/fonts"
else
targetDir = publicDir + "/lib-dev"
pmUIFontsDir = pmUIDir + "/fonts"
end
jsTargetDir = targetDir + "/js"
cssTargetDir = targetDir + "/css"
cssImagesTargetDir = cssTargetDir + "/images"
imgTargetDir = targetDir + "/img"
pmUIDir = targetDir + "/pmUI"
mafeDir = targetDir + "/mafe"
pmdynaformDir = targetDir + "/pmdynaform"
prepareDirs([pmUIDir, mafeDir, pmdynaformDir, jsTargetDir, cssTargetDir, cssImagesTargetDir, imgTargetDir, pmUIFontsDir])
buildPmUi(Dir.pwd + "/vendor/colosa/pmUI", targetDir, mode)
buildPmdynaform(Dir.pwd + "/vendor/colosa/pmDynaform", targetDir, mode)
buildMafe(Dir.pwd + "/vendor/colosa/MichelangeloFE", targetDir, mode)
pmuiHash = getHash(Dir.pwd + "/vendor/colosa/pmUI")
mafeHash = getHash(Dir.pwd + "/vendor/colosa/MichelangeloFE")
pmdynaformHash = getHash(Dir.pwd + "/vendor/colosa/pmDynaform")
hashVendors = pmuiHash+"-"+mafeHash
## Building minified JS Files
puts "Building file: " + "/js/mafe-#{hashVendors}.js".cyan
mafeCompresedFile = targetDir + "/js/mafe-#{hashVendors}.js"
mafeCompresedContent = ""
getJsIncludeFiles().each do |filename|
mafeCompresedContent += File.read filename
mafeCompresedContent += "\n"
end
File.open(mafeCompresedFile, 'w+') do |writeFile|
writeFile.write mafeCompresedContent
end
#Building minified CSS Files
puts "Building file: " + "/css/mafe-#{hashVendors}.css".cyan
mafeCompresedFile = targetDir + "/css/mafe-#{hashVendors}.css"
mafeCompresedContent = ""
getCssIncludeFiles().each do |filename|
mafeCompresedContent += File.read filename
mafeCompresedContent += "\n"
end
File.open(mafeCompresedFile, 'w+') do |writeFile|
writeFile.write mafeCompresedContent
end
# Create buildhash file
puts "create file: " + "/buildhash".cyan
File.open(targetDir+"/buildhash", 'w+') do |writeFile|
writeFile.write hashVendors
end
puts "create file: " + "/versions".cyan
versions = {
:pmui_ver => getVersion(Dir.pwd + "/vendor/colosa/pmUI"),
:pmui_hash => pmuiHash,
:mafe_ver => getVersion(Dir.pwd + "/vendor/colosa/MichelangeloFE"),
:mafe_hash => mafeHash,
:pmdynaform_ver => getVersion(Dir.pwd + "/vendor/colosa/pmDynaform"),
:pmdynaform_hash => pmdynaformHash
}
File.open(targetDir+"/versions", 'w+') do |writeFile|
writeFile.write versions.to_json
end
puts "-- DONE --\n".bold
#task argv1.to_sym do ; end
end
def buildPmUi(homeDir, targetDir, mode)
puts "\nBuilding PMUI library".green.bold
# Defining target directories
pmUIDir = targetDir + "/pmUI"
pmUIFontsDir = targetDir + "/fonts"
jsTargetDir = targetDir + "/js"
cssTargetDir = targetDir + "/css"
imgTargetDir = targetDir + "/img"
version = getVersion(homeDir)
puts "Generating Theme files"
themeDir = Dir.pwd + "/vendor/colosa/MichelangeloFE/themes/mafe"
executeInto(homeDir, ["compileTheme[#{themeDir}]", "js"])
puts "\nCopying lib files into: #{pmUIDir}".bold
copyFiles({
"#{homeDir}/build/js/pmui-#{version}.js" => "#{pmUIDir}/pmui.min.js",
"#{themeDir}/build/pmui-mafe.css" => "#{pmUIDir}/pmui.min.css",
"#{themeDir}/build/images/*.png" => "#{targetDir}/css/images/",
"#{homeDir}/img/*" => "#{imgTargetDir}"
})
puts "\nCopying lib files into: #{jsTargetDir}".bold
copyFiles({homeDir + "/libraries/restclient/restclient-min.js" => "#{jsTargetDir}/restclient.min.js"})
puts "\nCopying font files into: #{pmUIFontsDir}".bold
theme = "mafe"
copyFiles({"#{homeDir}/themes/#{theme}/fonts/*" => "#{pmUIFontsDir}"})
puts "\nPMUI Build Finished".magenta
end
def buildPmdynaform(homeDir, targetDir, mode)
puts "\nBuilding PmDynaform library".green.bold
# Defining target directories
pmdynaformDir = targetDir + "/pmdynaform"
executeInto(homeDir, [ "default"])
system("cp -r #{homeDir}/build #{pmdynaformDir}")
system("cp -r #{homeDir}/libs #{pmdynaformDir}")
system("rm #{pmdynaformDir}/build/appBuild.js")
readyForm = "$(document).ready(function () {var data = document.location.search.replace(\"?data=\", \"\");data = decodeURIComponent(data);if (typeof data !== \"object\")data = JSON.parse(data);$(\".pmdynaform-container\").remove();new PMDynaform.View.Form({tagName: \"div\", renderTo: $(\".container\"), model: new PMDynaform.Model.Form(data)});});"
system("echo '#{readyForm}' >> #{pmdynaformDir}/build/appBuild.js ")
puts "\nPmDynaform Build Finished!".magenta
end
def buildMafe(homeDir, targetDir, mode)
puts "\nBuilding PM Michelangelo FE".green.bold
###
# Defining target directories
mafeDir = targetDir + "/mafe"
jsTargetDir = targetDir + "/js"
cssTargetDir = targetDir + "/css"
imgTargetDir = targetDir + "/img"
##
executeInto(homeDir, ["rmdir", "dir", "compass", "compress_js_files", "compress_app_files"])
#executeInto(homeDir, ["dir", "mafe"])
puts "\nCopying files into: #{mafeDir}".bold
copyFiles({
"#{homeDir}/build/js/designer.js" => "#{mafeDir}/designer.min.js",
"#{homeDir}/build/js/mafe.js" => "#{mafeDir}/mafe.min.js",
"#{homeDir}/build/css/mafe.css" => "#{mafeDir}/mafe.min.css",
"#{homeDir}/img/*.*" => "#{imgTargetDir}"
})
puts "\nCopying lib files into: #{jsTargetDir}".bold
copyFiles({
"#{homeDir}/lib/wz_jsgraphics/wz_jsgraphics.js" => "#{jsTargetDir}/wz_jsgraphics.js",
"#{homeDir}/lib/jQuery/jquery-1.10.2.min.js" => "#{jsTargetDir}/jquery-1.10.2.min.js",
"#{homeDir}/lib/underscore/underscore-min.js" => "#{jsTargetDir}/underscore-min.js",
"#{homeDir}/lib/jQueryUI/jquery-ui-1.10.3.custom.min.js" => "#{jsTargetDir}/jquery-ui-1.10.3.custom.min.js",
"#{homeDir}/lib/jQueryLayout/jquery.layout.min.js" => "#{jsTargetDir}/jquery.layout.min.js",
"#{homeDir}/lib/modernizr/modernizr.js" => "#{jsTargetDir}/modernizr.js"
})
puts "\nMichelangelo FE Build Finished\n".magenta
end
def prepareDirs(dirs)
homeDir = Dir.pwd
puts "Preparing Directories..."
dirs.each do |dir|
if File.directory?(dir)
puts "Removing #{dir}"
system "rm -rf #{dir}"
end
#Dir.mkdir(dir)
system("mkdir -p #{dir}")
end
end
def getVersion(path)
version = ""
Dir.chdir(path) do
version = `rake version`
end
if version.lines.count > 1
version = /([0-9\.]{5}+)/.match(version)
end
return version.strip
end
def getHash(path)
hash = ""
Dir.chdir(path) do
hash = `git rev-parse --short HEAD`
end
return hash.strip
end
def executeInto(path, tasks)
Dir.chdir(path) do
tasks.each do |task|
system "rake #{task}"
end
end
end
def copyFiles(files)
files.each do |from, to|
print " Copy ".green + from.gsub(Dir.pwd+'/vendor/colosa/', '')+' -> '.brown+to.gsub(Dir.pwd, '').gray
system('cp -Rf '+from+' '+to+' 2>&1')
if $? == 0
puts " (ok)".green
else
puts " (failed)".red
end
end
end
def getJsIncludeFiles
includeFiles = [
"workflow/public_html/lib/js/wz_jsgraphics.js",
"workflow/public_html/lib/js/jquery-1.10.2.min.js",
"workflow/public_html/lib/js/underscore-min.js",
"workflow/public_html/lib/js/jquery-ui-1.10.3.custom.min.js",
"workflow/public_html/lib/js/jquery.layout.min.js",
"workflow/public_html/lib/js/modernizr.js",
"workflow/public_html/lib/js/restclient.min.js",
"workflow/public_html/lib/pmUI/pmui.min.js",
"workflow/public_html/lib/mafe/mafe.min.js",
"workflow/public_html/lib/mafe/designer.min.js",
"gulliver/js/tinymce/jscripts/tiny_mce/tiny_mce.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/pmGrids/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/pmSimpleUploader/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/pmVariablePicker/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/visualchars/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/xhtmlxtras/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/wordcount/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/visualblocks/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/table/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/template/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/visualblocks/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/preview/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/print/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/style/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/save/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/tabfocus/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/searchreplace/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/paste/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/media/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/lists/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/insertdatetime/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/example/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/pagebreak/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/example_dependency/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/noneditable/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/fullpage/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/layer/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/legacyoutput/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/fullscreen/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/iespell/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/inlinepopups/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/autoresize/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/contextmenu/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/advlist/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/autolink/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/directionality/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/emotions/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/themes/advanced/editor_template.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/advhr/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/advlink/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/advimage/editor_plugin.js",
"gulliver/js/tinymce/jscripts/tiny_mce/plugins/nonbreaking/editor_plugin.js",
"gulliver/js/codemirror/lib/codemirror.js",
"gulliver/js/codemirror/mode/javascript/javascript.js",
"gulliver/js/codemirror/addon/edit/matchbrackets.js",
"gulliver/js/codemirror/mode/htmlmixed/htmlmixed.js",
"gulliver/js/codemirror/mode/xml/xml.js",
"gulliver/js/codemirror/mode/css/css.js",
"gulliver/js/codemirror/mode/clike/clike.js",
"gulliver/js/codemirror/mode/php/php.js",
]
return includeFiles
end
def getCssIncludeFiles
return [
"gulliver/js/codemirror/lib/codemirror.css",
# DEPRECATED
# "gulliver/js/tinymce/jscripts/tiny_mce/themes/advanced/skins/o2k7/ui.css",
# "gulliver/js/tinymce/jscripts/tiny_mce/themes/advanced/skins/o2k7/ui_silver.css",
# "gulliver/js/tinymce/jscripts/tiny_mce/plugins/inlinepopups/skins/clearlooks2/window.css",
# "gulliver/js/tinymce/jscripts/tiny_mce/themes/advanced/skins/o2k7/content.css",
#
"workflow/public_html/lib/pmUI/pmui.min.css",
"workflow/public_html/lib/mafe/mafe.min.css"
]
end
class String
def black; "\033[30m#{self}\033[0m" end
def red; "\033[31m#{self}\033[0m" end
def green; "\033[32m#{self}\033[0m" end
def brown; "\033[33m#{self}\033[0m" end
def blue; "\033[34m#{self}\033[0m" end
def magenta; "\033[35m#{self}\033[0m" end
def cyan; "\033[36m#{self}\033[0m" end
def gray; "\033[37m#{self}\033[0m" end
def bg_black; "\033[40m#{self}\0330m" end
def bg_red; "\033[41m#{self}\033[0m" end
def bg_green; "\033[42m#{self}\033[0m" end
def bg_brown; "\033[43m#{self}\033[0m" end
def bg_blue; "\033[44m#{self}\033[0m" end
def bg_magenta; "\033[45m#{self}\033[0m" end
def bg_cyan; "\033[46m#{self}\033[0m" end
def bg_gray; "\033[47m#{self}\033[0m" end
def bold; "\033[1m#{self}\033[22m" end
def reverse_color; "\033[7m#{self}\033[27m" end
end