This repository has been archived by the owner on Mar 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Rakefile
65 lines (51 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
65
require './lib/snippet'
require './lib/readme-generator'
require './lib/readable-snippets-generator'
require 'fileutils'
LIBRARY_SNIPPETS_DIR = "#{Dir.home}/Library/Developer/Xcode/UserData/CodeSnippets"
SANDBOXED_SNIPPETS_DIR = "TODO: support for the App-Store downloaded Xcode snippets"
BACKUP_DIR = 'backup'
def initialize_snippets
Dir.chdir BACKUP_DIR
snippets = Dir['*.codesnippet'].map do |snippet_file|
snippet = Snippet.parse(File.read(snippet_file))
end
Dir.chdir("../")
return snippets
end
def raw_snippets
@raw_snippets ||= initialize_snippets
end
def generate_readme
ReadmeGenerator.generate raw_snippets
end
def backup_files
FileUtils.rm_rf BACKUP_DIR
FileUtils.cp_r LIBRARY_SNIPPETS_DIR, BACKUP_DIR
# puts "#{Dir.entries(LIBRARY_SNIPPETS_DIR).count} snippets backed up."
end
def generate_readable_snippets
FileUtils.rm_rf 'readable_snippets'
FileUtils.mkdir 'readable_snippets'
ReadableSnippetsGenerator.generate raw_snippets
end
def copy_snippets_to_xcode
FileUtils.cp_r "#{BACKUP_DIR}/.", LIBRARY_SNIPPETS_DIR
end
task :backup do
backup_files
generate_readable_snippets
generate_readme
puts 'You have successfully backed up your snippets! Readable snippets are in ./readable_snippets folder.
Commit / Push to see your new cheatsheet :)'
end
task :clean_import do
FileUtils.cp_r "#{LIBRARY_SNIPPETS_DIR}/." , "#{Dir.home}/Desktop/OLD-snippets-backup"
FileUtils.rm_rf "#{LIBRARY_SNIPPETS_DIR}/."
copy_snippets_to_xcode
end
task :import do
copy_snippets_to_xcode
puts 'You have successfully imported your snippets in the Xcode.
Please re-start Xcode to see the them :)'
end