heroku_whiz 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c3bc391ad209aec5d41a9e32f27ea91fe8c29d58c3e69d3432a41ab7848fc9ee
4
- data.tar.gz: cf016eb8d4ee4acd39276401d90a82b6eafceb3649c0f4b57bd115f2dceda2c7
3
+ metadata.gz: f70cf65decd9910c18bb065d30defe5a9f30e61ea8dbe7adf95995c5838d3c15
4
+ data.tar.gz: bb3ce5eecb89cf1ec143b9b8a5c3082a36ebd55b9c8bd588375058baf7c0f96f
5
5
  SHA512:
6
- metadata.gz: 2d71fbce6a42e1998f6a733bf2ca12bbc6c9bb0eeee2a9e16020128395e0f1374b1dc54a953379afcfce7cddc1eae3920c9fae6f4669dd3947cb52296f31b69c
7
- data.tar.gz: caf12a507bf4f55ee42ca4705c45acf2a6699434eb4fa2a2cc09edb5906d5e05f6065ea5d9d86b0db1b3bce7e132d59d9cdfc6f1648bed46a8900b5d66713c31
6
+ metadata.gz: d7378be0f617fc11166e1c682a31c45a65aa5beb8df5e0731a3431989fa39f9d774f1664ac86c453f2f65add103b676ea3065cfdcc408d7edc0bf4d8595c1847
7
+ data.tar.gz: 34f5f3db437981f68c8748f0138555f53a7378b847551b2b66d7e71d398368cbb02176592c46eeb3f368a481eef12897cccaa5fd6cd2bf77671fe761831b2780
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/heroku_whiz.rb CHANGED
@@ -3,6 +3,8 @@
3
3
  # file: heroku_whiz.rb
4
4
 
5
5
  # created: 8th March 2022
6
+ # updated: 9th March 2022
7
+
6
8
  # description: Handy (experimental) Heroku gem for noobs to create a
7
9
  # simple Heroku app in a whiz!
8
10
 
@@ -14,7 +16,7 @@
14
16
  require 'open-uri'
15
17
  require 'fileutils'
16
18
  require 'clipboard'
17
-
19
+ require 'launchy'
18
20
 
19
21
  # Resources
20
22
  #
@@ -23,7 +25,8 @@ require 'clipboard'
23
25
 
24
26
  # Example usage:
25
27
  #
26
- # hw = HerokuWhiz.new dir: '/home/james/heroku', template: 'rack', appname: 'hello2', debug: true
28
+ # hw = HerokuWhiz.new dir: '/home/james/heroku', template: 'rack',
29
+ # appname: 'hello2', debug: true
27
30
  #
28
31
  # hw.wipe_clean # removes the previous local app file directory
29
32
  # hw.create # creates the local app file directory
@@ -33,52 +36,44 @@ require 'clipboard'
33
36
  # hw.app_url #=> e.g. https://frozen-dusk-65820.herokuapp.com/
34
37
 
35
38
 
36
- class HerokuWhiz
37
-
38
- def initialize(dir: '.', template: 'rack', appname: 'myapp',
39
- verbose: true, debug: false)
40
39
 
41
- @dir, @template, @appname, @verbose = dir, template, appname, verbose
40
+ class WhizBase
42
41
 
43
- @app_path = File.join(@dir, @appname)
42
+ def initialize(app_path, debug: false)
44
43
 
45
-
46
- end
47
-
48
- def app_url()
49
-
50
- app = `heroku config`.lines.first.split[1]
51
- s = "https://#{app}.herokuapp.com/"
52
-
53
- Clipboard.copy s
54
- puts 'app URL copied to clipboard.'
55
-
56
- return s
44
+ @app_path, debug = app_path, debug
57
45
 
58
46
  end
59
47
 
60
48
  def create()
61
49
 
62
- case @template.to_sym
63
- when :rack
64
- create_rack()
65
- else
66
- return puts 'template not recognised!'
67
- end
50
+ config = %q(
51
+ run lambda {|env|
52
+ [200, {'Content-Type'=>'text/plain'}, StringIO.new("Hello World!\n")]
53
+ })
68
54
 
69
- # build
70
- `bundle install`
71
- sleep 1
55
+ gemfile = %q(
56
+ source 'https://rubygems.org'
57
+ gem 'rack'
58
+ gem 'puma'
59
+ )
72
60
 
61
+ # Procfile: see https://devcenter.heroku.com/articles/procfile
62
+ # for more info
63
+ procfile = 'web: bundle exec rackup config.ru -p $PORT'
64
+
65
+ create_basefiles(config, gemfile, procfile)
73
66
  end
74
67
 
68
+ # currently only removes a file directory if there are no user created files
69
+ #
75
70
  def wipe_clean(setup=:local)
76
71
 
77
72
  return unless File.exists? @app_path
78
73
 
79
74
  # remove the app files
80
75
  #
81
- %w(Gemfile config.ru Gemfile.lock).each do |file|
76
+ %w(Gemfile config.ru Procfile Gemfile.lock).each do |file|
82
77
 
83
78
  puts 'removing file ' + file if @debug
84
79
  rm File.join(@app_path, file)
@@ -92,8 +87,7 @@ class HerokuWhiz
92
87
 
93
88
  return unless setup == :both
94
89
 
95
- app = `heroku config`.lines.first.split[1]
96
- `heroku apps:destroy --confirm #{app}`
90
+ `heroku apps:destroy --confirm #{heroku_app()}`
97
91
 
98
92
  end
99
93
 
@@ -122,12 +116,18 @@ class HerokuWhiz
122
116
  end
123
117
 
124
118
  def local_run()
119
+
120
+ #`heroku local &`
121
+ # attempted to use heroku local but couldn't automatically kill the
122
+ # process directly
123
+
125
124
  `bundle exec rackup -p 9292 config.ru &`
126
125
  end
127
126
 
128
127
  def local_testrun()
129
128
 
130
- r = IO.popen( "bundle exec rackup -p 9292 config.ru" )
129
+ #r = IO.popen("heroku local")
130
+ r = IO.popen("bundle exec rackup -p 9292 config.ru")
131
131
  puts 'r: ' + r.inspect if @debug
132
132
  sleep 2
133
133
 
@@ -136,36 +136,37 @@ class HerokuWhiz
136
136
 
137
137
  Process.kill('QUIT', r.pid)
138
138
 
139
-
140
139
  puts 'SUCCESS! Ready to deploy' if s == "Hello World!\n"
141
140
 
142
141
  end
143
142
 
144
143
  private
145
144
 
146
- def create_rack()
145
+ def create_basefiles(config, gemfile, procfile)
147
146
 
148
147
  FileUtils.mkdir_p @app_path
149
148
  FileUtils.chdir @app_path
150
149
 
151
150
  # write the config.ru file
152
151
  #
153
- config = %q(
154
- run lambda {|env|
155
- [200, {'Content-Type'=>'text/plain'}, StringIO.new("Hello World!\n")]
156
- })
157
152
  File.write File.join(@app_path, 'config.ru'), config
153
+ sleep 0.2
158
154
 
159
155
  # write the Gemfile
160
156
  #
161
- gemfile = %q(
162
- source 'https://rubygems.org'
163
- gem 'rack'
164
- gem 'puma'
165
- )
166
157
  File.write File.join(@app_path, 'Gemfile'), gemfile
167
- sleep 0.5
158
+ sleep 0.2
159
+
160
+ # write the Procfile (although not essential it will flag a warning when
161
+ # deploying if the file doesn't exist
162
+ #
163
+ File.write File.join(@app_path, 'Procfile'), procfile
164
+ sleep 0.2
165
+
166
+ end
168
167
 
168
+ def heroku_app()
169
+ `heroku config`.lines.first.split[1]
169
170
  end
170
171
 
171
172
  def rm(file)
@@ -182,3 +183,137 @@ gem 'puma'
182
183
 
183
184
  end
184
185
 
186
+ class SinatraWhiz < WhizBase
187
+
188
+ def initialize(app_path, debug: false)
189
+ super(app_path, debug: debug)
190
+ end
191
+
192
+ def create()
193
+
194
+ config = %q(
195
+ require './hello'
196
+ run Sinatra::Application
197
+ )
198
+
199
+ gemfile = %q(
200
+ source 'https://rubygems.org'
201
+ gem 'sinatra'
202
+ gem 'puma'
203
+ )
204
+
205
+ procfile = 'web: bundle exec rackup config.ru -p $PORT'
206
+
207
+ create_basefiles(config, gemfile, procfile)
208
+
209
+ hello_rb = %q(
210
+ require 'sinatra'
211
+
212
+ get '/' do
213
+ "Hello World!"
214
+ end
215
+ )
216
+ File.write File.join(@app_path, 'hello.rb'), hello_rb
217
+ sleep 0.3
218
+
219
+ end
220
+
221
+ end
222
+
223
+ class HerokuWhiz
224
+
225
+ def initialize(dir: '.', template: 'rack', appname: 'myapp',
226
+ verbose: true, debug: false)
227
+
228
+ @dir, @template, @appname, @verbose = dir, template, appname, verbose
229
+
230
+ @app_path = File.join(@dir, @appname)
231
+
232
+ case @template.to_sym
233
+ when :rack
234
+ @tapp = WhizBase.new @app_path, debug: debug
235
+ when :sinatra
236
+ @tapp = SinatraWhiz.new @app_path, debug: debug
237
+ end
238
+
239
+ end
240
+
241
+ def app_url()
242
+
243
+ s = "https://#{heroku_app()}.herokuapp.com/"
244
+
245
+ Clipboard.copy s
246
+ puts 'app URL copied to clipboard.'
247
+
248
+ return s
249
+
250
+ end
251
+
252
+ def app_open()
253
+ `heroku open`
254
+ end
255
+
256
+ def create()
257
+
258
+ return unless @tapp
259
+
260
+ @tapp.create
261
+
262
+ # build
263
+ `bundle install`
264
+ sleep 1
265
+
266
+ end
267
+
268
+ def goto(target)
269
+
270
+ case target.to_sym
271
+ when :apps
272
+ Launchy.open("https://dashboard.heroku.com/apps")
273
+ when :docs
274
+ Launchy.open('https://devcenter.heroku.com/articles/rack')
275
+ end
276
+
277
+ end
278
+
279
+ # currently only removes a file directory if there are no user created files
280
+ #
281
+ def wipe_clean(setup=:local)
282
+
283
+ return unless @tapp
284
+
285
+ @tapp.wipe_clean
286
+
287
+ end
288
+
289
+ def deploy()
290
+
291
+ return unless @tapp
292
+
293
+ @tapp.deploy
294
+
295
+ end
296
+
297
+ def local_run()
298
+
299
+ return unless @tapp
300
+
301
+ @tapp.local_run
302
+
303
+ end
304
+
305
+ def local_testrun()
306
+
307
+ return unless @tapp
308
+
309
+ @tapp.local_testrun()
310
+
311
+ end
312
+
313
+ private
314
+
315
+ def heroku_app()
316
+ `heroku config`.lines.first.split[1]
317
+ end
318
+
319
+ end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heroku_whiz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  n5lICiaMyvvvMKfV1rE1Pz0tCPqOu++rZFRC9XbrR+Vio0ha4mHPPAUsvY2f9DtE
36
36
  ZOz9jhKlb8t2o3xNUKH/e3WN
37
37
  -----END CERTIFICATE-----
38
- date: 2022-03-08 00:00:00.000000000 Z
38
+ date: 2022-03-09 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: clipboard
@@ -57,6 +57,26 @@ dependencies:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
59
  version: 1.3.6
60
+ - !ruby/object:Gem::Dependency
61
+ name: launchy
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '2.5'
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 2.5.0
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '2.5'
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 2.5.0
60
80
  description:
61
81
  email: digital.robertson@gmail.com
62
82
  executables: []
metadata.gz.sig CHANGED
Binary file