forked from sketchplugins/plugin-directory
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
84 lines (69 loc) · 2.15 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
require 'json'
require 'time'
data = IO.read('plugins.json')
data.force_encoding('utf-8')
plugins = JSON.parse(data)
desc "Clones all repositories to the 'clones' folder"
task :clone do
mkdir "clones"
plugins.each do |plugin|
name = plugin['name']
owner = plugin['owner']
url = "https://github.com/#{owner}/#{name}"
system("git clone #{url} clones/#{owner}-#{name}")
end
end
desc "Updates all clones in the 'clones' folder"
task :update do
plugins.each do |plugin|
name = plugin['name']
owner = plugin['owner']
url = "https://github.com/#{owner}/#{name}"
if File.directory? "clones/#{owner}-#{name}"
puts "Updating #{owner}-#{name} to latest version"
system("cd clones/#{owner}-#{name}/ && git up")
else
puts "Cloning #{owner}-#{name} to latest version"
system("git clone #{url} clones/#{owner}-#{name}")
end
end
end
desc "Generate README.md from plugins.json"
task :readme do
output = <<EOF
# Sketch Plugin Directory
A list of Sketch plugins hosted at GitHub, in alphabetical order.
**Note:** if you want to add yours, just open an issue with the URL, or send a pull request.
EOF
plugins.sort_by { |k| [k["title"] ? k["title"].downcase : k["name"].downcase, k["owner"].downcase] }.each do |plugin|
if plugin['lastUpdated']
last_update = Time.parse(plugin['lastUpdated'])
now = Time.now
if ( (now - last_update) > 60_000_000 )
next
end
end
if plugin['hidden'] == true
next
end
name = plugin['name']
owner = plugin['owner']
author = plugin['author'] || owner
title = plugin['title'] || name
url = plugin['homepage'] || "https://github.com/#{owner.downcase}/#{name.downcase}"
desc = plugin['description'].strip
output << "- [#{title}](#{url}), by #{author}:"
if !desc.empty?
output << " #{desc}"
end
output << "\n"
end
IO.write('README.md',output)
end
desc "List authors"
task :authors do
puts plugins.collect { |plugin| plugin['owner'] }.uniq.sort
puts plugins.collect { |plugin| plugin['owner'] }.uniq.sort.size
end
desc "Default: generate README.md from plugin"
task :default => :readme