groundwork 0.0.6 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/commands/unpack.rb +27 -0
- data/lib/groundwork.rb +1 -0
- data/lib/recipe.rb +1 -1
- data/lib/recipe_class.rb +108 -88
- data/lib/recipe_unpacker.rb +18 -0
- metadata +4 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
1.0.0
|
data/commands/unpack.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Groundwork
|
2
|
+
module Commands
|
3
|
+
def self.unpack args
|
4
|
+
cmd_opts = Trollop::options(args) do
|
5
|
+
opt :force, "Delete directory if exists", :default=>false
|
6
|
+
banner <<-STR
|
7
|
+
Usage:
|
8
|
+
groundwork unpack <name>
|
9
|
+
|
10
|
+
Expands an installed recipe to the current directory
|
11
|
+
STR
|
12
|
+
end
|
13
|
+
|
14
|
+
raise RuntimeError.new("Recipe not found: #{args[0]}") unless Groundwork.known_recipes[args[0]]
|
15
|
+
|
16
|
+
if File.exists?(args[0])
|
17
|
+
if cmd_opts[:force]
|
18
|
+
FileUtils.rm_rf args[0]
|
19
|
+
else
|
20
|
+
raise RuntimeError.new("Directory already exists: #{args[0]}\nUse -f to replace")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
Groundwork::Recipe.unpack args[0], Groundwork.known_recipes[args[0]]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/groundwork.rb
CHANGED
@@ -6,6 +6,7 @@ require File.join(File.dirname(__FILE__), "options.rb")
|
|
6
6
|
require File.join(File.dirname(__FILE__), "tar_wrapper.rb")
|
7
7
|
require File.join(File.dirname(__FILE__), "recipe.rb")
|
8
8
|
require File.join(File.dirname(__FILE__), "recipe_class.rb")
|
9
|
+
require File.join(File.dirname(__FILE__), "recipe_unpacker.rb")
|
9
10
|
|
10
11
|
module Groundwork
|
11
12
|
|
data/lib/recipe.rb
CHANGED
data/lib/recipe_class.rb
CHANGED
@@ -1,111 +1,131 @@
|
|
1
1
|
module Groundwork
|
2
|
-
|
3
|
-
|
2
|
+
class Recipe
|
3
|
+
class << self
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
# Takes a block and lists the files that that block will require as templates.
|
6
|
+
# See Groundwork::Recipe#possible
|
7
|
+
def required_files &block
|
8
|
+
dummy = Object.new
|
9
|
+
files = []
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
class << dummy
|
12
|
+
attr_reader :files
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
def directory *args
|
15
|
+
yield if block_given?
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
def file name, opts=nil
|
19
|
+
@files << opts[:from] if opts[:from]
|
20
|
+
@files << opts[:from_erb] if opts[:from_erb]
|
21
|
+
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
def possible name
|
24
|
+
@files << name
|
25
|
+
end
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
def method_missing *args ; end
|
28
|
+
end
|
29
29
|
|
30
|
-
|
31
|
-
|
30
|
+
dummy.instance_variable_set "@files", []
|
31
|
+
dummy.instance_eval &block
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
dummy.files
|
34
|
+
end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
def compile_file filename
|
37
|
+
compile File.read(filename), File.dirname(filename)
|
38
|
+
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
40
|
+
# Takes a script file, finds the files it requires (paths relative to the script file),
|
41
|
+
# reads/tars them and returns a string containing the script and the TAR blob, ready
|
42
|
+
# to write to a file
|
43
|
+
def compile script, in_directory
|
44
|
+
out = StringIO.new
|
45
|
+
data = nil
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
FileUtils.cd(in_directory) do
|
48
|
+
files = required_files do
|
49
|
+
eval script
|
50
|
+
end
|
51
51
|
|
52
|
-
|
53
|
-
|
52
|
+
data = TarWrapper.compress files
|
53
|
+
end
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
55
|
+
out.puts script
|
56
|
+
out.puts ""
|
57
|
+
out.puts "__END__"
|
58
|
+
out.puts data
|
59
59
|
|
60
|
-
|
61
|
-
|
60
|
+
out.string
|
61
|
+
end
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
63
|
+
# Takes a filename and runs the script contained in it. The file should be
|
64
|
+
# the results of Groundwork::Recipe#compile
|
65
|
+
def run script_file, args=[]
|
66
|
+
(script, data) = File.read(script_file).split("\n__END__\n")
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
# Generate a tree of file and directory calls that would create the given
|
75
|
-
# directory
|
76
|
-
def generate dir = FileUtils.pwd, options = {}
|
77
|
-
base = Pathname.new dir
|
78
|
-
|
79
|
-
handle_dir = lambda do |d, output, indent|
|
80
|
-
FileUtils.cd d do
|
81
|
-
Dir["*"].each do |file|
|
82
|
-
rel = Pathname.new(File.join(FileUtils.pwd,file))
|
83
|
-
relpath = rel.relative_path_from(base).to_s
|
84
|
-
|
85
|
-
next if options[:ignore] && options[:ignore].any?{|p| File.fnmatch(p,relpath) }
|
86
|
-
|
87
|
-
if File.directory? file
|
88
|
-
if Dir[File.join(file,"*")].empty?
|
89
|
-
output.puts((" "*indent)+"directory \"#{file}\"")
|
90
|
-
else
|
91
|
-
output.puts("")
|
92
|
-
output.puts((" "*indent)+"directory \"#{file}\" do")
|
93
|
-
handle_dir[file, output, indent+2]
|
94
|
-
output.puts((" "*indent)+"end")
|
95
|
-
output.puts("")
|
68
|
+
Groundwork::Recipe.new args do
|
69
|
+
self.tar = data if data
|
70
|
+
eval script
|
96
71
|
end
|
97
|
-
else
|
98
|
-
output.puts((" "*indent)+"file \"#{file}\", :from => \"#{relpath}\"")
|
99
|
-
end
|
100
72
|
end
|
101
|
-
end
|
102
|
-
end
|
103
73
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
74
|
+
# Takes the name of a directory and a block, and unpacks the script given
|
75
|
+
# in the block into the directory.
|
76
|
+
#
|
77
|
+
# If the second argument is given, the script is loaded from that filename instead
|
78
|
+
# of using the block
|
79
|
+
def unpack unpack_to, filename
|
80
|
+
(recipe, data) = File.read(filename).split("\n__END__\n")
|
81
|
+
|
82
|
+
FileUtils.mkdir unpack_to
|
108
83
|
|
84
|
+
FileUtils.cd unpack_to do
|
85
|
+
Groundwork::RecipeUnpacker.new do
|
86
|
+
self.tar = data if data
|
87
|
+
eval recipe
|
88
|
+
end
|
89
|
+
|
90
|
+
File.open("#{unpack_to}.recipe","w"){|f| f.puts recipe }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
# Generate a tree of file and directory calls that would create the given
|
95
|
+
# directory
|
96
|
+
def generate dir = FileUtils.pwd, options = {}
|
97
|
+
base = Pathname.new dir
|
98
|
+
|
99
|
+
handle_dir = lambda do |d, output, indent|
|
100
|
+
FileUtils.cd d do
|
101
|
+
Dir["*"].each do |file|
|
102
|
+
rel = Pathname.new(File.join(FileUtils.pwd,file))
|
103
|
+
relpath = rel.relative_path_from(base).to_s
|
104
|
+
|
105
|
+
next if options[:ignore] && options[:ignore].any?{|p| File.fnmatch(p,relpath) }
|
106
|
+
|
107
|
+
if File.directory? file
|
108
|
+
if Dir[File.join(file,"*")].empty?
|
109
|
+
output.puts((" "*indent)+"directory \"#{file}\"")
|
110
|
+
else
|
111
|
+
output.puts("")
|
112
|
+
output.puts((" "*indent)+"directory \"#{file}\" do")
|
113
|
+
handle_dir[file, output, indent+2]
|
114
|
+
output.puts((" "*indent)+"end")
|
115
|
+
output.puts("")
|
116
|
+
end
|
117
|
+
else
|
118
|
+
output.puts((" "*indent)+"file \"#{file}\", :from => \"#{relpath}\"")
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
str = StringIO.new
|
125
|
+
handle_dir[dir, str, 0]
|
126
|
+
str.string.gsub(/\n\n+/,"\n\n") # Collapse adjacent blank lines
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
109
130
|
end
|
110
|
-
end
|
111
131
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Groundwork
|
2
|
+
class RecipeUnpacker < Recipe
|
3
|
+
def directory *args, &block
|
4
|
+
yield if block_given?
|
5
|
+
end
|
6
|
+
|
7
|
+
def file name, opts = nil
|
8
|
+
if opts.is_a? Hash
|
9
|
+
if filename = (opts[:from] || opts[:from_erb])
|
10
|
+
FileUtils.mkdir_p File.dirname(filename)
|
11
|
+
File.open(filename,"w"){|f| f.print read_file(filename) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def method_missing *args ; end
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -3,10 +3,10 @@ name: groundwork
|
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
|
+
- 1
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 0.0.6
|
9
|
+
version: 1.0.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Andrews, Ross
|
@@ -59,11 +59,13 @@ files:
|
|
59
59
|
- lib/options.rb
|
60
60
|
- lib/recipe.rb
|
61
61
|
- lib/recipe_class.rb
|
62
|
+
- lib/recipe_unpacker.rb
|
62
63
|
- lib/tar_wrapper.rb
|
63
64
|
- commands/compile.rb
|
64
65
|
- commands/generate.rb
|
65
66
|
- commands/install.rb
|
66
67
|
- commands/list.rb
|
68
|
+
- commands/unpack.rb
|
67
69
|
- recipes/gem.recipe
|
68
70
|
- recipes/hello.recipe
|
69
71
|
has_rdoc: true
|