class JsProjectBuilder

Attributes

description[R]
dist_file_name[R]
dist_file_path[R]
dist_min_file_path[R]
dist_pack_file_path[R]
js_files[R]
name[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/js_project_builder.rb, line 8
def initialize(options = {})
  @options = {
    :dist_dir => 'dist',
    :src_dir => 'src',
    :sass => false,
    :sass_dir => 'src/sass',
    :license_file => 'license.txt',
    :version_file_path => 'version.yml'
  }.update(options)

  @name = @options[:name]
  @description = @options[:description]
  @dist_file_name = @options[:file_name]
  @dist_file_path = File.join(dist_dir, dist_file_name)
  @dist_min_file_path = @dist_file_path.ext('min.js')
  @dist_pack_file_path = @dist_file_path.ext('pack.js')
  @js_files = @options[:js_files].collect{|name| File.join(self.src_dir, name)}

  @version_yml = YAML::load(File.open(@options[:version_file_path]))
end

Public Instance Methods

build_number() click to toggle source
# File lib/js_project_builder.rb, line 53
def build_number
  @version_yml['build_number']
end
bump_build_number() click to toggle source
# File lib/js_project_builder.rb, line 69
def bump_build_number
  @version_yml['build_number'] += 1
  @version_yml['built_at'] = Time.now.strftime('%a %m %b %Y %H:%M:%S')
  write_version_file
  build_number
end
bump_version(type) click to toggle source
# File lib/js_project_builder.rb, line 57
def bump_version(type)
  index = {:major => 0, :minor => 1, :patch => 2}[type]

  arr = version.split('.').collect{|s| s.to_i }
  arr[index]+=1
  @version_yml['version'] = arr.join('.')
  
  write_version_file
  
  version
end
dist_dir() click to toggle source
# File lib/js_project_builder.rb, line 33
def dist_dir
  @options[:dist_dir]
end
join_files(target_file, files, include_license_file = true) click to toggle source

join given files into single target file. if include_license_file is true (by default) then license file will be added to the head of the target file

# File lib/js_project_builder.rb, line 78
def join_files(target_file, files, include_license_file = true)
  files.insert(0, license_file) if include_license_file

  existing_files = files.existing
  if existing_files.length != files.length
    raise "ERROR: The following files are missing: \n#{files.select{|f| !existing_files.include?(f) }.join("\n")}"
  end

  File.open(target_file, 'w') do |f|
    files.each do |fname|
      f.puts File.read(fname)
    end
  end
end
license_file() click to toggle source
# File lib/js_project_builder.rb, line 45
def license_file
  @options[:license_file]
end
sass?() click to toggle source
# File lib/js_project_builder.rb, line 41
def sass?
  @options[:sass]
end
sass_dir() click to toggle source
# File lib/js_project_builder.rb, line 37
def sass_dir
  @options[:sass_dir]
end
src_dir() click to toggle source
# File lib/js_project_builder.rb, line 29
def src_dir
  @options[:src_dir]
end
version() click to toggle source
# File lib/js_project_builder.rb, line 49
def version
  @version_yml['version']
end

Private Instance Methods

write_version_file() click to toggle source
# File lib/js_project_builder.rb, line 95
def write_version_file
  File.open(@options[:version_file_path], 'w'){|f| f.write(@version_yml.to_yaml) }
end