Skip to content

Instantly share code, notes, and snippets.

@dchentech
Last active December 20, 2015 14:49
Show Gist options
  • Save dchentech/6149713 to your computer and use it in GitHub Desktop.
Save dchentech/6149713 to your computer and use it in GitHub Desktop.
learn.eoe.cn Rails项目及其开源项目源码行数统计
# encoding: UTF-8
# learn.eoe.cn Rails项目及其开源项目源码行数统计
require 'active_support/all'
@total_ruby_lines_count = 0
@total_javascript_lines_count = 0
@total_haml_lines_count = 0
def count_lines_by_file_type pattern, exclude = nil
exclude_str = " | grep -v #{exclude} " if exclude
r = `git ls-files | grep '#{pattern}' #{exclude_str} | xargs wc -l`
r.length.zero? ? 0 : r.split("\n")[-1].split[0].to_i
end
def collect lib
path = lib.start_with?('/') ? lib : "#{ENV['HOME']}/github/eoecn/#{lib}"
FileUtils.chdir(path)
ruby_lines_count = count_lines_by_file_type('.rb$')
@total_ruby_lines_count += ruby_lines_count
javascript_lines_count = count_lines_by_file_type('.js$', 'faye-browser')
@total_javascript_lines_count += javascript_lines_count
haml_lines_count = count_lines_by_file_type('.haml$')
@total_haml_lines_count += haml_lines_count
puts "[#{lib}] Ruby:#{ruby_lines_count} | JavaScript:#{javascript_lines_count} | HAML:#{haml_lines_count}"
end
%w[
rails_engine_eoe
ucenter_authcode
rack_image_assets_cache_control
faye-online
qa-rails
videojs_user_track
stepstepstep
cross_time_calculation
/Users/mvj3/eoemobile/code/learn
].map {|lib| collect lib }
@total_ruby_lines_count += `cd /Users/mvj3/github/eoecn/rails3_acts_as_paranoid; git diff 908894323aad480c5c2746aaa191f6ac7e379b8c a2791773de1fe5e90d33bea85f506cd6425cb670 | cat | grep '^+' | grep -v '^+$' | wc -l`.strip.to_i # 为让 rails3_acts_as_paranoid 兼容默认值为false的做出的数个commits
@total_ruby_lines_count += 9 # markdown-ruby-china patch, 支持程序语言,文件名,别名等多种格式
puts "[total] Ruby:#{@total_ruby_lines_count} | JavaScript:#{@total_javascript_lines_count} | HAML:#{@total_haml_lines_count}"
=begin
[rails_engine_eoe] Ruby:884 | JavaScript:15 | HAML:0
[ucenter_authcode] Ruby:78 | JavaScript:0 | HAML:0
[rack_image_assets_cache_control] Ruby:28 | JavaScript:0 | HAML:0
[faye-online] Ruby:678 | JavaScript:52 | HAML:0
[qa-rails] Ruby:259 | JavaScript:280 | HAML:183
[videojs_user_track] Ruby:140 | JavaScript:84 | HAML:0
[stepstepstep] Ruby:271 | JavaScript:0 | HAML:0
[cross_time_calculation] Ruby:143 | JavaScript:0 | HAML:0
[/Users/mvj3/eoemobile/code/learn] Ruby:4113 | JavaScript:1108 | HAML:517
[total] Ruby:6721 | JavaScript:1539 | HAML:700
=end
collect 'statlysis'
# [statlysis] Ruby:1362 | JavaScript:0 | HAML:0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment