Class: Moku6::Initializer

Inherits:
Object
  • Object
show all
Defined in:
lib/moku6/initializer.rb

Overview

Backs ‘moku6 init`. Copies templates/init into ./ (never overwrites existing files).

Constant Summary collapse

TEMPLATE_DIR =

: String

File.expand_path("../../templates/init", __dir__.to_s)

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Initializer

: (?Hash[Symbol, untyped] options) -> void



15
16
17
18
# File 'lib/moku6/initializer.rb', line 15

def initialize(options = {})
  @options = options
  @dest_root = Dir.pwd
end

Instance Method Details

#runObject

: () -> void



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/moku6/initializer.rb', line 21

def run
  entries.each do |src|
    rel = src.delete_prefix("#{TEMPLATE_DIR}/")
    dest = File.join(@dest_root, rel)
    if File.exist?(dest)
      puts "skip (exists): #{rel}"
      next
    end
    FileUtils.mkdir_p(File.dirname(dest))
    FileUtils.cp(src, dest)
    puts "create: #{rel}"
  end
end