fanforce-app-factory 2.0.0.rc5 → 2.0.0.rc7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Rakefile +54 -3
  4. data/apps.json +8 -8
  5. data/lib/fanforce/app_factory.rb +19 -16
  6. data/lib/fanforce/app_factory/Rakefile +6 -14
  7. data/lib/fanforce/app_factory/Routes.rb +2 -2
  8. data/lib/fanforce/app_factory/app.rb +19 -8
  9. data/lib/fanforce/app_factory/cli.rb +5 -0
  10. data/lib/fanforce/app_factory/cli/bitbucket.rb +70 -0
  11. data/lib/fanforce/app_factory/cli/bundler.rb +21 -0
  12. data/lib/fanforce/app_factory/cli/env.rb +99 -0
  13. data/lib/fanforce/app_factory/cli/git.rb +58 -0
  14. data/lib/fanforce/app_factory/cli/iron.rb +61 -0
  15. data/lib/fanforce/app_factory/cli/pow.rb +46 -0
  16. data/lib/fanforce/app_factory/cli/scaffolding.rb +74 -0
  17. data/lib/fanforce/app_factory/cli/scaffolding_file.rb +510 -0
  18. data/lib/fanforce/app_factory/cli/scripts/config.rb +9 -0
  19. data/lib/fanforce/app_factory/cli/scripts/create.rb +64 -0
  20. data/lib/fanforce/app_factory/cli/scripts/destroy.rb +61 -0
  21. data/lib/fanforce/app_factory/cli/scripts/push.rb +70 -0
  22. data/lib/fanforce/app_factory/cli/scripts/restart.rb +40 -0
  23. data/lib/fanforce/app_factory/cli/scripts/setup.rb +70 -0
  24. data/lib/fanforce/app_factory/cli/scripts/status.rb +120 -0
  25. data/lib/fanforce/app_factory/cli/scripts/update.rb +41 -0
  26. data/lib/fanforce/app_factory/cli/uranium.rb +77 -0
  27. data/lib/fanforce/app_factory/cli/utils.rb +39 -0
  28. data/lib/fanforce/app_factory/cli_directory_of_apps.rb +50 -0
  29. data/lib/fanforce/app_factory/cli_single_app.rb +49 -0
  30. data/lib/fanforce/app_factory/controllers/base_controller.rb +0 -4
  31. data/lib/fanforce/app_factory/core_config.rb +25 -26
  32. data/lib/fanforce/app_factory/load.rb +8 -0
  33. data/lib/fanforce/app_factory/load_iron_worker.rb +2 -0
  34. data/lib/fanforce/app_factory/load_sprockets.rb +2 -0
  35. data/lib/fanforce/app_factory/scaffolding/._.gitignore.registry +1 -0
  36. data/lib/fanforce/app_factory/scaffolding/._Gemfile.registry +2 -0
  37. data/lib/fanforce/app_factory/scaffolding/._Rakefile.registry +2 -0
  38. data/lib/fanforce/app_factory/scaffolding/._config.json.registry +2 -0
  39. data/lib/fanforce/app_factory/scaffolding/._config.ru.registry +2 -0
  40. data/lib/fanforce/app_factory/scaffolding/._favicon.ico.registry +1 -0
  41. data/lib/fanforce/app_factory/scaffolding/._robots.txt.registry +2 -0
  42. data/lib/fanforce/app_factory/scaffolding/.gitignore +27 -0
  43. data/lib/fanforce/app_factory/scaffolding/Gemfile +9 -0
  44. data/lib/fanforce/app_factory/scaffolding/Rakefile +7 -0
  45. data/lib/fanforce/app_factory/{scafolding → scaffolding}/Routes.rb +5 -1
  46. data/lib/fanforce/app_factory/scaffolding/assets/css/._engagement.scss.registry +2 -0
  47. data/lib/fanforce/app_factory/scaffolding/assets/css/._fembedded.scss.registry +2 -0
  48. data/lib/fanforce/app_factory/scaffolding/assets/css/._promotional.scss.registry +3 -0
  49. data/lib/fanforce/app_factory/{scafolding/scafolding_assets → scaffolding/assets}/css/engagement.scss +8 -5
  50. data/lib/fanforce/app_factory/scaffolding/assets/css/fembedded.scss +22 -0
  51. data/lib/fanforce/app_factory/{scafolding/scafolding_assets → scaffolding/assets}/css/promotional.scss +9 -4
  52. data/lib/fanforce/app_factory/scaffolding/assets/img/._icon-16.png.registry +1 -0
  53. data/lib/fanforce/app_factory/scaffolding/assets/img/._icon-32.png.registry +1 -0
  54. data/lib/fanforce/app_factory/scaffolding/assets/img/._icon-42.png.registry +1 -0
  55. data/lib/fanforce/app_factory/scaffolding/assets/img/._marketplace.png.registry +1 -0
  56. data/lib/fanforce/app_factory/{scafolding/scafolding_assets → scaffolding/assets}/img/icon-16.png +0 -0
  57. data/lib/fanforce/app_factory/{scafolding/scafolding_assets → scaffolding/assets}/img/icon-32.png +0 -0
  58. data/lib/fanforce/app_factory/{scafolding/scafolding_assets → scaffolding/assets}/img/icon-42.png +0 -0
  59. data/lib/fanforce/app_factory/{scafolding/scafolding_assets → scaffolding/assets}/img/marketplace.png +0 -0
  60. data/lib/fanforce/app_factory/scaffolding/assets/img/promotional/._fanforce_bg.png.registry +1 -0
  61. data/lib/fanforce/app_factory/scaffolding/assets/img/promotional/._icon-42.png.registry +1 -0
  62. data/lib/fanforce/app_factory/scaffolding/assets/img/promotional/._icon-plus.png.registry +1 -0
  63. data/lib/fanforce/app_factory/{scafolding/scafolding_assets → scaffolding/assets}/img/promotional/fanforce_bg.png +0 -0
  64. data/lib/fanforce/app_factory/{scafolding/scafolding_assets → scaffolding/assets}/img/promotional/icon-42.png +0 -0
  65. data/lib/fanforce/app_factory/{scafolding/scafolding_assets → scaffolding/assets}/img/promotional/icon-plus.png +0 -0
  66. data/lib/fanforce/app_factory/scaffolding/assets/js/._fembedded-app.coffee.registry +2 -0
  67. data/lib/fanforce/app_factory/scaffolding/assets/js/._fembedded.js.registry +2 -0
  68. data/lib/fanforce/app_factory/scaffolding/assets/js/._promotional.js.registry +2 -0
  69. data/lib/fanforce/app_factory/scaffolding/assets/js/fembedded-app.coffee +11 -0
  70. data/lib/fanforce/app_factory/scaffolding/assets/js/fembedded.js +12 -0
  71. data/lib/fanforce/app_factory/scaffolding/assets/js/lib/._cookie.coffee.registry +2 -0
  72. data/lib/fanforce/app_factory/scaffolding/assets/js/lib/._filters.coffee.registry +2 -0
  73. data/lib/fanforce/app_factory/scaffolding/assets/js/lib/._utils.coffee.registry +2 -0
  74. data/lib/fanforce/app_factory/scaffolding/assets/js/lib/cookie.coffee +24 -0
  75. data/lib/fanforce/app_factory/scaffolding/assets/js/lib/filters.coffee +9 -0
  76. data/lib/fanforce/app_factory/scaffolding/assets/js/lib/utils.coffee +40 -0
  77. data/lib/fanforce/app_factory/scaffolding/assets/js/promotional.js +4 -0
  78. data/lib/fanforce/app_factory/scaffolding/config.json +24 -0
  79. data/lib/fanforce/app_factory/scaffolding/config.ru +8 -0
  80. data/lib/fanforce/app_factory/{scafolding/public → scaffolding}/favicon.ico +0 -0
  81. data/lib/fanforce/app_factory/scaffolding/layouts/._engagement.haml.registry +1 -0
  82. data/lib/fanforce/app_factory/scaffolding/layouts/._fembedded.haml.registry +2 -0
  83. data/lib/fanforce/app_factory/scaffolding/layouts/._promotional.haml.registry +1 -0
  84. data/lib/fanforce/app_factory/{scafolding → scaffolding}/layouts/engagement.haml +5 -4
  85. data/lib/fanforce/app_factory/scaffolding/layouts/fembedded.haml +26 -0
  86. data/lib/fanforce/app_factory/scaffolding/layouts/promotional.haml +19 -0
  87. data/lib/fanforce/app_factory/scaffolding/robots.txt +7 -0
  88. data/lib/fanforce/app_factory/scaffolding/views/._index.haml.registry +1 -0
  89. data/lib/fanforce/app_factory/{scafolding → scaffolding}/views/index.haml +13 -7
  90. data/lib/fanforce/app_factory/sinatra/_load.rb +7 -7
  91. data/lib/fanforce/app_factory/sinatra/helper_routes/app.rb +2 -2
  92. data/lib/fanforce/app_factory/sinatra/helper_routes/com_behavior.rb +2 -2
  93. data/lib/fanforce/app_factory/sinatra/helper_routes/com_broadcaster.rb +1 -1
  94. data/lib/fanforce/app_factory/sinatra/helper_routes/com_connector.rb +2 -2
  95. data/lib/fanforce/app_factory/sprockets/compiler.rb +0 -1
  96. data/lib/fanforce/app_factory/version.rb +1 -1
  97. data/workers.json +8 -8
  98. metadata +80 -38
  99. data/lib/fanforce/app_factory/asset_framework/app_factory/directives/internal-iframe/internal-iframe.scss +0 -1
  100. data/lib/fanforce/app_factory/asset_framework/app_factory/lib/cookie.coffee +0 -16
  101. data/lib/fanforce/app_factory/asset_framework/app_factory/lib/url.coffee +0 -20
  102. data/lib/fanforce/app_factory/asset_framework/app_factory/lib/utils.coffee +0 -11
  103. data/lib/fanforce/app_factory/asset_framework/app_factory/scafolding/_engagement.scss +0 -1
  104. data/lib/fanforce/app_factory/asset_framework/app_factory/scafolding/_promotional.scss +0 -1
  105. data/lib/fanforce/app_factory/asset_framework/app_factory/scafolding/_standard.scss +0 -1
  106. data/lib/fanforce/app_factory/asset_framework/app_factory/scafolding/promotional.coffee +0 -0
  107. data/lib/fanforce/app_factory/cli/_cleanorgs.rb +0 -54
  108. data/lib/fanforce/app_factory/scafolding/public/robots.txt +0 -2
  109. data/lib/fanforce/app_factory/scafolding/scafolding_assets/css/standard.scss +0 -10
  110. data/lib/fanforce/app_factory/scafolding/scafolding_assets/img/marketplace.psd +0 -0
  111. data/lib/fanforce/app_factory/scafolding/views/add_initiative.haml +0 -1
  112. data/lib/fanforce/app_factory/scafolding/views/add_source.haml +0 -1
  113. data/lib/fanforce/app_factory/scafolding/views/close_popup.haml +0 -8
  114. data/lib/fanforce/app_factory/scafolding/views/config.haml +0 -1
  115. data/lib/fanforce/app_factory/scafolding/views/convert_initiative.haml +0 -1
  116. data/lib/fanforce/app_factory/scafolding/views/dashboard.haml +0 -38
  117. data/lib/fanforce/app_factory/scafolding/views/edit_initiative.haml +0 -1
  118. data/lib/fanforce/app_factory/scafolding/views/engage.haml +0 -1
  119. data/lib/fanforce/app_factory/scafolding/views/new_message.haml +0 -1
  120. data/lib/fanforce/app_factory/scafolding/views/source_details.haml +0 -1
  121. data/lib/fanforce/app_factory/scafolding/views/widget_templates.haml +0 -1
  122. data/lib/fanforce/app_factory/sprockets/_all.rb +0 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d2cc605d9d2693397cdfe4a5a0a6db00790d73f8
4
- data.tar.gz: 9a3b89edf82df58d356092cf3db6994b5a28cd89
3
+ metadata.gz: f69a47588a1916426ea604400c5f15d599bfeb51
4
+ data.tar.gz: 7b39b239999a276a962daa1638dc496aac4082c3
5
5
  SHA512:
6
- metadata.gz: 04cb1fbe0ab56c6fbb25296b91ec7cc0ed552eb353d961022b1824ff6da9f0063245b0655859ee0a8c03c5b4db6bccf98e1e6448a347b37d7d067cb6466776d2
7
- data.tar.gz: 33de98411d8abd588756b27f6b980606f38909eda0167a7f6226aa549f0728981f11fafdc03254465dcab370990021a969321eda935025417e428fb49aebb65c
6
+ metadata.gz: c4173c97ea4d03b8e40aba38f92625b2a36baaf927574d5bf3eb2581d60f0fde4be57aa3a08bd83666a801f81d5d39601acf321aa0dc2181bc23cf2ead46b84b
7
+ data.tar.gz: 195b5b5a09f9cba89050a66cad0adcfeabc222b2eb680f86053cebb69f551ceff8ec329d3d53b1e39eaf983772f51bfbd5f98f3d3ac3458ab299b02921599576
data/.gitignore CHANGED
@@ -14,6 +14,7 @@ tmp
14
14
  .idea/
15
15
  .DS_STORE
16
16
  Gemfile.lock
17
+ !._*.registry
17
18
 
18
19
  # YARD artifacts
19
20
  .yardoc
data/Rakefile CHANGED
@@ -3,13 +3,64 @@ require 'rake/testtask'
3
3
  require 'fileutils'
4
4
  include FileUtils
5
5
 
6
- task :run_test do
6
+ task :pre_build do
7
7
  Rake::Task['test'].execute
8
8
  puts '---------------------------------------------------------------------'
9
- puts 'TESTS PASSED... READY TO BUILD...'
9
+ puts 'TESTS PASSED!'
10
10
  puts '---------------------------------------------------------------------'
11
+ puts 'UPDATING SCAFFOLDING DIGESTS...'
12
+ Rake::Task['scaffolding:register'].execute
13
+ puts 'READY TO BUILD!'
14
+ puts '---------------------------------------------------------------------'
15
+ end
16
+
17
+ namespace :scaffolding do
18
+ require 'digest'
19
+
20
+ class Fanforce::CLI
21
+ DIR = ''
22
+ TYPE = ''
23
+ end
24
+
25
+ require 'fanforce/app_factory/cli'
26
+ require 'fanforce/app_factory/cli/scaffolding_file'
27
+
28
+ task :register do
29
+ scaffolding_dir = File.expand_path('../lib/fanforce/app_factory/scaffolding', __FILE__)
30
+
31
+ Dir.glob("#{scaffolding_dir}/**/*", File::FNM_DOTMATCH).each do |scaffold_filepath|
32
+ next if scaffold_filepath =~ /\.registry/ or File.directory?(scaffold_filepath)
33
+
34
+ file_parts = scaffold_filepath.split('/')
35
+ registry_filepath = "#{file_parts[0...-1].join('/')}/._#{file_parts[-1]}.registry"
36
+
37
+ file = Fanforce::AppFactory::CLI::ScaffoldingFile.new(scaffold_filepath)
38
+ if [:file,:image,:partial].include?(file.scaffold_type)
39
+ next if file.digest_exists_in_registry?(file.scaffold_digest)
40
+ File.open(registry_filepath, 'a') {|f|
41
+ f.puts "fanforce-app-factory-#{Fanforce::AppFactory::VERSION}:#{file.scaffold_digest}"
42
+ }
43
+ elsif [:items].include?(file.scaffold_type)
44
+ scaffold_contents = File.open(file.scaffold_filepath).read
45
+ raise "item changes are not registered for #{file.scaffold_filepath}" if !file.list_matches_latest_registry?(scaffold_contents)
46
+ next
47
+ elsif [:json].include?(file.scaffold_type)
48
+ scaffold_contents = File.open(file.scaffold_filepath).read
49
+ raise "json changes are not registered for #{file.scaffold_filepath}" if !file.json_matches_latest_registry?(scaffold_contents)
50
+ next
51
+ elsif [:skipped].include?(file.scaffold_type)
52
+ next
53
+ else
54
+ raise "unknown scaffold type: #{file.scaffold_type}"
55
+ end
56
+
57
+ puts "- REGISTERED #{scaffold_filepath.gsub(scaffolding_dir, '')} (#{file.scaffold_type})"
58
+ end
59
+ end
60
+
11
61
  end
12
- task :build => :run_test
62
+
63
+ task :build => :pre_build
13
64
  task :default => :build
14
65
 
15
66
  ########################################################################
data/apps.json CHANGED
@@ -24,7 +24,7 @@
24
24
  "status": "active",
25
25
  "permissions": "ALL",
26
26
  "type": "development",
27
- "domain": "{{APP_ID}}.ffapp.gg",
27
+ "domain": "{{APP_ID}}.ffapp.dev",
28
28
  "dns_host": "127.0.0.1"
29
29
  },
30
30
  "config_override": {},
@@ -219,7 +219,7 @@
219
219
  "status": "active",
220
220
  "permissions": "ALL",
221
221
  "type": "development",
222
- "domain": "{{APP_ID}}.ffapp.gg",
222
+ "domain": "{{APP_ID}}.ffapp.dev",
223
223
  "dns_host": "127.0.0.1"
224
224
  },
225
225
  "config_override": {},
@@ -343,7 +343,7 @@
343
343
  "status": "active",
344
344
  "permissions": "ALL",
345
345
  "type": "development",
346
- "domain": "{{APP_ID}}.ffapp.gg",
346
+ "domain": "{{APP_ID}}.ffapp.dev",
347
347
  "dns_host": "127.0.0.1"
348
348
  },
349
349
  "config_override": {},
@@ -434,7 +434,7 @@
434
434
  "status": "active",
435
435
  "permissions": "ALL",
436
436
  "type": "development",
437
- "domain": "{{APP_ID}}.ffapp.gg",
437
+ "domain": "{{APP_ID}}.ffapp.dev",
438
438
  "dns_host": "127.0.0.1"
439
439
  },
440
440
  "config_override": {},
@@ -500,7 +500,7 @@
500
500
  "status": "active",
501
501
  "permissions": "ALL",
502
502
  "type": "development",
503
- "domain": "{{APP_ID}}.ffapp.gg",
503
+ "domain": "{{APP_ID}}.ffapp.dev",
504
504
  "dns_host": "127.0.0.1"
505
505
  },
506
506
  "config_override": {},
@@ -580,7 +580,7 @@
580
580
  "status": "active",
581
581
  "permissions": "ALL",
582
582
  "type": "development",
583
- "domain": "{{APP_ID}}.ffapp.gg",
583
+ "domain": "{{APP_ID}}.ffapp.dev",
584
584
  "dns_host": "127.0.0.1"
585
585
  },
586
586
  "config_override": {},
@@ -671,7 +671,7 @@
671
671
  "status": "active",
672
672
  "permissions": "ALL",
673
673
  "type": "development",
674
- "domain": "{{APP_ID}}.ffapp.gg",
674
+ "domain": "{{APP_ID}}.ffapp.dev",
675
675
  "dns_host": "127.0.0.1"
676
676
  },
677
677
  "config_override": {},
@@ -718,7 +718,7 @@
718
718
  "status": "active",
719
719
  "permissions": "ALL",
720
720
  "type": "development",
721
- "domain": "{{APP_ID}}.ffapp.gg",
721
+ "domain": "{{APP_ID}}.ffapp.dev",
722
722
  "dns_host": "127.0.0.1"
723
723
  },
724
724
  "config_override": {},
@@ -1,23 +1,26 @@
1
- require 'redis'
2
- require 'fileutils'
3
- require 'rack/jsonr'
4
- require 'sinatra/base'
5
- require 'active_support/all'
1
+ require_relative 'app_factory/version'
2
+ require_relative 'app_factory/load'
6
3
 
7
- require 'fanforce/api'
8
- require 'fanforce/app_worker'
4
+ ########################################################################################################################
9
5
 
10
- require_relative 'app_factory/version'
6
+ class Fanforce::AppFactory
11
7
 
8
+ def self.generate(app_base_dir)
9
+ require_relative 'app_factory/app'
10
+ require_relative 'app_factory/load_sprockets' if ENV['RACK_ENV'] == 'development'
11
+
12
+ Fanforce::App.load(app_base_dir)
13
+ end
14
+ end
15
+
16
+ ########################################################################################################################
17
+
18
+ # The following is run if file is required from config.ru or Rakefile
12
19
  if caller[0].split(':')[0] =~ /^(.+)\/(config\.ru|Rakefile)$/
13
- $root_dir = $1
14
- $loader_filename = $2
20
+ app_base_dir = $1
21
+ loader_filename = $2
15
22
  ENV['RACK_ENV'] ||= 'development'
16
23
 
17
- require_relative 'app_factory/app'
18
- require_relative 'app_factory/core_config'
19
- require_relative 'app_factory/sprockets/_all' if ENV['RACK_ENV'] == 'development'
20
-
21
- Fanforce::App.start($root_dir, $loader_filename)
22
- load "#{Fanforce::App.config.factory_dir}/Rakefile" if $loader_filename == 'Rakefile'
24
+ Fanforce::AppFactory.generate(app_base_dir)
25
+ load "#{Fanforce::App.config.factory_dir}/Rakefile" if loader_filename == 'Rakefile'
23
26
  end
@@ -2,7 +2,7 @@ require 'fileutils'
2
2
  require 'json'
3
3
  require 'yaml'
4
4
 
5
- require_relative 'sprockets/_all'
5
+ require_relative 'sprockets/load_sprockets'
6
6
 
7
7
  ########################################################################################################################
8
8
 
@@ -18,7 +18,7 @@ namespace :assets do
18
18
  desc 'Precompile assets for production'
19
19
  task :precompile => :clean do
20
20
  config = App.config
21
- sprockets = SprocketsCompiler.setup(config.root_dir)
21
+ sprockets = SprocketsCompiler.setup(config.base_dir)
22
22
 
23
23
  puts 'PRECOMPILING ASSETS... '
24
24
  SprocketsCompiler.new(sprockets: sprockets, precompile: [/(\/|^)[^_\/]+[^\/]*\.(css|js|png|gif|jpeg|jpg|otf|eot|svg|ttf|woff)/]).compile
@@ -31,24 +31,16 @@ namespace :assets do
31
31
  asset_list[logical_path] = "/assets/#{asset.digest_path}"
32
32
  end
33
33
  end
34
- IO.write File.join(config.root_dir, '/public/asset_manifest.json'), JSON.generate(asset_list)
35
- IO.write File.join(config.root_dir, '/public/asset_manifest.json'), "ASSETS=#{JSON.generate(asset_list)}"
36
- IO.write File.join(config.root_dir, '/public/asset_manifest.json'), asset_list.to_yaml
37
- puts 'DONE'
38
-
39
- print 'ENSURING FAVICON EXISTS... '
40
- FileUtils.cp("#{config.factory_dir}/scafolding/public/favicon.ico", "#{config.root_dir}/public/favicon.ico") if !File.exists?(config.root_dir+'/public/favicon.ico')
41
- puts 'DONE'
42
-
43
- print 'ENSURING ROBOTS.TXT EXISTS... '
44
- FileUtils.cp("#{config.factory_dir}/scafolding/public/robots.txt", "#{config.root_dir}/public/robots.txt") if !File.exists?(config.root_dir+'/public/robots.txt')
34
+ IO.write File.join(config.base_dir, '/public/asset_manifest.json'), JSON.generate(asset_list)
35
+ IO.write File.join(config.base_dir, '/public/asset_manifest.json'), "ASSETS=#{JSON.generate(asset_list)}"
36
+ IO.write File.join(config.base_dir, '/public/asset_manifest.json'), asset_list.to_yaml
45
37
  puts 'DONE'
46
38
  end
47
39
 
48
40
  desc 'Clean assets folder'
49
41
  task :clean do
50
42
  print 'DESTROYING PUBLIC/ASSETS... '
51
- FileUtils.rm_rf File.join(App.config.root_dir, '/public/assets')
43
+ FileUtils.rm_rf File.join(App.config.base_dir, '/public/assets')
52
44
  puts 'DONE'
53
45
  end
54
46
 
@@ -1,7 +1,7 @@
1
1
  class Fanforce::App::Sinatra
2
2
 
3
3
  get '/internals/config.json' do
4
- file = File.open("#{Fanforce::App.root_dir}/config.json")
4
+ file = File.open("#{Fanforce::App.base_dir}/config.json")
5
5
  config = MultiJson.load(file.read, symbolize_keys: true)
6
6
  config[:iron_workers] ||= []
7
7
 
@@ -14,7 +14,7 @@ class Fanforce::App::Sinatra
14
14
  end
15
15
 
16
16
  post '/internals/config.json' do
17
- filename = "#{Fanforce::App.root_dir}/config.json"
17
+ filename = "#{Fanforce::App.base_dir}/config.json"
18
18
  file = File.open(filename)
19
19
  old_config = MultiJson.load(file.read, symbolize_keys: true)
20
20
  new_config = MultiJson.load(params[:config], symbolize_keys: true)
@@ -1,14 +1,25 @@
1
+ require 'redis'
2
+ require 'fileutils'
3
+ require 'rack/jsonr'
4
+ require 'sinatra/base'
5
+ require 'active_support/all'
6
+ require 'fanforce/api'
7
+ require 'fanforce/app_worker'
8
+
9
+ require_relative 'core_config'
10
+
1
11
  class Fanforce::App
2
- @@initialized = nil
12
+ @@loaded = nil
3
13
  @@config = nil
4
14
 
5
15
  # Only one instance is allowed to initialize, and the resulting instance is stored in Fanforce::App.
6
- # @param root_dir [String] root dir of app
16
+ # @param base_dir [String] base dir of app
7
17
  # @param loader_filename [String] either config.ru or Rakefile
8
18
  # @return [Fanforce::App]
9
- def self.start(root_dir, loader_filename)
10
- @@initialized ? (raise 'Only one instance of Fanforce::AppFactory can be initialized') : @@initialized = true
11
- @@config = CoreConfig.new(root_dir, loader_filename)
19
+ def self.load(base_dir)
20
+ @@loaded ? (raise 'Only one instance of Fanforce::AppFactory can be loaded per process') : @@loaded = true
21
+ @@config = CoreConfig.new(base_dir)
22
+ return self
12
23
  end
13
24
 
14
25
  def self.app_id
@@ -20,8 +31,8 @@ class Fanforce::App
20
31
  block ? block.call(@@config) : @@config
21
32
  end
22
33
 
23
- def self.root_dir
24
- @@config.root_dir
34
+ def self.base_dir
35
+ @@config.base_dir
25
36
  end
26
37
 
27
38
  def self.is_bugsnag_enabled?
@@ -38,7 +49,7 @@ class Fanforce::App
38
49
  def self.call(env)
39
50
  if ENV['RACK_ENV'] == 'development' and env['PATH_INFO'] =~ /^\/assets\//
40
51
  env['PATH_INFO'] = env['PATH_INFO'].gsub(/^\/assets/, '')
41
- sprockets = SprocketsCompiler.setup(root_dir)
52
+ sprockets = SprocketsCompiler.setup(base_dir)
42
53
  return sprockets.index.call(env)
43
54
  end
44
55
  require_relative 'sinatra/_load'
@@ -0,0 +1,5 @@
1
+ require_relative 'version'
2
+
3
+ module Fanforce::AppFactory::CLI
4
+ require_relative 'cli/utils'
5
+ end
@@ -0,0 +1,70 @@
1
+ require 'bitbucket_rest_api'
2
+ require 'rest_client'
3
+
4
+ class Fanforce::AppFactory::CLI::Bitbucket
5
+ include Fanforce::AppFactory::CLI::Utils
6
+
7
+ attr_reader :app
8
+
9
+ def initialize(app)
10
+ @app = app
11
+ end
12
+
13
+ def bitbucket
14
+ @@bitbucket = ::BitBucket.new(login: config[:bitbucket][:user], password: config[:bitbucket][:password])
15
+ end
16
+
17
+ def create
18
+ repo_name = "app-#{app.dir_name}"
19
+ error "Bitbucket repo already exists (#{repo_name})" if find_repo(repo_name)
20
+ create_repo(repo_name)
21
+ puts "#{'Created '.format(:green,:bold)}" + "#{repo_name} repository on bitbucket"
22
+ end
23
+
24
+ def setup
25
+ repo_name = "app-#{app.dir_name}"
26
+ error "Bitbucket repo does not exist (#{repo_name})" if !find_repo(repo_name)
27
+ "#{'Found '.format(:green,:bold)}" + "#{repo_name} repository already exists on bitbucket"
28
+ setup_git_remote(repo_name)
29
+ end
30
+
31
+ def destroy
32
+ repo_name = "app-#{app.dir_name}"
33
+ if find_repo(repo_name)
34
+ RestClient::Request.execute(:method => :delete, :url => "https://#{config[:bitbucket][:user]}:#{config[:bitbucket][:password]}@api.bitbucket.org/1.0/repositories/#{config[:bitbucket][:user]}/#{repo_name}", :ssl_version => 'SSLv23')
35
+ puts "#{'Removed'.format(:green,:bold)}" + " #{repo_name}"
36
+ else
37
+ puts "#{'Already Removed'.format(:green,:bold)}" + " #{repo_name}"
38
+ end
39
+ end
40
+
41
+ def find_repo(repo_name)
42
+ bitbucket.repos.find(config[:bitbucket][:user], repo_name)
43
+ rescue
44
+ return nil
45
+ end
46
+
47
+ def setup_git_remote(repo_name)
48
+ if (`git remote`).split(/\r?\n/).include?(config[:bitbucket][:user])
49
+ puts "#{'Updated '.format(:green,:bold)}" + "git remote for #{config[:bitbucket][:user]}"
50
+ `git remote rm #{config[:bitbucket][:user]}`
51
+ elsif (`git remote`).split(/\r?\n/).include?('bitbucket')
52
+ `git remote rm bitbucket`
53
+ puts "#{'Removed '.format(:red,:bold)}" + "git remote for #{config[:bitbucket][:user]}"
54
+ puts "#{'Created '.format(:green,:bold)}" + 'git remote for bitbucket'
55
+ else
56
+ puts "#{'Created '.format(:green,:bold)}" + 'git remote for bitbucket'
57
+ end
58
+ `git remote add bitbucket git@bitbucket.org:#{config[:bitbucket][:user]}/#{repo_name}.git`
59
+
60
+ puts "#{'Pushing '.format(:green,:bold)}" + "latest commit to #{config[:bitbucket][:user]}..."
61
+ console_command('git push bitbucket --all')
62
+ end
63
+
64
+ def create_repo(repo_name)
65
+ bitbucket.repos.create(name: repo_name, is_private: true)
66
+ rescue ::BitBucket::Error::Unauthorized => e
67
+ raise "Bitbucket user #{config[:bitbucket][:user]} does not seem to exist: #{e.message}"
68
+ end
69
+
70
+ end
@@ -0,0 +1,21 @@
1
+ class Fanforce::AppFactory::CLI::Bundler
2
+ include Fanforce::AppFactory::CLI::Utils
3
+
4
+ attr_reader :app
5
+
6
+ def initialize(app)
7
+ @app = app
8
+ end
9
+
10
+ def setup
11
+ if Gem::Specification::find_all_by_name('bundler').empty?
12
+ puts 'Installing Bundler... '
13
+ `gem install bundler`
14
+ puts 'DONE'
15
+ end
16
+
17
+ console_command('bundle')
18
+ puts 'DONE'.format(:green)
19
+ end
20
+
21
+ end
@@ -0,0 +1,99 @@
1
+ require 'yaml'
2
+
3
+ class Fanforce::AppFactory::CLI::Env
4
+ include Fanforce::AppFactory::CLI::Utils
5
+
6
+ attr_reader :app
7
+
8
+ def initialize(app)
9
+ @app = app
10
+ end
11
+
12
+ def setup(environment)
13
+ bind_path = "#{app.dir}/../.env/_bind.yml"
14
+ error 'You must setup .env/_bind.yml before updating env variables.' if !File.exists?(bind_path)
15
+
16
+ vars = app_vars(environment)
17
+ has_workers = File.directory?("#{app.dir}/workers") ? true : false
18
+
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)
25
+ end
26
+
27
+ def push_env_to(environment, vars, create_worker_env=true)
28
+ vars.each {|k,v| puts " - #{k}" }
29
+ workers_dir = "#{app.dir}/workers"
30
+ workers_env_dir = "#{workers_dir}/.env"
31
+ if create_worker_env and File.directory?(workers_dir) and vars['IRON_PROJECT_ID']
32
+ FileUtils.mkdir_p(workers_env_dir) unless File.directory?(workers_env_dir)
33
+ File.open("#{workers_env_dir}/#{environment}.rb", 'w') {|f| f.write convert_hash_to_ruby_env(vars) }
34
+ end
35
+ if environment == :development
36
+ update_powenv
37
+ File.open("#{app.dir}/.appenv", 'w') {|f| f.write convert_hash_to_shell_env(vars) }
38
+ 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)
43
+ end
44
+ end
45
+
46
+ def convert_hash_to_shell_env(hash)
47
+ hash.inject('') {|script, (k,v)| script += "export #{k}=#{v.to_s.to_json}\n" }
48
+ end
49
+
50
+ def convert_hash_to_ruby_env(hash)
51
+ hash.inject('') {|script, (k,v)| script += "ENV['#{k}']=#{v.to_s.to_json}\n" }
52
+ end
53
+
54
+ def load_app_vars(environment)
55
+ environment = environment.to_sym
56
+ vars = {'FANFORCE_APP_ID' => app._id}
57
+ raw_yaml = File.read("#{app.dir}/../.env/_bind.yml")
58
+ bindings = (raw_yaml.present?) ? YAML.load(raw_yaml) : {}
59
+ bindings.each do |filename, dir_names|
60
+ file = YAML.load_file("#{app.dir}/../.env/#{filename}.yml").symbolize_keys
61
+ next if file[environment].blank?
62
+
63
+ dir_names = [app.dir_name] if dir_names.is_a?(String) and dir_names.upcase == 'ALL'
64
+ file[environment].each do |k,v|
65
+ dir_names.each {|dir_name| vars["#{filename}_#{k}".upcase] = v if dir_name == app.dir_name }
66
+ end
67
+ end
68
+ return vars
69
+ end
70
+
71
+ def app_vars(environment)
72
+ @vars ||= {}
73
+ @vars[environment] ||= load_app_vars(environment)
74
+ end
75
+
76
+ # .POWENV #######################################################################
77
+
78
+ def create_powenv
79
+ file = powenv_lines.join("\n") + "\n"
80
+ File.open("#{app.dir}/.powenv", 'w') {|f| f.write file }
81
+ end
82
+
83
+ def update_powenv
84
+ return create_powenv if !File.exists?("#{app.dir}/.powenv")
85
+
86
+ lines = File.open("#{app.dir}/.powenv", 'r') {|f| f.readlines}.map {|l| l.strip }
87
+
88
+ powenv_lines.each do |line|
89
+ lines << line if !lines.include?(line)
90
+ end
91
+
92
+ File.open("#{app.dir}/.powenv", 'w') {|f| f.write(lines.join "\n") }
93
+ end
94
+
95
+ def powenv_lines
96
+ ['source .appenv']
97
+ end
98
+
99
+ end