anvil-core 0.2.0 → 0.3.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.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/VERSION +1 -1
- data/lib/anvil/bundler.rb +1 -1
- data/lib/anvil/cli.rb +3 -3
- data/lib/anvil/config.rb +2 -5
- data/lib/anvil/config/class_methods.rb +1 -1
- data/lib/anvil/extensions_manager.rb +114 -0
- data/lib/anvil/task/projects.rb +15 -0
- data/lib/config_extensions/core.rb +8 -0
- data/lib/tasks/projects/add_task.rb +1 -0
- data/spec/lib/anvil/{task_manager_spec.rb → extensions_manager_spec.rb} +23 -22
- data/spec/lib/anvil/task/projects_spec.rb +11 -0
- metadata +6 -5
- data/lib/anvil/task_manager.rb +0 -77
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6c16dfa2cd3d0c90a22a516bf1b13460181c7cf
|
4
|
+
data.tar.gz: af1c0ea76f8e8085021494cad7bb388ece2f12a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8f17c066f653dc6b4129a8c2ba29f6c73f758bb1923356c5224113b5d9147a727be611973e573b15b57b68c6243d09cb3a73a5a778761bca381c569db590f7e
|
7
|
+
data.tar.gz: 8f5c3e91887ef1dbd0125e8afbfcda7804f3a06b8d5beee3d5f52cf3b86a685dedeb972e105cf3902b6ebfa9381c883923fe1f54b2787f7cf2ccb42668b8e685
|
data/README.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/anvil/bundler.rb
CHANGED
data/lib/anvil/cli.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
|
-
require 'anvil/
|
3
|
+
require 'anvil/extensions_manager'
|
4
4
|
require 'tasks/help_task'
|
5
5
|
|
6
6
|
module Anvil
|
@@ -27,7 +27,7 @@ HELP
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def load_tasks
|
30
|
-
Anvil::
|
30
|
+
Anvil::ExtensionsManager.load_tasks
|
31
31
|
end
|
32
32
|
|
33
33
|
# Builds a task and prepares it to run
|
@@ -59,7 +59,7 @@ HELP
|
|
59
59
|
|
60
60
|
def print_help
|
61
61
|
printf('%s', HELP)
|
62
|
-
tasks = Anvil::
|
62
|
+
tasks = Anvil::ExtensionsManager.tasks_by_name
|
63
63
|
tasks.each { |task| print_task_line(task) }
|
64
64
|
end
|
65
65
|
|
data/lib/anvil/config.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'mixlib/config'
|
4
4
|
require 'anvil/config/class_methods'
|
5
|
+
require 'anvil/extensions_manager'
|
5
6
|
require 'gem_ext/mixlib'
|
6
7
|
|
7
8
|
module Anvil
|
@@ -9,10 +10,6 @@ module Anvil
|
|
9
10
|
module Config
|
10
11
|
extend Mixlib::Config
|
11
12
|
extend Anvil::Config::ClassMethods
|
12
|
-
|
13
|
-
config_context :github do
|
14
|
-
configurable :user
|
15
|
-
configurable :token
|
16
|
-
end
|
17
13
|
end
|
18
14
|
end
|
15
|
+
Anvil::ExtensionsManager.load_config_extensions
|
@@ -33,7 +33,7 @@ module Anvil
|
|
33
33
|
FileUtils.mkdir_p(base_path)
|
34
34
|
FileUtils.mkdir_p(base_tasks_path)
|
35
35
|
FileUtils.mkdir_p(base_projects_path)
|
36
|
-
FileUtils.touch(base_config_path) unless File.
|
36
|
+
FileUtils.touch(base_config_path) unless File.exist?(base_config_path)
|
37
37
|
end
|
38
38
|
|
39
39
|
def init_config
|
@@ -0,0 +1,114 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'anvil/task'
|
5
|
+
require 'rugged'
|
6
|
+
|
7
|
+
module Anvil
|
8
|
+
# Manage loading and finding anvil tasks
|
9
|
+
class ExtensionsManager
|
10
|
+
PATTERNS = {
|
11
|
+
tasks: '/tasks/**/*_task.rb',
|
12
|
+
config_extensions: '/config_extensions/**/*.rb'
|
13
|
+
}
|
14
|
+
@tasks_loaded = false
|
15
|
+
|
16
|
+
class << self
|
17
|
+
attr_accessor :tasks_loaded
|
18
|
+
|
19
|
+
def tasks_by_name
|
20
|
+
new.tasks_by_name
|
21
|
+
end
|
22
|
+
|
23
|
+
def load_tasks
|
24
|
+
new.load_tasks
|
25
|
+
end
|
26
|
+
|
27
|
+
def load_config_extensions
|
28
|
+
new.load_config_extensions
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def tasks_by_name
|
33
|
+
all_tasks.sort_by { |t| t.name }
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [Array] all known {Anvil::Task} desdendants
|
37
|
+
def all_tasks
|
38
|
+
load_tasks unless self.class.tasks_loaded
|
39
|
+
::Anvil::Task.descendants
|
40
|
+
end
|
41
|
+
|
42
|
+
# Loads all known anvil tasks
|
43
|
+
def load_tasks
|
44
|
+
all_files_for(:tasks).each { |file| load(file) }
|
45
|
+
self.class.tasks_loaded = true
|
46
|
+
end
|
47
|
+
|
48
|
+
def load_config_extensions
|
49
|
+
all_files_for(:config_extensions).each { |file| load(file) }
|
50
|
+
end
|
51
|
+
|
52
|
+
# @param extension_type [Symbol] either :tasks or :config.
|
53
|
+
# @see {Anvil::ExtensionsManager::PATTERNS}
|
54
|
+
# @return [Array] all known anvil files for a given extension type
|
55
|
+
def all_files_for(extension_type)
|
56
|
+
[files_from_env(extension_type),
|
57
|
+
files_from_anvil(extension_type),
|
58
|
+
files_from_current_project(extension_type),
|
59
|
+
files_from_gems(extension_type)
|
60
|
+
].compact.reduce(&:+).uniq
|
61
|
+
end
|
62
|
+
|
63
|
+
# @param extension_type [Symbol] either :tasks or :config.
|
64
|
+
# @see {Anvil::ExtensionsManager::PATTERNS}
|
65
|
+
# @return [Array] all the core anvil extensions
|
66
|
+
def files_from_anvil(extension_type)
|
67
|
+
files_from_path(File.expand_path('../..', __FILE__), extension_type)
|
68
|
+
end
|
69
|
+
|
70
|
+
# @param extension_type [Symbol] either :tasks or :config.
|
71
|
+
# @see {Anvil::ExtensionsManager::PATTERNS}
|
72
|
+
# @return [Array] all possible anvil extensions
|
73
|
+
def files_from_current_project(pattern)
|
74
|
+
path = current_project_path + '/lib/anvil/'
|
75
|
+
files_from_path(path, pattern)
|
76
|
+
end
|
77
|
+
|
78
|
+
# @param extension_type [Symbol] either :tasks or :config.
|
79
|
+
# @see {Anvil::ExtensionsManager::PATTERNS}
|
80
|
+
# @return [Array] anvil extensions installed in gems
|
81
|
+
def files_from_gems(pattern)
|
82
|
+
Gem.find_latest_files "anvil#{PATTERNS[pattern]}"
|
83
|
+
end
|
84
|
+
|
85
|
+
# @param extension_type [Symbol] either :tasks or :config.
|
86
|
+
# @see {Anvil::ExtensionsManager::PATTERNS}
|
87
|
+
# @return [Array] anvil tasks in the specified dir
|
88
|
+
def files_from_env(pattern)
|
89
|
+
if ENV['ANVIL_EXTENSIONS_DIR']
|
90
|
+
env_dir_list = ENV['ANVIL_EXTENSIONS_DIR'].split(':').join(',')
|
91
|
+
|
92
|
+
Dir["{#{env_dir_list}}#{PATTERNS[pattern]}"]
|
93
|
+
else
|
94
|
+
[]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
protected
|
99
|
+
|
100
|
+
# @return [String] top level dir if this is a git managed project
|
101
|
+
def current_project_path
|
102
|
+
Rugged::Repository.discover(Dir.pwd).gsub('.git/', '')
|
103
|
+
rescue Rugged::RepositoryError
|
104
|
+
''
|
105
|
+
end
|
106
|
+
|
107
|
+
# @param path [String] a path to glob their anvil tasks
|
108
|
+
# @param pattern [Symbol] the pattern to load files
|
109
|
+
# @return [Array] all anvil tasks in the given path
|
110
|
+
def files_from_path(path, pattern)
|
111
|
+
Dir["#{path}#{PATTERNS[pattern]}"]
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
data/lib/anvil/task/projects.rb
CHANGED
@@ -9,16 +9,31 @@ module Anvil
|
|
9
9
|
|
10
10
|
def change_project(project)
|
11
11
|
Dir.chdir(project_path(project))
|
12
|
+
rescue Errno::ENOENT
|
13
|
+
log_project_does_not_exists project
|
12
14
|
end
|
13
15
|
|
14
16
|
def on_project(project)
|
15
17
|
Dir.chdir(project_path(project)) do
|
16
18
|
yield(git)
|
17
19
|
end
|
20
|
+
rescue Errno::ENOENT
|
21
|
+
log_project_does_not_exists project
|
22
|
+
end
|
23
|
+
|
24
|
+
def on_each_project(projects)
|
25
|
+
projects.each do |project|
|
26
|
+
on_project(project) { |project_git| yield project, project_git }
|
27
|
+
end
|
18
28
|
end
|
19
29
|
|
20
30
|
protected
|
21
31
|
|
32
|
+
def log_project_does_not_exists(project)
|
33
|
+
logger.info "Anvil knows nothing about #{project}."
|
34
|
+
logger.info 'Please, check anvil help projects:add first to add the project to anvil.'
|
35
|
+
end
|
36
|
+
|
22
37
|
def git
|
23
38
|
Git.open(Dir.pwd)
|
24
39
|
end
|
@@ -1,27 +1,27 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'anvil/
|
2
|
+
require 'anvil/extensions_manager'
|
3
3
|
|
4
|
-
describe Anvil::
|
5
|
-
describe '
|
4
|
+
describe Anvil::ExtensionsManager do
|
5
|
+
describe '#all_tasks' do
|
6
6
|
it 'returns the Anvil::Task descendants' do
|
7
7
|
expect(::Anvil::Task).to receive(:descendants)
|
8
|
-
|
8
|
+
subject.all_tasks
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
describe '
|
13
|
-
let(:gemfile_path) {
|
12
|
+
describe '#files_from_current_project' do
|
13
|
+
let(:gemfile_path) { subject.send :current_project_path }
|
14
14
|
let(:project_task_path) { gemfile_path + '/lib/anvil/' }
|
15
15
|
|
16
16
|
it 'returns the task files in the path' do
|
17
|
-
expect(
|
18
|
-
.to receive(:files_from_path).with(project_task_path)
|
17
|
+
expect(subject)
|
18
|
+
.to receive(:files_from_path).with(project_task_path, :tasks)
|
19
19
|
|
20
|
-
|
20
|
+
subject.files_from_current_project(:tasks)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
describe '
|
24
|
+
describe 'current_project_path' do
|
25
25
|
let(:pwd) { '/home/user/src/project/' }
|
26
26
|
context 'on a path managed by git' do
|
27
27
|
before do
|
@@ -30,7 +30,7 @@ describe Anvil::TaskManager do
|
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'returns the repo workdir' do
|
33
|
-
expect(
|
33
|
+
expect(subject.send(:current_project_path))
|
34
34
|
.to eq(pwd)
|
35
35
|
end
|
36
36
|
end
|
@@ -42,39 +42,40 @@ describe Anvil::TaskManager do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'returns an empty string' do
|
45
|
-
expect(
|
45
|
+
expect(subject.send(:current_project_path))
|
46
46
|
.to be_empty
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
describe '
|
51
|
+
describe '#files_from_gems' do
|
52
52
|
it 'asks Gem to return the anvil tasks' do
|
53
|
-
expect(Gem)
|
54
|
-
|
53
|
+
expect(Gem)
|
54
|
+
.to receive(:find_latest_files).with('anvil/tasks/**/*_task.rb')
|
55
|
+
subject.files_from_gems(:tasks)
|
55
56
|
end
|
56
57
|
end
|
57
58
|
|
58
|
-
describe '
|
59
|
+
describe '#files_from_env' do
|
59
60
|
context 'with empty env variable' do
|
60
61
|
it 'returns an empty array' do
|
61
|
-
expect(
|
62
|
+
expect(subject.files_from_env(:tasks)).to eq([])
|
62
63
|
end
|
63
64
|
end
|
64
65
|
end
|
65
66
|
|
66
|
-
describe '
|
67
|
+
describe '#load_tasks' do
|
67
68
|
let(:all_files) { %w[file1 file2] }
|
68
69
|
|
69
70
|
before do
|
70
|
-
|
71
|
+
allow(subject).to receive(:all_files_for).and_return(all_files)
|
71
72
|
end
|
72
73
|
|
73
74
|
it 'loads the files' do
|
74
|
-
expect(
|
75
|
-
expect(
|
75
|
+
expect(subject).to receive(:load).with(all_files[0])
|
76
|
+
expect(subject).to receive(:load).with(all_files[1])
|
76
77
|
|
77
|
-
|
78
|
+
subject.load_tasks
|
78
79
|
end
|
79
80
|
end
|
80
81
|
end
|
@@ -45,4 +45,15 @@ describe Anvil::Task::Projects, fakefs: true do
|
|
45
45
|
expect { |b| subject.on_project(project, &b) }.to yield_with_args
|
46
46
|
end
|
47
47
|
end
|
48
|
+
|
49
|
+
describe '#on_each_project' do
|
50
|
+
let(:projects) { %w(anvil-core anvil-plugins) }
|
51
|
+
before do
|
52
|
+
expect(subject).to receive(:on_project).twice.and_yield(double('git'))
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'works on each project' do
|
56
|
+
expect { |b| subject.on_each_project(projects, &b) }.to yield_control.twice
|
57
|
+
end
|
58
|
+
end
|
48
59
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anvil-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fran Casas
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-06-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: git
|
@@ -174,6 +174,7 @@ files:
|
|
174
174
|
- lib/anvil/cli.rb
|
175
175
|
- lib/anvil/config.rb
|
176
176
|
- lib/anvil/config/class_methods.rb
|
177
|
+
- lib/anvil/extensions_manager.rb
|
177
178
|
- lib/anvil/parser.rb
|
178
179
|
- lib/anvil/rubygems.rb
|
179
180
|
- lib/anvil/task.rb
|
@@ -182,9 +183,9 @@ files:
|
|
182
183
|
- lib/anvil/task/options.rb
|
183
184
|
- lib/anvil/task/projects.rb
|
184
185
|
- lib/anvil/task/repositories.rb
|
185
|
-
- lib/anvil/task_manager.rb
|
186
186
|
- lib/anvil/version.rb
|
187
187
|
- lib/anvil/versioner.rb
|
188
|
+
- lib/config_extensions/core.rb
|
188
189
|
- lib/gem_ext/mixlib.rb
|
189
190
|
- lib/tasks/gem/build_task.rb
|
190
191
|
- lib/tasks/gem/bump_task.rb
|
@@ -197,11 +198,11 @@ files:
|
|
197
198
|
- spec/lib/anvil/assures/file_assure_spec.rb
|
198
199
|
- spec/lib/anvil/cli_spec.rb
|
199
200
|
- spec/lib/anvil/config_spec.rb
|
201
|
+
- spec/lib/anvil/extensions_manager_spec.rb
|
200
202
|
- spec/lib/anvil/parser_spec.rb
|
201
203
|
- spec/lib/anvil/task/naming_spec.rb
|
202
204
|
- spec/lib/anvil/task/options_spec.rb
|
203
205
|
- spec/lib/anvil/task/projects_spec.rb
|
204
|
-
- spec/lib/anvil/task_manager_spec.rb
|
205
206
|
- spec/lib/anvil/task_spec.rb
|
206
207
|
- spec/lib/anvil/versioner_spec.rb
|
207
208
|
- spec/lib/tasks/gem/build_task_spec.rb
|
@@ -250,11 +251,11 @@ test_files:
|
|
250
251
|
- spec/lib/anvil/assures/file_assure_spec.rb
|
251
252
|
- spec/lib/anvil/cli_spec.rb
|
252
253
|
- spec/lib/anvil/config_spec.rb
|
254
|
+
- spec/lib/anvil/extensions_manager_spec.rb
|
253
255
|
- spec/lib/anvil/parser_spec.rb
|
254
256
|
- spec/lib/anvil/task/naming_spec.rb
|
255
257
|
- spec/lib/anvil/task/options_spec.rb
|
256
258
|
- spec/lib/anvil/task/projects_spec.rb
|
257
|
-
- spec/lib/anvil/task_manager_spec.rb
|
258
259
|
- spec/lib/anvil/task_spec.rb
|
259
260
|
- spec/lib/anvil/versioner_spec.rb
|
260
261
|
- spec/lib/tasks/gem/build_task_spec.rb
|
data/lib/anvil/task_manager.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
require 'anvil/config'
|
5
|
-
require 'anvil/task'
|
6
|
-
require 'rugged'
|
7
|
-
|
8
|
-
module Anvil
|
9
|
-
# Manage loading and finding anvil tasks
|
10
|
-
module TaskManager
|
11
|
-
@tasks_loaded = false
|
12
|
-
|
13
|
-
# Loads all known anvil tasks
|
14
|
-
def self.load_tasks
|
15
|
-
all_files.each { |file| load(file) }
|
16
|
-
@tasks_loaded = true
|
17
|
-
end
|
18
|
-
|
19
|
-
# @return [Array] all the core anvil tasks
|
20
|
-
def self.files_from_anvil
|
21
|
-
files_from_path(File.expand_path('../..', __FILE__))
|
22
|
-
end
|
23
|
-
|
24
|
-
# @return [Array] all possible anvil tasks in this project
|
25
|
-
def self.files_from_current_project
|
26
|
-
path = current_project_path + '/lib/anvil/'
|
27
|
-
files_from_path(path)
|
28
|
-
end
|
29
|
-
|
30
|
-
# @return [String] top level dir if this is a git managed project
|
31
|
-
def self.current_project_path
|
32
|
-
Rugged::Repository.discover(Dir.pwd).gsub('.git/', '')
|
33
|
-
rescue Rugged::RepositoryError
|
34
|
-
''
|
35
|
-
end
|
36
|
-
|
37
|
-
# @param path [String] a path to glob their anvil tasks
|
38
|
-
# @return [Array] all anvil tasks in the given path
|
39
|
-
def self.files_from_path(path)
|
40
|
-
Dir[path + '/tasks/**/*_task.rb']
|
41
|
-
end
|
42
|
-
|
43
|
-
# @return [Array] anvil tasks installed in gems
|
44
|
-
def self.files_from_gems
|
45
|
-
Gem.find_latest_files 'anvil/tasks/**/*_task.rb'
|
46
|
-
end
|
47
|
-
|
48
|
-
# @return [Array] anvil tasks in the specified dir
|
49
|
-
def self.files_from_env
|
50
|
-
if ENV['ANVIL_TASKS_DIR']
|
51
|
-
env_dir_list = ENV['ANVIL_TASKS_DIR'].split(':').join(',')
|
52
|
-
|
53
|
-
Dir["{#{env_dir_list}}/*_task.rb"]
|
54
|
-
else
|
55
|
-
[]
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# @return [Array] all known anvil task files
|
60
|
-
def self.all_files
|
61
|
-
[files_from_env,
|
62
|
-
files_from_anvil,
|
63
|
-
files_from_current_project,
|
64
|
-
files_from_gems].compact.reduce(&:+).uniq
|
65
|
-
end
|
66
|
-
|
67
|
-
# @return [Array] all known {Anvil::Task} desdendants
|
68
|
-
def self.all_tasks
|
69
|
-
load_tasks unless @tasks_loaded
|
70
|
-
::Anvil::Task.descendants
|
71
|
-
end
|
72
|
-
|
73
|
-
def self.tasks_by_name
|
74
|
-
all_tasks.sort_by { |t| t.name }
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|