2 # Based on convert script from vwall/compass-twitter-bootstrap gem.
3 # https://github.com/vwall/compass-twitter-bootstrap/blob/master/build/convert.rb
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this work except in compliance with the License.
7 # You may obtain a copy of the License in the LICENSE file, or at:
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
21 require 'term/ansicolor'
24 require_relative 'converter/fonts_conversion'
25 require_relative 'converter/less_conversion'
26 require_relative 'converter/js_conversion'
27 require_relative 'converter/logger'
28 require_relative 'converter/network'
33 include LessConversion
35 include FontsConversion
37 def initialize(repo: 'twbs/bootstrap', branch: 'master', save_to: {}, cache_path: 'tmp/converter-cache-bootstrap')
40 @branch = branch || 'master'
41 @branch_sha = get_branch_sha
42 @cache_path = cache_path
43 @repo_url = "https://github.com/#@repo"
45 js: 'assets/javascripts/bootstrap',
46 scss: 'assets/stylesheets/bootstrap',
47 fonts: 'assets/fonts/bootstrap'}.merge(save_to)
50 def_delegators :@logger, :log, :log_status, :log_processing, :log_transform, :log_file_info, :log_processed, :log_http_get_file, :log_http_get_files, :silence_log
53 log_status "Convert Bootstrap LESS to Sass"
54 puts " repo : #@repo_url"
55 puts " branch : #@branch_sha #@repo_url/tree/#@branch"
56 puts " save to: #{@save_to.to_json}"
57 puts " twbs cache: #{@cache_path}"
60 @save_to.each { |_, v| FileUtils.mkdir_p(v) }
63 process_stylesheet_assets
64 process_javascript_assets
68 def save_file(path, content, mode='w')
69 dir = File.dirname(path)
70 FileUtils.mkdir_p(dir) unless File.directory?(dir)
71 File.open(path, mode) { |file| file.write(content) }
74 # Update version.rb file with BOOTSTRAP_SHA
76 path = 'lib/bootstrap-sass/version.rb'
77 content = File.read(path).sub(/BOOTSTRAP_SHA\s*=\s*['"][\w]+['"]/, "BOOTSTRAP_SHA = '#@branch_sha'")
78 File.open(path, 'w') { |f| f.write(content) }