Class: JsProjectBuilder
- Inherits:
-
Object
- Object
- JsProjectBuilder
- Defined in:
- lib/js_project_builder.rb,
lib/js_project_builder_tasks.rb
Defined Under Namespace
Classes: Tasks
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#dist_file_name ⇒ Object
readonly
Returns the value of attribute dist_file_name.
-
#dist_file_path ⇒ Object
readonly
Returns the value of attribute dist_file_path.
-
#dist_min_file_path ⇒ Object
readonly
Returns the value of attribute dist_min_file_path.
-
#dist_pack_file_path ⇒ Object
readonly
Returns the value of attribute dist_pack_file_path.
-
#js_files ⇒ Object
readonly
Returns the value of attribute js_files.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #build_number ⇒ Object
- #bump_build_number ⇒ Object
- #bump_version(type) ⇒ Object
- #dist_dir ⇒ Object
-
#initialize(options = {}) ⇒ JsProjectBuilder
constructor
A new instance of JsProjectBuilder.
-
#join_files(target_file, files, include_license_file = true) ⇒ Object
join given files into single target file.
- #license_file ⇒ Object
- #sass? ⇒ Boolean
- #sass_dir ⇒ Object
- #src_dir ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ JsProjectBuilder
Returns a new instance of JsProjectBuilder.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/js_project_builder.rb', line 8 def initialize( = {}) @options = { :dist_dir => 'dist', :src_dir => 'src', :sass => false, :sass_dir => 'src/sass', :license_file => 'license.txt', :version_file_path => 'version.yml' }.update() @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 |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
4 5 6 |
# File 'lib/js_project_builder.rb', line 4 def description @description end |
#dist_file_name ⇒ Object (readonly)
Returns the value of attribute dist_file_name.
4 5 6 |
# File 'lib/js_project_builder.rb', line 4 def dist_file_name @dist_file_name end |
#dist_file_path ⇒ Object (readonly)
Returns the value of attribute dist_file_path.
4 5 6 |
# File 'lib/js_project_builder.rb', line 4 def dist_file_path @dist_file_path end |
#dist_min_file_path ⇒ Object (readonly)
Returns the value of attribute dist_min_file_path.
4 5 6 |
# File 'lib/js_project_builder.rb', line 4 def dist_min_file_path @dist_min_file_path end |
#dist_pack_file_path ⇒ Object (readonly)
Returns the value of attribute dist_pack_file_path.
4 5 6 |
# File 'lib/js_project_builder.rb', line 4 def dist_pack_file_path @dist_pack_file_path end |
#js_files ⇒ Object (readonly)
Returns the value of attribute js_files.
4 5 6 |
# File 'lib/js_project_builder.rb', line 4 def js_files @js_files end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/js_project_builder.rb', line 4 def name @name end |
Instance Method Details
#build_number ⇒ Object
53 54 55 |
# File 'lib/js_project_builder.rb', line 53 def build_number @version_yml['build_number'] end |
#bump_build_number ⇒ Object
69 70 71 72 73 74 |
# 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) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# 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 ⇒ Object
33 34 35 |
# File 'lib/js_project_builder.rb', line 33 def dist_dir @options[:dist_dir] end |
#join_files(target_file, files, include_license_file = true) ⇒ Object
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
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# 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 ⇒ Object
45 46 47 |
# File 'lib/js_project_builder.rb', line 45 def license_file @options[:license_file] end |
#sass? ⇒ Boolean
41 42 43 |
# File 'lib/js_project_builder.rb', line 41 def sass? @options[:sass] end |
#sass_dir ⇒ Object
37 38 39 |
# File 'lib/js_project_builder.rb', line 37 def sass_dir @options[:sass_dir] end |
#src_dir ⇒ Object
29 30 31 |
# File 'lib/js_project_builder.rb', line 29 def src_dir @options[:src_dir] end |
#version ⇒ Object
49 50 51 |
# File 'lib/js_project_builder.rb', line 49 def version @version_yml['version'] end |