thor-tree 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +19 -0
- data/Rakefile +8 -0
- data/lib/core_ext/hash.rb +9 -0
- data/lib/thor/tree.rb +41 -0
- data/lib/thor/tree/directory.rb +60 -0
- data/lib/thor/tree/file.rb +71 -0
- data/lib/thor/tree/version.rb +5 -0
- data/lib/thor/tree/writer.rb +30 -0
- data/spec/fixtures/example.yml +22 -0
- data/spec/fixtures/templates/d0/fa2 +1 -0
- data/spec/fixtures/templates/d0/fa4 +1 -0
- data/spec/fixtures/templates/d0/fb1 +1 -0
- data/spec/fixtures/templates/d0/fb2 +1 -0
- data/spec/fixtures/templates/fa3 +1 -0
- data/spec/fixtures/templates/fa5 +1 -0
- data/spec/fixtures/templates/fc0 +1 -0
- data/spec/fixtures/templates/fc1 +1 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/thor/tree_spec.rb +257 -0
- data/thor-tree.gemspec +27 -0
- metadata +166 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 471568ac26bad590864b2d59805462e84017e011
|
4
|
+
data.tar.gz: 2135ab48ad2ca7b35587a532d4e75b4006a235ee
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 166980fdc94f00ca409915b4d5a26807e4731a18df7b91e18970f08415f4129cdd4e372ab3da1cf87568c04494e848ede9a5ce4d8908df2737c78ec5112510f2
|
7
|
+
data.tar.gz: 7530dcf55d8e411234572d9a0fd4431abdeb68a1dff380d58a43d0f6c98b2223d8342b79840902f3fcabb1755e0168a838d21679fa28ec6eb1ce64f379887c8b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.0@thor-tree-gem
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Chris Enedah
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Thor::Tree
|
2
|
+
==========
|
3
|
+
|
4
|
+
Description
|
5
|
+
-----------
|
6
|
+
Thor::Tree is a file and directory generator extension for [Thor][thor]. It will parse a file tree described in a YAML file and generate the desired file and directory structure. File content may be specified with templates or copied from source files.
|
7
|
+
|
8
|
+
[thor]: https://github.com/erikhuda/thor
|
9
|
+
|
10
|
+
Installation
|
11
|
+
------------
|
12
|
+
gem install thor-tree
|
13
|
+
|
14
|
+
Usage
|
15
|
+
-----
|
16
|
+
Please see [the specifications][specs] and [example YAML file][example_yml] for an example.
|
17
|
+
|
18
|
+
[specs]: https://github.com/ikezue/thor-tree/blob/master/spec/thor/tree_spec.rb
|
19
|
+
[example_yml]: https://github.com/ikezue/thor-tree/blob/master/spec/fixtures/example.yml
|
data/Rakefile
ADDED
data/lib/thor/tree.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'safe_yaml'
|
2
|
+
require 'core_ext/hash'
|
3
|
+
require 'path'
|
4
|
+
require 'thor'
|
5
|
+
require 'thor/actions'
|
6
|
+
require 'thor/tree/directory'
|
7
|
+
require 'thor/tree/file'
|
8
|
+
require 'thor/tree/version'
|
9
|
+
require 'thor/tree/writer'
|
10
|
+
|
11
|
+
class Thor
|
12
|
+
class Tree
|
13
|
+
def initialize(file)
|
14
|
+
@options = YAML.load_file(Path(file).expand, safe: true).symbolize_keys!
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_template_variable(key, value)
|
18
|
+
Tree::File.set_template_variable key, value
|
19
|
+
end
|
20
|
+
|
21
|
+
def write
|
22
|
+
source_paths.each do |path|
|
23
|
+
Tree::File.source_paths << path
|
24
|
+
end
|
25
|
+
|
26
|
+
Tree::Writer.new([], {}, destination_root: options[:destination_root]).tap do |w|
|
27
|
+
w.write options[:content]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def options
|
34
|
+
@options ||= {}
|
35
|
+
end
|
36
|
+
|
37
|
+
def source_paths
|
38
|
+
options[:source_paths] ||= []
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
class Thor
|
2
|
+
class Tree
|
3
|
+
class Directory < Thor
|
4
|
+
include Thor::Actions
|
5
|
+
|
6
|
+
attr_reader :path
|
7
|
+
|
8
|
+
class << self
|
9
|
+
def ===(args)
|
10
|
+
args.is_a?(Hash) &&
|
11
|
+
(args.empty? || args.keys.all? { |key| key.start_with?(':') == false })
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(args, options = {}, config = {})
|
16
|
+
@path = Path.new args.first.to_s
|
17
|
+
super
|
18
|
+
self.destination_root = Writer.root_path
|
19
|
+
end
|
20
|
+
|
21
|
+
no_tasks do
|
22
|
+
def add(path, args)
|
23
|
+
case args
|
24
|
+
when File
|
25
|
+
add_file path, args
|
26
|
+
when Directory
|
27
|
+
add_subdirectory path, args
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def write
|
32
|
+
empty_directory @path
|
33
|
+
subdirectories.each { |dir| dir.write }
|
34
|
+
files.each { |file| file.write }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def add_file(file_path, options)
|
41
|
+
files << File.new([@path / file_path, options])
|
42
|
+
end
|
43
|
+
|
44
|
+
def add_subdirectory(dir_path, contents)
|
45
|
+
path = @path / dir_path
|
46
|
+
|
47
|
+
subdirectories.find { |dir| dir.path == path } || Tree::Directory.new([path]).tap do |dir|
|
48
|
+
subdirectories << dir
|
49
|
+
end.tap do |dir|
|
50
|
+
contents.each do |content_path, options|
|
51
|
+
dir.add content_path, options
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def files; @files ||= []; end
|
57
|
+
def subdirectories; @subdirectories ||= []; end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
class Thor
|
2
|
+
class Tree
|
3
|
+
class File < Thor
|
4
|
+
include Thor::Actions
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def ===(args)
|
8
|
+
args.is_a?(String) ||
|
9
|
+
args.is_a?(Hash) && !args.empty? && args.keys.first.start_with?(':')
|
10
|
+
end
|
11
|
+
|
12
|
+
def set_template_variable(key, value)
|
13
|
+
@_template_variables ||= {}
|
14
|
+
@_template_variables[key] = value
|
15
|
+
end
|
16
|
+
|
17
|
+
def template_variables
|
18
|
+
@_template_variables || {}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# @examples
|
23
|
+
# File.new [ 'path/to/dst', ':create_file' ]
|
24
|
+
# File.new [ 'path/to/dst', { ':create_file' => 'file content' } ]
|
25
|
+
# File.new [ 'path/to/dst', ':copy_file' ]
|
26
|
+
# File.new [ 'path/to/dst', { ':copy_file' => 'source_file' } ]
|
27
|
+
# File.new [ 'path/to/dst', ':template' ]
|
28
|
+
# File.new [ 'path/to/dst', { ':template' => 'source_file' } ]
|
29
|
+
def initialize(args, options = {}, config = {})
|
30
|
+
@_path = Path.new args[0].to_s
|
31
|
+
@_filename = @_path.basename
|
32
|
+
options.merge! options_from_args(args[1])
|
33
|
+
super
|
34
|
+
self.destination_root = Writer.root_path
|
35
|
+
File.template_variables.each { |key, value| instance_variable_set key, value }
|
36
|
+
end
|
37
|
+
|
38
|
+
no_tasks do
|
39
|
+
def write
|
40
|
+
case options[:action]
|
41
|
+
when :copy_file
|
42
|
+
copy_file options[:source] || @_filename, @_path, options[:thor_opts]
|
43
|
+
when :create_file
|
44
|
+
create_file @_path, options[:content].to_s, options[:thor_opts]
|
45
|
+
when :template
|
46
|
+
template options[:source] || @_filename, @_path, options[:thor_opts]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
def options_from_args(args)
|
54
|
+
Hash.new.tap do |opts|
|
55
|
+
[:copy_file, :create_file, :template].tap do |actions|
|
56
|
+
case args
|
57
|
+
when String
|
58
|
+
opts[:action] = actions.find { |action| action == args[1..-1].to_sym } || :create_file
|
59
|
+
when Hash
|
60
|
+
h = args.map { |k, v| [k[1..-1].to_sym, v] }.to_h
|
61
|
+
opts[:action] = actions.find { |action| action == h.keys.first } || :create_file
|
62
|
+
opts[:content] = h.delete :create_file
|
63
|
+
opts[:source] = h.delete(:copy_file) || h.delete(:template)
|
64
|
+
opts[:thor_opts] = h
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class Thor
|
2
|
+
class Tree
|
3
|
+
class Writer < Thor
|
4
|
+
include Thor::Actions
|
5
|
+
|
6
|
+
class << self
|
7
|
+
# Destination root for class
|
8
|
+
def root_path=(path); @_destination_root = path; end
|
9
|
+
def root_path; @_destination_root; end
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(args=[], options={}, config={})
|
13
|
+
super
|
14
|
+
Writer.root_path = Path(destination_root).expand
|
15
|
+
end
|
16
|
+
|
17
|
+
no_tasks do
|
18
|
+
def write(contents)
|
19
|
+
return unless contents.is_a?(Hash)
|
20
|
+
|
21
|
+
Tree::Directory.new([Writer.root_path]).tap do |root|
|
22
|
+
contents.each do |content_path, options|
|
23
|
+
root.add content_path, options
|
24
|
+
end
|
25
|
+
end.write
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
destination_root: 'spec/sandbox'
|
2
|
+
|
3
|
+
source_paths:
|
4
|
+
- 'spec/fixtures'
|
5
|
+
- 'spec/fixtures/templates'
|
6
|
+
|
7
|
+
content:
|
8
|
+
fa0: { ':create_file': 'fa0 content' }
|
9
|
+
fa1: ':create_file'
|
10
|
+
fa2: { ':copy_file': 'd0/fa2'}
|
11
|
+
fa3: ':copy_file'
|
12
|
+
fa4: { ':template': 'd0/fa4' }
|
13
|
+
fa5: ':template'
|
14
|
+
da0: {}
|
15
|
+
da1:
|
16
|
+
fb0: ':create_file'
|
17
|
+
fb1: { ':copy_file': 'd0/fb1' }
|
18
|
+
fb2: { ':template': 'd0/fb2' }
|
19
|
+
db0:
|
20
|
+
dc0: {}
|
21
|
+
fc0: ':copy_file'
|
22
|
+
fc1: ':template'
|
@@ -0,0 +1 @@
|
|
1
|
+
fa2 content
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= @fa4_content %>
|
@@ -0,0 +1 @@
|
|
1
|
+
fb1 content
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= @fb2_content %>
|
@@ -0,0 +1 @@
|
|
1
|
+
fa3 content
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= @fa5_content %>
|
@@ -0,0 +1 @@
|
|
1
|
+
fc0 content
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= @fc1_content %>
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
# config.run_all_when_everything_filtered = true
|
10
|
+
# config.filter_run :focus
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
config.order = 'random'
|
17
|
+
end
|
@@ -0,0 +1,257 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'thor/tree'
|
3
|
+
|
4
|
+
describe Thor::Tree do
|
5
|
+
describe "#set_template_variable" do
|
6
|
+
let(:tmp_dir) { Path.tmpdir }
|
7
|
+
let(:src) { tmp_dir / 'src' }
|
8
|
+
let(:dst) { tmp_dir / 'dst' }
|
9
|
+
let(:tree_yaml) { tmp_dir / 'tree.yml' }
|
10
|
+
let(:ivar_value) { 'some value' }
|
11
|
+
|
12
|
+
before do
|
13
|
+
File.open src, 'w' do |f|
|
14
|
+
f.write "<%= @ivar %>\n"
|
15
|
+
end
|
16
|
+
|
17
|
+
File.open tree_yaml, 'w' do |f|
|
18
|
+
f.write "destination_root: #{tmp_dir}\n"
|
19
|
+
f.write "source_paths:\n"
|
20
|
+
f.write "- #{tmp_dir}\n"
|
21
|
+
f.write "content:\n"
|
22
|
+
f.write " dst: { ':template': 'src' }\n"
|
23
|
+
end
|
24
|
+
|
25
|
+
tree_writer = Thor::Tree.new(tree_yaml)
|
26
|
+
tree_writer.set_template_variable '@ivar', ivar_value
|
27
|
+
tree_writer.write
|
28
|
+
end
|
29
|
+
|
30
|
+
after do
|
31
|
+
tmp_dir.rm_rf
|
32
|
+
end
|
33
|
+
|
34
|
+
it "sets a value for an ERB variable" do
|
35
|
+
expect(File.read dst).to match(ivar_value)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#write" do
|
40
|
+
describe "file creation" do
|
41
|
+
context "with :create_file" do
|
42
|
+
let(:tmp_dir) { Path.tmpdir }
|
43
|
+
let(:file1) { tmp_dir / 'file1' }
|
44
|
+
let(:file2) { tmp_dir / 'file2' }
|
45
|
+
let(:tree_yaml) { tmp_dir / 'tree.yml' }
|
46
|
+
let(:file2_content) { 'some_content' }
|
47
|
+
|
48
|
+
before do
|
49
|
+
File.open tree_yaml, 'w' do |f|
|
50
|
+
f.write "destination_root: #{tmp_dir}\n"
|
51
|
+
f.write "content:\n"
|
52
|
+
f.write " file1: ':create_file'\n"
|
53
|
+
f.write " file2: { ':create_file': #{file2_content} }\n"
|
54
|
+
end
|
55
|
+
|
56
|
+
Thor::Tree.new(tree_yaml).write
|
57
|
+
end
|
58
|
+
|
59
|
+
after do
|
60
|
+
tmp_dir.rm_rf
|
61
|
+
end
|
62
|
+
|
63
|
+
it "creates the named file" do
|
64
|
+
expect(file1).to exist
|
65
|
+
end
|
66
|
+
|
67
|
+
it "creates files with the specified content" do
|
68
|
+
expect(File.read file2).to eq(file2_content)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "with :copy_file" do
|
73
|
+
let(:tmp_dir) { Path.tmpdir }
|
74
|
+
let(:src) { tmp_dir / 'src' }
|
75
|
+
let(:dst) { tmp_dir / 'dst' }
|
76
|
+
let(:tree_yaml) { tmp_dir / 'tree.yml' }
|
77
|
+
let(:src_content) { 'some content' }
|
78
|
+
|
79
|
+
before do
|
80
|
+
File.open src, 'w' do |f|
|
81
|
+
f.write src_content
|
82
|
+
end
|
83
|
+
|
84
|
+
File.open tree_yaml, 'w' do |f|
|
85
|
+
f.write "destination_root: #{tmp_dir}\n"
|
86
|
+
f.write "source_paths:\n"
|
87
|
+
f.write "- #{tmp_dir}\n"
|
88
|
+
f.write "content:\n"
|
89
|
+
f.write " dst: { ':copy_file': 'src' }\n"
|
90
|
+
end
|
91
|
+
|
92
|
+
Thor::Tree.new(tree_yaml).write
|
93
|
+
end
|
94
|
+
|
95
|
+
after do
|
96
|
+
tmp_dir.rm_rf
|
97
|
+
end
|
98
|
+
|
99
|
+
it "creates a copy of the source file" do
|
100
|
+
expect(File.read dst).to eq(src_content)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
context "with :template" do
|
105
|
+
let(:tmp_dir) { Path.tmpdir }
|
106
|
+
let(:src) { tmp_dir / 'src' }
|
107
|
+
let(:dst) { tmp_dir / 'dst' }
|
108
|
+
let(:tree_yaml) { tmp_dir / 'tree.yml' }
|
109
|
+
let(:src_content) { 'some content with a <%= @variable %>' }
|
110
|
+
let(:variable_value) { 'some value' }
|
111
|
+
|
112
|
+
before do
|
113
|
+
File.open src, 'w' do |f|
|
114
|
+
f.write src_content
|
115
|
+
end
|
116
|
+
|
117
|
+
File.open tree_yaml, 'w' do |f|
|
118
|
+
f.write "destination_root: #{tmp_dir}\n"
|
119
|
+
f.write "source_paths:\n"
|
120
|
+
f.write "- #{tmp_dir}\n"
|
121
|
+
f.write "content:\n"
|
122
|
+
f.write " dst: { ':template': 'src' }\n"
|
123
|
+
end
|
124
|
+
|
125
|
+
tree_writer = Thor::Tree.new(tree_yaml)
|
126
|
+
tree_writer.set_template_variable '@variable', variable_value
|
127
|
+
tree_writer.write
|
128
|
+
end
|
129
|
+
|
130
|
+
after do
|
131
|
+
tmp_dir.rm_rf
|
132
|
+
end
|
133
|
+
|
134
|
+
it "creates a copy of the source file with interpolated source content" do
|
135
|
+
expect(File.read dst).to eq(src_content.gsub(/<%=.*%>/, variable_value))
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "directory creation" do
|
141
|
+
let(:tmp_dir) { Path.tmpdir }
|
142
|
+
let(:tree_yaml) { tmp_dir / 'tree.yml' }
|
143
|
+
|
144
|
+
before do
|
145
|
+
File.open tree_yaml, 'w' do |f|
|
146
|
+
f.write "destination_root: #{tmp_dir}\n"
|
147
|
+
f.write "content:\n"
|
148
|
+
f.write " dir_1:\n"
|
149
|
+
f.write " dir_11:\n"
|
150
|
+
f.write " file_111: ':create_file'\n"
|
151
|
+
f.write " dir_12:\n"
|
152
|
+
f.write " dir_121: {}\n"
|
153
|
+
end
|
154
|
+
|
155
|
+
Thor::Tree.new(tree_yaml).write
|
156
|
+
end
|
157
|
+
|
158
|
+
after do
|
159
|
+
tmp_dir.rm_rf
|
160
|
+
end
|
161
|
+
|
162
|
+
it "creates the directory tree" do
|
163
|
+
root = tmp_dir / 'dir_1'
|
164
|
+
expect(root).to exist
|
165
|
+
expect(root.children).to eq([root/'dir_11', root/'dir_12'])
|
166
|
+
expect((root/'dir_11').children).to eq([root/'dir_11'/'file_111'])
|
167
|
+
expect((root/'dir_12').children).to eq([root/'dir_12'/'dir_121'])
|
168
|
+
expect(root / 'dir_12' / 'dir_121').to be_a_directory
|
169
|
+
expect(root / 'dir_11' / 'file_111').to be_a_file
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
context "example.yml" do
|
175
|
+
let(:output) do
|
176
|
+
{
|
177
|
+
files_to_create: {
|
178
|
+
'fa0' => 'fa0 content',
|
179
|
+
'fa1' => '',
|
180
|
+
'da1/fb0' => '',
|
181
|
+
},
|
182
|
+
files_to_copy: {
|
183
|
+
'fa2' => 'fa2 content',
|
184
|
+
'fa3' => 'fa3 content',
|
185
|
+
'da1/fb1' => 'fb1 content',
|
186
|
+
'da1/db0/fc0' => 'fc0 content',
|
187
|
+
},
|
188
|
+
files_to_template: {
|
189
|
+
'fa4' => 'fa4 content',
|
190
|
+
'fa5' => 'fa5 content',
|
191
|
+
'da1/fb2' => 'fb2 content',
|
192
|
+
'da1/db0/fc1' => 'fc1 content',
|
193
|
+
},
|
194
|
+
directories: {
|
195
|
+
'da0' => [],
|
196
|
+
'da1' => ['fb0', 'db0'],
|
197
|
+
'da1/db0' => ['dc0'],
|
198
|
+
'da1/db0/dc0' => [],
|
199
|
+
}
|
200
|
+
}
|
201
|
+
end
|
202
|
+
|
203
|
+
let(:directories) { output[:directories].keys }
|
204
|
+
let(:files_to_create) { output[:files_to_create].keys }
|
205
|
+
let(:files_to_copy) { output[:files_to_copy].keys }
|
206
|
+
let(:files_to_template) { output[:files_to_template].keys }
|
207
|
+
|
208
|
+
before do
|
209
|
+
(Path.dir / '..' / 'sandbox').rm_rf
|
210
|
+
|
211
|
+
template_variables = Hash.new.tap do |h|
|
212
|
+
h['@fa4_content'] = 'fa4 content'
|
213
|
+
h['@fa5_content'] = 'fa5 content'
|
214
|
+
h['@fb2_content'] = 'fb2 content'
|
215
|
+
h['@fc1_content'] = 'fc1 content'
|
216
|
+
end
|
217
|
+
|
218
|
+
example_yaml = Path.dir / '..' / 'fixtures' / 'example.yml'
|
219
|
+
|
220
|
+
Thor::Tree.new(example_yaml).tap do |tree|
|
221
|
+
template_variables.each do |key, value|
|
222
|
+
tree.set_template_variable key, value
|
223
|
+
end
|
224
|
+
end.write
|
225
|
+
end
|
226
|
+
|
227
|
+
it "creates the tree" do
|
228
|
+
files_to_create.each do |file|
|
229
|
+
(Path.dir / '..' / 'sandbox' / file).should exist
|
230
|
+
end
|
231
|
+
|
232
|
+
files_to_create.each do |file|
|
233
|
+
File.read(Path.dir / '..' / 'sandbox' / file).strip.should == output[:files_to_create][file]
|
234
|
+
end
|
235
|
+
|
236
|
+
files_to_copy.each do |file|
|
237
|
+
File.read(Path.dir / '..' / 'sandbox' / file).strip.should == output[:files_to_copy][file]
|
238
|
+
end
|
239
|
+
|
240
|
+
files_to_template.each do |file|
|
241
|
+
File.read(Path.dir / '..' / 'sandbox' / file).strip.should == output[:files_to_template][file]
|
242
|
+
end
|
243
|
+
|
244
|
+
directories.each do |dir|
|
245
|
+
(Path.dir / '..' / 'sandbox' / dir).should exist
|
246
|
+
end
|
247
|
+
|
248
|
+
directories.each do |dir|
|
249
|
+
(Path.dir / '..' / 'sandbox' / dir).children(false).map { |c| c.to_s }.tap do |subdirs|
|
250
|
+
output[:directories][dir].each do |sub|
|
251
|
+
subdirs.should include sub
|
252
|
+
end
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
data/thor-tree.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'thor/tree/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'thor-tree'
|
8
|
+
gem.version = Thor::Tree::VERSION
|
9
|
+
gem.authors = ['ikezue']
|
10
|
+
gem.email = ['ikezue@gmail.com']
|
11
|
+
gem.description = %q{A thor extension for generating directory structures from file trees defined in YAML}
|
12
|
+
gem.summary = gem.description
|
13
|
+
gem.homepage = 'https://github.com/ikezue/thor-tree'
|
14
|
+
gem.license = 'MIT'
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
|
+
gem.require_paths = ['lib']
|
20
|
+
|
21
|
+
gem.add_dependency 'path', '~> 1.3.1'
|
22
|
+
gem.add_dependency 'safe_yaml', '~> 0.9.4'
|
23
|
+
gem.add_dependency 'thor', '~> 0.18.1'
|
24
|
+
gem.add_development_dependency 'bundler', '~> 1.5.2'
|
25
|
+
gem.add_development_dependency 'rake', '~> 10.1.0'
|
26
|
+
gem.add_development_dependency 'rspec', '~> 2.14.1'
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: thor-tree
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ikezue
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: path
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.3.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.3.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: safe_yaml
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.9.4
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.18.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.18.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.5.2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.5.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 10.1.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 10.1.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.14.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.14.1
|
97
|
+
description: A thor extension for generating directory structures from file trees
|
98
|
+
defined in YAML
|
99
|
+
email:
|
100
|
+
- ikezue@gmail.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".ruby-version"
|
108
|
+
- Gemfile
|
109
|
+
- LICENSE
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- lib/core_ext/hash.rb
|
113
|
+
- lib/thor/tree.rb
|
114
|
+
- lib/thor/tree/directory.rb
|
115
|
+
- lib/thor/tree/file.rb
|
116
|
+
- lib/thor/tree/version.rb
|
117
|
+
- lib/thor/tree/writer.rb
|
118
|
+
- spec/fixtures/example.yml
|
119
|
+
- spec/fixtures/templates/d0/fa2
|
120
|
+
- spec/fixtures/templates/d0/fa4
|
121
|
+
- spec/fixtures/templates/d0/fb1
|
122
|
+
- spec/fixtures/templates/d0/fb2
|
123
|
+
- spec/fixtures/templates/fa3
|
124
|
+
- spec/fixtures/templates/fa5
|
125
|
+
- spec/fixtures/templates/fc0
|
126
|
+
- spec/fixtures/templates/fc1
|
127
|
+
- spec/spec_helper.rb
|
128
|
+
- spec/thor/tree_spec.rb
|
129
|
+
- thor-tree.gemspec
|
130
|
+
homepage: https://github.com/ikezue/thor-tree
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata: {}
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 2.2.1
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: A thor extension for generating directory structures from file trees defined
|
154
|
+
in YAML
|
155
|
+
test_files:
|
156
|
+
- spec/fixtures/example.yml
|
157
|
+
- spec/fixtures/templates/d0/fa2
|
158
|
+
- spec/fixtures/templates/d0/fa4
|
159
|
+
- spec/fixtures/templates/d0/fb1
|
160
|
+
- spec/fixtures/templates/d0/fb2
|
161
|
+
- spec/fixtures/templates/fa3
|
162
|
+
- spec/fixtures/templates/fa5
|
163
|
+
- spec/fixtures/templates/fc0
|
164
|
+
- spec/fixtures/templates/fc1
|
165
|
+
- spec/spec_helper.rb
|
166
|
+
- spec/thor/tree_spec.rb
|