<commit_before>BUNDLE_NAME  = "#{PACKAGE_INFO['package-name']}.AdiumMessageStyle"
ARCHIVE_NAME = "#{PACKAGE_INFO['package-name']}-#{PACKAGE_INFO['package-version']}.tar.bz2"

INSTALL_DIR  = ENV['HOME']/'Library/Application Support/Adium 2.0/Message Styles'

def template_file template_path, output_path
  output = File.read template_path
  output.gsub!(%r( \$\{ ([^\}]+) \} )x) { PACKAGE_INFO[$1.gsub(/_/, '-')] }
  
  output_path = output_path / File.basename(template_path) \
    if File.directory? output_path
  
  File.open(output_path, 'w') { |io| io.write output }
end

def uglify?
  unless defined? @uglify
    @uglify = ( %w[ true yes 1 ].include? ENV['uglify'] and defined? Uglifier )
  else
    @uglify
  end
end

desc 'assemble the message style bundle for packaging or installation'
task :assemble => [:compile, 'dist/'] do
  begin
    require 'uglifier'
  rescue LoadError
    puts "Uglifier is not available. JavaScript won't be minified."
  end
  
  package_name    = PACKAGE_INFO['package-name']
  package_version = PACKAGE_INFO['package-version']
  
  PACKAGE_INFO['include-files'].each do |file|
    if file.is_a? Hash
      file.each { |from, to| cp from, 'dist'/to }
    else
      cp file, 'dist'
    end
  end
  
  contents_dir = 'dist'/BUNDLE_NAME/'Contents'
  mkdir_p contents_dir
  
  template_file 'templates/Info.plist', contents_dir
  
  resources_dir = contents_dir/'Resources'
  mkdir_p resources_dir
  
  FileList[%w[
    files/**/*
    build/Variants/**/*
    build/stylesheets/*
    build/scripts/_require.js
    build/scripts/modules.js
  ]].reject do |source|
    # skip directories
    File.directory? source
  end.each do |source|
    target = source.pathmap "%{^(build|files),#{resources_dir}}p"
    dir = target.dirname
    
    mkdir_p dir unless File.directory? dir
    
    if File.exist?(target) and File.mtime(target) > File.mtime(source)
      puts "[SKIP] #{source}"
      next
    elsif uglify? and source.extname == '.js'
      puts "[Uglifier] #{source} => #{target}"
      File.open(target, 'w') { |io| io << Uglifier.compile(File.read source) }
    else
      cp source, target
    end
  end
  
end

desc 'package for distribution'
task :package => :assemble do
  sh 'tar', 'jcf', ARCHIVE_NAME, '-s', '/^dist/GentleGlow/', 'dist'
end

desc "install to Adium's Message Styles folder"
task :install => :assemble do
  rm_rf INSTALL_DIR/BUNDLE_NAME
  cp_r 'dist'/BUNDLE_NAME, INSTALL_DIR
end

namespace :clean do
  
  desc 'remove assembled bundle'
  task :assemble do
    rm_rf 'dist'
  end
  
  desc 'remove distribution package'
  task :package do
    rm_f ARCHIVE_NAME
  end
  
end<commit_msg>remove assembled style and tarball package with "rake clean"<commit_after>BUNDLE_NAME  = "#{PACKAGE_INFO['package-name']}.AdiumMessageStyle"
ARCHIVE_NAME = "#{PACKAGE_INFO['package-name']}-#{PACKAGE_INFO['package-version']}.tar.bz2"

INSTALL_DIR  = ENV['HOME']/'Library/Application Support/Adium 2.0/Message Styles'

def template_file template_path, output_path
  output = File.read template_path
  output.gsub!(%r( \$\{ ([^\}]+) \} )x) { PACKAGE_INFO[$1.gsub(/_/, '-')] }
  
  output_path = output_path / File.basename(template_path) \
    if File.directory? output_path
  
  File.open(output_path, 'w') { |io| io.write output }
end

def uglify?
  unless defined? @uglify
    @uglify = ( %w[ true yes 1 ].include? ENV['uglify'] and defined? Uglifier )
  else
    @uglify
  end
end

desc 'assemble the message style bundle for packaging or installation'
task :assemble => [:compile, 'dist/'] do
  begin
    require 'uglifier'
  rescue LoadError
    puts "Uglifier is not available. JavaScript won't be minified."
  end
  
  package_name    = PACKAGE_INFO['package-name']
  package_version = PACKAGE_INFO['package-version']
  
  PACKAGE_INFO['include-files'].each do |file|
    if file.is_a? Hash
      file.each { |from, to| cp from, 'dist'/to }
    else
      cp file, 'dist'
    end
  end
  
  contents_dir = 'dist'/BUNDLE_NAME/'Contents'
  mkdir_p contents_dir
  
  template_file 'templates/Info.plist', contents_dir
  
  resources_dir = contents_dir/'Resources'
  mkdir_p resources_dir
  
  FileList[%w[
    files/**/*
    build/Variants/**/*
    build/stylesheets/*
    build/scripts/_require.js
    build/scripts/modules.js
  ]].reject do |source|
    # skip directories
    File.directory? source
  end.each do |source|
    target = source.pathmap "%{^(build|files),#{resources_dir}}p"
    dir = target.dirname
    
    mkdir_p dir unless File.directory? dir
    
    if File.exist?(target) and File.mtime(target) > File.mtime(source)
      puts "[SKIP] #{source}"
      next
    elsif uglify? and source.extname == '.js'
      puts "[Uglifier] #{source} => #{target}"
      File.open(target, 'w') { |io| io << Uglifier.compile(File.read source) }
    else
      cp source, target
    end
  end
  
end

desc 'package for distribution'
task :package => :assemble do
  sh 'tar', 'jcf', ARCHIVE_NAME, '-s', '/^dist/GentleGlow/', 'dist'
end

desc "install to Adium's Message Styles folder"
task :install => :assemble do
  rm_rf INSTALL_DIR/BUNDLE_NAME
  cp_r 'dist'/BUNDLE_NAME, INSTALL_DIR
end

task :clean => 'clean:assemble'
task :clean => 'clean:package'

namespace :clean do
  
  desc 'remove assembled bundle'
  task :assemble do
    rm_rf 'dist'
  end
  
  desc 'remove distribution package'
  task :package do
    rm_f ARCHIVE_NAME
  end
  
end
{'fraction_non_alphanumeric': 0.13150583441378033, 'fraction_numerical': 0.0018521948508983144, 'mean_word_length': 3.4407894736842106, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4809641', 'n_tokens_mistral': 1930, 'n_tokens_neox': 1911, 'n_words': 467}