forked from flux-doctrine/awesome-fbp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
88 lines (77 loc) · 2.59 KB
/
Copy pathRakefile
File metadata and controls
88 lines (77 loc) · 2.59 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
require 'json'
require 'pathname'
require 'stringio'
require 'yaml'
PROJECTS = Dir['projects/**/*.yaml'].sort_by do |path|
path.delete_prefix('projects/').delete_suffix('.yaml')
end.freeze
SHOWCASE = Dir['showcase/**/*.yaml'].sort_by do |path|
path.delete_prefix('showcase/').delete_suffix('.yaml')
end.freeze
namespace :list do
task :people => Dir['people/*.md'].sort do |t|
t.prerequisites.each do |path|
handle = Pathname(path).to_s.delete_prefix('people/').delete_suffix('.md')
puts "[@#{handle}](https://github.com/#{handle}),"
end
end
end
task default: %w(projects.json projects.md showcase.json showcase.md)
file 'projects.json': PROJECTS do |t|
File.open(t.name, 'w') do |out|
out.puts generate_json(t.prerequisites)
end
end
file 'projects.md': PROJECTS do |t|
File.open(t.name, 'w') do |out|
out.puts generate_markdown(t.prerequisites)
end
end
file 'showcase.json': SHOWCASE do |t|
File.open(t.name, 'w') do |out|
out.puts generate_json(t.prerequisites)
end
end
file 'showcase.md': SHOWCASE 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 "| Project | Summary | Author | Language | License | Updated | Links |"
out.puts "| :------ | :------ | :----- | :------- | :------ | :------ | :---- |"
load_projects(input_paths).each do |project|
project_authors = project[:authors].map { it.delete_prefix('https://github.com/') }
project_author = "[@#{project_authors.first}](https://github.com/#{project_authors.first})"
project_link = "[#{project[:label]}](#{project[:links].first})"
project_links = project[:links].map do |url|
emoji = case
when url.start_with?('https://github.com') then ':octocat:'
when %w(crates.io hex.pm).any? { url.start_with?("https://#{it}") } then '📦'
when %w(docs.rs hexdocs.pm).any? { url.start_with?("https://#{it}") } then ':book:'
else ':house:'
end
"[#{emoji}](#{url})"
end
out.puts "| " + [
project_link,
project[:summary].strip,
project_author,
project[:language] || 'TBD',
(project[:license] || 'Unknown').split('-').first,
project[:updated] || '',
project_links.join(' '),
].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|
YAML.safe_load(File.read(input_path), symbolize_names: true)
end
end