firebase-cloning-tool 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8bbc183fa81c4278c81c6c6799fcd6ff5af74095
4
+ data.tar.gz: 59c9eb735d2afd8895c6f4f09e08f54d3166b295
5
+ SHA512:
6
+ metadata.gz: 5934a4124fb6c9a705e1c56ce1ad5bc414abd5368da77bd1443e82ca77002191ee49be85b389a3be44f396f5a2ca6bec4cce8fa983ac688c7938a434c2eb4b30
7
+ data.tar.gz: 82b73b5bfa574db035b88844f7e149e5f56d5792b3fc42708d76b248e626a1fb47d05c8644d8818a459ce0f4423451ab24e91edbcedaec6d85df5e2c119b1b02
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in firebase-cloning-tool.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 epool
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Firebase::Cloning::Tool
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/firebase/cloning/tool`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'firebase-cloning-tool'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install firebase-cloning-tool
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/firebase-cloning-tool.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "firebase/cloning/tool"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'firebase/cloning/tool'
4
+
5
+ Firebase::Cloning::Tool.clone_firebase_remote_config
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'firebase/cloning/tool/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "firebase-cloning-tool"
8
+ spec.version = Firebase::Cloning::Tool::VERSION
9
+ spec.authors = ["epool"]
10
+ spec.email = ["eduardo.alejandro.pool.ake@gmail.com"]
11
+
12
+ spec.summary = %q{Tool for cloning firebase remote config projects.}
13
+ spec.description = %q{Tool for cloning firebase remote config projects.}
14
+ spec.homepage = "https://github.com/epool/firebase-cloning-tool"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "bin"
27
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency 'capybara', '~> 2.7.1'
31
+ spec.add_dependency 'selenium-webdriver', '~> 2.53.1'
32
+ spec.add_dependency 'chromedriver-helper', '~> 1.0.0'
33
+ spec.add_dependency 'pry'
34
+ spec.add_dependency 'pry-byebug', '~> 3.2.0'
35
+
36
+ spec.add_development_dependency "bundler", "~> 1.12"
37
+ spec.add_development_dependency "rake", "~> 10.0"
38
+ end
@@ -0,0 +1,165 @@
1
+ require "firebase/cloning/tool/version"
2
+ require 'capybara'
3
+ require 'capybara/dsl'
4
+ require 'pry'
5
+ require 'io/console'
6
+
7
+ module Firebase
8
+ module Cloning
9
+ module Tool
10
+
11
+ def self.wait_until_text_is_present(text, wait=5)
12
+ wait.times do
13
+ break if Capybara.has_text? text
14
+ puts 'Waiting for text: ' + text + '...'
15
+ sleep 1
16
+ end
17
+ end
18
+
19
+ def self.wait_until_text_is_not_present(text, wait=5)
20
+ wait.times do
21
+ break if Capybara.has_no_text? text
22
+ puts 'Waiting until text dissapear: ' + text + '...'
23
+ sleep 1
24
+ end
25
+ end
26
+
27
+ def self.do_login(email, password)
28
+ puts 'Trying sign in for ' + email + '...'
29
+ Capybara.fill_in('Email', with: email)
30
+ Capybara.find('#next').click
31
+ Capybara.fill_in('Passwd', with: password)
32
+ Capybara.find('#signIn').click
33
+ wait_until_text_is_present('Welcome back to Firebase')
34
+ puts 'Sign in completed.'
35
+ end
36
+
37
+ def self.go_to_settings
38
+ puts 'Going to project settings...'
39
+ Capybara.find('.md-button.md-gmp-blue-theme.md-ink-ripple.md-icon-button').click
40
+ Capybara.find('button', :text => 'Project settings').click
41
+ wait_until_text_is_present('Web API Key')
42
+ puts 'Project settings loaded.'
43
+ end
44
+
45
+ def self.update_web_api_key(remoteConfigValues)
46
+ puts 'Updating web api key...'
47
+ web_api_key = Capybara.find('label', :text => 'Web API Key').first(:xpath,".//..").find('span').text()
48
+ remoteConfigValues['firebase_web_api_key'] = web_api_key
49
+ puts 'Web api key updated.'
50
+ end
51
+
52
+ def self.create_new_project(project_name)
53
+ puts 'Creating new project: ' + project_name + '...'
54
+ Capybara.find('button', :text => 'CREATE NEW PROJECT').click
55
+ Capybara.find(:xpath, '//input[@placeholder="My awesome project"]').set project_name
56
+ Capybara.find('button', :text => 'CREATE PROJECT').click
57
+ wait_until_text_is_not_present('Create a project')
58
+ puts 'Project ' + project_name + ' created.'
59
+ wait_until_text_is_present('Overview')
60
+ puts 'Project ' + project_name + ' loaded.'
61
+ end
62
+
63
+ def self.go_to_project(project_name)
64
+ puts 'Opening ' + project_name + ' project...'
65
+ Capybara.find('md-card', :text => project_name).click
66
+ wait_until_text_is_present('Overview')
67
+ puts 'Project ' + project_name + ' loaded.'
68
+ end
69
+
70
+ def self.go_to_remote_config(has_config=false)
71
+ puts 'Going to remote config...'
72
+ Capybara.find('.c5e-entry-displayname', :text => 'Remote Config').first(:xpath,".//..").click
73
+ if has_config
74
+ puts 'Waiting for remote config data...'
75
+ wait_until_text_is_present('ADD PARAMETER')
76
+ Capybara.find('button', :text => 'ADD PARAMETER').click
77
+ else
78
+ puts 'Waiting to add new remote config data...'
79
+ wait_until_text_is_present('ADD YOUR FIRST PARAMETER')
80
+ Capybara.find('button', :text => 'ADD YOUR FIRST PARAMETER').click
81
+ end
82
+ puts 'Remote config loaded.'
83
+ end
84
+
85
+ def self.copy_remote_config
86
+ puts 'Copying remote config to memory...'
87
+ remoteConfigValues = {}
88
+ Capybara.all('.r10g-param-row.layout-xs-column.layout-row.flex').each {
89
+ |element|
90
+ remoteConfigValues[element.find('.r10g-codefont.r10g-param-row-key.fb-highlightable').text()] = element.find('.chip-value.fb-highlightable').text()
91
+ }
92
+ puts 'Remote config copied.'
93
+ return remoteConfigValues
94
+ end
95
+
96
+ def self.paste_remote_config(remoteConfigValues)
97
+ puts 'Pasting remote config from memory...'
98
+ remoteConfigValues.each do | key, value |
99
+ Capybara.find(:xpath, '//input[@name="paramKey"]').set key
100
+ Capybara.find(:xpath, '//input[@placeholder="(empty string)"]').set value
101
+ Capybara.find('button', :text => 'ADD PARAMETER').click
102
+ Capybara.find('button', :text => 'ADD PARAMETER').click
103
+ end
104
+ Capybara.find('button', :text => 'CANCEL').click
105
+ puts 'Remote config pasted.'
106
+ end
107
+
108
+ def self.publish_changes
109
+ puts 'Publishing remote config...'
110
+ Capybara.find('button.md-secondary', :text => 'PUBLISH CHANGES').click
111
+ Capybara.find('button.md-primary', :text => 'PUBLISH CHANGES').click
112
+ wait_until_text_is_present('Published')
113
+ puts 'Remote config published.'
114
+ end
115
+
116
+ def self.clone_firebase_remote_config
117
+ print 'Email: '
118
+ email = gets.chomp
119
+ print 'Password: '
120
+ password = STDIN.noecho(&:gets).chomp
121
+ puts
122
+ print 'Source(Project Name): '
123
+ source_project = gets.chomp
124
+ print 'Destination(New Project Name): '
125
+ destination_project = gets.chomp
126
+
127
+ # overrides selenium's driver to use chrome browser
128
+ Capybara.register_driver :chrome_driver do |app|
129
+ Capybara::Selenium::Driver.new(app, {:browser => :chrome})
130
+ end
131
+
132
+ # selecting the driver
133
+ Capybara.default_driver = :chrome_driver
134
+
135
+ Capybara.visit 'https://console.firebase.google.com/'
136
+ do_login(email, password)
137
+
138
+ go_to_project(source_project)
139
+ go_to_remote_config(true)
140
+
141
+ remoteConfigValues = copy_remote_config()
142
+ Capybara.visit 'https://console.firebase.google.com/'
143
+ wait_until_text_is_present('Welcome back to Firebase')
144
+
145
+ if !Capybara.has_text? destination_project
146
+ create_new_project(destination_project)
147
+ else
148
+ go_to_project(destination_project)
149
+ end
150
+
151
+ go_to_settings()
152
+ update_web_api_key(remoteConfigValues)
153
+ go_to_remote_config()
154
+
155
+ paste_remote_config(remoteConfigValues)
156
+
157
+ publish_changes()
158
+ go_to_settings()
159
+
160
+ puts 'Project cloned successfully!!!'
161
+ end
162
+
163
+ end
164
+ end
165
+ end
@@ -0,0 +1,7 @@
1
+ module Firebase
2
+ module Cloning
3
+ module Tool
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: firebase-cloning-tool
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - epool
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capybara
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.7.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.7.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: selenium-webdriver
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.53.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.53.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: chromedriver-helper
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 3.2.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.2.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.12'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.12'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ description: Tool for cloning firebase remote config projects.
112
+ email:
113
+ - eduardo.alejandro.pool.ake@gmail.com
114
+ executables:
115
+ - console
116
+ - firebase-cloning-tool
117
+ - setup
118
+ extensions: []
119
+ extra_rdoc_files: []
120
+ files:
121
+ - ".gitignore"
122
+ - Gemfile
123
+ - LICENSE.txt
124
+ - README.md
125
+ - Rakefile
126
+ - bin/console
127
+ - bin/firebase-cloning-tool
128
+ - bin/setup
129
+ - firebase-cloning-tool.gemspec
130
+ - lib/firebase/cloning/tool.rb
131
+ - lib/firebase/cloning/tool/version.rb
132
+ homepage: https://github.com/epool/firebase-cloning-tool
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.6.7
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: Tool for cloning firebase remote config projects.
156
+ test_files: []