public
Created

Appnovation build script for SproutCore->PhoneGap apps

  • Download Gist
phonegap-build.rb
Ruby
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
# ruby phonegap-sc.rb -a alfresco -o ../output/path
require 'fileutils'
require 'pathname'
require 'optparse'
 
config = {}
argparser = OptionParser.new {|opts|
opts.on('-a', '--application-name [name]', "The application name (required)"){|name|
config[:app_name] = name
}
config[:build] = true
opts.on('-n', '--no-build', "Do not run sc-build") {
config[:build] = false
}
config[:source] = '.'
opts.on('-s', '--source [directory]', "Source path (default: .)") {|source|
config[:source] = source
}
config[:output] = 'www'
opts.on('-o', '--output [directory]', "Input path (default: www)") {|output|
config[:output] = output
}
 
config[:mode] = 'production'
opts.on('-M', '--mode [mode]', "Mode (default: production)") {|mode|
config[:mode] = mode
}
}
argparser.parse!
 
config[:input] = File.join('tmp', 'build')
config[:source] = File.expand_path(config[:source])
config[:output] = File.expand_path(config[:output])
 
start_time = Time.now
 
puts "Starting at #{start_time.localtime}"
 
if config[:build] or not File.exists?(config[:input])
build_bin = File.join(config[:source], 'bin', 'sc-build')
build_bin = 'sc-build' unless File.exist?(build_bin)
puts "Building: #{build_bin} #{config[:app_name]} -r --languages=en --mode=#{config[:mode]}"
FileUtils.rm_rf config[:input]
`#{build_bin} #{config[:app_name]} -r --languages=en --mode=#{config[:mode]}`
end
 
built_path = Dir[File.join(config[:input], 'static', config[:app_name])]
 
puts "Copying: #{config[:output]}"
FileUtils.rm_rf config[:output]
FileUtils.mkdir_p config[:output] + "/static/#{config[:app_name]}"
deployed_path = Dir[File.join(config[:output], 'static')]
FileUtils.cp_r built_path, deployed_path
 
 
 
puts "Cleanup"
 
app_path = Dir[File.join(config[:output], 'static', config[:app_name], 'en', '*')].first
 
['index.html', 'javascript-packed.js'].each do |file_name|
path = File.join(app_path, file_name)
if File.exist?(path)
data = File.read(path)
data.gsub! /\/static\//, 'static/'
File.open(path, 'w+'){|f| f.puts data }
end
end
 
['stylesheet-packed.css'].each do |file_name|
path = File.join(app_path, file_name)
if File.exist?(path)
data = File.read(path)
data.gsub! /\/static\//, '../../../../static/'
File.open(path, 'w+'){|f| f.puts data }
end
end
 
FileUtils.mv "#{app_path}/index.html", "#{config[:output]}/index.html"
 
elapsed = Time.now - start_time
 
puts "Ready (took #{elapsed.to_i}s)"

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.