Skip to content

Instantly share code, notes, and snippets.

@wagenet
Created October 4, 2010 15:25
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save wagenet/609875 to your computer and use it in GitHub Desktop.
Save wagenet/609875 to your computer and use it in GitHub Desktop.
#######################
#### DOCUMENTATION ####
#######################
#
# Run as:
#
# ruby phonegap-sc.rb APP_NAME
# ruby phonegap-sc.rb APP_NAME PROJECT_PATH
# ruby phonegap-sc.rb APP_NAME PROJECT_PATH OUTPUT_PATH
#
# This script will build your app and then modify the output
# into a form suitable for PhoneGap. By default, the output
# directory will be 'www'. You should be able to replace the
# default PhoneGap www folder with this.
require 'fileutils'
require 'pathname'
app_name = ARGV[0]
source_path = File.expand_path(ARGV[1] || '.')
build_bin = File.join(source_path, 'bin', 'sc-build')
build_bin = 'sc-build' unless File.exist?(build_bin)
input_path = File.join('tmp', 'build')
output_path = ARGV[2] || 'www'
puts "Building"
FileUtils.rm_rf input_path
`#{build_bin} #{app_name} -r --languages=en`
puts "Copying to #{output_path}"
FileUtils.rm_rf output_path
FileUtils.cp_r input_path, output_path
app_path = Dir[File.join(output_path, 'static', app_name, 'en', '*')].first
puts "Cleanup"
['index.html', 'javascript.js', 'stylesheet.css'].each do |file_name|
path = File.join(app_path, file_name)
data = File.read(path)
data.gsub! /\/static/, 'static'
File.open(path, 'w+'){|f| f.puts data }
end
FileUtils.mv "#{app_path}/index.html", "#{output_path}/index.html"
puts "Ready"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment