class Rhllor::RhllorCli

Public Class Methods

init(config) click to toggle source
# File lib/rhllor.rb, line 6
def self.init(config)
  project_path = File.expand_path(File.join(File.dirname(__FILE__), '../project'))
  Dir.glob("#{project_path}/**/{*,.*}")
    .select{ |template_path| File.file?(template_path) }
    .reject{ |template_path| template_path.include?('.DS_Store') } # 排除掉该死的隐藏文件
    .each do |template_path|

    relative_path = template_path.sub(project_path, '').gsub('__artifactId__', config[:name])
    current_path = File.join(Dir.pwd, relative_path)
    # 创建文件夹
    dirname = File.dirname(current_path)
    FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
    # 生成文件
    puts "Writing #{current_path}..."
    File.open(current_path, 'w') do |out|
      template = File.open(template_path).read()
      content = Liquid::Template.parse(template).render(config.deep_stringify_keys())
      out.write(content)
    end
  end
end