7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/minimum-term/tasks.rb', line 7
def install_tasks
namespace :minimum_term do
desc "Clean up intermediary json files"
task :cleanup do
path = File.expand_path("../contracts")
files = Dir.glob(File.join(path, "/**/*.schema.json")) +
Dir.glob(File.join(path, "/**/*.blueprint-ast.json"))
files.each do |file|
FileUtils.rm_f(file)
end
end
desc "Transform all MSON files in DATA_DIR to JSON Schema using drafter"
task :mson_to_json_schema, [:keep_intermediary_files] => :cleanup do |t, args|
if ENV['DATA_DIR'].blank?
puts "Please set DATA_DIR for me to work in"
exit(-1)
end
data_dir = File.expand_path(ENV['DATA_DIR'])
unless Dir.exist?(data_dir)
puts "Not such directory: #{data_dir}"
exit(-1)
end
keep_intermediary_files = args.to_hash.values.include?('keep_intermediary_files')
files = ENV['FILES'].to_s.split(',')
files = Dir.glob(File.join(data_dir, '**/*.mson')) if files.empty?
if files.empty?
puts "No FILES given and nothing found in #{data_dir}"
exit(-1)
end
puts "Converting #{files.length} files:"
ok = true
files.each do |file|
ok = ok && MinimumTerm::Conversion.mson_to_json_schema(
filename: file,
keep_intermediary_files: keep_intermediary_files,
verbose: true)
end
exit(-1) unless ok
end
end
end
|