Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent overwriting the manifest in the first phase of the build #63

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/middleman-imageoptim/manifest_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ def ignored?
private

def manifest_content
if @source_file.nil?
path = File.join(@app.config[:build_dir], @destination_path)
if !File.exist?(path)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick but this would be generally easier to understand using the positive form:

if File.exists?(path)
  do B
else
  do A
end

Instead of if !x do A else do B

YAML.dump({})
else
File.read(@source_file)
File.read(path)
end
end
end
Expand Down
3 changes: 2 additions & 1 deletion lib/middleman-imageoptim/optimizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def process_image(source, destination = nil, mode = nil)
say_status '%{source} (%{percent_change} / %{size_change} %{size_change_type})', Utils.file_size_stats(source, destination)
FileUtils.move(destination, source)
else
say_status '[skipped] %{source} not updated', source: source
skip_message = '[skipped] %{source} - optimized version is identical to source (may have been previously optimized)'
say_status skip_message, source: source
end
ensure
ensure_file_mode(mode, source) unless mode.nil?
Expand Down