-
-
Notifications
You must be signed in to change notification settings - Fork 155
/
Copy pathdocs.cr
56 lines (46 loc) · 1.63 KB
/
docs.cr
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
module Mint
class Cli < Admiral::Command
class Docs < Admiral::Command
include Command
define_help description: "Generates API Documentation."
define_flag include_core : Bool,
description: "If specified, documentation will be generated for the standard library as well.",
default: false
define_flag include_packages : Bool,
description: "If specified, documentation will be generated for used packages as well.",
default: false
define_argument directory : String,
description: "The directory to generate the docs to.",
default: "docs",
required: true
def run
execute "Generating documentation" do
directory = arguments.directory
json = MintJson.current
jsons =
if flags.include_packages
SourceFiles.packages(json, include_self: true)
else
[json]
end
asts =
Dir.glob(SourceFiles.globs(jsons)).map do |file|
Ast.new.tap do |ast|
ast.merge(Parser.parse(File.read(file), file))
end
end
asts << Core.ast if flags.include_core
terminal.measure %(#{COG} Clearing the "#{directory}" directory...) do
FileUtils.rm_rf directory
Dir.mkdir directory
end
terminal.measure "#{COG} Generating documentation..." do
StaticDocumentationGenerator.generate(asts).each do |path, contents|
File.write_p(Path[directory, path], contents.call)
end
end
end
end
end
end
end