heroku_whiz 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5800f5f32cb8db97a0533705239764f93beda9e9f5bd05440d2e3a29c82e2b68
4
- data.tar.gz: 6e3b4e3ff383822c3c6db9b62f4010f422e3a85cec747f70eba7f4d6e61885e1
3
+ metadata.gz: c8fa80bb83fdb773d2b05d79c4df5e1f176de51608c90eb8e24506e88c22027f
4
+ data.tar.gz: 2a3c0e94b9737149aefa1e10148e88bb1875c62be15775807d33edb75859e155
5
5
  SHA512:
6
- metadata.gz: '049384d28472b0b534610be275db670e977509be3af49132907ad6f5b6825ea20ae9c13a1f8e6a88196d023e27e1456fccc418ac250f506d89e96e6f7580f507'
7
- data.tar.gz: feef8ec4211b1e8e9d7a790a5ae06c35997b5fb62f2da53eec1d0eb91f68cbef49eee1e3914e8a21a251d22cb30a2e72f00483c4a7f4bbc8e43e217239737546
6
+ metadata.gz: 1f00da4e02b5bd3ec99079d64a085b08581d2f1ce326e4a293e5931f59eae480b81854b33e0c9930c14d9dc0604894e1de662008cbd2d25246cd06bddee09397
7
+ data.tar.gz: 6f9fbaa7facaf1227583a364f19c29be59ba7a6ab136e929e11fd8d386af995e8fe28b9897ece4cb25c7c5e14825d565ccc6c34f70657f9f636badbca128b3ef
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/heroku_whiz.rb CHANGED
@@ -3,18 +3,40 @@
3
3
  # file: heroku_whiz.rb
4
4
 
5
5
  # created: 8th March 2022
6
- # description: Handy (experimental) Heroku gem for noobs to create a
6
+ # updated: 9th March 2022
7
+
8
+ # description: Handy (experimental) Heroku gem for noobs to create a
7
9
  # simple Heroku app in a whiz!
8
10
 
9
- # note: If this gem becomes outdated because of a change in the Heroku app
10
- # setup process, please inform the owner of this project via *Issues*
11
+ # Q: Why Heroku?
12
+ #
13
+ # A: With a quick Twitter search for Free wen hosting, a
14
+ # popular Tweet mentioned Heroku
15
+ #
16
+ # 10 FREE Hosting/Clouds for Your website:
17
+ #
18
+ # ➡️ GitHub Pages
19
+ # ➡️ Heroku
20
+ # ➡️ Amazon Web Services (AWS)
21
+ # ➡️ Vercel
22
+ # ➡️ Firebase Hosting
23
+ # ➡️ Awardspace
24
+ # ➡️ Netlify
25
+ # ➡️ Google Cloud
26
+ # ➡️ Cloudflare
27
+ # ➡️ Weebly
28
+ #
29
+
30
+
31
+ # note: If this gem becomes outdated because of a change in the Heroku app
32
+ # setup process, please inform the owner of this project via *Issues*
11
33
  # on GitHub (https://github.com/jrobertson/heroku_whiz).
12
34
 
13
35
 
14
36
  require 'open-uri'
15
37
  require 'fileutils'
16
38
  require 'clipboard'
17
-
39
+ require 'launchy'
18
40
 
19
41
  # Resources
20
42
  #
@@ -23,8 +45,9 @@ require 'clipboard'
23
45
 
24
46
  # Example usage:
25
47
  #
26
- # hw = HerokuWhiz.new dir: '/home/james/heroku', template: 'rack', appname: 'hello2', debug: true
27
- #
48
+ # hw = HerokuWhiz.new dir: '/home/james/heroku', template: 'rack',
49
+ # appname: 'hello2', debug: true
50
+ #
28
51
  # hw.wipe_clean # removes the previous local app file directory
29
52
  # hw.create # creates the local app file directory
30
53
  # #hw.local_run # runs the web app locally
@@ -33,52 +56,44 @@ require 'clipboard'
33
56
  # hw.app_url #=> e.g. https://frozen-dusk-65820.herokuapp.com/
34
57
 
35
58
 
36
- class HerokuWhiz
37
59
 
38
- def initialize(dir: '.', template: 'rack', appname: 'myapp',
39
- verbose: true, debug: false)
60
+ class WhizBase
40
61
 
41
- @dir, @template, @appname, @verbose = dir, template, appname, verbose
62
+ def initialize(app_path, verbose: true, debug: false)
42
63
 
43
- @app_path = File.join(@dir, @appname)
64
+ @app_path, @verbose, debug = app_path, verbose, debug
44
65
 
45
-
46
66
  end
47
67
 
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
57
-
58
- end
68
+ def create(add: nil)
59
69
 
60
- def create()
70
+ config = %q(
71
+ run lambda {|env|
72
+ [200, {'Content-Type'=>'text/plain'}, StringIO.new("Hello World!\n")]
73
+ })
61
74
 
62
- case @template.to_sym
63
- when :rack
64
- create_rack()
65
- else
66
- return puts 'template not recognised!'
67
- end
75
+ gemfile = %q(
76
+ source 'https://rubygems.org'
77
+ gem 'rack'
78
+ gem 'puma'
79
+ )
68
80
 
69
- # build
70
- `bundle install`
71
- sleep 1
81
+ # Procfile: see https://devcenter.heroku.com/articles/procfile
82
+ # for more info
83
+ procfile = 'web: bundle exec rackup config.ru -p $PORT'
72
84
 
85
+ create_basefiles(config, gemfile, procfile)
73
86
  end
74
87
 
88
+ # currently only removes a file directory if there are no user created files
89
+ #
75
90
  def wipe_clean(setup=:local)
76
91
 
77
92
  return unless File.exists? @app_path
78
93
 
79
94
  # remove the app files
80
95
  #
81
- %w(Gemfile config.ru Gemfile.lock).each do |file|
96
+ %w(Gemfile config.ru Procfile Gemfile.lock).each do |file|
82
97
 
83
98
  puts 'removing file ' + file if @debug
84
99
  rm File.join(@app_path, file)
@@ -86,15 +101,20 @@ class HerokuWhiz
86
101
 
87
102
  end
88
103
 
104
+ appname = heroku_app()
105
+
106
+ if setup == :both then
107
+
108
+ Clipboard.copy appname
109
+ puts 'App name ' + appname + ' copied to clipboard'
110
+ `heroku apps:destroy #{appname}`
111
+
112
+ end
113
+
89
114
  rm_rf File.join(@app_path, '.git')
90
115
  rmdir File.join(@app_path, '.git')
91
116
  rmdir @app_path
92
117
 
93
- return unless setup == :both
94
-
95
- app = `heroku config`.lines.first.split[1]
96
- `heroku apps:destroy --confirm #{app}`
97
-
98
118
  end
99
119
 
100
120
  def deploy()
@@ -110,24 +130,33 @@ class HerokuWhiz
110
130
 
111
131
  #`heroku create #{@appname}`
112
132
 
113
- # the above statement was commented out because there's a
133
+ # the above statement was commented out because there's a
114
134
  # high probability the appname you have chosen has already been taken
115
135
  # e.g. hello2 => hello2.herokuapp.com
116
-
136
+
137
+ puts 'Running *heroku create*' if @verbose
117
138
  `heroku create`
118
- sleep 2
139
+ sleep 3
119
140
 
141
+ puts 'Running *git push heroku master*' if @verbose
120
142
  r = `git push heroku master`
143
+ sleep 10
121
144
 
122
145
  end
123
146
 
124
147
  def local_run()
148
+
149
+ #`heroku local &`
150
+ # attempted to use heroku local but couldn't automatically kill the
151
+ # process directly
152
+
125
153
  `bundle exec rackup -p 9292 config.ru &`
126
154
  end
127
155
 
128
156
  def local_testrun()
129
157
 
130
- r = IO.popen( "bundle exec rackup -p 9292 config.ru" )
158
+ #r = IO.popen("heroku local")
159
+ r = IO.popen("bundle exec rackup -p 9292 config.ru")
131
160
  puts 'r: ' + r.inspect if @debug
132
161
  sleep 2
133
162
 
@@ -135,7 +164,6 @@ class HerokuWhiz
135
164
  sleep 1
136
165
 
137
166
  Process.kill('QUIT', r.pid)
138
-
139
167
 
140
168
  puts 'SUCCESS! Ready to deploy' if s == "Hello World!\n"
141
169
 
@@ -143,29 +171,32 @@ class HerokuWhiz
143
171
 
144
172
  private
145
173
 
146
- def create_rack()
174
+ def create_basefiles(config, gemfile, procfile)
147
175
 
148
176
  FileUtils.mkdir_p @app_path
149
177
  FileUtils.chdir @app_path
150
178
 
151
179
  # write the config.ru file
152
180
  #
153
- config = %q(
154
- run lambda do |env|
155
- [200, {'Content-Type'=>'text/plain'}, StringIO.new("Hello World!\n")]
156
- end)
157
181
  File.write File.join(@app_path, 'config.ru'), config
182
+ sleep 0.2
158
183
 
159
184
  # write the Gemfile
160
185
  #
161
- gemfile = %q(
162
- source 'https://rubygems.org'
163
- gem 'rack'
164
- gem 'puma'
165
- )
166
186
  File.write File.join(@app_path, 'Gemfile'), gemfile
167
- sleep 0.5
187
+ sleep 0.2
168
188
 
189
+ # write the Procfile (although not essential it will flag a warning when
190
+ # deploying if the file doesn't exist
191
+ #
192
+ File.write File.join(@app_path, 'Procfile'), procfile
193
+ sleep 0.2
194
+
195
+ end
196
+
197
+ def heroku_app()
198
+ s = `heroku config`
199
+ s.lines.first.split[1] if s
169
200
  end
170
201
 
171
202
  def rm(file)
@@ -182,3 +213,186 @@ gem 'puma'
182
213
 
183
214
  end
184
215
 
216
+ class SinatraWhizError < Exception
217
+ end
218
+
219
+ class SinatraWhiz < WhizBase
220
+
221
+ def initialize(app_path, verbose: true, debug: false)
222
+ super(app_path, verbose: verbose, debug: debug)
223
+ end
224
+
225
+ def create(add: nil)
226
+
227
+ if add then
228
+
229
+ FileUtils.mkdir_p @app_path
230
+ FileUtils.chdir @app_path
231
+
232
+ # copying the files into file directory @app_path
233
+ # ensure the files config.ru, Gemfile, and Procfile exist
234
+ #
235
+ a = Dir.glob(File.join(add,'*'))
236
+ files = a.map {|x| File.basename(x)}
237
+
238
+ expected = %w(config.ru Gemfile Procfile)
239
+ found = (files & expected)
240
+
241
+ if found.length < 3 then
242
+ raise SinatraWhizError, 'missing ' + (expected - found).join(', ')
243
+ end
244
+
245
+ puts 'copying files ' + a.inspect if @debug
246
+
247
+ a.each {|x| FileUtils.cp x, @app_path }
248
+
249
+ else
250
+
251
+ config = %q(
252
+ require './hello'
253
+ run Sinatra::Application
254
+ )
255
+ gemfile = %q(
256
+ source 'https://rubygems.org'
257
+ gem 'sinatra'
258
+ gem 'puma'
259
+ )
260
+
261
+ procfile = 'web: bundle exec rackup config.ru -p $PORT'
262
+ create_basefiles(config, gemfile, procfile)
263
+
264
+ hello_rb = %q(
265
+ require 'sinatra'
266
+
267
+ get '/' do
268
+ "Hello World!"
269
+ end
270
+ )
271
+ File.write File.join(@app_path, 'hello.rb'), hello_rb
272
+ sleep 0.3
273
+
274
+ end
275
+
276
+ end
277
+
278
+ def local_testrun()
279
+ r = IO.popen("bundle exec rackup -p 9292 config.ru")
280
+ puts 'r: ' + r.inspect if @debug
281
+ sleep 2
282
+
283
+ s = URI.open('http://127.0.0.1:9292').read
284
+ sleep 1
285
+
286
+ Process.kill('QUIT', r.pid)
287
+
288
+ puts 'SUCCESS! Ready to deploy' if s == "Hello World!"
289
+ end
290
+
291
+ def wipe_clean(setup=nil)
292
+
293
+ rm File.join(@app_path, 'hello.rb')
294
+ super(setup)
295
+
296
+ end
297
+
298
+ end
299
+
300
+ class HerokuWhiz
301
+
302
+ def initialize(dir: '.', template: 'rack', appname: File.basename(Dir.pwd),
303
+ verbose: true, debug: false)
304
+
305
+ @dir, @template, @appname, @verbose = dir, template, appname, verbose
306
+
307
+ @app_path = File.join(@dir, @appname)
308
+ FileUtils.chdir @app_path if File.exists? @app_path
309
+
310
+ case @template.to_sym
311
+ when :rack
312
+ @tapp = WhizBase.new @app_path, verbose: verbose, debug: debug
313
+ when :sinatra
314
+ @tapp = SinatraWhiz.new @app_path, verbose: verbose, debug: debug
315
+ end
316
+
317
+ end
318
+
319
+ def app_url()
320
+
321
+ s = "https://#{heroku_app()}.herokuapp.com/"
322
+
323
+ Clipboard.copy s
324
+ puts 'app URL copied to clipboard.'
325
+
326
+ return s
327
+
328
+ end
329
+
330
+ def app_open()
331
+ `heroku open`
332
+ end
333
+
334
+ def create(add: nil)
335
+
336
+ return unless @tapp
337
+
338
+ @tapp.create add: add
339
+
340
+ # build
341
+ `bundle install`
342
+ sleep 1
343
+
344
+ end
345
+
346
+ def goto(target)
347
+
348
+ case target.to_sym
349
+ when :apps
350
+ Launchy.open("https://dashboard.heroku.com/apps")
351
+ when :docs
352
+ Launchy.open('https://devcenter.heroku.com/articles/rack')
353
+ end
354
+
355
+ end
356
+
357
+ # currently only removes a file directory if there are no user created files
358
+ #
359
+ def wipe_clean(setup=:local)
360
+
361
+ return unless @tapp
362
+
363
+ @tapp.wipe_clean setup
364
+
365
+ end
366
+
367
+ def deploy()
368
+
369
+ return unless @tapp
370
+
371
+ @tapp.deploy
372
+
373
+ end
374
+
375
+ def local_run()
376
+
377
+ return unless @tapp
378
+
379
+ @tapp.local_run
380
+
381
+ end
382
+
383
+ def local_testrun()
384
+
385
+ return unless @tapp
386
+
387
+ @tapp.local_testrun()
388
+
389
+ end
390
+
391
+ private
392
+
393
+ def heroku_app()
394
+ s = `heroku config`
395
+ s.lines.first.split[1] if s
396
+ end
397
+
398
+ 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.0
4
+ version: 0.2.1
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