Class: Embork::Builder
- Inherits:
-
Object
- Object
- Embork::Builder
- Defined in:
- lib/embork/builder.rb
Instance Method Summary collapse
- #build ⇒ Object
- #clean! ⇒ Object
-
#initialize(borkfile) ⇒ Builder
constructor
A new instance of Builder.
Constructor Details
#initialize(borkfile) ⇒ Builder
Returns a new instance of Builder.
9 10 11 12 |
# File 'lib/embork/builder.rb', line 9 def initialize(borkfile) @borkfile = borkfile @project_root = @borkfile.project_root end |
Instance Method Details
#build ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/embork/builder.rb', line 14 def build @environment = Embork::Environment.new(@borkfile) @sprockets_environment = @environment.sprockets_environment @version = generate_version @sprockets_environment.context_class.use_bundled_assets = true @sprockets_environment.context_class.bundle_version = @version Dir.chdir @project_root do config_path = File.join 'config', Embork.env.to_s build_path = File.join 'build', Embork.env.to_s asset_list = generate_asset_list config_path manifest_path = File.join build_path, 'manifest.json' manifest = Sprockets::Manifest.new(@sprockets_environment, manifest_path) manifest.compile(asset_list) # version assets asset_list.each do |asset| digested_name = manifest.assets[asset] gzipped_name = "%s%s" % [ digested_name, '.gz' ] versioned_name = generate_versioned_name(asset) # Do the actual renaming and removing of the gzipped file. # nginx handles gzipping just fine Dir.chdir build_path do File.rename digested_name, versioned_name FileUtils.rm gzipped_name end end # Link the index file since, chances are, you don't want to reconfigure # your index file every time you deploy. Dir.chdir build_path do @borkfile.html.each do |file| dirname = File.dirname file extname = File.extname file basename = File.basename file, extname src_format = [ File.join(dirname, basename), @version, extname ] FileUtils.ln_sf(("%s-%s%s" % src_format), file) end end if @borkfile.backend == :static_index static_path = 'static' static_pathname = Pathname.new static_path static_directories = [] static_files = [] Find.find(static_path) do |file| relative_name = Pathname.new(file).relative_path_from(static_pathname) if FileTest.directory? file static_directories.push relative_name else static_files.push relative_name end end static_directories.each do |dir| Dir.chdir(build_path) { FileUtils.mkdir_p dir } end static_files.each do |file| src = File.join static_path, file dest = File.join build_path, file FileUtils.cp src, dest end # Write the current version Dir.chdir build_path do File.open('current-version', 'w') { |f| f.puts @version } end # Clean up FileUtils.rm manifest_path end @version end |