diff --git a/lib/motion/project/app.rb b/lib/motion/project/app.rb index 05e90766..0cf9c895 100644 --- a/lib/motion/project/app.rb +++ b/lib/motion/project/app.rb @@ -71,7 +71,16 @@ def builder end def setup(&block) - config.setup_blocks << block + config_without_setup.setup_blocks << block + config + end + + def pre_setup(&block) + config_without_setup.pre_setup_blocks << block + end + + def post_setup(&block) + config_without_setup.post_setup_blocks << block end def build(platform, opts={}) diff --git a/lib/motion/project/config.rb b/lib/motion/project/config.rb index fb6297a5..2bba78bf 100644 --- a/lib/motion/project/config.rb +++ b/lib/motion/project/config.rb @@ -78,7 +78,8 @@ def self.make(template, project_dir, build_mode) def initialize(project_dir, build_mode) @project_dir = project_dir - @files = Dir.glob(File.join(project_dir, 'app/**/*.rb')) + @files = [] + @app_dir = 'app' @build_mode = build_mode @name = 'Untitled' @resources_dirs = [File.join(project_dir, 'resources')] @@ -106,16 +107,51 @@ def variables map end + def pre_setup_blocks + @pre_setup_blocks ||= [] + end + def setup_blocks @setup_blocks ||= [] end + def post_setup_blocks + @post_setup_blocks ||= [] + end + def setup + should_validate = false + + if @pre_setup_blocks + @pre_setup_blocks.each { |b| b.call(self) } + should_validate = true + @pre_setup_blocks = nil + end + + if @app_dir + Dir.glob(File.join(project_dir, "#{@app_dir}/**/*.rb")).each do |app_file| + @files << app_file unless @files.include?(app_file) + end + should_validate = true + @app_dir = nil + end + if @setup_blocks @setup_blocks.each { |b| b.call(self) } + should_validate = true @setup_blocks = nil + end + + if @post_setup_blocks + @post_setup_blocks.each { |b| b.call(self) } + should_validate = true + @post_setup_blocks = nil + end + + if should_validate validate end + self end