phonegap-build 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in phonegap.gemspec
4
+ gemspec
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.join(File.dirname(__FILE__), *%w[.. lib])
4
+
5
+ require 'optparse'
6
+ require 'phonegap'
7
+
8
+ options = {
9
+ platforms: [],
10
+ config: "debug",
11
+ target: "emulator",
12
+ name: "app",
13
+ build: true
14
+ }
15
+
16
+ opts = OptionParser.new do |opts|
17
+ opts.summary_width = 25
18
+ opts.banner = "Usage: phonegap [OPTIONS] PATH"
19
+
20
+ opts.separator ""
21
+ opts.separator "Configuration:"
22
+
23
+ opts.on("--ios", "Compile iOS applications") do |v|
24
+ options[:platforms] << :ios
25
+ end
26
+
27
+ opts.on("--android", "Compile Android applications") do |v|
28
+ options[:platforms] << :android
29
+ end
30
+
31
+ opts.separator ""
32
+ opts.separator "Optional:"
33
+
34
+ opts.on("--target [TARGET]", String, "Either 'device' or 'emulator'") do |v|
35
+ options[:target] = v
36
+ end
37
+
38
+ opts.on("--config [TYPE]", String, "Either 'debug' or 'release'") do |v|
39
+ options[:config] = v
40
+ end
41
+
42
+ opts.on("--name [NAME]", String, "Application name") do |v|
43
+ options[:name] = v
44
+ end
45
+
46
+ opts.on("--[no-]build", "Build application (default is true)") do |v|
47
+ options[:build] = v
48
+ end
49
+
50
+ opts.separator ""; opts.separator "Miscellaneous:"
51
+
52
+ opts.on_tail("-?", "--help", "Display this usage information") do
53
+ puts "#{opts}\n"
54
+ exit
55
+ end
56
+
57
+ opts.on_tail("-v", "--version", "Display version") do |v|
58
+ puts "PhoneGap #{PhoneGap::VERSION}"
59
+ exit
60
+ end
61
+
62
+ opts.parse!
63
+ end
64
+
65
+ path = ARGV[0]
66
+
67
+ if path.nil? or options[:platforms].empty?
68
+ puts "#{opts}\n"
69
+ exit
70
+ end
71
+
72
+ PhoneGap.build(path, options)
@@ -0,0 +1,15 @@
1
+ require "phonegap/version"
2
+
3
+ module PhoneGap
4
+ autoload :Builder, "phonegap/builder"
5
+ autoload :Builders, "phonegap/builders"
6
+
7
+ def build(path, options = {})
8
+ platforms = options[:platforms] || []
9
+ platforms.each do |platform|
10
+ Builders.for_platform(platform).build(path, options)
11
+ end
12
+ end
13
+
14
+ extend self
15
+ end
@@ -0,0 +1,76 @@
1
+ require "fileutils"
2
+ require "pathname"
3
+
4
+ module PhoneGap
5
+ class Builder
6
+ class << self
7
+ def register(platform)
8
+ @platform = platform
9
+ Builders.register self
10
+ end
11
+
12
+ def platform
13
+ @platform
14
+ end
15
+
16
+ def build(path, options)
17
+ self.new(path, options).build
18
+ end
19
+ end
20
+
21
+ attr_reader :options, :path, :build_path, :web_path
22
+
23
+ def initialize(path, options)
24
+ @options = options
25
+ @path = Pathname.new(path)
26
+ raise "Path doesn't exist" unless @path.exist?
27
+
28
+ @web_path = @path.join("public") if @path.join("public").exist?
29
+ @web_path = @path.join("www") if @path.join("www").exist?
30
+
31
+ unless @web_path
32
+ @web_path = @path.dup
33
+ @path = @path.parent
34
+ end
35
+
36
+ @build_path = @path.join("build", platform)
37
+ end
38
+
39
+ def build
40
+ raise "Implement"
41
+ end
42
+
43
+ protected
44
+ def setup_build
45
+ FileUtils.rm_rf(build_path)
46
+ FileUtils.mkdir_p(build_path)
47
+ end
48
+
49
+ def setup_template
50
+ FileUtils.cp_r(template_path, build_path) if template_path.exist?
51
+ end
52
+
53
+ def setup_platform
54
+ local_platform_path = path.join("platforms", platform)
55
+ FileUtils.cp_r(local_platform_path, build_path) if local_platform_path.exist?
56
+ end
57
+
58
+ def setup_application
59
+ www_path = build_path.join("www")
60
+ www_path.rmtree
61
+ FileUtils.cp_r(web_path, www_path)
62
+ end
63
+
64
+ def template_path
65
+ Pathname.new(File.join(File.dirname(__FILE__), *%w{ .. .. templates }, platform))
66
+ end
67
+
68
+ def platform_path
69
+ Pathname.new(File.join(File.dirname(__FILE__), *%w{ .. .. platform }, platform))
70
+ end
71
+
72
+ def platform
73
+ self.class.platform.to_s
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,20 @@
1
+ module PhoneGap
2
+ module Builders
3
+ extend self
4
+
5
+ def for_platform(platform)
6
+ builders.find {|b| b.platform == platform }
7
+ end
8
+
9
+ def builders
10
+ @builders ||= []
11
+ end
12
+
13
+ def register(builder)
14
+ builders << builder
15
+ end
16
+ end
17
+ end
18
+
19
+ require "phonegap/builders/ios"
20
+ require "phonegap/builders/android"
@@ -0,0 +1,11 @@
1
+ module PhoneGap
2
+ module Builders
3
+ class Android < Builder
4
+ register :android
5
+
6
+ def build
7
+ raise "Not implemented yet"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,32 @@
1
+ module PhoneGap
2
+ module Builders
3
+ class IOS < Builder
4
+ register :ios
5
+
6
+ def build
7
+ setup_build
8
+
9
+ create_script = platform_path.join("create_project.sh")
10
+ system(
11
+ create_script.to_s,
12
+ options[:name],
13
+ build_path.to_s
14
+ )
15
+
16
+ setup_template
17
+ setup_application
18
+ setup_platform
19
+
20
+ return if options[:build] == false
21
+
22
+ build_script = platform_path.join("build.sh")
23
+ system(
24
+ build_script.to_s,
25
+ options[:config],
26
+ options[:target],
27
+ build_path.to_s
28
+ )
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module PhoneGap
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,18 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "phonegap/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "phonegap-build"
7
+ s.version = PhoneGap::VERSION
8
+ s.authors = ["Alex MacCaw"]
9
+ s.email = ["maccman@gmail.com"]
10
+ s.homepage = "http://github.com/maccman/phonegap"
11
+ s.summary = %q{Generate PhoneGap applications from the command-line}
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_paths = ["lib"]
17
+ s.executables = ["phonegap"]
18
+ end
@@ -0,0 +1,72 @@
1
+ #!/bin/bash
2
+
3
+ # iPhone OS Device SDKs:
4
+ # Device - iPhone OS 2.2.1 -sdk iphoneos2.2.1
5
+ # Device - iPhone OS 3.0 -sdk iphoneos3.0
6
+ # Device - iPhone OS 3.1 -sdk iphoneos3.1
7
+ #
8
+ # iPhone OS Simulator SDKs:
9
+ # Simulator - iPhone OS 2.2.1 -sdk iphonesimulator2.2.1
10
+ # Simulator - iPhone OS 3.0 -sdk iphonesimulator3.0
11
+ # Simulator - iPhone OS 3.1 -sdk iphonesimulator3.1
12
+ #
13
+ # run 'xcodebuild -showsdks' to show the valid sdks on the system
14
+
15
+ current_sdk_version=3.0
16
+ xcodebuild="/usr/bin/xcodebuild"
17
+
18
+ # check whether the xcodebuild command exists
19
+ if [ ! -f $xcodebuild ]; then
20
+ echo "$xcodebuild not found."
21
+ exit
22
+ fi
23
+
24
+ # check whether it is a proper build command (at least two arguments, configuration and xcode_proj_folder)
25
+ if [ $# -lt 2 ]; then
26
+ echo "Usage: $0 <configuration> [target] <xcode_proj_folder>"
27
+ echo " <configuration>: typically 'debug' or 'release'"
28
+ echo " [target]: either 'device' or 'emulator' (optional)"
29
+ echo " <xcode_proj_folder>: the path to the folder containing your Xcode project file"
30
+ exit
31
+ fi
32
+
33
+ # First argument is the build configuration
34
+ configuration="$1"
35
+
36
+ # Second argument may be the emulator/device parameter if available (thus 3rd argument is the xcode project path).
37
+ # If not, it will be the path to folder containing the xcode project path
38
+ sdk=""
39
+ xcodeproj_folder=""
40
+ archs="armv6 armv7"
41
+
42
+ if [ $2 == "emulator" ]; then
43
+ sdk="-sdk iphonesimulator$current_sdk_version"
44
+ xcodeproj_folder=$3
45
+ archs="i386"
46
+ elif [ $2 == "device" ]; then
47
+ sdk="-sdk iphoneos$current_sdk_version"
48
+ xcodeproj_folder=$3
49
+ else
50
+ xcodeproj_folder=$2
51
+ fi
52
+
53
+ # the next lines will title-case the configuration value
54
+ configuration_len=${#configuration}
55
+ non_first_letter_substring="`echo ${configuration:1:configuration_len-1}|tr '[A-Z]' '[a-z]'`"
56
+ first_letter="`echo ${configuration:0:1}|tr '[a-z]' '[A-Z]'`"
57
+ configuration=$first_letter$non_first_letter_substring
58
+
59
+ # Check whether the xcode project path exists
60
+ if [ ! -d $xcodeproj_folder ]; then
61
+ echo "Path to xcode folder '$xcodeproj_folder' not found."
62
+ exit
63
+ fi
64
+
65
+ echo 'PhoneGap: building...'
66
+
67
+ # change to the project directory, and run the build
68
+ cd $xcodeproj_folder
69
+ echo $xcodebuild -alltargets -configuration $configuration $sdk
70
+ $xcodebuild -alltargets -configuration $configuration $sdk VALID_ARCHS="$archs"
71
+
72
+ echo 'PhoneGap: build done.'
@@ -0,0 +1,114 @@
1
+ #!/bin/bash
2
+
3
+ # ############################################################################
4
+ #
5
+ # MIT licensed
6
+ # http://www.opensource.org/licenses/mit-license.php
7
+ #
8
+ # Script to create a new PhoneGap project from the PhoneGap Template.
9
+ # You need to install PhoneGapLib first (through the installer)
10
+ # before this script can work.
11
+ #
12
+ # Make sure you set the executable bit on this script. In Terminal.app, type:
13
+ # chmod 755 create_project.sh
14
+ #
15
+ # Usage:
16
+ # ./create_project.sh <PROJECT_NAME> <PATH_TO_PUT_NEW_PROJECT>
17
+ # <PROJECT_NAME> - the name of the project (cannot have spaces in it)
18
+ # <PATH_TO_PUT_NEW_PROJECT> - the path to put the new project folder in
19
+ #
20
+ # Written by Shazron Abdullah (2011)
21
+ #
22
+ # ############################################################################
23
+
24
+ set -o pipefail
25
+
26
+ function checkExitCode {
27
+ rc=$?
28
+ if [ $rc != 0 ] ; then
29
+ echo "Error $rc, exiting."
30
+ cleanUp
31
+ exit $rc
32
+ fi
33
+ }
34
+
35
+ function cleanUp {
36
+ echo 'Cleaning up...'
37
+ cd -
38
+ rm -rf $TEMP_PROJECT_DIR_PATH
39
+ }
40
+
41
+ PHONEGAP_TEMPLATE_PATH="$HOME/Library/Application Support/Developer/Shared/Xcode/Project Templates/PhoneGap/PhoneGap-based Application/"
42
+
43
+ # ##############################################
44
+ # SCRIPT ARGUMENTS
45
+ # ##############################################
46
+
47
+ # 1st argument: name of the project
48
+ PROJECT_NAME=$1
49
+
50
+ # 2nd argument: path to put new project
51
+ NEW_PROJECT_PATH=$2
52
+
53
+ # ##############################################
54
+ # CHECKS
55
+ # ##############################################
56
+
57
+ if [ ! -d "$PHONEGAP_TEMPLATE_PATH" ]; then
58
+ read -p "PhoneGapLib is not installed. Download the iOS PhoneGap installer from http://phonegap.com. Go there now (y/n)? "
59
+ [ "$REPLY" == "y" ] && open http://www.phonegap.com/download/
60
+ exit 1
61
+ fi
62
+
63
+ if [ ! -d "$NEW_PROJECT_PATH" ]; then
64
+ echo "The target folder '$NEW_PROJECT_PATH' does not exist."
65
+ exit 1
66
+ fi
67
+
68
+ NEW_PROJECT_PATH=`cd $NEW_PROJECT_PATH; pwd`
69
+
70
+ # ##############################################
71
+ # TEMPORARY WORKING DIRECTORY
72
+ # ##############################################
73
+
74
+ # create temporary working directory
75
+ TEMP_PROJECT_DIR_PATH=`mktemp -d -t 'phonegap'`
76
+ trap "{ cd - ; rm -rf $TEMP_PROJECT_DIR_PATH; exit 255; }" SIGINT
77
+ cd $TEMP_PROJECT_DIR_PATH
78
+
79
+ # ##############################################
80
+ # TEMPLATE COPY, FIND/REPLACE
81
+ # ##############################################
82
+
83
+ # copy PHONEGAP_TEMPLATE_PATH into TEMP_PROJECT_DIR_PATH
84
+ cp -r "$PHONEGAP_TEMPLATE_PATH" "$TEMP_PROJECT_DIR_PATH"
85
+
86
+ checkExitCode
87
+
88
+ # replace file contents of ___PROJECTNAME___ token
89
+ find "$TEMP_PROJECT_DIR_PATH" | xargs grep '___PROJECTNAME___' -sl | xargs -L1 sed -i "" "s/___PROJECTNAME___/${PROJECT_NAME}/g"
90
+
91
+ checkExitCode
92
+
93
+ # replace file contents of ___PROJECTNAMEASIDENTIFIER___ token
94
+ find "$TEMP_PROJECT_DIR_PATH" | xargs grep '___PROJECTNAMEASIDENTIFIER___' -sl | xargs -L1 sed -i "" "s/___PROJECTNAMEASIDENTIFIER___/${PROJECT_NAME}/g"
95
+
96
+ checkExitCode
97
+
98
+ # replace filenames that have ___PROJECTNAME___ token
99
+ cd "$TEMP_PROJECT_DIR_PATH";find . -d -name "*___PROJECTNAME___*" | awk '{print("mv "$1 " " $1)}' | sed "s/\(.*\)___PROJECTNAME___/\1${PROJECT_NAME}/g" | sh;
100
+
101
+ checkExitCode
102
+
103
+ # # replace filenames that have ___PROJECTNAMEASIDENTIFIER___ token
104
+ cd "$TEMP_PROJECT_DIR_PATH";find . -d -name "*___PROJECTNAMEASIDENTIFIER___*" | awk '{print("mv "$1" "$1)}' | sed "s/\(.*\)___PROJECTNAMEASIDENTIFIER___/\1${PROJECT_NAME}/g" | sh;
105
+
106
+ checkExitCode
107
+
108
+ # copy PHONEGAP_TEMPLATE_PATH into NEW_PROJECT_PATH
109
+ mkdir -p "$NEW_PROJECT_PATH"
110
+ cp -r "$TEMP_PROJECT_DIR_PATH/" "$NEW_PROJECT_PATH"
111
+
112
+ checkExitCode
113
+
114
+ exit 0
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: phonegap-build
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.2
6
+ platform: ruby
7
+ authors:
8
+ - Alex MacCaw
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-08-04 00:00:00 -05:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description:
18
+ email:
19
+ - maccman@gmail.com
20
+ executables:
21
+ - phonegap
22
+ extensions: []
23
+
24
+ extra_rdoc_files: []
25
+
26
+ files:
27
+ - .gitignore
28
+ - Gemfile
29
+ - Rakefile
30
+ - bin/phonegap
31
+ - lib/phonegap.rb
32
+ - lib/phonegap/builder.rb
33
+ - lib/phonegap/builders.rb
34
+ - lib/phonegap/builders/android.rb
35
+ - lib/phonegap/builders/ios.rb
36
+ - lib/phonegap/version.rb
37
+ - phonegap.gemspec
38
+ - platform/ios/build.sh
39
+ - platform/ios/create_project.sh
40
+ has_rdoc: true
41
+ homepage: http://github.com/maccman/phonegap
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options: []
46
+
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: "0"
61
+ requirements: []
62
+
63
+ rubyforge_project:
64
+ rubygems_version: 1.6.0
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Generate PhoneGap applications from the command-line
68
+ test_files: []
69
+