-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathRakefile
65 lines (58 loc) · 1.61 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
require 'json'
require 'json-schema'
require 'pry'
require 'pp'
require 'fileutils'
require 'pathname'
# Schema for new Bricks.
brick_info_schema = {
"type" => "object",
"required" => ["name","version","language","created"],
"properties" => {
"name" => {"type" => "string"},
"author" => {
"type" => "object",
"properties" => {
"name" => {"type" => "string"},
"email" => {"type" => "string"}
}
},
"created" => {"type" => "string"},
"version" => {"type" => "string"},
"category" => {"type" => "string"},
"language" => {"type" => "string"},
"description" => { "type" => "string"},
"tags" => {"type" => "string"},
"is_live" => {"type" => "boolean"},
"parameters" => {
"type" => "array",
"properties" => {
"name" => {"type" => "string"},
"description" => {"type" => "string"},
"type" => {"type" => "string"},
"mandatory" => {"type" => "boolean"},
}
}
},
}
desc 'Gets info.json from /apps/ and validates.'
task :default do
root = Pathname(__FILE__).expand_path.dirname
bricks_root = root + "./apps/*/info.json"
production_bricks = []
bricks = Dir.glob(bricks_root).map do |path|
brick = JSON.parse(File.read(path))
if JSON::Validator.validate!(brick_info_schema, brick)
production_bricks << brick
else
fail JSON::Schema::ValidationError
end
end
task(:write).invoke(production_bricks)
end
desc 'Writes JSON file to location.'
task :write, :file do |w, bricks|
File.open("./build/bricks.json", 'w') do |f|
f.puts bricks.file.to_json
end
end