zendesk_apps_tools 1.35.3 → 1.35.4
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 +4 -4
- data/features/new.feature +35 -34
- data/features/package.feature +15 -3
- data/features/step_definitions/app_steps.rb +4 -2
- data/lib/zendesk_apps_tools/command.rb +24 -16
- data/lib/zendesk_apps_tools/command_helpers.rb +5 -0
- data/lib/zendesk_apps_tools/common.rb +40 -5
- data/lib/zendesk_apps_tools/translate.rb +64 -42
- data/lib/zendesk_apps_tools/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4342a16a235ffb9c17d645b0b4671daf9af7ca82
|
4
|
+
data.tar.gz: fd5be11e0931293a51a78b53238cde0922895873
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b39f3699022df810613fdf8604e29592d5203e93ec185edf549649e3fbdcfbb70bda50e268e7c98dec94d5a9ee3c5af908b43f8aa83a5a729debfb206ad0127
|
7
|
+
data.tar.gz: 9c66857e215dac587315f9eb2ae699635be503219abc3ab83ff59df20fb4cd946a249e93b836ef256f0774affaee5f36fc3658b8b493d438d59cb183fc481240
|
data/features/new.feature
CHANGED
@@ -8,22 +8,23 @@ Feature: create a template for a new zendesk app
|
|
8
8
|
| author email | john@example.com |
|
9
9
|
| author url | http://myapp.com |
|
10
10
|
| app name | John Test App |
|
11
|
+
| iframe uri | assets/iframe.html |
|
11
12
|
| app dir | |
|
12
13
|
|
13
14
|
Then the app file "manifest.json" is created
|
14
15
|
And I reset the working directory
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
Scenario: create a template for a new zendesk app by running 'zat new --v1' command
|
18
|
+
Given an app directory "tmp/aruba" exists
|
19
|
+
When I run "zat new --v1" command with the following details:
|
20
|
+
| author name | John Citizen |
|
21
|
+
| author email | john@example.com |
|
22
|
+
| author url | http://myapp.com |
|
23
|
+
| app name | John Test App |
|
24
|
+
| app dir | tmp/aruba |
|
24
25
|
|
25
|
-
|
26
|
-
|
26
|
+
Then the app file "tmp/aruba/manifest.json" is created with:
|
27
|
+
"""
|
27
28
|
{
|
28
29
|
"name": "John Test App",
|
29
30
|
"author": {
|
@@ -37,9 +38,9 @@ Feature: create a template for a new zendesk app
|
|
37
38
|
"version": "1.0",
|
38
39
|
"frameworkVersion": "1.0"
|
39
40
|
}
|
40
|
-
|
41
|
-
|
42
|
-
|
41
|
+
"""
|
42
|
+
And the app file "tmp/aruba/app.js" is created with:
|
43
|
+
"""
|
43
44
|
(function() {
|
44
45
|
|
45
46
|
return {
|
@@ -52,9 +53,9 @@ Feature: create a template for a new zendesk app
|
|
52
53
|
};
|
53
54
|
|
54
55
|
}());
|
55
|
-
|
56
|
-
|
57
|
-
|
56
|
+
"""
|
57
|
+
And the app file "tmp/aruba/templates/layout.hdbs" is created with:
|
58
|
+
"""
|
58
59
|
<header>
|
59
60
|
<span class="logo"></span>
|
60
61
|
<h3>{{setting "name"}}</h3>
|
@@ -65,9 +66,9 @@ Feature: create a template for a new zendesk app
|
|
65
66
|
{{author.name}}
|
66
67
|
</a>
|
67
68
|
</footer>
|
68
|
-
|
69
|
-
|
70
|
-
|
69
|
+
"""
|
70
|
+
And the app file "tmp/aruba/translations/en.json" is created with:
|
71
|
+
"""
|
71
72
|
{
|
72
73
|
"app": {
|
73
74
|
"description": "Play the famous zen tunes in your help desk.",
|
@@ -84,21 +85,21 @@ Feature: create a template for a new zendesk app
|
|
84
85
|
"role": "Role",
|
85
86
|
"groups": "Groups"
|
86
87
|
}
|
87
|
-
|
88
|
+
"""
|
88
89
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
90
|
+
Scenario: create a template for a new iframe only app by running 'zat new' command
|
91
|
+
Given an app directory "tmp/aruba" exists
|
92
|
+
And I move to the app directory
|
93
|
+
When I run "zat new" command with the following details:
|
94
|
+
| author name | John Citizen |
|
95
|
+
| author email | john@example.com |
|
96
|
+
| author url | http://myapp.com |
|
97
|
+
| app name | John Test App |
|
98
|
+
| iframe uri | assets/iframe.html |
|
99
|
+
| app dir | tmp/aruba |
|
99
100
|
|
100
|
-
|
101
|
-
|
101
|
+
Then the app file "tmp/aruba/manifest.json" is created with:
|
102
|
+
"""
|
102
103
|
{
|
103
104
|
"name": "John Test App",
|
104
105
|
"author": {
|
@@ -109,10 +110,10 @@ Feature: create a template for a new zendesk app
|
|
109
110
|
"defaultLocale": "en",
|
110
111
|
"private": true,
|
111
112
|
"location": { "zendesk":
|
112
|
-
{ "ticket_sidebar": "assets/
|
113
|
+
{ "ticket_sidebar": "assets/iframe.html" }
|
113
114
|
},
|
114
115
|
"version": "1.0",
|
115
116
|
"frameworkVersion": "2.0"
|
116
117
|
}
|
117
|
-
"""
|
118
|
+
"""
|
118
119
|
And I reset the working directory
|
data/features/package.feature
CHANGED
@@ -1,21 +1,33 @@
|
|
1
1
|
Feature: package a zendesk app into a zip file
|
2
2
|
|
3
3
|
Background: create a new zendesk app
|
4
|
-
|
4
|
+
|
5
5
|
|
6
6
|
Scenario: package a zendesk app by running 'zat package' command
|
7
|
+
Given an app is created in directory "tmp/aruba"
|
7
8
|
When I run the command "zat package --path tmp/aruba" to package the app
|
8
|
-
And the command output should contain "adding
|
9
|
+
And the command output should contain "adding assets/iframe.html"
|
9
10
|
And the command output should contain "adding assets/logo-small.png"
|
10
11
|
And the command output should contain "adding assets/logo.png"
|
11
12
|
And the command output should contain "adding manifest.json"
|
12
|
-
And the command output should contain "adding templates/layout.hdbs"
|
13
13
|
And the command output should contain "adding translations/en.json"
|
14
14
|
And the command output should contain "created"
|
15
15
|
And the zip file should exist in directory "tmp/aruba/tmp"
|
16
16
|
|
17
|
+
Scenario: package a v1 zendesk app by running 'zat package' command
|
18
|
+
Given a v1 app is created in directory "tmp/aruba"
|
19
|
+
When I run the command "zat package --path tmp/aruba" to package the app
|
20
|
+
And the command output should contain "adding app.js"
|
21
|
+
And the command output should contain "adding templates/layout.hdbs"
|
22
|
+
And the command output should contain "adding assets/logo-small.png"
|
23
|
+
And the command output should contain "adding assets/logo.png"
|
24
|
+
And the command output should contain "adding manifest.json"
|
25
|
+
And the command output should contain "adding translations/en.json"
|
26
|
+
And the command output should contain "created"
|
27
|
+
And the zip file should exist in directory "tmp/aruba/tmp"
|
17
28
|
|
18
29
|
Scenario: package a zendesk app by running 'zat package' command
|
30
|
+
Given an app is created in directory "tmp/aruba"
|
19
31
|
When I create a symlink from "./templates/translation.erb.tt" to "tmp/aruba/assets/translation.erb.tt"
|
20
32
|
Then "tmp/aruba/assets/translation.erb.tt" should be a symlink
|
21
33
|
When I run the command "zat package --path tmp/aruba" to package the app
|
@@ -17,14 +17,16 @@ Given /^an app directory "(.*?)" exists$/ do |app_dir|
|
|
17
17
|
FileUtils.mkdir_p(@app_dir)
|
18
18
|
end
|
19
19
|
|
20
|
-
Given /^
|
20
|
+
Given /^a(n|(?: v1)) app is created in directory "(.*?)"$/ do |version, app_dir|
|
21
|
+
v1 = !!version[/v1/]
|
21
22
|
steps %(
|
22
23
|
Given an app directory "#{app_dir}" exists
|
23
|
-
And I run "zat new" command with the following details:
|
24
|
+
And I run "zat new #{'--v1' if v1}" command with the following details:
|
24
25
|
| author name | John Citizen |
|
25
26
|
| author email | john@example.com |
|
26
27
|
| author url | http://myapp.com |
|
27
28
|
| app name | John Test App |
|
29
|
+
#{'| iframe uri | assets/iframe.html |' unless v1}
|
28
30
|
| app dir | #{app_dir} |
|
29
31
|
)
|
30
32
|
end
|
@@ -10,11 +10,6 @@ module ZendeskAppsTools
|
|
10
10
|
include Thor::Actions
|
11
11
|
include ZendeskAppsTools::CommandHelpers
|
12
12
|
|
13
|
-
SHARED_OPTIONS = {
|
14
|
-
['path', '-p'] => './',
|
15
|
-
clean: false
|
16
|
-
}.freeze
|
17
|
-
|
18
13
|
map %w(-v) => :version
|
19
14
|
|
20
15
|
source_root File.expand_path(File.join(File.dirname(__FILE__), '../..'))
|
@@ -28,9 +23,11 @@ module ZendeskAppsTools
|
|
28
23
|
desc 'new', 'Generate a new app'
|
29
24
|
method_option :'iframe-only', type: :boolean,
|
30
25
|
default: false,
|
31
|
-
|
32
|
-
aliases: ['
|
26
|
+
hide: true,
|
27
|
+
aliases: ['--v2']
|
28
|
+
method_option :v1, type: :boolean, default: false, desc: 'Create a version 1 app template'
|
33
29
|
def new
|
30
|
+
check_new_options
|
34
31
|
enter = ->(variable) { "Enter this app author's #{variable}:\n" }
|
35
32
|
invalid = ->(variable) { "Invalid #{variable}, try again:" }
|
36
33
|
@author_name = get_value_from_stdin(enter.call('name'),
|
@@ -45,24 +42,24 @@ module ZendeskAppsTools
|
|
45
42
|
@app_name = get_value_from_stdin("Enter a name for this new app:\n",
|
46
43
|
error_msg: invalid.call('app name'))
|
47
44
|
|
48
|
-
@iframe_location = if options[:
|
45
|
+
@iframe_location = if options[:v1]
|
46
|
+
'_legacy'
|
47
|
+
else
|
49
48
|
iframe_uri_text = 'Enter your iFrame URI or leave it blank to use'\
|
50
49
|
" a default local template page:\n"
|
51
50
|
get_value_from_stdin(iframe_uri_text, allow_empty: true, default: 'assets/iframe.html')
|
52
|
-
else
|
53
|
-
'_legacy'
|
54
51
|
end
|
55
52
|
|
56
53
|
prompt_new_app_dir
|
57
54
|
|
58
|
-
skeleton = options[:
|
59
|
-
is_custom_iframe = options[:
|
55
|
+
skeleton = options[:v1] ? 'app_template' : 'app_template_iframe'
|
56
|
+
is_custom_iframe = !options[:v1] && @iframe_location != 'assets/iframe.html'
|
60
57
|
directory_options = is_custom_iframe ? { exclude_pattern: /iframe.html/ } : {}
|
61
58
|
directory(skeleton, @app_dir, directory_options)
|
62
59
|
end
|
63
60
|
|
64
61
|
desc 'validate', 'Validate your app'
|
65
|
-
|
62
|
+
shared_options(except: [:unattended])
|
66
63
|
def validate
|
67
64
|
setup_path(options[:path])
|
68
65
|
begin
|
@@ -91,7 +88,7 @@ module ZendeskAppsTools
|
|
91
88
|
end
|
92
89
|
|
93
90
|
desc 'package', 'Package your app'
|
94
|
-
|
91
|
+
shared_options(except: [:unattended])
|
95
92
|
def package
|
96
93
|
return false unless invoke(:validate, [])
|
97
94
|
|
@@ -152,7 +149,7 @@ module ZendeskAppsTools
|
|
152
149
|
end
|
153
150
|
|
154
151
|
desc 'create', 'Create app on your account'
|
155
|
-
|
152
|
+
shared_options
|
156
153
|
method_option :zipfile, default: nil, required: false, type: :string
|
157
154
|
def create
|
158
155
|
cache.clear
|
@@ -166,7 +163,7 @@ module ZendeskAppsTools
|
|
166
163
|
end
|
167
164
|
|
168
165
|
desc 'update', 'Update app on the server'
|
169
|
-
|
166
|
+
shared_options
|
170
167
|
method_option :zipfile, default: nil, required: false, type: :string
|
171
168
|
def update
|
172
169
|
cache.clear
|
@@ -186,6 +183,17 @@ module ZendeskAppsTools
|
|
186
183
|
|
187
184
|
protected
|
188
185
|
|
186
|
+
def check_new_options
|
187
|
+
if options[:'iframe-only']
|
188
|
+
if options[:v1]
|
189
|
+
say_error_and_exit "Apps can't be created with both --v1 and --v2 (or --iframe-only)."
|
190
|
+
else
|
191
|
+
warning = 'v2 is the default for new apps, the --v2 and --iframe-only options have no effect.'
|
192
|
+
say_status 'warning', warning, :yellow
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
189
197
|
def setup_path(path)
|
190
198
|
@destination_stack << relative_to_original_destination_root(path) unless @destination_stack.last == path
|
191
199
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'zendesk_apps_tools/common'
|
2
3
|
require 'zendesk_apps_tools/api_connection'
|
3
4
|
require 'zendesk_apps_tools/deploy'
|
@@ -14,6 +15,10 @@ module ZendeskAppsTools
|
|
14
15
|
include ZendeskAppsTools::Directory
|
15
16
|
include ZendeskAppsTools::PackageHelper
|
16
17
|
|
18
|
+
def self.included(base)
|
19
|
+
base.extend(ClassMethods)
|
20
|
+
end
|
21
|
+
|
17
22
|
def cache
|
18
23
|
@cache ||= begin
|
19
24
|
require 'zendesk_apps_tools/cache'
|
@@ -1,5 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module ZendeskAppsTools
|
2
3
|
module Common
|
4
|
+
module ClassMethods
|
5
|
+
def shared_options(except: [])
|
6
|
+
unless except.include? :path
|
7
|
+
method_option :path,
|
8
|
+
type: :string,
|
9
|
+
default: './',
|
10
|
+
aliases: ['-p']
|
11
|
+
end
|
12
|
+
unless except.include? :clean
|
13
|
+
method_option :clean,
|
14
|
+
type: :boolean,
|
15
|
+
default: false
|
16
|
+
end
|
17
|
+
unless except.include? :unattended
|
18
|
+
method_option :unattended,
|
19
|
+
type: :boolean,
|
20
|
+
default: false,
|
21
|
+
desc: 'Experimental: Never prompt for input, expecting all input from the original invocation. Many '\
|
22
|
+
'commands invoked with this option will just crash.'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.included(base)
|
28
|
+
base.extend(ClassMethods)
|
29
|
+
end
|
30
|
+
|
3
31
|
def say_error_and_exit(msg)
|
4
32
|
say_error msg
|
5
33
|
exit 1
|
@@ -10,6 +38,7 @@ module ZendeskAppsTools
|
|
10
38
|
end
|
11
39
|
|
12
40
|
def get_value_from_stdin(prompt, opts = {})
|
41
|
+
error_if_unattended(prompt)
|
13
42
|
options = {
|
14
43
|
valid_regex: opts[:allow_empty] ? /^.*$/ : /\S+/,
|
15
44
|
error_msg: 'Invalid, try again:',
|
@@ -20,20 +49,26 @@ module ZendeskAppsTools
|
|
20
49
|
|
21
50
|
while input = ask(prompt, thor_options)
|
22
51
|
return '' if options[:allow_empty] && input.empty?
|
23
|
-
if input.to_s =~ options[:valid_regex]
|
24
|
-
|
25
|
-
else
|
26
|
-
say_error options[:error_msg]
|
27
|
-
end
|
52
|
+
break if input.to_s =~ options[:valid_regex]
|
53
|
+
say_error options[:error_msg]
|
28
54
|
end
|
29
55
|
|
30
56
|
input
|
31
57
|
end
|
32
58
|
|
33
59
|
def get_password_from_stdin(prompt)
|
60
|
+
error_if_unattended(prompt)
|
34
61
|
password = ask(prompt, echo: false)
|
35
62
|
say ''
|
36
63
|
password
|
37
64
|
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def error_if_unattended(prompt)
|
69
|
+
return unless options[:unattended]
|
70
|
+
say_error 'Would have prompted for a value interactively, but we are running unattended.'
|
71
|
+
say_error_and_exit prompt
|
72
|
+
end
|
38
73
|
end
|
39
74
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'thor'
|
2
3
|
require 'json'
|
3
4
|
require 'zendesk_apps_tools/common'
|
@@ -12,7 +13,7 @@ module ZendeskAppsTools
|
|
12
13
|
LOCALE_ENDPOINT = 'https://support.zendesk.com/api/v2/locales/agent.json'
|
13
14
|
|
14
15
|
desc 'to_yml', 'Create Zendesk translation file from en.json'
|
15
|
-
|
16
|
+
shared_options(except: [:clean])
|
16
17
|
def to_yml
|
17
18
|
setup_path(options[:path]) if options[:path]
|
18
19
|
manifest = JSON.parse(File.open("#{destination_root}/manifest.json").read)
|
@@ -22,72 +23,56 @@ module ZendeskAppsTools
|
|
22
23
|
app_name = get_value_from_stdin('What is the name of this app?', error_msg: 'Invalid name, try again:')
|
23
24
|
end
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
package = en_json['app']['package']
|
28
|
-
say('No package defined inside en.json! Abort.', :red) and exit 1 unless package
|
26
|
+
package = package_name_from_json(error_out: true)
|
29
27
|
en_json['app'].delete('package')
|
30
28
|
|
31
29
|
write_yml(en_json, app_name, package)
|
32
30
|
end
|
33
31
|
|
34
32
|
desc 'to_json', 'Convert Zendesk translation yml to I18n formatted json'
|
35
|
-
|
33
|
+
shared_options(except: [:clean])
|
36
34
|
def to_json
|
37
35
|
require 'yaml'
|
38
36
|
setup_path(options[:path]) if options[:path]
|
39
37
|
en_yml = YAML.load_file("#{destination_root}/translations/en.yml")
|
40
38
|
package = /^txt.apps.([^\.]+)/.match(en_yml['parts'][0]['translation']['key'])[1]
|
41
39
|
translations = en_yml['parts'].map { |part| part['translation'] }
|
42
|
-
|
43
|
-
|
40
|
+
en_hash = array_to_nested_hash(translations)['txt']['apps'][package]
|
41
|
+
en_hash['app']['package'] = package
|
44
42
|
|
45
|
-
write_json('translations/en.json',
|
43
|
+
write_json('translations/en.json', en_hash)
|
46
44
|
end
|
47
45
|
|
48
46
|
desc 'update', 'Update translation files from Zendesk'
|
49
|
-
|
50
|
-
|
47
|
+
shared_options(except: [:clean])
|
48
|
+
method_option :package_name, type: :string
|
49
|
+
def update
|
51
50
|
setup_path(options[:path]) if options[:path]
|
52
|
-
app_package =
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
require 'faraday'
|
59
|
-
locale_response = Faraday.get(LOCALE_ENDPOINT)
|
60
|
-
|
61
|
-
if locale_response.status == 200
|
62
|
-
locales = JSON.parse(locale_response.body)['locales']
|
63
|
-
|
64
|
-
locales = locales.map { |locale| fetch_locale_async locale, app_package}.map(&:value)
|
65
|
-
|
66
|
-
locales.each do |locale|
|
67
|
-
translations = locale['translations']
|
51
|
+
app_package = package_name_for_update
|
52
|
+
locale_list
|
53
|
+
.map { |locale| fetch_locale_async locale, app_package }
|
54
|
+
.each do |locale_thread|
|
55
|
+
locale = locale_thread.value
|
56
|
+
translations = locale['translations']
|
68
57
|
|
69
58
|
locale_name = ZendeskAppsTools::LocaleIdentifier.new(locale['locale']).locale_id
|
70
|
-
write_json(
|
59
|
+
write_json(
|
60
|
+
"#{destination_root}/translations/#{locale_name}.json",
|
61
|
+
nest_translations_hash(translations, "txt.apps.#{app_package}.")
|
62
|
+
)
|
71
63
|
end
|
72
|
-
|
73
|
-
|
74
|
-
elsif locale_response.status == 401
|
75
|
-
say('Authentication failed', :red)
|
76
|
-
end
|
64
|
+
say('Translations updated', :green)
|
77
65
|
end
|
78
66
|
|
79
67
|
desc 'pseudotranslate', 'Generate a Pseudo-translation to use for testing. This will pretend to be French.'
|
80
|
-
|
68
|
+
shared_options(except: [:clean])
|
81
69
|
def pseudotranslate
|
82
70
|
setup_path(options[:path]) if options[:path]
|
83
71
|
|
84
|
-
|
85
|
-
|
86
|
-
package = en_json['app']['package']
|
87
|
-
say('No package defined inside en.json! Abort.', :red) and exit 1 unless package
|
72
|
+
package = package_name_from_json(error_out: true)
|
88
73
|
|
89
74
|
pseudo = build_pseudotranslation(en_json, package)
|
90
|
-
write_json(
|
75
|
+
write_json('translations/fr.json', pseudo)
|
91
76
|
end
|
92
77
|
|
93
78
|
def self.source_root
|
@@ -108,7 +93,7 @@ module ZendeskAppsTools
|
|
108
93
|
end
|
109
94
|
|
110
95
|
def write_json(filename, translations_hash)
|
111
|
-
create_file(filename, JSON.pretty_generate(translations_hash) + "\n")
|
96
|
+
create_file(filename, JSON.pretty_generate(translations_hash) + "\n", force: options[:unattended])
|
112
97
|
end
|
113
98
|
|
114
99
|
def nest_translations_hash(translations_hash, key_prefix)
|
@@ -134,7 +119,9 @@ module ZendeskAppsTools
|
|
134
119
|
def write_yml(en_json, app_name, package_name)
|
135
120
|
titles = to_flattened_namespaced_hash(en_json, :title)
|
136
121
|
values = to_flattened_namespaced_hash(en_json, :value)
|
137
|
-
@translations = titles.each
|
122
|
+
@translations = titles.each do |k, v|
|
123
|
+
titles[k] = { 'title' => v, 'value' => escape_special_characters(values[k]) }
|
124
|
+
end
|
138
125
|
@app_name = app_name
|
139
126
|
@package_name = package_name
|
140
127
|
template(File.join(Translate.source_root, 'templates/translation.erb.tt'), 'translations/en.yml')
|
@@ -158,7 +145,7 @@ module ZendeskAppsTools
|
|
158
145
|
end
|
159
146
|
|
160
147
|
def array_to_nested_hash(array)
|
161
|
-
array.
|
148
|
+
array.each_with_object({}) do |item, result|
|
162
149
|
keys = item['key'].split('.')
|
163
150
|
current = result
|
164
151
|
keys[0..-2].each do |key|
|
@@ -176,6 +163,41 @@ module ZendeskAppsTools
|
|
176
163
|
translations['app.package'] = package_name # don't pseudo translate the package name
|
177
164
|
nest_translations_hash(translations, '')
|
178
165
|
end
|
166
|
+
|
167
|
+
def locale_list
|
168
|
+
say('Fetching translations...')
|
169
|
+
require 'net/http'
|
170
|
+
require 'faraday'
|
171
|
+
locale_response = Faraday.get(LOCALE_ENDPOINT)
|
172
|
+
|
173
|
+
return JSON.parse(locale_response.body)['locales'] if locale_response.status == 200
|
174
|
+
if locale_response.status == 401
|
175
|
+
say_error_and_exit 'Authentication failed'
|
176
|
+
else
|
177
|
+
say_error_and_exit "Failed to download locales, got HTTP status #{locale_response.status}"
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def package_name_for_update
|
182
|
+
options[:package_name] ||
|
183
|
+
package_name_from_json(error_out: options[:unattended]) ||
|
184
|
+
get_value_from_stdin('What is the package name for this app? (without leading app_)',
|
185
|
+
valid_regex: /^[a-z_]+$/,
|
186
|
+
error_msg: 'Invalid package name, try again:')
|
187
|
+
end
|
188
|
+
|
189
|
+
def en_json
|
190
|
+
@en_json ||= begin
|
191
|
+
path = "#{destination_root}/translations/en.json"
|
192
|
+
JSON.parse(File.open(path).read) if File.exist? path
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def package_name_from_json(error_out: false)
|
197
|
+
package = en_json && en_json['app']['package']
|
198
|
+
return package if package
|
199
|
+
say_error_and_exit 'No package defined inside en.json!' if error_out
|
200
|
+
end
|
179
201
|
end
|
180
202
|
end
|
181
203
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zendesk_apps_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.35.
|
4
|
+
version: 1.35.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James A. Rosen
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2016-
|
14
|
+
date: 2016-10-13 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: thor
|