cordovaplugincreator 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/cordovaplugincreator +62 -0
- data/lib/PluginDirectory.rb +36 -0
- data/lib/PluginExampleApp.rb +60 -0
- data/lib/PluginFiles.rb +163 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4cc1e1b94b7caeef37b6decbb785fae05c613b33
|
4
|
+
data.tar.gz: 124d9491fd0a62017a2bcea9201ae7a9dc0c717c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9b0afde26133f6fe3f3a55c5197404a660c6079095edde5e9abdfa4ce5af697545de0cf277a2c432dfdb83eac284a20353d24bd2b04aef909f0f22a276a7fc0d
|
7
|
+
data.tar.gz: 366549174ac96eab9202e86ab3418b3fc3707f80deb9190c9f8c82513d2c82d201409aeabdbb86e654f226746ecfb296a5ee0a598306c3eeadde0834f3bbe010
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
$LOAD_PATH << File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
|
+
require 'optparse'
|
5
|
+
require 'PluginDirectory.rb'
|
6
|
+
require 'PluginFiles.rb'
|
7
|
+
require 'PluginExampleApp.rb'
|
8
|
+
|
9
|
+
options = {}
|
10
|
+
|
11
|
+
option_parser = OptionParser.new do | opts |
|
12
|
+
opts.on("-n NAME") do | name |
|
13
|
+
options[:name] = name
|
14
|
+
end
|
15
|
+
|
16
|
+
opts.on("-p PATH") do | path |
|
17
|
+
options[:path] = path
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.on("-b BUNDLE") do | bundle_id |
|
21
|
+
if bundle_id
|
22
|
+
options[:bundle_id] = bundle_id
|
23
|
+
else
|
24
|
+
options[:bundle_id] = "com.yourcompany"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on("-v","--verbose") do
|
29
|
+
options[:verbose] = true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
option_parser.parse!
|
34
|
+
|
35
|
+
if options[:name] && options[:path]
|
36
|
+
|
37
|
+
plugin_directory = PluginDirectory.new options
|
38
|
+
|
39
|
+
plugin_directory.create_root_directory_for_plugin
|
40
|
+
plugin_directory.create_plugin_directory_structure
|
41
|
+
|
42
|
+
|
43
|
+
plugin_files = PluginFiles.new options
|
44
|
+
|
45
|
+
plugin_files.create_plugin_xml_file
|
46
|
+
plugin_files.create_plugin_readme
|
47
|
+
plugin_files.create_package_file
|
48
|
+
plugin_files.create_ios_header_file
|
49
|
+
plugin_files.create_ios_implementation_file
|
50
|
+
plugin_files.create_android_source_file
|
51
|
+
plugin_files.create_javascript_source_file
|
52
|
+
|
53
|
+
|
54
|
+
plugin_example = PluginExampleApp.new options
|
55
|
+
|
56
|
+
plugin_example.create_example_app_for_testing
|
57
|
+
plugin_example.install_plugin
|
58
|
+
plugin_example.build_example_app
|
59
|
+
|
60
|
+
else
|
61
|
+
puts "A valid plugin name AND path are required"
|
62
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class PluginDirectory
|
2
|
+
|
3
|
+
def initialize(options)
|
4
|
+
@name, @path, @verbose = options[:name], options[:path], options[:verbose]
|
5
|
+
end
|
6
|
+
|
7
|
+
public
|
8
|
+
|
9
|
+
def create_root_directory_for_plugin
|
10
|
+
|
11
|
+
if @verbose
|
12
|
+
puts "Creating Plugin Root Directory"
|
13
|
+
end
|
14
|
+
|
15
|
+
unless @path == nil
|
16
|
+
Dir.chdir(@path.to_s)
|
17
|
+
Dir.mkdir(@name.to_s)
|
18
|
+
Dir.chdir(@name.to_s)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_plugin_directory_structure
|
23
|
+
if @verbose
|
24
|
+
puts "Creating Plugin Directory Structure"
|
25
|
+
end
|
26
|
+
|
27
|
+
Dir.mkdir("src")
|
28
|
+
Dir.mkdir("www")
|
29
|
+
|
30
|
+
Dir.chdir("src")
|
31
|
+
Dir.mkdir("ios")
|
32
|
+
Dir.mkdir("android")
|
33
|
+
|
34
|
+
Dir.chdir(@path.to_s + "/" + @name.to_s)
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
class PluginExampleApp
|
2
|
+
def initialize options
|
3
|
+
@name, @path, @bundle_id, @verbose = options[:name], options[:path], options[:bundle_id], options[:verbose]
|
4
|
+
end
|
5
|
+
|
6
|
+
def create_example_app_for_testing
|
7
|
+
if @verbose
|
8
|
+
puts "Creating Example Cordova App for Plugin"
|
9
|
+
end
|
10
|
+
|
11
|
+
Dir.chdir(@path)
|
12
|
+
|
13
|
+
if @verbose
|
14
|
+
puts "Running Create Command"
|
15
|
+
end
|
16
|
+
|
17
|
+
create_successful = system("cordova create #{@name}_example #{@bundle_id}.#{@name} #{@name}")
|
18
|
+
|
19
|
+
if @verbose && create_successful
|
20
|
+
puts "Create Command Successful"
|
21
|
+
end
|
22
|
+
|
23
|
+
Dir.chdir("#{@name}_example")
|
24
|
+
|
25
|
+
if @verbose
|
26
|
+
puts "Adding platforms"
|
27
|
+
end
|
28
|
+
|
29
|
+
system("cordova platform add ios")
|
30
|
+
system("cordova platform add android")
|
31
|
+
|
32
|
+
if @verbose
|
33
|
+
puts "Platforms added"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def install_plugin
|
38
|
+
if @verbose
|
39
|
+
puts "Adding our plugin"
|
40
|
+
end
|
41
|
+
|
42
|
+
plugin_successful = system("cordova plugin add #{@path}/#{@name}")
|
43
|
+
|
44
|
+
if @verbose && plugin_successful
|
45
|
+
puts "Plugin installed successfully"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def build_example_app
|
50
|
+
if @verbose
|
51
|
+
puts "Running Build command"
|
52
|
+
end
|
53
|
+
|
54
|
+
build_successful = system("cordova build")
|
55
|
+
|
56
|
+
if @verbose && build_successful
|
57
|
+
puts "Built successfully"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/PluginFiles.rb
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
class PluginFiles
|
2
|
+
def initialize(options)
|
3
|
+
@name, @path, @bundle_id, @verbose = options[:name], options[:path], options[:bundle_id], options[:verbose]
|
4
|
+
end
|
5
|
+
|
6
|
+
def create_plugin_xml_file
|
7
|
+
if @verbose
|
8
|
+
puts "Creating Plugin XML File"
|
9
|
+
end
|
10
|
+
|
11
|
+
bundle_id_as_path = @bundle_id.gsub("\.", "\/")
|
12
|
+
|
13
|
+
plugin_template = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
14
|
+
<plugin xmlns=\"http://apache.org/cordova/ns/plugins/1.0\"
|
15
|
+
id=\"#{@bundle_id}.#{@name}\" version=\"0.0.1\">
|
16
|
+
<name>#{@name}</name>
|
17
|
+
<description>#{@name}</description>
|
18
|
+
<license>Apache 2.0</license>
|
19
|
+
<keywords></keywords>
|
20
|
+
<js-module src=\"www/#{@name}.js\" name=\"#{@name}\">
|
21
|
+
<clobbers target=\"#{@name}\" />
|
22
|
+
</js-module>
|
23
|
+
<platform name=\"android\">
|
24
|
+
<config-file target=\"res/xml/config.xml\" parent=\"/*\">
|
25
|
+
<feature name=\"#{@name}\">
|
26
|
+
<param name=\"android-package\" value=\"#{@bundle_id}.#{@name}\" />
|
27
|
+
</feature>
|
28
|
+
</config-file>
|
29
|
+
<source-file src=\"src/android/CDV#{@name}.java\" target-dir=\"src/#{bundle_id_as_path}/#{@name}/\" />
|
30
|
+
</platform>
|
31
|
+
<platform name=\"ios\">
|
32
|
+
<config-file target=\"config.xml\" parent=\"/*\">
|
33
|
+
<feature name=\"#{@name}\">
|
34
|
+
<param name=\"ios-package\" value= \"CDV#{@name}\" />
|
35
|
+
</feature>
|
36
|
+
</config-file>
|
37
|
+
<header-file src=\"src/ios/CDV#{@name}.h\" target-dir=\"#{@name}/Classes\" />
|
38
|
+
<source-file src=\"src/ios/CDV#{@name}.m\" target-dir=\"#{@name}/Classes\" />
|
39
|
+
</platform>
|
40
|
+
</plugin>"
|
41
|
+
|
42
|
+
File.write(Dir.pwd + "/plugin.xml", plugin_template)
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_plugin_readme
|
46
|
+
if @verbose
|
47
|
+
puts "Creating Plugin README file"
|
48
|
+
end
|
49
|
+
|
50
|
+
File.write(Dir.pwd + "/README.md", "##{@name}")
|
51
|
+
end
|
52
|
+
|
53
|
+
def create_package_file
|
54
|
+
if @verbose
|
55
|
+
puts "Creating Plugin Package file"
|
56
|
+
end
|
57
|
+
|
58
|
+
package_template = "{
|
59
|
+
\"version\": \"0.0.1\",
|
60
|
+
\"name\": \"#{@bundle_id}.#{@name}\",
|
61
|
+
\"cordova_name\": \"#{@name}\",
|
62
|
+
\"description\": \"#{@name}\",
|
63
|
+
\"license\": \"MIT\",
|
64
|
+
\"keywords\": [],
|
65
|
+
\"engines\": [
|
66
|
+
{
|
67
|
+
\"name\": \"cordova\",
|
68
|
+
\"version\": \">=3.0.0\"
|
69
|
+
}
|
70
|
+
]
|
71
|
+
}"
|
72
|
+
|
73
|
+
File.write(Dir.pwd + "/package.json", package_template)
|
74
|
+
end
|
75
|
+
|
76
|
+
def create_ios_header_file
|
77
|
+
|
78
|
+
if @verbose
|
79
|
+
puts "Creating iOS header file"
|
80
|
+
end
|
81
|
+
|
82
|
+
ios_header_template = "
|
83
|
+
//CDV#{@name}
|
84
|
+
//
|
85
|
+
#import <Cordova/CDV.h>
|
86
|
+
|
87
|
+
@interface #{@name} : CDVPlugin
|
88
|
+
@end
|
89
|
+
"
|
90
|
+
|
91
|
+
Dir.chdir(Dir.pwd + "/src/ios")
|
92
|
+
File.write(Dir.pwd + "/CDV#{@name}.h", ios_header_template)
|
93
|
+
end
|
94
|
+
|
95
|
+
def create_ios_implementation_file
|
96
|
+
if @verbose
|
97
|
+
puts "Creating iOS source file"
|
98
|
+
end
|
99
|
+
|
100
|
+
ios_implementation_template = "
|
101
|
+
//CDV#{@name}.m
|
102
|
+
//
|
103
|
+
#import \"CDV#{@name}.h\"
|
104
|
+
|
105
|
+
@implementation #{@name}
|
106
|
+
@end
|
107
|
+
"
|
108
|
+
|
109
|
+
File.write(Dir.pwd + "/CDV#{@name}.m", ios_implementation_template)
|
110
|
+
end
|
111
|
+
|
112
|
+
def create_android_source_file
|
113
|
+
if @verbose
|
114
|
+
puts "Creating Android source file"
|
115
|
+
end
|
116
|
+
|
117
|
+
android_source_template = "
|
118
|
+
/**
|
119
|
+
* #{@name}
|
120
|
+
*/
|
121
|
+
|
122
|
+
package #{@bundle_id}.#{@name};
|
123
|
+
|
124
|
+
import org.apache.cordova.CallbackContext;
|
125
|
+
import org.apache.cordova.CordovaPlugin;
|
126
|
+
import org.apache.cordova.PluginResult;
|
127
|
+
import org.apache.cordova.PluginResult.Status;
|
128
|
+
import org.json.JSONArray;
|
129
|
+
import org.json.JSONException;
|
130
|
+
import org.json.JSONObject;
|
131
|
+
import java.util.Iterator;
|
132
|
+
|
133
|
+
public class CDV#{@name} extends CordovaPlugin {
|
134
|
+
|
135
|
+
@Override
|
136
|
+
public boolean execute(String action, JSONArray inputs, CallbackContext callbackContext) throws JSONException {
|
137
|
+
PluginResult result = null;
|
138
|
+
callbackContext.sendPluginResult(result);
|
139
|
+
return true;
|
140
|
+
}
|
141
|
+
}
|
142
|
+
"
|
143
|
+
|
144
|
+
Dir.chdir(@path + "/" + @name + "/" + "src/android")
|
145
|
+
File.write(Dir.pwd + "/CDV#{@name}.java", android_source_template)
|
146
|
+
end
|
147
|
+
|
148
|
+
def create_javascript_source_file
|
149
|
+
if @verbose
|
150
|
+
puts "Creating JavaScript source file"
|
151
|
+
end
|
152
|
+
|
153
|
+
javascript_source_file = "
|
154
|
+
var #{@name} = {
|
155
|
+
};
|
156
|
+
|
157
|
+
module.exports = #{@name};
|
158
|
+
"
|
159
|
+
|
160
|
+
Dir.chdir(@path + "/" + @name + "/" + "www")
|
161
|
+
File.write(Dir.pwd + "/#{@name}.js", javascript_source_file)
|
162
|
+
end
|
163
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cordovaplugincreator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Don Marges
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: optparse
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: A generator for creating Cordova plugins. Building a Cordova Plugin from
|
28
|
+
scratch can be cumbersome as there is a very specific structure to follow. This
|
29
|
+
creates everything for you!
|
30
|
+
email: donniemarges@gmail.com
|
31
|
+
executables:
|
32
|
+
- cordovaplugincreator
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- bin/cordovaplugincreator
|
37
|
+
- lib/PluginDirectory.rb
|
38
|
+
- lib/PluginExampleApp.rb
|
39
|
+
- lib/PluginFiles.rb
|
40
|
+
homepage: http://rubygems.org/gems/cordovaplugincreator
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata: {}
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 2.2.2
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: Cordova Plugin Creator
|
64
|
+
test_files: []
|