Class: TRMNLP::Commands::Init

Inherits:
Base
  • Object
show all
Defined in:
lib/trmnlp/commands/init.rb

Defined Under Namespace

Classes: Options

Instance Method Summary collapse

Methods inherited from Base

#initialize, options_from, run

Constructor Details

This class inherits a constructor from TRMNLP::Commands::Base

Instance Method Details

#call(name) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/trmnlp/commands/init.rb', line 12

def call(name)
  destination_dir = Pathname.new(options.dir).join(name)

  unless destination_dir.exist?
    reporter.info "Creating #{destination_dir}"
    destination_dir.mkpath
  end

  template_dir.glob('**/{*,.*}').each do |source_pathname|
    next if source_pathname.directory?
    next if options.skip_liquid && source_pathname.extname == '.liquid'

    relative_pathname = source_pathname.relative_path_from(template_dir)
    destination_pathname = destination_dir.join(relative_pathname)
    destination_pathname.dirname.mkpath

    if destination_pathname.exist?
      answer = prompt("#{destination_pathname} already exists. Overwrite? (y/n): ").downcase
      if answer != 'y'
        reporter.info "Skipping #{destination_pathname}"
        next
      end
    end

    reporter.info "Creating #{destination_pathname}"
    FileUtils.cp(source_pathname, destination_pathname)
  end

  reporter.info <<~HEREDOC

    To start the local server:

        cd #{Pathname.new(destination_dir).relative_path_from(Dir.pwd)}
        trmnlp serve

    To publish the plugin:

        trmnlp login
        trmnlp push
  HEREDOC
end