fanforce-app-factory 2.0.0.rc24 → 2.0.0.rc25

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@ require 'fileutils'
2
2
  require 'json'
3
3
  require 'yaml'
4
4
 
5
- require_relative 'sprockets/load_sprockets'
5
+ require_relative 'load_sprockets'
6
6
 
7
7
  ########################################################################################################################
8
8
 
@@ -10,21 +10,20 @@ class Fanforce::AppFactory::CLI::Env
10
10
  end
11
11
 
12
12
  def setup(environment)
13
+ environment = environment.to_sym
13
14
  bind_path = "#{app.dir}/../.env/_bind.yml"
14
15
  error 'You must setup .env/_bind.yml before updating env variables.' if !File.exists?(bind_path)
15
16
 
16
- vars = app_vars(environment)
17
+ vars = vars(environment)
17
18
  has_workers = File.directory?("#{app.dir}/workers") ? true : false
19
+ return log "#{'Skipped'.format(:bold)} #{environment.to_s.titleize} has 0 env variables" if vars.blank? or vars.size == 0
18
20
 
19
- if vars.blank? or vars.size == 0
20
- return puts "#{'Skipped'.format(:bold)} #{environment.to_s.titleize} has 0 env variables"
21
- end
22
- puts "#{'Updated'.format(:green,:bold)} #{environment.to_s.titleize}#{has_workers ? '... and workers have' : ' has'} #{vars.size} env variables"
23
-
24
- push_env_to(environment, vars)
21
+ push_to(environment, vars)
22
+ log "#{'Updated'.format(:green,:bold)} #{environment.to_s.titleize}#{has_workers ? '... and workers have' : ' has'} #{vars.size} env variables"
25
23
  end
26
24
 
27
25
  def push_env_to(environment, vars, create_worker_env=true)
26
+ environment = environment.to_sym
28
27
  vars.each {|k,v| puts " - #{k}" }
29
28
  workers_dir = "#{app.dir}/workers"
30
29
  workers_env_dir = "#{workers_dir}/.env"
@@ -36,10 +35,8 @@ class Fanforce::AppFactory::CLI::Env
36
35
  update_powenv
37
36
  File.open("#{app.dir}/.appenv", 'w') {|f| f.write convert_hash_to_shell_env(vars) }
38
37
  else
39
- return if config[:heroku][environment].blank?
40
- heroku = auth_heroku(environment)
41
- heroku_app_name = get_heroku_app_name(app, environment)
42
- heroku.put_config_vars(heroku_app_name, vars)
38
+ error 'could not find heroku in .fanforce-app-factory' if config[:heroku][environment].blank?
39
+ Fanforce::AppFactory::CLI::Heroku.new(app).update_config(environment, vars)
43
40
  end
44
41
  end
45
42
 
@@ -51,7 +48,7 @@ class Fanforce::AppFactory::CLI::Env
51
48
  hash.inject('') {|script, (k,v)| script += "ENV['#{k}']=#{v.to_s.to_json}\n" }
52
49
  end
53
50
 
54
- def load_app_vars(environment)
51
+ def load_vars(environment)
55
52
  environment = environment.to_sym
56
53
  vars = {'FANFORCE_APP_ID' => app._id}
57
54
  raw_yaml = File.read("#{app.dir}/../.env/_bind.yml")
@@ -68,9 +65,9 @@ class Fanforce::AppFactory::CLI::Env
68
65
  return vars
69
66
  end
70
67
 
71
- def app_vars(environment)
68
+ def vars(environment)
72
69
  @vars ||= {}
73
- @vars[environment] ||= load_app_vars(environment)
70
+ @vars[environment] ||= load_vars(environment)
74
71
  end
75
72
 
76
73
  # .POWENV #######################################################################
@@ -96,4 +93,4 @@ class Fanforce::AppFactory::CLI::Env
96
93
  ['source .appenv']
97
94
  end
98
95
 
99
- end
96
+ end
@@ -0,0 +1,83 @@
1
+ class Fanforce::AppFactory::CLI::Heroku
2
+ include Fanforce::AppFactory::CLI::Utils
3
+
4
+ attr_reader :app
5
+
6
+ require_gem 'heroku-api', 'heroku-api'
7
+
8
+ def initialize(app)
9
+ @app = app
10
+ end
11
+
12
+ def heroku(environment)
13
+ @heroku ||= {}
14
+ @heroku[environment] ||= Heroku::API.new(:username => config[:heroku][environment][:user], :password => config[:heroku][environment][:password])
15
+ rescue Exception => e
16
+ #raise "Heroku user #{config[:heroku][environment][:user]} does not seem to exist: #{e.message}" if e.response.status == 404
17
+ raise
18
+ end
19
+
20
+ def setup(environment)
21
+ environment = environment.to_sym
22
+ return puts "OOPS... #{environment.to_s.upcase}".format(:red,:bold) + ' has not been setup for Heroku' if config[:heroku].blank? or config[:heroku][environment].blank?
23
+
24
+ heroku = heroku(environment)
25
+ heroku_app_name = app_name(environment)
26
+ begin
27
+ heroku.get_app(heroku_app_name)
28
+ puts "#{'Found '.format(:green,:bold)}" + "#{environment} app on heroku (#{heroku_app_name})"
29
+ rescue
30
+ heroku.post_app(name: heroku_app_name)
31
+ puts "#{'Created '.format(:green,:bold)}" + "#{environment} on heroku (#{heroku_app_name})"
32
+ end
33
+
34
+ # Setup standard app domain
35
+ domain = "#{app._id}.#{Fanforce::Base::DomainEnvironments.method(environment).call[:apps_base]}"
36
+ domain_found = heroku.get_domains(heroku_app_name).body.inject(false) {|result, d| d['domain'] == domain ? (break true) : false }
37
+ if domain_found
38
+ puts "#{'Found '.format(:green,:bold)}" + "#{domain} domain on #{environment}"
39
+ else
40
+ heroku.post_domain(heroku_app_name, domain)
41
+ puts "#{'Added '.format(:green,:bold)}" + "#{domain} domain to #{environment}"
42
+ end
43
+
44
+ # Setup default short domain
45
+ domain = "#{app._id}.#{Fanforce::Base::DomainEnvironments.method(environment).call[:default_short_domain]}"
46
+ domain_found = heroku.get_domains(heroku_app_name).body.inject(false) {|result, d| d['domain'] == domain ? (break true) : false }
47
+ if domain_found
48
+ puts "#{'Found '.format(:green,:bold)}" + "#{domain} domain on #{environment}"
49
+ else
50
+ heroku.post_domain(heroku_app_name, domain)
51
+ puts "#{'Added '.format(:green,:bold)}" + "#{domain} domain to #{environment}"
52
+ end
53
+
54
+ remote_name = "#{env(environment)}-heroku"
55
+ if (`git remote`).split(/\r?\n/).include?(remote_name)
56
+ puts "#{'Updated '.format(:green,:bold)}" + "git remote for #{remote_name}"
57
+ `git remote rm #{remote_name}`
58
+ else
59
+ puts "#{'Created '.format(:green,:bold)}" + "git remote for #{remote_name}"
60
+ end
61
+ `git remote add #{remote_name} git@#{config[:heroku][environment][:git_ssh_domain] || 'heroku.com'}:#{heroku_app_name}.git`
62
+ end
63
+
64
+ def update_config(environment, vars)
65
+ heroku(environment).put_config_vars(app_name(environment), vars) if vars
66
+ end
67
+
68
+ def env(environment)
69
+ case environment
70
+ when :staging then env = :stg
71
+ when :production then env = :prd
72
+ end
73
+ end
74
+
75
+ def app_name(environment)
76
+ environment = environment.to_sym
77
+ raise 'unknown environment' if ![:production, :staging].include?(environment)
78
+
79
+ heroku_app_name = "#{env(environment)}-#{app.dir_name}"
80
+ heroku_app_name.length > 30 ? heroku_app_name.gsub!(/(a|e|i|o|u)/, '') : heroku_app_name
81
+ end
82
+
83
+ end
@@ -15,12 +15,12 @@ class Fanforce::AppFactory::CLI::Iron
15
15
  end
16
16
 
17
17
  env = Fanforce::AppFactory::CLI::Env.new(app)
18
- vars = env.app_vars(environment) || {}
18
+ vars = env.vars(environment) || {}
19
19
 
20
20
  return puts "#{'Skipped '.format(:bold)} #{environment.to_s.titleize} is missing IRON_TOKEN and/or IRON_PROJECT_ID env variables" if vars['IRON_TOKEN'].blank? or vars['IRON_PROJECT_ID'].blank?
21
21
 
22
22
  puts "#{'Updating Env'.format(:green,:bold)} #{environment.to_s.titleize}... and workers have #{vars.size} env variables"
23
- env.push_env_to(environment, vars, true)
23
+ env.push_to(environment, vars, true)
24
24
 
25
25
  iron_worker = IronWorkerNG::Client.new(:token => vars['IRON_TOKEN'], :project_id => vars['IRON_PROJECT_ID'])
26
26
  Dir.chdir("#{app.dir}/workers") do
@@ -3,36 +3,45 @@ class Fanforce::AppFactory::CLI::Scripts
3
3
 
4
4
  require_relative '../lib/env'
5
5
  require_relative '../lib/iron'
6
+ require_relative '../lib/heroku'
6
7
 
7
8
  ######################################################################################################################
8
9
 
9
10
  def push(environment, command)
11
+ environment = environment.to_sym
10
12
  command = command.to_sym
11
13
  app = Fanforce::CLI::App.load(Fanforce::CLI::DIR)
12
14
 
13
- if [:all,:iron].include?(command)
14
- if Fanforce::CLI::TYPE == :directory_of_apps
15
- confirm("\nYou are about to push iron works for #{Fanforce::CLI::Apps.total_count} apps in this directory.\n"+
16
- 'ARE YOU SURE?', true)
17
- Fanforce::CLI::Apps.each do |app, processed_count, total_count|
18
- log divider '+-----------------------------------------------------------------------------------------------'
19
- log "#{'APP'.format(:bold)} - #{app._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... "
20
- push_app_workers(app, environment)
21
- end
22
- elsif Fanforce::CLI::TYPE == :single_app
23
- log divider '+-------------------------------------------------------------------------------------------------'
24
- app = Fanforce::CLI::App.load(Fanforce::CLI::DIR)
25
- push_app_workers(app, environment)
15
+ if Fanforce::CLI::TYPE == :directory_of_apps
16
+ confirm("\nYou are about to push iron works for #{Fanforce::CLI::Apps.total_count} apps in this directory.\n"+
17
+ 'ARE YOU SURE?', true)
18
+ Fanforce::CLI::Apps.each do |app, processed_count, total_count|
19
+ log divider '+-----------------------------------------------------------------------------------------------'
20
+ log "#{'APP'.format(:bold)} - #{app._id.upcase.gsub('-',' ').format(:bold)} (#{processed_count} of #{total_count})... "
21
+ push_app(app, environment, command)
26
22
  end
27
- elsif command.to_s.include?('.worker')
23
+ elsif Fanforce::CLI::TYPE == :single_app
28
24
  log divider '+---------------------------------------------------------------------------------------------------'
29
25
  app = Fanforce::CLI::App.load(Fanforce::CLI::DIR)
30
- push_app_worker(app, environment, command.to_s)
26
+ push_app(app, environment, command)
31
27
  end
32
28
 
33
29
  log divider '----------------------------------------------------------------------------------------------------++'
34
30
  end
35
31
 
32
+ def push_app(app, environment, command)
33
+ if command.to_s.include?('.worker')
34
+ push_app_worker(app, environment, command.to_s)
35
+ elsif [:all,:iron].include?(command)
36
+ push_app_workers(app, environment)
37
+ elsif [:all,:env].include?(command)
38
+ push_env(app, environment)
39
+ elsif [:all,:heroku].include?(command)
40
+ error 'Heroku is not setup for development' if environment == :development
41
+ push_heroku(app, environment)
42
+ end
43
+ end
44
+
36
45
  def push_app_worker(app, environment, filename)
37
46
  Dir.chdir(app.dir) do
38
47
  Fanforce::AppFactory::CLI::Iron.new(app).upload(environment, filename)
@@ -42,39 +51,29 @@ class Fanforce::AppFactory::CLI::Scripts
42
51
  def push_app_workers(app, environment)
43
52
  Dir.chdir(app.dir) do
44
53
  Fanforce::AppFactory::CLI::Iron.new(app).upload(environment)
54
+ end
55
+ end
45
56
 
46
- # if [:all,:bitbucket].include?(command) and config[:bitbucket].present?
47
- # if !(`git remote`).split(/\r?\n/).include?('bitbucket')
48
- # setup_bitbucket(app)
49
- # else
50
- # puts "\n#{'Pushing '.format(:green,:bold)}" + "latest commit to Bitbucket (#{$Config[:bitbucket][:user]})..."
51
- # Run.command('git push bitbucket --all')
52
- # end
53
- # end
54
-
55
- # environments = (environment==:all) ? [:staging,:production] : [environment]
56
- # environments.each do |environment|
57
- # if [:all,:heroku].include?(command)
58
- # remote_name = "#{env(environment)}-heroku"
59
- # setup_heroku(app, environment) if !(`git remote`).split(/\r?\n/).include?(remote_name)
60
- #
61
- # vars = Env.vars_by_app(environment)[app.dir_name] || {}
62
- # puts "\n#{"Updating Env Vars".format(:green,:bold)} on Heroku #{environment.to_s.titleize} (#{vars.size} variables)..."
63
- # push_env_to(environment, app, vars)
64
- #
65
- # puts "\n#{'Pushing '.format(:green,:bold)}" + "latest commit to Heroku #{environment.to_s.titleize} (#{remote_name})..."
66
- # Run.command("git push #{remote_name} master")
67
- # end
68
- #
69
- # if [:all,:iron].include?(command)
70
- # puts ''
71
- # upload_iron(app, command, [environment])
72
- # end
73
- # end
57
+ def push_env(app, environment)
58
+ Fanforce::AppFactory::CLI::Env.new(app).setup(environment)
59
+ end
74
60
 
61
+ def push_heroku(app, environment)
62
+ case environment
63
+ when :staging then env = :stg
64
+ when :production then env = :prd
75
65
  end
76
- end
66
+ remote_name = "#{env}-heroku"
67
+
68
+ heroku = Fanforce::AppFactory::CLI::Heroku.new(app)
69
+ heroku.setup(environment) if !(`git remote`).split(/\r?\n/).include?(remote_name)
77
70
 
71
+ vars = Fanforce::AppFactory::CLI::Env.new(app).vars(environment)
72
+ heroku.update_config(environment, vars)
73
+ log 'Updated ENV'.format(:green,:bold) + " on Heroku #{environment.to_s.titleize} (#{vars.size} variables)..."
78
74
 
75
+ puts "\n#{'Pushing '.format(:green,:bold)}" + "latest commit to Heroku #{environment.to_s.titleize} (#{remote_name})..."
76
+ console_command("git push #{remote_name} master", true)
77
+ end
79
78
 
80
79
  end
@@ -36,8 +36,8 @@ class Fanforce::AppFactory::CLI::Scripts
36
36
 
37
37
  Fanforce::CLI.register(self, :push,
38
38
  ['RACK_ENV all/TYPE', 'Push everything to the selected environment'],
39
- # ['RACK_ENV env', 'Setup the correct ENV variables in selected environment'],
40
- # ['RACK_ENV heroku', 'Create heroku app (if needed) and push latest commit'],
39
+ ['RACK_ENV env', 'Setup the correct ENV variables in selected environment'],
40
+ ['RACK_ENV heroku', 'Create heroku app (if needed) and push latest commit'],
41
41
  ['RACK_ENV iron', 'Upload iron workers to selected environment']
42
42
  ) { require_relative 'cli/scripts/push' }
43
43
 
@@ -36,8 +36,8 @@ class Fanforce::AppFactory::CLI::Scripts
36
36
 
37
37
  Fanforce::CLI.register(self, :push,
38
38
  ['RACK_ENV all/TYPE', 'Push everything to the selected environment'],
39
- # ['RACK_ENV env', 'Setup the correct ENV variables in selected environment'],
40
- # ['RACK_ENV heroku', 'Create heroku app (if needed) and push latest commit'],
39
+ ['RACK_ENV env', 'Setup the correct ENV variables in selected environment'],
40
+ ['RACK_ENV heroku', 'Create heroku app (if needed) and push latest commit'],
41
41
  ['RACK_ENV iron', 'Upload iron workers to selected environment'],
42
42
  ['RACK_ENV FILENAME.worker', 'Upload single iron worker to selected environment']
43
43
  ) { require_relative 'cli/scripts/push' }
@@ -59,9 +59,9 @@ class App::Sinatra
59
59
 
60
60
 
61
61
  ######################################################################################################################
62
- # ENGAGE
62
+ # VISITOR
63
63
 
64
- #static '/:organization_slug/:com_behavior_shortid/:initiative_id', :engagement do route_engagement_page_ui end
64
+ #static '/:organization_slug/:com_behavior_shortid/:initiative_id', :engagement do route_visitor_page_ui(:engagement) end
65
65
 
66
66
  ######################################################################################################################
67
67
 
@@ -0,0 +1,5 @@
1
+ fanforce-app-factory-2.0.0.rc6:02405b7a50a0ed450d10c57b6d6ad034a247e9d1
2
+ fanforce-app-factory-2.0.0.rc16:b4b9aa096770b68ec2c9da62349443747d5afa88
3
+ fanforce-app-factory-2.0.0.rc24:34de59db0e183647f76f1a35ad2bef51ef043a98
4
+ fanforce-app-factory-2.0.0.rc24:e26e07d033f76de23a645ec185b856c332caa9b6
5
+ fanforce-app-factory-2.0.0.rc24:704a6dfc8e71d43ffec0fcbe859c7c2860595a2c
@@ -1,12 +1,13 @@
1
1
  -# AppFactoryScaffolding : FILE
2
2
  -#######################################################################################################################
3
3
  !!! 5
4
- %html.engagement-layout
4
+ %html.visitor-layout
5
5
  %head
6
6
  %title Fanforce
7
7
  %meta{'http-equiv'=>'Content-Type', content:'text/html; charset=iso-8859-1'}/
8
8
  %meta{'http-equiv'=>'Content-Language', content: 'en-us'}/
9
- = stylesheet '/engagement.css'
9
+ = stylesheet '/visitor.css'
10
+ %script(src='//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.js')
10
11
  %body
11
12
  .lyt-root
12
13
  .lyt-header
@@ -24,6 +25,7 @@
24
25
 
25
26
  = yield_content :after_fanforce_js
26
27
  :coffeescript
28
+ FF.css_framework = 'bootstrap3'
27
29
  FF.on('visitor.logout', ->
28
30
  $('#hello').html('')
29
31
  )
@@ -43,4 +43,8 @@ class Fanforce::App::Sinatra
43
43
  json success: true
44
44
  end
45
45
 
46
+ def route_visitor_page_ui(page_name)
47
+ page :"visitor/#{page_name}", :layout => :visitor
48
+ end
49
+
46
50
  end
@@ -8,10 +8,6 @@ class Fanforce::App::Sinatra
8
8
  page :edit_initiative, :layout => :fembedded, com_dir: params[:com_behavior_shortid]
9
9
  end
10
10
 
11
- def route_engagement_page_ui
12
- page :engagement, :layout => :engagement, com_dir: params[:com_behavior_shortid]
13
- end
14
-
15
11
  def route_archive_initiative_callback
16
12
  json status: 'finished'
17
13
  end
@@ -1,6 +1,6 @@
1
1
  class Fanforce::App::Sinatra
2
2
 
3
- def route_new_message_ui
3
+ def route_new_message_ui
4
4
  page :new_message, :layout => :fembedded, com_dir: params[:com_behavior_shortid]
5
5
  end
6
6
 
@@ -1,5 +1,5 @@
1
1
  class Fanforce
2
2
  class AppFactory
3
- VERSION = '2.0.0.rc24'
3
+ VERSION = '2.0.0.rc25'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fanforce-app-factory
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.rc24
4
+ version: 2.0.0.rc25
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -406,6 +406,7 @@ files:
406
406
  - lib/fanforce/app_factory/cli/lib/bundler.rb
407
407
  - lib/fanforce/app_factory/cli/lib/env.rb
408
408
  - lib/fanforce/app_factory/cli/lib/git.rb
409
+ - lib/fanforce/app_factory/cli/lib/heroku.rb
409
410
  - lib/fanforce/app_factory/cli/lib/iron.rb
410
411
  - lib/fanforce/app_factory/cli/lib/pow.rb
411
412
  - lib/fanforce/app_factory/cli/lib/scaffolding.rb
@@ -439,12 +440,12 @@ files:
439
440
  - lib/fanforce/app_factory/scaffolding/Gemfile
440
441
  - lib/fanforce/app_factory/scaffolding/Rakefile
441
442
  - lib/fanforce/app_factory/scaffolding/Routes.rb
442
- - lib/fanforce/app_factory/scaffolding/assets/css/._engagement.scss.registry
443
443
  - lib/fanforce/app_factory/scaffolding/assets/css/._fembedded.scss.registry
444
444
  - lib/fanforce/app_factory/scaffolding/assets/css/._promotional.scss.registry
445
- - lib/fanforce/app_factory/scaffolding/assets/css/engagement.scss
445
+ - lib/fanforce/app_factory/scaffolding/assets/css/._visitor.scss.registry
446
446
  - lib/fanforce/app_factory/scaffolding/assets/css/fembedded.scss
447
447
  - lib/fanforce/app_factory/scaffolding/assets/css/promotional.scss
448
+ - lib/fanforce/app_factory/scaffolding/assets/css/visitor.scss
448
449
  - lib/fanforce/app_factory/scaffolding/assets/img/._icon-16.png.registry
449
450
  - lib/fanforce/app_factory/scaffolding/assets/img/._icon-32.png.registry
450
451
  - lib/fanforce/app_factory/scaffolding/assets/img/._icon-42.png.registry
@@ -474,12 +475,12 @@ files:
474
475
  - lib/fanforce/app_factory/scaffolding/config.json
475
476
  - lib/fanforce/app_factory/scaffolding/config.ru
476
477
  - lib/fanforce/app_factory/scaffolding/favicon.ico
477
- - lib/fanforce/app_factory/scaffolding/layouts/._engagement.haml.registry
478
478
  - lib/fanforce/app_factory/scaffolding/layouts/._fembedded.haml.registry
479
479
  - lib/fanforce/app_factory/scaffolding/layouts/._promotional.haml.registry
480
- - lib/fanforce/app_factory/scaffolding/layouts/engagement.haml
480
+ - lib/fanforce/app_factory/scaffolding/layouts/._visitor.haml.registry
481
481
  - lib/fanforce/app_factory/scaffolding/layouts/fembedded.haml
482
482
  - lib/fanforce/app_factory/scaffolding/layouts/promotional.haml
483
+ - lib/fanforce/app_factory/scaffolding/layouts/visitor.haml
483
484
  - lib/fanforce/app_factory/scaffolding/robots.txt
484
485
  - lib/fanforce/app_factory/scaffolding/views/._index.haml.registry
485
486
  - lib/fanforce/app_factory/scaffolding/views/index.haml
@@ -1,2 +0,0 @@
1
- fanforce-app-factory-2.0.0.rc6:02405b7a50a0ed450d10c57b6d6ad034a247e9d1
2
- fanforce-app-factory-2.0.0.rc16:b4b9aa096770b68ec2c9da62349443747d5afa88