-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
46 lines (40 loc) · 1.04 KB
/
Rakefile
1
2
3
4
5
6
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
require "bundler/gem_tasks"
require "rake/testtask"
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/**/*_test.rb"]
end
task(default: :test)
require "json"
require "yaml"
# Convert a YAML file to JSON and write it out to a new file.
#
# @param path [String]
# @return [String]
def yaml2json(path, pretty: true)
path = File.expand_path(path)
ext = case File.extname(path).downcase
when ".yml" then ".yml"
when ".yaml" then ".yaml"
else ""
end
base_name = File.basename(path, ext)
dir = File.dirname(path)
out_file = File.join(dir, "#{base_name}.json")
input = YAML.load_file(path)
output = pretty ? JSON.pretty_generate(input) : input.to_json
File.open(out_file, "a") { |f| f.write(output) }
return out_file
end
task :yaml2json, [:path] do |_, arg|
yaml2json(arg[:path])
end
task :schema do |t|
[
"schema/class.schema.yml",
"schema/attr.schema.yml",
"schema/func.schema.yml",
"schema/param.schema.yml",
].each { |f| yaml2json(f) }
end