wisco 0.2.4 → 0.2.7
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/lib/wisco/commands/fixtures.rb +40 -5
- data/lib/wisco/terminal_output.rb +22 -0
- data/lib/wisco/version.rb +1 -1
- data/lib/wisco.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 684776c3daf8185ae8be30ecc9afbeacdb216190f4f7c9d080ff3d8acc7bf5cb
|
|
4
|
+
data.tar.gz: b577efaddd5424680968a77acefaad54217cca76665a936c18f5083d8d4b8289
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2c13a0b3baad7d55e1c21b02d6be5d9a023e0f119265f57cc604b628711ac9639825505259e362c3f5be3035eec0f3be0523841de48dff6b4184a30a8f3185f7
|
|
7
|
+
data.tar.gz: a6ff5b3f26ea143eceb6068e76c28fce4622ffd8393fd63b45fc78404e2c28d0be755f6cdddd22cd0f53237892b712e7c7bee406dc23136e01259135fd96ea5a
|
|
@@ -17,7 +17,7 @@ module Wisco
|
|
|
17
17
|
config_path = Wisco.config_path(target_dir)
|
|
18
18
|
|
|
19
19
|
unless File.exist?(config_path)
|
|
20
|
-
|
|
20
|
+
Wisco::TerminalOutput.emit_error "Error: No #{Wisco::WISCO_DIR}/#{Wisco::CONFIG_FILENAME} found in #{target_dir}."
|
|
21
21
|
warn " Run '#{Wisco::CLI_NAME} init' first."
|
|
22
22
|
exit 1
|
|
23
23
|
end
|
|
@@ -27,7 +27,7 @@ module Wisco
|
|
|
27
27
|
connector_file = config.dig('connector', 'file')
|
|
28
28
|
|
|
29
29
|
if connector_path.nil? || connector_file.nil?
|
|
30
|
-
|
|
30
|
+
Wisco::TerminalOutput.emit_error "Error: #{Wisco::WISCO_DIR}/#{Wisco::CONFIG_FILENAME} is missing connector path/file. Run '#{Wisco::CLI_NAME} init' again."
|
|
31
31
|
exit 1
|
|
32
32
|
end
|
|
33
33
|
|
|
@@ -53,13 +53,13 @@ module Wisco
|
|
|
53
53
|
cf_file = File.join(fixtures_dir, 'config_fields.json')
|
|
54
54
|
cf_opt = nil # set to cf_file once the user has filled it in
|
|
55
55
|
|
|
56
|
-
if raw_cf
|
|
56
|
+
if raw_cf.present?
|
|
57
57
|
if config_fields_ready?(cf_file)
|
|
58
58
|
cf_opt = cf_file
|
|
59
59
|
else
|
|
60
60
|
write_config_fields_template(raw_cf, cf_file)
|
|
61
61
|
warn " Written: #{cf_file}"
|
|
62
|
-
|
|
62
|
+
Wisco::TerminalOutput.emit_warning(" Action required: fill in config_fields.json, then re-run fixtures.")
|
|
63
63
|
next
|
|
64
64
|
end
|
|
65
65
|
end
|
|
@@ -120,6 +120,14 @@ module Wisco
|
|
|
120
120
|
end
|
|
121
121
|
|
|
122
122
|
template = schema_to_template(fields)
|
|
123
|
+
|
|
124
|
+
# Merge config_fields.json if present — its keys are prepended to the template
|
|
125
|
+
cf_file = File.join(fixtures_dir, 'config_fields.json')
|
|
126
|
+
if File.exist?(cf_file)
|
|
127
|
+
cf_template = read_json_without_sentinel(cf_file)
|
|
128
|
+
template = cf_template.merge(template)
|
|
129
|
+
end
|
|
130
|
+
|
|
123
131
|
content = "#{SENTINEL}\n#{JSON.pretty_generate(template)}\n"
|
|
124
132
|
File.write(output_file, content)
|
|
125
133
|
puts " Written: #{output_file}"
|
|
@@ -221,6 +229,14 @@ module Wisco
|
|
|
221
229
|
puts " Written: #{output_file}"
|
|
222
230
|
end
|
|
223
231
|
|
|
232
|
+
def read_json_without_sentinel(path)
|
|
233
|
+
lines = File.readlines(path)
|
|
234
|
+
lines.shift while lines.first&.lstrip&.start_with?('#')
|
|
235
|
+
JSON.parse(lines.join)
|
|
236
|
+
rescue StandardError
|
|
237
|
+
{}
|
|
238
|
+
end
|
|
239
|
+
|
|
224
240
|
def config_fields_ready?(path)
|
|
225
241
|
return false unless File.exist?(path)
|
|
226
242
|
|
|
@@ -235,10 +251,29 @@ module Wisco
|
|
|
235
251
|
def write_config_fields_template(config_fields_array, output_file)
|
|
236
252
|
stringified = stringify_keys_deep(config_fields_array)
|
|
237
253
|
template = schema_to_template(stringified)
|
|
238
|
-
|
|
254
|
+
comments = build_config_fields_comments(stringified)
|
|
255
|
+
content = "#{SENTINEL}\n#{comments}#{JSON.pretty_generate(template)}\n"
|
|
239
256
|
File.write(output_file, content)
|
|
240
257
|
end
|
|
241
258
|
|
|
259
|
+
def build_config_fields_comments(fields)
|
|
260
|
+
return '' if fields.empty?
|
|
261
|
+
|
|
262
|
+
lines = ['# Config fields:']
|
|
263
|
+
fields.each do |field|
|
|
264
|
+
parts = []
|
|
265
|
+
parts << "label: #{field['label'].inspect}" if field['label']
|
|
266
|
+
parts << "hint: #{field['hint'].inspect}" if field['hint']
|
|
267
|
+
parts << "type: #{field['type'] || 'string'}"
|
|
268
|
+
parts << (field.fetch('optional', true) ? 'optional' : 'required')
|
|
269
|
+
parts << "control_type: #{field['control_type']}" if field['control_type']
|
|
270
|
+
parts << "pick_list: #{field['pick_list']}" if field['pick_list']
|
|
271
|
+
lines << "# #{field['name']}: #{parts.join(', ')}"
|
|
272
|
+
end
|
|
273
|
+
lines << '#'
|
|
274
|
+
lines.map { |l| "#{l}\n" }.join
|
|
275
|
+
end
|
|
276
|
+
|
|
242
277
|
def stringify_keys_deep(obj)
|
|
243
278
|
case obj
|
|
244
279
|
when Hash then obj.transform_keys(&:to_s).transform_values { |v| stringify_keys_deep(v) }
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Wisco
|
|
2
|
+
module TerminalOutput
|
|
3
|
+
RED = 31
|
|
4
|
+
YELLOW = 33
|
|
5
|
+
|
|
6
|
+
module_function
|
|
7
|
+
|
|
8
|
+
def emit_error(message)
|
|
9
|
+
warn(colorize(message, RED))
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def emit_warning(message)
|
|
13
|
+
warn(colorize(message, YELLOW))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def colorize(message, color_code)
|
|
17
|
+
return message unless $stderr.tty?
|
|
18
|
+
|
|
19
|
+
"\e[#{color_code}m#{message}\e[0m"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
data/lib/wisco/version.rb
CHANGED
data/lib/wisco.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: wisco
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- mbillington
|
|
@@ -73,6 +73,7 @@ files:
|
|
|
73
73
|
- lib/wisco/config.rb
|
|
74
74
|
- lib/wisco/connector.rb
|
|
75
75
|
- lib/wisco/path_utils.rb
|
|
76
|
+
- lib/wisco/terminal_output.rb
|
|
76
77
|
- lib/wisco/version.rb
|
|
77
78
|
- lib/wisco/workato_api.rb
|
|
78
79
|
homepage: https://github.com/billingtonm/wisco
|