polyglot_cli 0.1.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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.rubocop.yml +14 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/polyglot +63 -0
- data/lib/polyglot_cli/commands/login.rb +28 -0
- data/lib/polyglot_cli/commands/pull.rb +47 -0
- data/lib/polyglot_cli/commands/push.rb +103 -0
- data/lib/polyglot_cli/commands/setup.rb +37 -0
- data/lib/polyglot_cli/commands/status.rb +20 -0
- data/lib/polyglot_cli/error_handler.rb +26 -0
- data/lib/polyglot_cli/helpers/depaginate.rb +17 -0
- data/lib/polyglot_cli/helpers/general.rb +39 -0
- data/lib/polyglot_cli/helpers/nest.rb +31 -0
- data/lib/polyglot_cli/helpers/terminal.rb +15 -0
- data/lib/polyglot_cli/io/config.rb +21 -0
- data/lib/polyglot_cli/io/locale.rb +23 -0
- data/lib/polyglot_cli/io/token.rb +21 -0
- data/lib/polyglot_cli/resources/base.rb +22 -0
- data/lib/polyglot_cli/resources/language.rb +6 -0
- data/lib/polyglot_cli/resources/project.rb +7 -0
- data/lib/polyglot_cli/resources/session.rb +6 -0
- data/lib/polyglot_cli/resources/translation.rb +8 -0
- data/lib/polyglot_cli/resources/translation_key.rb +6 -0
- data/lib/polyglot_cli/version.rb +3 -0
- data/lib/polyglot_cli.rb +36 -0
- data/polyglot_cli.gemspec +39 -0
- metadata +178 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ae72077047be9a770cf1ce424f9591f153a342d7
|
4
|
+
data.tar.gz: 82447037cdd587057e644b3e797e3248d90365c0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3ad2c8a20c1d4c9a6dafc9c55e5485328fcc4a28034f53777df0b66412cb7d5bd59b903a4201c8718a5b43ea209426cd0a368ecb68825b5ce76af7b11a852a4f
|
7
|
+
data.tar.gz: 85a71e6b4028c54d0b1edb62ed28b66b800c8a0b450b26494db33f2448c94c28a8dcc3388921addb29fa497d1a99595386c1f6a7e2a32d3987e77cb5347947f5
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.1
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Ivan Grgurevic
|
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
|
+
# PolyglotCli
|
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/polyglot_cli`. 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 'polyglot_cli'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install polyglot_cli
|
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. Then, run `rake spec` to run the tests. 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]/polyglot_cli.
|
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
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "polyglot_cli"
|
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
|
data/bin/setup
ADDED
data/exe/polyglot
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'commander/import'
|
5
|
+
require 'polyglot_cli'
|
6
|
+
|
7
|
+
program :name, 'polyglot'
|
8
|
+
program :version, PolyglotCli::VERSION
|
9
|
+
program :description, 'A client for managing polyglot\'s translations.'
|
10
|
+
|
11
|
+
command :login do |c|
|
12
|
+
c.syntax = 'polyglot login'
|
13
|
+
c.description = 'Fetches and writes your API Key to the home folder using the email and password you provide.'
|
14
|
+
c.action do
|
15
|
+
PolyglotCli::ErrorHandler.rescuable do
|
16
|
+
PolyglotCli::Command::Login.init
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
command :init do |c|
|
22
|
+
c.syntax = 'polyglot init'
|
23
|
+
c.description = 'Sets up a Polyglot project you need for your current project.'
|
24
|
+
c.action do
|
25
|
+
PolyglotCli::ErrorHandler.rescuable do
|
26
|
+
PolyglotCli::Command::Setup.init
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
command :pull do |c|
|
32
|
+
c.syntax = 'polyglot pull [options]'
|
33
|
+
c.description = 'Pulls all translations from Polyglot and stores them in ./config/locales'
|
34
|
+
c.option '--locale STRING', String, 'Only pulls the specified locale'
|
35
|
+
c.option '--path STRING', String, 'Writes the translations to the specified location'
|
36
|
+
c.action do |args, options|
|
37
|
+
PolyglotCli::ErrorHandler.rescuable do
|
38
|
+
PolyglotCli::Command::Pull.init(options)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
command :push do |c|
|
44
|
+
c.syntax = 'polyglot push'
|
45
|
+
c.description = 'Writes all translations to Polyglot API'
|
46
|
+
c.option '--locale STRING', String, 'Only pushes the specified locale'
|
47
|
+
c.option '--path STRING', String, 'Reads the translations from the specified location'
|
48
|
+
c.action do |args, options|
|
49
|
+
PolyglotCli::ErrorHandler.rescuable do
|
50
|
+
PolyglotCli::Command::Push.init(options)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
command :status do |c|
|
56
|
+
c.syntax = 'polyglot status'
|
57
|
+
c.description = 'Displays if changes have been made on the server.'
|
58
|
+
c.action do
|
59
|
+
PolyglotCli::ErrorHandler.rescuable do
|
60
|
+
PolyglotCli::Command::Status.init
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module PolyglotCli
|
2
|
+
module Command
|
3
|
+
class Login
|
4
|
+
include Helper::Terminal
|
5
|
+
|
6
|
+
def self.init
|
7
|
+
new.call
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@email = prompt.ask('Email:') { |q| q.validate :email }
|
12
|
+
@password = prompt.mask('Password:')
|
13
|
+
end
|
14
|
+
|
15
|
+
def call
|
16
|
+
PolyglotCli::IO::Token.write(token)
|
17
|
+
success
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def token
|
23
|
+
prompt.say('Logging into API...')
|
24
|
+
PolyglotCli::Resource::Session.create(email: @email, password: @password).token
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module PolyglotCli
|
2
|
+
module Command
|
3
|
+
class Pull
|
4
|
+
include Helper::Nest
|
5
|
+
include Helper::Terminal
|
6
|
+
include Helper::General
|
7
|
+
|
8
|
+
def self.init(options)
|
9
|
+
new(options).call
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(options)
|
13
|
+
@locale = options.locale
|
14
|
+
@path = options.path
|
15
|
+
end
|
16
|
+
|
17
|
+
def call
|
18
|
+
languages(@locale).each do |language|
|
19
|
+
PolyglotCli::IO::Locale.write(locale_path, translation_hash(language))
|
20
|
+
end
|
21
|
+
update_config
|
22
|
+
success
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def locale_path
|
28
|
+
@path || config[:locale_path]
|
29
|
+
end
|
30
|
+
|
31
|
+
def translation_hash(language)
|
32
|
+
hash = { language.locale => {} }
|
33
|
+
|
34
|
+
translations(language).each do |t|
|
35
|
+
hash[language.locale].deep_merge!(nest(t.translation_key.name, t.value))
|
36
|
+
end
|
37
|
+
|
38
|
+
hash
|
39
|
+
end
|
40
|
+
|
41
|
+
def translations(language)
|
42
|
+
prompt.say("Getting #{language.name} translations...")
|
43
|
+
PolyglotCli::Resource::Translation.token(token).depaginate(project_id: project_id, language_id: language.id)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
module PolyglotCli
|
2
|
+
module Command
|
3
|
+
class Push
|
4
|
+
include Helper::Nest
|
5
|
+
include Helper::Terminal
|
6
|
+
include Helper::General
|
7
|
+
|
8
|
+
def self.init(options)
|
9
|
+
new(options).call
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(options)
|
13
|
+
@locale = options.locale
|
14
|
+
@path = options.path
|
15
|
+
end
|
16
|
+
|
17
|
+
def call
|
18
|
+
if server_changed?
|
19
|
+
prompt.error('Changes have been made on the server. Please pull before pushing.')
|
20
|
+
else
|
21
|
+
languages(@locale).each do |language|
|
22
|
+
prompt.say("Processing push for #{language.name}...")
|
23
|
+
process(language)
|
24
|
+
end
|
25
|
+
update_config
|
26
|
+
success
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def process(language)
|
33
|
+
local = local_translations(language.locale)
|
34
|
+
# Update translations
|
35
|
+
remote_translations(language).each do |translation|
|
36
|
+
process_update(translation, local)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Create translation keys and translations
|
40
|
+
local.each do |key, value|
|
41
|
+
process_create(key, value, language.id)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def process_create(key, value, language_id)
|
46
|
+
key_id = translation_keys[key]
|
47
|
+
|
48
|
+
if key_id.nil?
|
49
|
+
prompt.ok("Creating translation key \"#{key}\"...")
|
50
|
+
key_id = PolyglotCli::Resource::TranslationKey.token(token).create(name: key, project_id: project_id).id
|
51
|
+
end
|
52
|
+
|
53
|
+
create_translation(value, key_id, language_id)
|
54
|
+
end
|
55
|
+
|
56
|
+
def create_translation_key(name)
|
57
|
+
PolyglotCli::Resource::TranslationKey.token(token).create(name: name, project_id: project_id).id
|
58
|
+
end
|
59
|
+
|
60
|
+
def create_translation(value, key_id, language_id)
|
61
|
+
prompt.ok("Creating translation for key \"#{key_id}\"...")
|
62
|
+
PolyglotCli::Resource::Translation.token(token).create(
|
63
|
+
value: value,
|
64
|
+
translation_key_id: key_id,
|
65
|
+
language_id: language_id
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
def process_update(translation, local)
|
70
|
+
new_value = local.delete(translation.translation_key.name)
|
71
|
+
return if new_value == translation.value
|
72
|
+
|
73
|
+
prompt.ok("Updating translation #{translation.id}...")
|
74
|
+
translation.update(value: new_value)
|
75
|
+
end
|
76
|
+
|
77
|
+
def translation_keys
|
78
|
+
return @translation_keys if @translation_keys.present?
|
79
|
+
prompt.say('Getting translation keys...')
|
80
|
+
@translation_keys =
|
81
|
+
PolyglotCli::Resource::TranslationKey
|
82
|
+
.token(token)
|
83
|
+
.depaginate(project_id: project_id)
|
84
|
+
.each_with_object({}) do |translation_key, hash|
|
85
|
+
hash[translation_key.name] = translation_key.id
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def remote_translations(language)
|
90
|
+
prompt.say("Getting #{language.name} translations...")
|
91
|
+
PolyglotCli::Resource::Translation.token(token).depaginate(project_id: project_id, language_id: language.id)
|
92
|
+
end
|
93
|
+
|
94
|
+
def local_translations(locale)
|
95
|
+
denest(PolyglotCli::IO::Locale.read(locale_path, locale)[locale])
|
96
|
+
end
|
97
|
+
|
98
|
+
def locale_path
|
99
|
+
@path || config[:locale_path]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module PolyglotCli
|
2
|
+
module Command
|
3
|
+
class Setup
|
4
|
+
include Helper::Terminal
|
5
|
+
include Helper::General
|
6
|
+
|
7
|
+
def self.init
|
8
|
+
new.call
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
PolyglotCli::IO::Config.write(
|
13
|
+
project_id: project_id_prompt,
|
14
|
+
locale_path: locale_path_prompt
|
15
|
+
)
|
16
|
+
success
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def project_id_prompt
|
22
|
+
prompt.enum_select('Choose a project: ', projects)
|
23
|
+
end
|
24
|
+
|
25
|
+
def locale_path_prompt
|
26
|
+
prompt.ask('Where would you like to store your locale files?', default: 'config/locales')
|
27
|
+
end
|
28
|
+
|
29
|
+
def projects
|
30
|
+
prompt.say('Getting projects...')
|
31
|
+
PolyglotCli::Resource::Project.token(token).depaginate.each_with_object({}) do |r, hash|
|
32
|
+
hash[r.name] = r.id
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module PolyglotCli
|
2
|
+
module Command
|
3
|
+
class Status
|
4
|
+
include Helper::Terminal
|
5
|
+
include Helper::General
|
6
|
+
|
7
|
+
def self.init
|
8
|
+
new.call
|
9
|
+
end
|
10
|
+
|
11
|
+
def call
|
12
|
+
if server_changed?
|
13
|
+
prompt.warn('Changes have occured on the server.')
|
14
|
+
else
|
15
|
+
prompt.ok('No changes have been made on the server.')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module PolyglotCli
|
2
|
+
class ErrorHandler
|
3
|
+
extend Helper::Terminal
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def rescuable
|
7
|
+
yield
|
8
|
+
rescue => e
|
9
|
+
handle(e)
|
10
|
+
end
|
11
|
+
|
12
|
+
def handle(e)
|
13
|
+
prompt.error(
|
14
|
+
case e
|
15
|
+
when JsonApiClient::Errors::NotAuthorized
|
16
|
+
'You are not authorized.'
|
17
|
+
when Errno::ENOENT
|
18
|
+
'We could not find a file that we need. Please try logging in and initializing the project.'
|
19
|
+
else
|
20
|
+
"An error happened. The elves are against you. This might help:\n\n#{e.message}"
|
21
|
+
end
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module PolyglotCli
|
2
|
+
module Helper
|
3
|
+
module Depaginate
|
4
|
+
PER_PAGE = 100
|
5
|
+
|
6
|
+
def depaginate_query(query)
|
7
|
+
depaginated_array = []
|
8
|
+
page = query.page(1).per(PER_PAGE).all
|
9
|
+
until page.nil?
|
10
|
+
depaginated_array += page
|
11
|
+
page = page.pages.next
|
12
|
+
end
|
13
|
+
depaginated_array
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module PolyglotCli
|
2
|
+
module Helper
|
3
|
+
module General
|
4
|
+
def token
|
5
|
+
@token ||= PolyglotCli::IO::Token.read
|
6
|
+
end
|
7
|
+
|
8
|
+
def config
|
9
|
+
@config ||= PolyglotCli::IO::Config.read
|
10
|
+
end
|
11
|
+
|
12
|
+
def project_id
|
13
|
+
config[:project_id]
|
14
|
+
end
|
15
|
+
|
16
|
+
def project
|
17
|
+
prompt.say('Getting project...')
|
18
|
+
PolyglotCli::Resource::Project.token(token).find(project_id).first
|
19
|
+
end
|
20
|
+
|
21
|
+
def server_changed?
|
22
|
+
return true if config[:project_updated_at].nil?
|
23
|
+
Time.parse(project.updated_at) > Time.parse(config[:project_updated_at])
|
24
|
+
end
|
25
|
+
|
26
|
+
def languages(locale)
|
27
|
+
prompt.say('Getting languages...')
|
28
|
+
results = PolyglotCli::Resource::Language.token(token).depaginate(project_id: project_id)
|
29
|
+
results.select! { |l| l.locale == locale } unless locale.nil?
|
30
|
+
results
|
31
|
+
end
|
32
|
+
|
33
|
+
def update_config
|
34
|
+
config[:project_updated_at] = project.updated_at
|
35
|
+
PolyglotCli::IO::Config.write(config)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module PolyglotCli
|
2
|
+
module Helper
|
3
|
+
module Nest
|
4
|
+
def nest(translation_key, value)
|
5
|
+
# Try get first nested key
|
6
|
+
key = translation_key.slice!(/^.+?\./) # Regex: select all chars until first dot
|
7
|
+
|
8
|
+
if key.nil?
|
9
|
+
# If no nested key return key/value hash
|
10
|
+
{ translation_key => value }
|
11
|
+
else
|
12
|
+
# Recursively try to get next nested key
|
13
|
+
key.delete!('.')
|
14
|
+
{ key => nest(translation_key, value) }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def denest(nested_hash)
|
19
|
+
nested_hash.each_with_object({}) do |(key, value), hash|
|
20
|
+
if value.is_a? Hash
|
21
|
+
denest(value).map do |h_key, h_value|
|
22
|
+
hash["#{key}.#{h_key}"] = h_value
|
23
|
+
end
|
24
|
+
else
|
25
|
+
hash[key] = value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module PolyglotCli
|
2
|
+
module IO
|
3
|
+
class Config
|
4
|
+
extend Helper::Terminal
|
5
|
+
|
6
|
+
CONFIG_FILE_PATH = "#{Dir.pwd}/.polyglot.yml".freeze
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def write(data)
|
10
|
+
prompt.say("Writing config to #{CONFIG_FILE_PATH}")
|
11
|
+
File.open(CONFIG_FILE_PATH, 'w') { |f| YAML.dump(data, f) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def read
|
15
|
+
prompt.say("Reading config from #{CONFIG_FILE_PATH}")
|
16
|
+
YAML.load_file(CONFIG_FILE_PATH)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module PolyglotCli
|
2
|
+
module IO
|
3
|
+
class Locale
|
4
|
+
extend Helper::Terminal
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def write(locale_path, data)
|
8
|
+
prompt.say("Writing translations to #{path(locale_path, data.keys[0])}")
|
9
|
+
File.open(path(locale_path, data.keys[0]), 'w') { |f| YAML.dump(data, f) }
|
10
|
+
end
|
11
|
+
|
12
|
+
def read(locale_path, locale)
|
13
|
+
prompt.say("Reading translations from #{path(locale_path, locale)}")
|
14
|
+
YAML.load_file(path(locale_path, locale))
|
15
|
+
end
|
16
|
+
|
17
|
+
def path(locale_path, locale)
|
18
|
+
"#{Dir.pwd}/#{locale_path}/#{locale}.yml"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module PolyglotCli
|
2
|
+
module IO
|
3
|
+
class Token
|
4
|
+
extend Helper::Terminal
|
5
|
+
|
6
|
+
AUTH_FILE_PATH = "#{Dir.home}/.polyglot.auth".freeze
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def write(token)
|
10
|
+
prompt.say("Writing token to #{AUTH_FILE_PATH}")
|
11
|
+
File.open(AUTH_FILE_PATH, 'w') { |f| f.write(token) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def read
|
15
|
+
prompt.say("Reading token from #{AUTH_FILE_PATH}")
|
16
|
+
File.read(AUTH_FILE_PATH)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module PolyglotCli
|
2
|
+
module Resource
|
3
|
+
class Base < JsonApiClient::Resource
|
4
|
+
extend PolyglotCli::Helper::Depaginate
|
5
|
+
|
6
|
+
self.site = if ENV['POLYGLOT_CLI_ENV'] == 'development'
|
7
|
+
'http://polyglot.infinum.co.dev/api/v2/'
|
8
|
+
else
|
9
|
+
'https://polyglot.infinum.co/api/v2/'
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.token(token)
|
13
|
+
self.connection_options = { headers: { 'X-Auth-Token' => token } }
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.depaginate(opts = {})
|
18
|
+
depaginate_query(where(opts))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/polyglot_cli.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'YAML'
|
2
|
+
require 'polyglot_cli/version'
|
3
|
+
|
4
|
+
# Helpers
|
5
|
+
require 'polyglot_cli/helpers/depaginate'
|
6
|
+
require 'polyglot_cli/helpers/nest'
|
7
|
+
require 'polyglot_cli/helpers/terminal'
|
8
|
+
require 'polyglot_cli/helpers/general'
|
9
|
+
|
10
|
+
# JSON API Resources
|
11
|
+
require 'json_api_client'
|
12
|
+
require 'polyglot_cli/resources/base'
|
13
|
+
require 'polyglot_cli/resources/language'
|
14
|
+
require 'polyglot_cli/resources/project'
|
15
|
+
require 'polyglot_cli/resources/session'
|
16
|
+
require 'polyglot_cli/resources/translation'
|
17
|
+
require 'polyglot_cli/resources/translation_key'
|
18
|
+
|
19
|
+
# File Accessors
|
20
|
+
require 'polyglot_cli/io/config'
|
21
|
+
require 'polyglot_cli/io/locale'
|
22
|
+
require 'polyglot_cli/io/token'
|
23
|
+
|
24
|
+
# Commands
|
25
|
+
require 'polyglot_cli/commands/login'
|
26
|
+
require 'polyglot_cli/commands/pull'
|
27
|
+
require 'polyglot_cli/commands/push'
|
28
|
+
require 'polyglot_cli/commands/setup'
|
29
|
+
require 'polyglot_cli/commands/status'
|
30
|
+
|
31
|
+
# Error Handler
|
32
|
+
require 'polyglot_cli/error_handler'
|
33
|
+
|
34
|
+
module PolyglotCli
|
35
|
+
# Your code goes here...
|
36
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'polyglot_cli/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'polyglot_cli'
|
8
|
+
spec.version = PolyglotCli::VERSION
|
9
|
+
spec.authors = ['Ivan Grgurevic']
|
10
|
+
spec.email = ['ivan.grgurevic@infinum.hr']
|
11
|
+
|
12
|
+
spec.summary = 'A ruby cli for pulling and pushing polyglot translations'
|
13
|
+
# spec.description = 'Write a longer description or delete this line.'
|
14
|
+
# spec.homepage = "Put your gem's website or public repo URL here."
|
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'] = 'https://rubygems.org'
|
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 do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = 'exe'
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
|
32
|
+
spec.add_development_dependency 'bundler', '~> 1.13'
|
33
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
34
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
35
|
+
spec.add_development_dependency 'pry-byebug'
|
36
|
+
spec.add_dependency 'json_api_client'
|
37
|
+
spec.add_dependency 'commander'
|
38
|
+
spec.add_dependency 'tty-prompt'
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: polyglot_cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ivan Grgurevic
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
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: json_api_client
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: commander
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: tty-prompt
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- ivan.grgurevic@infinum.hr
|
114
|
+
executables:
|
115
|
+
- polyglot
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".rubocop.yml"
|
122
|
+
- ".ruby-version"
|
123
|
+
- ".travis.yml"
|
124
|
+
- Gemfile
|
125
|
+
- LICENSE.txt
|
126
|
+
- README.md
|
127
|
+
- Rakefile
|
128
|
+
- bin/console
|
129
|
+
- bin/setup
|
130
|
+
- exe/polyglot
|
131
|
+
- lib/polyglot_cli.rb
|
132
|
+
- lib/polyglot_cli/commands/login.rb
|
133
|
+
- lib/polyglot_cli/commands/pull.rb
|
134
|
+
- lib/polyglot_cli/commands/push.rb
|
135
|
+
- lib/polyglot_cli/commands/setup.rb
|
136
|
+
- lib/polyglot_cli/commands/status.rb
|
137
|
+
- lib/polyglot_cli/error_handler.rb
|
138
|
+
- lib/polyglot_cli/helpers/depaginate.rb
|
139
|
+
- lib/polyglot_cli/helpers/general.rb
|
140
|
+
- lib/polyglot_cli/helpers/nest.rb
|
141
|
+
- lib/polyglot_cli/helpers/terminal.rb
|
142
|
+
- lib/polyglot_cli/io/config.rb
|
143
|
+
- lib/polyglot_cli/io/locale.rb
|
144
|
+
- lib/polyglot_cli/io/token.rb
|
145
|
+
- lib/polyglot_cli/resources/base.rb
|
146
|
+
- lib/polyglot_cli/resources/language.rb
|
147
|
+
- lib/polyglot_cli/resources/project.rb
|
148
|
+
- lib/polyglot_cli/resources/session.rb
|
149
|
+
- lib/polyglot_cli/resources/translation.rb
|
150
|
+
- lib/polyglot_cli/resources/translation_key.rb
|
151
|
+
- lib/polyglot_cli/version.rb
|
152
|
+
- polyglot_cli.gemspec
|
153
|
+
homepage:
|
154
|
+
licenses:
|
155
|
+
- MIT
|
156
|
+
metadata:
|
157
|
+
allowed_push_host: https://rubygems.org
|
158
|
+
post_install_message:
|
159
|
+
rdoc_options: []
|
160
|
+
require_paths:
|
161
|
+
- lib
|
162
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
|
+
requirements:
|
169
|
+
- - ">="
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '0'
|
172
|
+
requirements: []
|
173
|
+
rubyforge_project:
|
174
|
+
rubygems_version: 2.6.7
|
175
|
+
signing_key:
|
176
|
+
specification_version: 4
|
177
|
+
summary: A ruby cli for pulling and pushing polyglot translations
|
178
|
+
test_files: []
|