forked from artob/flows.rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
93 lines (83 loc) · 2.93 KB
/
Rakefile
File metadata and controls
93 lines (83 loc) · 2.93 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
require 'fileutils'
require 'json'
require 'pathname'
require 'stringio'
require 'tomlrb' # https://rubygems.org/gems/tomlrb
require 'yaml'
PACKAGES = Dir['lib/**/Cargo.toml'].sort_by do |path|
path.delete_prefix('lib/').delete_suffix('/Cargo.toml')
end.map { Pathname(it) }.freeze
task default: %w(.cargo/packages.json .cargo/packages.md readmes)
task readmes: PACKAGES.map { it.parent.join('README.md').to_s }.to_a - %w[lib/flows/README.md]
PACKAGES.each do |package_toml|
package_path = package_toml.parent
package_meta = Tomlrb.load_file(package_toml, symbolize_keys: true)
package_name = package_meta[:package][:name]
next if package_name == 'flows'
package_title = (package_meta[:package][:metadata][:readme][:title] rescue nil)
package_description = package_meta[:package][:description]
file package_path.join('README.md') => %[.readme/README.md.j2] do |t|
template_path = Pathname(t.prerequisites.first).realpath
File.open(t.name, 'w') do |out|
Dir.chdir(package_path) do
FileUtils.ln_sf(template_path, 'README.md.j2')
begin
command = %W[minijinja-cli --strict README.md.j2 /dev/stdin -fjson]
IO.popen(command, "r+") do |pipe|
pipe.puts JSON.pretty_unparse({
package: {
title: package_title,
name: package_name,
description: package_description,
}
})
pipe.close_write
out.puts pipe.read
end
ensure
FileUtils.rm('README.md.j2')
end
end
end
end
end
file '.cargo/packages.json': PACKAGES do |t|
File.open(t.name, 'w') do |out|
out.puts generate_json(t.prerequisites)
end
end
file '.cargo/packages.md': PACKAGES do |t|
File.open(t.name, 'w') do |out|
out.puts generate_markdown(t.prerequisites)
end
end
def generate_markdown(input_paths)
StringIO.open do |out|
out.puts "| Package | Summary | Crate | Docs |"
out.puts "| :------ | :------ | :---- | :--- |"
load_projects(input_paths).each do |project|
package_name = project[:package][:name]
package_link = "[#{package_name}](https://github.com/artob/flows.rs/tree/master/lib/#{package_name})"
package_summary = project[:package][:description].gsub("Building blocks for flow", 'Flow')
package_links = [
"[](https://crates.io/crates/#{package_name})",
"[](https://docs.rs/#{package_name})",
]
out.puts "| " + [
package_link,
package_summary,
package_links[0],
package_links[1],
].join(" | ") + " |"
end
out.string
end
end
def generate_json(input_paths)
JSON.pretty_unparse(load_projects(input_paths))
end
def load_projects(input_paths)
input_paths.map do |input_path|
Tomlrb.load_file(input_path, symbolize_keys: true)
end
end