More WIP
This commit is contained in:
parent
3b41335582
commit
086c49a387
1 changed files with 35 additions and 22 deletions
|
@ -7,13 +7,14 @@ require 'digest/sha1'
|
||||||
require 'middleman-core/rack'
|
require 'middleman-core/rack'
|
||||||
require 'middleman-core/callback_manager'
|
require 'middleman-core/callback_manager'
|
||||||
require 'middleman-core/contracts'
|
require 'middleman-core/contracts'
|
||||||
|
require 'middleman-core/dependencies'
|
||||||
|
|
||||||
module Middleman
|
module Middleman
|
||||||
class Builder
|
class Builder
|
||||||
extend Forwardable
|
extend Forwardable
|
||||||
include Contracts
|
include Contracts
|
||||||
|
|
||||||
OutputResult = Struct.new(:path, :layouts, :partials)
|
OutputResult = Struct.new(:path, :source_path, :depends_on)
|
||||||
|
|
||||||
# Make app & events available to `after_build` callbacks.
|
# Make app & events available to `after_build` callbacks.
|
||||||
attr_reader :app, :events
|
attr_reader :app, :events
|
||||||
|
@ -79,14 +80,17 @@ module Middleman
|
||||||
::Middleman::Profiling.start
|
::Middleman::Profiling.start
|
||||||
|
|
||||||
::Middleman::Util.instrument 'builder.output' do
|
::Middleman::Util.instrument 'builder.output' do
|
||||||
if @manifest && m = load_manifest!
|
files =
|
||||||
incremental_resources = calculate_incremental(m)
|
# if @manifest && m = load_manifest!
|
||||||
|
# incremental_resources = calculate_incremental(m)
|
||||||
|
|
||||||
logger.debug '== Building files'
|
# logger.debug '== Building files'
|
||||||
output_resources(incremental_resources)
|
# output_resources(incremental_resources)
|
||||||
else
|
# else
|
||||||
output_files
|
output_files
|
||||||
end
|
# end
|
||||||
|
|
||||||
|
build_manifest!(files) if @manifest && !@has_error
|
||||||
end
|
end
|
||||||
|
|
||||||
::Middleman::Profiling.report('build')
|
::Middleman::Profiling.report('build')
|
||||||
|
@ -99,7 +103,6 @@ module Middleman
|
||||||
@app.execute_callbacks(:after_build, [self])
|
@app.execute_callbacks(:after_build, [self])
|
||||||
end
|
end
|
||||||
|
|
||||||
build_manifest! if @manifest && !@has_error
|
|
||||||
|
|
||||||
!@has_error
|
!@has_error
|
||||||
end
|
end
|
||||||
|
@ -113,6 +116,7 @@ module Middleman
|
||||||
css_files = ::Middleman::Util.instrument 'builder.prerender.output' do
|
css_files = ::Middleman::Util.instrument 'builder.prerender.output' do
|
||||||
resources = @app.sitemap.resources.select { |resource| resource.ext == '.css' }
|
resources = @app.sitemap.resources.select { |resource| resource.ext == '.css' }
|
||||||
output_resources(resources)
|
output_resources(resources)
|
||||||
|
resources
|
||||||
end
|
end
|
||||||
|
|
||||||
::Middleman::Util.instrument 'builder.prerender.check-files' do
|
::Middleman::Util.instrument 'builder.prerender.check-files' do
|
||||||
|
@ -128,7 +132,7 @@ module Middleman
|
||||||
|
|
||||||
# Find all the files we need to output and do so.
|
# Find all the files we need to output and do so.
|
||||||
# @return [Array<Resource>] List of resources that were output.
|
# @return [Array<Resource>] List of resources that were output.
|
||||||
Contract ResourceList
|
Contract ArrayOf[OutputResult]
|
||||||
def output_files
|
def output_files
|
||||||
logger.debug '== Building files'
|
logger.debug '== Building files'
|
||||||
|
|
||||||
|
@ -149,7 +153,7 @@ module Middleman
|
||||||
output_resources(resources)
|
output_resources(resources)
|
||||||
end
|
end
|
||||||
|
|
||||||
Contract ResourceList => ResourceList
|
Contract ResourceList => ArrayOf[OutputResult]
|
||||||
def output_resources(resources)
|
def output_resources(resources)
|
||||||
results = if @parallel
|
results = if @parallel
|
||||||
::Parallel.map(resources, &method(:output_resource))
|
::Parallel.map(resources, &method(:output_resource))
|
||||||
|
@ -157,9 +161,6 @@ module Middleman
|
||||||
resources.map(&method(:output_resource))
|
resources.map(&method(:output_resource))
|
||||||
end
|
end
|
||||||
|
|
||||||
@partial_files = results.reduce(Set.new) { |sum, r| r ? sum + r[:partials] : sum }
|
|
||||||
@layout_files = results.reduce(Set.new) { |sum, r| r ? sum + r[:layouts] : sum }
|
|
||||||
|
|
||||||
@has_error = true if results.any? { |r| r == false }
|
@has_error = true if results.any? { |r| r == false }
|
||||||
|
|
||||||
if @cleaning && !@has_error
|
if @cleaning && !@has_error
|
||||||
|
@ -177,7 +178,7 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
resources
|
results
|
||||||
end
|
end
|
||||||
|
|
||||||
# Figure out the correct event mode.
|
# Figure out the correct event mode.
|
||||||
|
@ -246,15 +247,14 @@ module Middleman
|
||||||
::Middleman::Util.instrument 'builder.output.resource', path: File.basename(resource.destination_path) do
|
::Middleman::Util.instrument 'builder.output.resource', path: File.basename(resource.destination_path) do
|
||||||
output_file = @build_dir + resource.destination_path.gsub('%20', ' ')
|
output_file = @build_dir + resource.destination_path.gsub('%20', ' ')
|
||||||
|
|
||||||
layouts = Set.new
|
depends_on = Set.new
|
||||||
partials = Set.new
|
|
||||||
|
|
||||||
@app.render_layout do |f|
|
@app.render_layout do |f|
|
||||||
layouts << f[:full_path]
|
depends_on << f[:full_path]
|
||||||
end
|
end
|
||||||
|
|
||||||
@app.render_partial do |f|
|
@app.render_partial do |f|
|
||||||
partials << f[:full_path]
|
depends_on << f[:full_path]
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
@ -276,7 +276,7 @@ module Middleman
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
OutputResult.new(output_file, layouts, partials)
|
OutputResult.new(output_file.to_s, resource.destination_path, depends_on)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -337,6 +337,8 @@ module Middleman
|
||||||
def load_manifest!
|
def load_manifest!
|
||||||
return nil unless File.exist?(MANIFEST_FILE)
|
return nil unless File.exist?(MANIFEST_FILE)
|
||||||
|
|
||||||
|
deps = ::Middleman::Dependencies.new
|
||||||
|
|
||||||
m = ::YAML.load(File.read(MANIFEST_FILE))
|
m = ::YAML.load(File.read(MANIFEST_FILE))
|
||||||
|
|
||||||
all_files = Set.new(@app.files.files.map { |f| f[:full_path].relative_path_from(@app.root_path).to_s })
|
all_files = Set.new(@app.files.files.map { |f| f[:full_path].relative_path_from(@app.root_path).to_s })
|
||||||
|
@ -350,6 +352,11 @@ module Middleman
|
||||||
|
|
||||||
@global_paths = Set.new(partial_and_layout_files) + ruby_files
|
@global_paths = Set.new(partial_and_layout_files) + ruby_files
|
||||||
|
|
||||||
|
# Add file refs
|
||||||
|
all_files.each do |f|
|
||||||
|
deps.record!(f, m[f])
|
||||||
|
end
|
||||||
|
|
||||||
(all_files + ruby_files).select do |f|
|
(all_files + ruby_files).select do |f|
|
||||||
if m[f]
|
if m[f]
|
||||||
dig = ::Digest::SHA1.file(f).to_s
|
dig = ::Digest::SHA1.file(f).to_s
|
||||||
|
@ -358,7 +365,7 @@ module Middleman
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue StandardError, ::Psych::SyntaxError => error
|
rescue ::Psych::SyntaxError => error
|
||||||
logger.error "Manifest file (#{MANIFEST_FILE}) was malformed."
|
logger.error "Manifest file (#{MANIFEST_FILE}) was malformed."
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -389,9 +396,15 @@ module Middleman
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_manifest!
|
Contract ArrayOf[OutputResult] => Any
|
||||||
|
def build_manifest!(files)
|
||||||
|
require 'byebug'
|
||||||
|
byebug
|
||||||
all_files = Set.new(@app.files.files.map { |f| f[:full_path].to_s })
|
all_files = Set.new(@app.files.files.map { |f| f[:full_path].to_s })
|
||||||
ruby_files = Set.new(Dir[File.join(app.root, "**/*.rb")]) << File.expand_path("Gemfile.lock", @app.root)
|
ruby_files = Set.new(Dir[File.join(app.root, "**/*.rb")])
|
||||||
|
|
||||||
|
gemfile_path = File.expand_path("Gemfile.lock", @app.root)
|
||||||
|
ruby_files << gemfile_path if File.exist?(gemfile_path)
|
||||||
|
|
||||||
manifest = (all_files + ruby_files).each_with_object({}) do |source_file, sum|
|
manifest = (all_files + ruby_files).each_with_object({}) do |source_file, sum|
|
||||||
path = Pathname(source_file).relative_path_from(@app.root_path).to_s
|
path = Pathname(source_file).relative_path_from(@app.root_path).to_s
|
||||||
|
|
Loading…
Add table
Reference in a new issue