Skip to content

Instantly share code, notes, and snippets.

@alexrothenberg
Last active August 2, 2017 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexrothenberg/d0d8ed94b5921e24f7d7ea42ae471bb1 to your computer and use it in GitHub Desktop.
Save alexrothenberg/d0d8ed94b5921e24f7d7ea42ae471bb1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'fileutils'
def analyze
Dir.glob("public/dist/**/*.{js,css}").reduce({}) do |hash, filename|
filename =~ /public\/dist\/([^-]*)(-.{10})?\.(.*)/
name = "#{$1}.#{$3}"
# puts name
hash[name] = File.new(filename).size
hash
end
end
def run(command)
output = `#{command} 2>&1`
raise output unless $?.success?
end
def analyze_for_week(week)
FileUtils.rm_rf 'public/dist'
run("git reset --hard")
run("git checkout v1.17.#{week}.1")
FileUtils.rm_rf 'node_modules'
FileUtils.rm_rf 'facesheet/node_modules'
run("bundle check || bundle install")
run("yarn")
FileUtils.cd('facesheet') do
run("yarn && npm rebuild node-sass && bower install")
run("ember build --output-path ../public/dist/facesheet --environment=production")
end
run("gulp dist")
{ week => analyze }
end
def save(analysis)
File.open(File.expand_path('~/chirpolith_analysis.raw'), 'a') do |f|
f.puts analysis.inspect
end
week = analysis.keys.first
File.open(File.expand_path('~/chirpolith_analysis.csv'), 'a') do |f|
values = COLUMNS.map do |column|
analysis[week][column]
end
f.print "#{week}\t"
f.puts values.join("\t")
end
end
COLUMNS = ["javascripts/application.js", "javascripts/templates.js", "javascripts/new_task.js", "javascripts/browserify.js", "javascripts/demographics.js", "javascripts/vendor.js", "facesheet/assets/facesheet.js", "facesheet/assets/vendor.js", "stylesheets/application.css", "stylesheets/print.css", "facesheet/assets/facesheet.css", "facesheet/assets/vendor.css"]
if ARGV.length != 1
puts "Please tell me which week to do"
exit(1)
end
week = ARGV[0].to_i
puts "**** WEEK: #{week} *******"
analysis = analyze_for_week(week)
save(analysis)
# (1..52).each do |week|
# puts
# puts
# puts
# puts "**** WEEK: #{week} *******"
# analysis = analyze_for_week(week)
# save(analysis)
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment