This repository has been archived by the owner on Jul 14, 2023. It is now read-only.
/
generator.rb
72 lines (60 loc) · 1.52 KB
/
generator.rb
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
require "neat/version"
require "fileutils"
require "thor"
module Neat
class Generator < Thor
map ["-v", "--version"] => :version
desc "install", "Install Neat into your project"
def install
if neat_files_already_exist?
puts "Neat files already installed, doing nothing."
else
install_files
puts "Neat files installed to neat/"
end
end
desc "update", "Update Neat"
def update
if neat_files_already_exist?
remove_neat_directory
install_files
puts "Neat files updated."
else
puts "No existing neat installation. Doing nothing."
end
end
desc "remove", "Remove Neat"
def remove
if neat_files_already_exist?
remove_neat_directory
puts "Neat was successfully removed."
else
puts "No existing neat installation. Doing nothing."
end
end
desc "version", "Show Neat version"
def version
say "Neat #{Neat::VERSION}"
end
private
def neat_files_already_exist?
File.directory?("neat")
end
def install_files
FileUtils.mkdir_p("neat")
FileUtils.cp_r(all_stylesheets, "neat/")
end
def remove_neat_directory
FileUtils.rm_rf("neat")
end
def all_stylesheets
Dir["#{stylesheets_directory}/*"]
end
def stylesheets_directory
File.join(top_level_directory, "app", "assets", "stylesheets")
end
def top_level_directory
File.dirname(File.dirname(File.dirname(__FILE__)))
end
end
end