bluepotion 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/bluepotion +200 -0
  3. data/lib/project/version.rb +1 -1
  4. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 843068c1c8ba6af4bd308d825109986b0361d4b1
4
- data.tar.gz: a7733756b70dde4407a24f100e0513c9d31df1c3
3
+ metadata.gz: 39918d184e5ae449d4e9df5fd437de0a52d6b78c
4
+ data.tar.gz: 9692a88bd0a3b3c0c5496e8429c55aed9fef0ae8
5
5
  SHA512:
6
- metadata.gz: 550fd29b558508b3c1c963b49f62c96a2d15c2e1542de02f40a0df473159a6b37015321b9824a3a1f1d53578b1dccfd08a6a39bc8adde46632305cce013f33cf
7
- data.tar.gz: 4bcb7d36b43f1c347d78400337a420dc298f90bd82ad3341fff6684918298f01c29c34a80a1e843bbc64223b8c8e91b1e05f0ada3daf29eb3151a28d7953f752
6
+ metadata.gz: ac5ff6f73940d83cc30ec744c3fa4996e10c4cdeff56cb6dd33a8bd000e008e3efd4411a69d8c3292328c57edb860c6132f161227fe813de27bc59e2c16fead8
7
+ data.tar.gz: e9a3227eeae6afe7e8570de4e97e7ba4a47c5d9b4af966f40f18888a34da35c9dc0552d5eecc148f5341e6fd6cdd5c63d4a76673322efe8855c449cebaead502
@@ -0,0 +1,200 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "erb"
4
+ require "rubygems"
5
+ require 'open-uri'
6
+
7
+ $:.unshift(File.join(File.dirname(__FILE__), "/../lib/project"))
8
+ require "version"
9
+
10
+ class PotionCommandLine
11
+ HELP_TEXT = %{ potion version #{BluePotion::VERSION}
12
+
13
+ Some things you can do with the bluepotion command:
14
+
15
+ > bluepotion create my_new_app
16
+
17
+ > bluepotion create screen foo
18
+
19
+ Misc
20
+ > bluepotion -h, --help
21
+ > bluepotion -v, --version
22
+ }
23
+
24
+ class << self
25
+ VALID_CREATE_TYPES = [
26
+ :screen
27
+ ]
28
+
29
+ def create(template_or_app_name, *options)
30
+ if template_or_app_name.nil?
31
+ puts "BluePotion - Invalid command, try adding an application name or template name."
32
+ return
33
+ end
34
+
35
+ options.compact!
36
+ if options.first == 'dry_run'
37
+ @dry_run = true
38
+ options.slice!(0)
39
+ end
40
+
41
+ if options.count > 0
42
+ unless options.first.include?('--')
43
+ name = options.slice!(0)
44
+ unless VALID_CREATE_TYPES.include?(template_or_app_name.to_sym)
45
+ puts "BluePotion - Invalid command, do something like this: bluepotion create screen foo\n"
46
+ return
47
+ end
48
+ end
49
+ end
50
+
51
+ if name
52
+ insert_from_template(template_or_app_name, name)
53
+ else
54
+ #ensure_template_dir
55
+ create_app(template_or_app_name)
56
+ options.each do |option|
57
+ if SKIP_FLAGS.include?(option)
58
+ Dir.chdir("./#{template_or_app_name}")
59
+ remove(option.split('-').last, true)
60
+ Dir.chdir('..')
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ def create_app(app_name)
67
+ puts ' Creating app'
68
+
69
+ `motion create --template=git@github.com:infinitered/blutpotion-template.git #{app_name}`
70
+
71
+ puts %{
72
+ Complete. Things you should do:
73
+ > cd #{app_name}
74
+ > bundle
75
+ > rake newclear
76
+ (main)> exit
77
+ }
78
+ end
79
+
80
+ def template_path(template_name)
81
+ sub_path = "templates/#{template_name}/"
82
+
83
+ # First check local directory, use that if it exists
84
+ if Dir.exist?("#{Dir.pwd}/#{sub_path}")
85
+ "#{Dir.pwd}/#{sub_path}"
86
+ else # Then check the gem
87
+ begin
88
+ spec = Gem::Specification.find_by_name("bluepotion")
89
+ gem_root = spec.gem_dir
90
+ "#{gem_root}/#{sub_path}"
91
+ rescue Exception => e
92
+ puts "BluePotion - could not find template directory\n"
93
+ nil
94
+ end
95
+ end
96
+ end
97
+
98
+ def insert_from_template(template_name, name)
99
+ return unless %w{screenl}.include? template_name
100
+
101
+ puts "\n Creating #{template_name}: #{name}\n\n"
102
+
103
+ return unless (@template_path = template_path(template_name))
104
+ files = Dir["#{@template_path}**/*"].select {|f| !File.directory? f}
105
+
106
+ @name = name.gsub(/_?(screen|controller|stylesheet)/,'')
107
+ @name_camel_case = @name.split('_').map{|word| word.capitalize}.join
108
+
109
+ files.each do |template_file_path_and_name|
110
+ @in_app_path = File.dirname(template_file_path_and_name).gsub(@template_path, '')
111
+ @ext = File.extname(template_file_path_and_name)
112
+ @file_name = File.basename(template_file_path_and_name, @ext)
113
+
114
+ @new_file_name = @file_name.gsub('name', @name)
115
+ @new_file_path_name = "#{Dir.pwd}/#{@in_app_path}/#{@new_file_name}#{@ext}"
116
+
117
+ if @dry_run
118
+ puts "\n Instance vars:"
119
+ self.instance_variables.each{|var| puts " #{var} = #{self.instance_variable_get(var)}"}
120
+ puts
121
+ end
122
+
123
+ if Dir.exist?(@in_app_path)
124
+ puts " Using existing directory: #{@in_app_path}"
125
+ else
126
+ puts " \u0394 Creating directory: #{@in_app_path}"
127
+ Dir.mkdir(@in_app_path) unless @dry_run
128
+ end
129
+
130
+ results = load_and_parse_erb(template_file_path_and_name)
131
+
132
+ if File.exists?(@new_file_path_name)
133
+ puts " X File exists, SKIPPING: #{@new_file_path_name}"
134
+ else
135
+ puts " \u0394 Creating file: #{@new_file_path_name}"
136
+ File.open(@new_file_path_name, 'w+') { |file| file.write(results) } unless @dry_run
137
+ end
138
+ end
139
+
140
+ puts "\n Done"
141
+ end
142
+
143
+ def load_and_parse_erb(template_file_name_and_path)
144
+ template_file = File.open(template_file_name_and_path, 'r').read
145
+ erb = ERB.new(template_file)
146
+ erb.result(binding)
147
+ end
148
+
149
+ def remove(type, show_output=true)
150
+ case type
151
+ when 'foo'
152
+ #remove_lines('Gemfile', /gem ('|")cdq('|")/, show_output)
153
+ #remove_lines('app/app_delegate.rb', /include CDQ|cdq.setup/, show_output)
154
+ #remove_lines('Rakefile', /schema:build/, show_output)
155
+ #File.delete('schemas/0001_initial.rb') if File.exists?('schemas/0001_initial.rb')
156
+ #File.delete('resources/cdq.yml') if File.exists?('resources/cdq.yml')
157
+ #Dir.delete('schemas') if Dir.exists?('schemas')
158
+ else
159
+ puts "BluePotion - Invalid command option '#{type}', bluepotion remove only works with foo"
160
+ end
161
+ end
162
+
163
+ def remove_lines(file, match, show_output)
164
+ puts "Modifying #{file}" if show_output
165
+ data = IO.readlines(file)
166
+ File.open(file, 'w') do |f|
167
+ data.each do |line|
168
+ unless line =~ match
169
+ f.puts line
170
+ end
171
+ end
172
+ end
173
+ end
174
+
175
+ end
176
+ end
177
+
178
+ # Process input, execute actions
179
+ unless ARGV.length > 0
180
+ puts "bluepotion - Invalid command, do something like this: bluepotion create my_new_app\n"
181
+ puts PotionCommandLine::HELP_TEXT
182
+ exit
183
+ end
184
+
185
+ action = ARGV[0]
186
+ query = ARGV[1]
187
+
188
+ case action
189
+ when 'create'
190
+ PotionCommandLine.create(ARGV[1], ARGV[2], ARGV[3])
191
+ when 'remove'
192
+ PotionCommandLine.remove(ARGV[1])
193
+ when '--help', '-h'
194
+ puts PotionCommandLine::HELP_TEXT
195
+ when '-v', '--version'
196
+ puts BluePotion::VERSION
197
+ else
198
+ puts 'bluepotion - Invalid action'
199
+ puts PotionCommandLine::HELP_TEXT
200
+ end
@@ -1,3 +1,3 @@
1
1
  module BluePotion
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,11 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bluepotion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - InfiniteRed
8
- - ClearSight Studio
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
@@ -28,12 +27,13 @@ dependencies:
28
27
  description: BluePotion - Just like RedPotion, but for Android
29
28
  email:
30
29
  - hello@infinitered.com
31
- - hello@clearsightstudio.com
32
- executables: []
30
+ executables:
31
+ - bluepotion
33
32
  extensions: []
34
33
  extra_rdoc_files: []
35
34
  files:
36
35
  - README.md
36
+ - bin/bluepotion
37
37
  - lib/bluepotion.rb
38
38
  - lib/project/ext/activity.rb
39
39
  - lib/project/ext/array_list.rb