This repository has been archived by the owner on Apr 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use TaskEnv to pass around data to tasks, add config.require support.
We want the graph to be lazily loaded, so I've added TaskEnv, a monad style class that encapsulates the loading of the config, graph and other things. This is the only object we pass to tasks other than the options, so they can use this to get the graph and config. In addition, the first config option called "require" has been added. This is a config option that takes a list of files, folders or shell-globs that should be required when Shanty is loaded. This is used to load custom build-scripts or project types from within a repo that aren't proper packaged plugins or the like. Tasks have been renamed to TaskSets to better distinguish the difference between the classes that have tasks in them, and the tasks themselves. Finally, I have upgraded the Ruby version on Travis to 2.2.
- Loading branch information
1 parent
bdf32b6
commit 6419458
Showing
9 changed files
with
160 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.DS_Store | ||
*.gem | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
language: ruby | ||
rvm: | ||
- 2.1.4 | ||
- 2.2.0 | ||
notifications: | ||
webhooks: https://hubot-shantytown.rhcloud.com/hubot/travis?room=#shantytow n | ||
script: bundle exec ./bin/shanty --trace test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
require 'deep_merge' | ||
require 'yaml' | ||
|
||
module Shanty | ||
# | ||
class TaskEnv | ||
CONFIG_FILE = '.shanty.yml' | ||
DEFAULT_CONFIG = {} | ||
|
||
def load! | ||
(config['require'] || {}).each do |requirement| | ||
requirement = "#{requirement}/**/*.rb" unless requirement.include?('.rb') | ||
Dir[requirement].each { |f| require f } | ||
end | ||
end | ||
|
||
def graph | ||
@graph ||= construct_project_graph | ||
end | ||
|
||
private | ||
|
||
def environment | ||
@environment = ENV['SHANTY_ENV'] || 'local' | ||
end | ||
|
||
def root | ||
@root ||= find_root | ||
end | ||
|
||
def config | ||
return @config unless @config.nil? | ||
|
||
file_config = YAML.load_file("#{root}/#{CONFIG_FILE}") || {} | ||
@config = DEFAULT_CONFIG.deep_merge!(file_config[environment]) | ||
end | ||
|
||
def find_root | ||
if root_dir.nil? | ||
fail "Could not find a #{CONFIG_FILE} file in this or any parent directories. \ | ||
Please run `shanty init` in the directory you want to be the root of your project structure." | ||
end | ||
|
||
root_dir | ||
end | ||
|
||
def root_dir | ||
Pathname.new(Dir.pwd).ascend do |d| | ||
return d if d.join(CONFIG_FILE).exist? | ||
end | ||
end | ||
|
||
def construct_project_graph | ||
project_templates = Dir.chdir(root) do | ||
Discoverer.new.discover_all | ||
end | ||
|
||
projects = project_templates.map do |project_template| | ||
project_template.type.new(project_template) | ||
end | ||
|
||
graph = Graph.new(projects) | ||
|
||
Mutator.new.apply_mutations(graph) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module Shanty | ||
# Public: Discover shanty tasks | ||
class TaskSet | ||
class << self | ||
attr_reader :task_sets, :tasks, :partial_task | ||
end | ||
|
||
# This method is auto-triggered by Ruby whenever a class inherits from | ||
# Shanty::TaskSet. This means we can build up a list of all the tasks | ||
# without requiring them to register with us - neat! | ||
def self.inherited(task_set) | ||
@task_sets ||= [] | ||
@task_sets << task_set | ||
end | ||
|
||
def self.desc(desc) | ||
partial_task[:desc] = desc | ||
end | ||
|
||
def self.param(name, options = {}) | ||
partial_task[:params][name] = options | ||
end | ||
|
||
def self.option(name, options = {}) | ||
partial_task[:options][name] = options | ||
end | ||
|
||
def self.method_added(name) | ||
@tasks ||= {} | ||
@tasks[name] = partial_task.merge(klass: self) | ||
|
||
# Now reset the task definition. | ||
@partial_task = {} | ||
end | ||
|
||
def self.partial_task | ||
@partial_task ||= {} | ||
@partial_task[:params] ||= {} | ||
@partial_task[:options] ||= {} | ||
|
||
@partial_task | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters