envoy-cli 1.0.0rc1 → 1.0.0rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bootstrap/base/Gruntfile.js +13 -0
- data/bootstrap/templates/index.js.erb +3 -1
- data/bootstrap/templates/package.json +4 -8
- data/lib/envoy.rb +5 -5
- data/lib/{tasks → envoy}/plugin.rb +5 -0
- data/lib/{tasks → envoy}/routes.rb +2 -2
- data/lib/envoy/schema.rb +86 -0
- data/lib/{tasks → envoy}/test.rb +0 -0
- data/lib/envoy/version.rb +1 -1
- data/lib/{tasks → envoy}/workers.rb +0 -0
- data/lib/inc/generator.rb +36 -2
- data/lib/inc/schema_model.rb +98 -0
- metadata +8 -7
- data/bootstrap/base/.envoyrc +0 -1
- data/bootstrap/base/gulpfile.js +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 09cc0766e2fbb6a44d96f4cd2ad4e7a3b8012f36
|
4
|
+
data.tar.gz: b152d8336231821b31d49c66ef5c647004013f12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6bd6788c27b249f1a7e33370f7cb400d2a1fd88600bdcd27fe443c6d20e6484f55431867395b4cd08b09f5fc55756e17baf3e9153e6f9d1b7b7ab685ea3ff39
|
7
|
+
data.tar.gz: d94b22579d54c2e21d04d8618f0dc814e060a4e2825faba6b54852ec8adcf81f1837f91e796622ad048a190504832f9f14d3919490a9cddd62aba3e0d6d562bf
|
@@ -1,24 +1,20 @@
|
|
1
1
|
{
|
2
2
|
"name": "",
|
3
|
-
"version": "",
|
3
|
+
"version": "0.0.1",
|
4
4
|
"description": "",
|
5
5
|
"main": "index.js",
|
6
6
|
"repository": "",
|
7
7
|
"private": true,
|
8
|
-
"scripts": {
|
9
|
-
"setup": "./bin/setup",
|
10
|
-
"invoke": "./bin/invoke"
|
11
|
-
},
|
12
8
|
"author": "",
|
13
9
|
"license": "SEE LICENSE IN license.md",
|
14
10
|
"devDependencies": {
|
11
|
+
"grunt": "^1.0.1",
|
12
|
+
"grunt-aws-lambda": "^0.12.0"
|
15
13
|
},
|
16
14
|
"dependencies": {
|
17
|
-
"
|
18
|
-
"envoy-platform-sdk": "git+ssh://git@github.com/envoy/envoy-platform-sdk-nodejs.git"
|
15
|
+
"envoy-platform-sdk": "git+ssh://git@github.com/envoy/envoy-platform-sdk-nodejs.git#develop"
|
19
16
|
},
|
20
17
|
"bundledDependencies": [
|
21
|
-
"dotenv",
|
22
18
|
"envoy-platform-sdk"
|
23
19
|
]
|
24
20
|
}
|
data/lib/envoy.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
require 'envoy/version'
|
2
1
|
require 'thor'
|
3
2
|
|
4
3
|
require 'inc/runner'
|
5
4
|
require 'inc/commands'
|
6
5
|
require 'inc/mixins'
|
7
6
|
require 'inc/generator'
|
7
|
+
require 'inc/schema_model'
|
8
8
|
|
9
9
|
require 'unirest'
|
10
10
|
require 'colorize'
|
11
11
|
|
12
12
|
project_root = File.dirname(File.absolute_path(__FILE__))
|
13
|
-
Dir.glob("#{project_root}/
|
13
|
+
Dir.glob("#{project_root}/envoy/**/*.rb", &method(:require))
|
14
14
|
|
15
15
|
module Envoy
|
16
16
|
class Main < Commands
|
@@ -20,12 +20,12 @@ module Envoy
|
|
20
20
|
|
21
21
|
# Authenticates the user by storing their auth_token in ~/.envoy-cfg
|
22
22
|
# @param --local [String] will use localhost:3000 as the API url
|
23
|
-
# @param --
|
23
|
+
# @param --endpoint [String] can be used to override the endpoint for this profile
|
24
24
|
# @param --profile NAME [String] will save the login information for that profile, in order
|
25
25
|
# to use that info, you must specify the same profile name on other requests
|
26
26
|
|
27
27
|
desc "login", "Login to your account"
|
28
|
-
option :
|
28
|
+
option :endpoint, type: :string
|
29
29
|
|
30
30
|
def login
|
31
31
|
# collect login information
|
@@ -55,7 +55,7 @@ module Envoy
|
|
55
55
|
'access_token' => res['access_token']
|
56
56
|
}
|
57
57
|
conf['local'] = true if options.local
|
58
|
-
conf['api_path'] = options.
|
58
|
+
conf['api_path'] = options.endpoint if options.endpoint
|
59
59
|
|
60
60
|
config.params[profile(options)] = conf
|
61
61
|
|
@@ -136,9 +136,14 @@ module Envoy
|
|
136
136
|
bootstrap = options.bootstrap
|
137
137
|
if dir
|
138
138
|
# @TODO create dir if it doesn't already exist
|
139
|
+
unless Dir.exists? dir
|
140
|
+
Dir.mkdir dir
|
141
|
+
end
|
139
142
|
Dir.chdir dir
|
140
143
|
end
|
141
144
|
|
145
|
+
destination_root = Dir.pwd
|
146
|
+
|
142
147
|
if file_exist?('config/default.json') || file_exist?("config/#{profile.downcase}.json")
|
143
148
|
prompt.yes?("It looks you've already created a plugin here. Would you like to register it?") || exit
|
144
149
|
else
|
@@ -5,7 +5,8 @@ module Envoy
|
|
5
5
|
include Envoy::Generator
|
6
6
|
|
7
7
|
desc 'add <name>', 'Add a route to your plugin'
|
8
|
-
def add(name)
|
8
|
+
def add(name = false)
|
9
|
+
name ||= prompt.ask("Route name (lowercase alphanumeric):")
|
9
10
|
setup_route name
|
10
11
|
end
|
11
12
|
|
@@ -22,7 +23,6 @@ module Envoy
|
|
22
23
|
say_status 'request', indent_lines(pretty_json(min_json(fake_data))).lstrip, :magenta
|
23
24
|
output = `node_modules/.bin/invoke local #{fake_data.to_json.to_json}`
|
24
25
|
output = output.split('------%%------')
|
25
|
-
puts output
|
26
26
|
json = JSON.parse output[1]
|
27
27
|
if json.dig('payload', 'body', 'html')
|
28
28
|
tmpfile = ".tmp/response-#{Time.now.to_i}.html"
|
data/lib/envoy/schema.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
module Envoy
|
2
|
+
class Schema < Commands
|
3
|
+
include Mixins
|
4
|
+
include Envoy::Generator
|
5
|
+
include Envoy::SchemaModel
|
6
|
+
|
7
|
+
desc 'add <name>', 'Add a schema to your plugin'
|
8
|
+
def add(name = false)
|
9
|
+
unless name
|
10
|
+
name = prompt.ask("Name (lowercase alphanumeric):") do |q|
|
11
|
+
q.required true
|
12
|
+
q.validate(/^[\w0-9\-]+$/)
|
13
|
+
q.modify :downcase
|
14
|
+
end
|
15
|
+
end
|
16
|
+
profiles = get_profiles
|
17
|
+
|
18
|
+
modify_profiles(profiles) do |profile, data|
|
19
|
+
if data.dig('schema', name)
|
20
|
+
next error "The schema <#{name}> already exists in environment <#{profile}>. Skipping."
|
21
|
+
end
|
22
|
+
data['schema'][name] = []
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
desc 'remove <name>', 'Remove a schema from your plugin'
|
27
|
+
def remove(name = nil)
|
28
|
+
profiles = get_profiles
|
29
|
+
schemas = []
|
30
|
+
read_profiles(profiles) do |_, data|
|
31
|
+
schemas |= data['schema'].keys
|
32
|
+
end
|
33
|
+
|
34
|
+
if schemas.empty?
|
35
|
+
error('No schemas to remove.') && exit
|
36
|
+
end
|
37
|
+
|
38
|
+
unless name
|
39
|
+
name = prompt.select("Select schema to remove:", schemas)
|
40
|
+
end
|
41
|
+
|
42
|
+
modify_profiles(profiles) do |profile, data|
|
43
|
+
unless data.dig('schema', name)
|
44
|
+
next warn "The schema <#{name}> does not exist in environment <#{profile}>. Skipping."
|
45
|
+
end
|
46
|
+
data['schema'].delete(name)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
desc 'add-field <name>', 'Remove a schema from your plugin'
|
51
|
+
def add_field(schema = nil, key = nil)
|
52
|
+
profiles = get_profiles
|
53
|
+
schemas = []
|
54
|
+
read_profiles(profiles) do |_, data|
|
55
|
+
schemas |= data['schema'].keys
|
56
|
+
end
|
57
|
+
|
58
|
+
unless schema
|
59
|
+
schema = prompt.select("Select schema to add a field to:", schemas)
|
60
|
+
end
|
61
|
+
|
62
|
+
until key
|
63
|
+
key = prompt.ask("Key (required):")
|
64
|
+
end
|
65
|
+
|
66
|
+
type = choose_field_type
|
67
|
+
|
68
|
+
config = get_field_options type
|
69
|
+
config[:type] = type
|
70
|
+
config[:key] = key
|
71
|
+
|
72
|
+
modify_profiles(profiles) do |profile, data|
|
73
|
+
unless data.dig('schema', schema)
|
74
|
+
next warn "The schema <#{schema}> does not exist in environment <#{profile}>. Skipping."
|
75
|
+
end
|
76
|
+
if data['schema'][schema].detect { |f| f["key"] == key }
|
77
|
+
if prompt.yes?("Discovered schema field with key <#{key}> in <#{profile}:#{schema}>. Override?")
|
78
|
+
data.dig('schema', schema).push(config)
|
79
|
+
end
|
80
|
+
else
|
81
|
+
data.dig('schema', schema).push(config)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/lib/{tasks → envoy}/test.rb
RENAMED
File without changes
|
data/lib/envoy/version.rb
CHANGED
File without changes
|
data/lib/inc/generator.rb
CHANGED
@@ -12,7 +12,7 @@ module Envoy
|
|
12
12
|
'installable_on' => ['location'],
|
13
13
|
'oauth2' => {},
|
14
14
|
'schema' => {},
|
15
|
-
'
|
15
|
+
'setup_flow' => [],
|
16
16
|
'routes' => [],
|
17
17
|
'jobs_handled' => {}
|
18
18
|
})
|
@@ -91,11 +91,45 @@ module Envoy
|
|
91
91
|
.select { |file| file.end_with? '.json' }
|
92
92
|
.map { |file| file.chomp('.json') }
|
93
93
|
if choose && profiles.length > 1
|
94
|
-
profiles = prompt.multi_select("Select
|
94
|
+
profiles = prompt.multi_select("Select environments to apply this change to:", profiles)
|
95
95
|
end
|
96
96
|
profiles
|
97
97
|
end
|
98
98
|
|
99
|
+
def get_profile(choose = true)
|
100
|
+
profiles = Dir.entries("#{destination_root}/config")
|
101
|
+
.select { |file| file.end_with? '.json' }
|
102
|
+
.map { |file| file.chomp('.json') }
|
103
|
+
if choose && profiles.length > 1
|
104
|
+
profile = prompt.select("Select environment to apply this change to", profiles)
|
105
|
+
else
|
106
|
+
profile = profiles[0]
|
107
|
+
end
|
108
|
+
profile
|
109
|
+
end
|
110
|
+
|
111
|
+
def modify_profiles(profiles)
|
112
|
+
read_profiles(profiles) do |profile, data|
|
113
|
+
state_hash = data.to_json.hash
|
114
|
+
yield profile, data
|
115
|
+
if state_hash != data.to_json.hash
|
116
|
+
write_data("config/#{profile}.json", data)
|
117
|
+
else
|
118
|
+
say_status("no change", "config/#{profile}.json", :yellow)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def read_profiles(profiles)
|
124
|
+
unless profiles.is_a? Array
|
125
|
+
profiles = [profiles]
|
126
|
+
end
|
127
|
+
profiles.each do |profile|
|
128
|
+
data = read_data("config/#{profile}.json")
|
129
|
+
yield profile, data
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
99
133
|
def setup_worker(name)
|
100
134
|
@job_name = name
|
101
135
|
template "templates/worker.js.erb", "workers/#{name}.js"
|
@@ -0,0 +1,98 @@
|
|
1
|
+
module Envoy
|
2
|
+
module SchemaModel
|
3
|
+
SCHEMA_CONFIG = {
|
4
|
+
string: {
|
5
|
+
desc: 'Single-line Input',
|
6
|
+
asks: %w(label note is_required default_value read_only placeholder)
|
7
|
+
},
|
8
|
+
textarea: {
|
9
|
+
desc: 'Multi-line Input',
|
10
|
+
asks: %w(label note is_required default_value read_only placeholder)
|
11
|
+
},
|
12
|
+
checkbox: {
|
13
|
+
desc: 'Checkbox',
|
14
|
+
asks: %w(label note default_value)
|
15
|
+
},
|
16
|
+
select: {
|
17
|
+
desc: 'Select',
|
18
|
+
asks: %w(label note is_required default_value options)
|
19
|
+
},
|
20
|
+
divider: {
|
21
|
+
desc: 'Divider Line',
|
22
|
+
asks: []
|
23
|
+
},
|
24
|
+
note: {
|
25
|
+
desc: 'Paragraph of Text',
|
26
|
+
asks: %w(label note)
|
27
|
+
}
|
28
|
+
}.freeze
|
29
|
+
|
30
|
+
def choose_field_type
|
31
|
+
prompt.select("Choose field type") do |menu|
|
32
|
+
# menu.default :string
|
33
|
+
SCHEMA_CONFIG.each do |key, value|
|
34
|
+
menu.choice value[:desc] + " (#{key})", key
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_field_options(type)
|
40
|
+
config = {}
|
41
|
+
SCHEMA_CONFIG[type.to_sym][:asks].each do |ask|
|
42
|
+
out = send("schema_ask_#{ask}")
|
43
|
+
config[out[0]] = out[1]
|
44
|
+
end
|
45
|
+
config
|
46
|
+
end
|
47
|
+
|
48
|
+
def schema_ask_label
|
49
|
+
['label', prompt.ask("Label:")]
|
50
|
+
end
|
51
|
+
|
52
|
+
def schema_ask_note
|
53
|
+
['note', prompt.ask("Note:")]
|
54
|
+
end
|
55
|
+
|
56
|
+
def schema_ask_default_value
|
57
|
+
value = prompt.ask("Default Value:")
|
58
|
+
['default_value', value || nil]
|
59
|
+
end
|
60
|
+
|
61
|
+
def schema_ask_is_required
|
62
|
+
required = prompt.yes?("Required?")
|
63
|
+
['is_required', required]
|
64
|
+
end
|
65
|
+
|
66
|
+
def schema_ask_read_only
|
67
|
+
required = prompt.yes?("Read Only?")
|
68
|
+
['read_only', required]
|
69
|
+
end
|
70
|
+
|
71
|
+
def schema_ask_options
|
72
|
+
type = prompt.select("How should this select load its options?", {
|
73
|
+
"I'll specify the exact options now." => :static,
|
74
|
+
"It will load the options on demand from an endpoint." => :dynamic
|
75
|
+
})
|
76
|
+
if type == :static
|
77
|
+
continue = true
|
78
|
+
index = 1
|
79
|
+
options = []
|
80
|
+
while continue
|
81
|
+
say "> Option #{index}:"
|
82
|
+
value = prompt.ask("Value:", required: true)
|
83
|
+
label = prompt.ask("Label:", default: value)
|
84
|
+
continue = prompt.yes?("Add another option?")
|
85
|
+
index += 1
|
86
|
+
options.push({ value: value, label: label })
|
87
|
+
end
|
88
|
+
else
|
89
|
+
options = prompt.ask("Route name:")
|
90
|
+
end
|
91
|
+
['options', options]
|
92
|
+
end
|
93
|
+
|
94
|
+
def schema_ask_placeholder
|
95
|
+
['placeholder', prompt.ask('Placeholder')]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: envoy-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.0rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Boskovic
|
@@ -206,12 +206,11 @@ files:
|
|
206
206
|
- Gemfile
|
207
207
|
- bin/envoy
|
208
208
|
- bin/envoy.bak
|
209
|
-
- bootstrap/base/.envoyrc
|
210
209
|
- bootstrap/base/.jshintrc
|
211
210
|
- bootstrap/base/.nvmrc
|
211
|
+
- bootstrap/base/Gruntfile.js
|
212
212
|
- bootstrap/base/config/.gitkeep
|
213
213
|
- bootstrap/base/docs/.gitkeep
|
214
|
-
- bootstrap/base/gulpfile.js
|
215
214
|
- bootstrap/base/i18n/.gitkeep
|
216
215
|
- bootstrap/base/index.js
|
217
216
|
- bootstrap/base/lib/.gitkeep
|
@@ -238,15 +237,17 @@ files:
|
|
238
237
|
- bootstrap/templates/worker.js.erb
|
239
238
|
- envoy-cli.gemspec
|
240
239
|
- lib/envoy.rb
|
240
|
+
- lib/envoy/plugin.rb
|
241
|
+
- lib/envoy/routes.rb
|
242
|
+
- lib/envoy/schema.rb
|
243
|
+
- lib/envoy/test.rb
|
241
244
|
- lib/envoy/version.rb
|
245
|
+
- lib/envoy/workers.rb
|
242
246
|
- lib/inc/commands.rb
|
243
247
|
- lib/inc/generator.rb
|
244
248
|
- lib/inc/mixins.rb
|
245
249
|
- lib/inc/runner.rb
|
246
|
-
- lib/
|
247
|
-
- lib/tasks/routes.rb
|
248
|
-
- lib/tasks/test.rb
|
249
|
-
- lib/tasks/workers.rb
|
250
|
+
- lib/inc/schema_model.rb
|
250
251
|
- readme.md
|
251
252
|
homepage: http://rubygemspec.org/gems/envoy-cli
|
252
253
|
licenses:
|
data/bootstrap/base/.envoyrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{}
|
data/bootstrap/base/gulpfile.js
DELETED
File without changes
|