Module: SC::Buildfile::Commands

Included in:
SC::Buildfile
Defined in:
lib/sproutcore/buildfile/buildfile_dsl.rb

Overview

Describe the domain-specific-language helpers supported by buildfiles. This is included as a mixin for the buildfile.

Instance Method Summary collapse

Instance Method Details

#build_task(*args, &block) ⇒ Object

Define a build task. A build task will not run if the destination file is newer than the source files.



47
48
49
# File 'lib/sproutcore/buildfile/buildfile_dsl.rb', line 47

def build_task(*args, &block)
  define_task(::SC::Buildfile::BuildTask, *args, &block)
end

#config(config_name, opts = {}) {|opts| ... } ⇒ Object

Register the passed configuration settings scoped to a target. Optional pass a block to edit the config.

Example:

config :all, :url_root => "static"
config :sproutcore do |c|
   c.url_root = "static"
end

Yields:

  • (opts)


134
135
136
137
138
139
# File 'lib/sproutcore/buildfile/buildfile_dsl.rb', line 134

def config(config_name, opts = {}, &block)
  opts = ::SC::HashStruct.new(opts)
  yield(opts) if block_given?
  add_config config_name, opts
  return self
end

#desc(description) ⇒ Object

Describe the next rake task.

Example:

desc "Run the Unit Tests"
task :test => [:build]
  runtests
end


93
94
95
# File 'lib/sproutcore/buildfile/buildfile_dsl.rb', line 93

def desc(description)
  last_description = description
end

#import(*args) ⇒ Object

Import the partial Rakefiles fn. Imported files are loaded after the current file is completely loaded. This allows the import statement to appear anywhere in the importing file, and yet allowing the imported files to depend on objects defined in the importing file.

A common use of the import statement is to include files containing dependency declarations.

Example:

import ".depend", "my_rules"


62
63
64
65
66
67
68
# File 'lib/sproutcore/buildfile/buildfile_dsl.rb', line 62

def import(*args)
  base_path = current_path.nil? ? nil : File.dirname(current_path)
  args.each do |fn| 
    fn = File.expand_path(fn, base_path)
    add_import(fn)
  end
end

#mode(build_mode, &block) ⇒ Object

Scope any config statements inside the passed block to the named mode. Normally if you call a config statement outside of a mode block, it will scope to all modes.

Example: mode :debug do

config :all, :combine_javascript => NO


117
118
119
120
121
122
123
# File 'lib/sproutcore/buildfile/buildfile_dsl.rb', line 117

def mode(build_mode, &block)
  old_mode = current_mode
  self.current_mode = build_mode.to_sym
  yield if block_given?
  self.current_mode = old_mode
  return self
end

#namespace(name = nil, &block) ⇒ Object

Create a new rake namespace and use it for evaluating the given block. Returns a NameSpace object that can be used to lookup tasks defined in the namespace.

E.g.

ns = namespace "nested" do
  task :run
end
task_run = ns[:run] # find :run in the given namespace.


81
82
83
# File 'lib/sproutcore/buildfile/buildfile_dsl.rb', line 81

def namespace(name=nil, &block)
  in_namespace(name, &block)
end

#project(name = nil, type = nil) ⇒ Object

Register info about this buildfile as a project



151
152
153
154
155
# File 'lib/sproutcore/buildfile/buildfile_dsl.rb', line 151

def project(name=nil, type=nil)
  self.project_name = name.nil? ? :default : name.to_sym
  self.project_type = type.nil? ? :default : type.to_sym
  self.project!
end

#proxy(proxy_path, opts = {}) ⇒ Object

Register a proxy setting

Example:

proxy '/url', :to => 'localhost:3000'


146
147
148
# File 'lib/sproutcore/buildfile/buildfile_dsl.rb', line 146

def proxy(proxy_path, opts={})
  add_proxy proxy_path, opts
end

#replace_task(*args, &block) ⇒ Object

Replace an existing task instead of enhancing it.

Example:

replace_task :clobber => :clean do
   rm_rf 'javascript'
end


34
35
36
37
38
39
40
41
42
# File 'lib/sproutcore/buildfile/buildfile_dsl.rb', line 34

def replace_task(*args, &block)
  @is_redefining = true
  begin
    define_task(::SC::Buildfile::Task, *args, &block)
  rescue Exception => e
    @is_redefining = false
    raise e
  end
end

#task(*args, &block) ⇒ Object

Declare a basic task.

Example:

task :clobber => [:clean] do
  rm_rf "html"
end


23
24
25
# File 'lib/sproutcore/buildfile/buildfile_dsl.rb', line 23

def task(*args, &block)
  define_task(::SC::Buildfile::Task, *args, &block)
end

#task_options(opts) ⇒ Object

Describe options on the next rake task.

Example:

options :log => :env|:name|:none
task :test => [:build]
  runtests
end


105
106
107
# File 'lib/sproutcore/buildfile/buildfile_dsl.rb', line 105

def task_options(opts)
  last_task_options = opts
end