Class: Lono::Configset::New

Inherits:
Sequence
  • Object
show all
Includes:
Blueprint::Helper, Utils::Generators::Tree
Defined in:
lib/lono/configset/new.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Blueprint::Helper

#user_info

Class Method Details

.cli_optionsObject



13
14
15
16
17
18
# File 'lib/lono/configset/new.rb', line 13

def self.cli_options
  [
    [:demo, type: :boolean, default: true, desc: "Include demo template"],
    [:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files."],
  ]
end

.source_rootObject



8
9
10
11
# File 'lib/lono/configset/new.rb', line 8

def self.source_root
  templates = File.expand_path("../../templates", File.dirname(__FILE__))
  "#{templates}/configset"
end

Instance Method Details

#create_licenseObject



46
47
48
49
# File 'lib/lono/configset/new.rb', line 46

def create_license
  return unless ENV['LONO_LICENSE_FILE']
  copy_file ENV['LONO_LICENSE_FILE'], "#{@cwd}/#{configset_name}/LICENSE.txt"
end

#create_projectObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/lono/configset/new.rb', line 34

def create_project
  puts "=> Creating new configset called #{configset_name}."
  if @demo
    options = {}
  else
    create_file "#{@cwd}/#{configset_name}/lib/configset.rb"
    options = {exclude_pattern: %r{configset\.rb}}
  end

  directory ".", "#{@cwd}/#{configset_name}", options
end

#set_cwdObject

for specs



25
26
27
# File 'lib/lono/configset/new.rb', line 25

def set_cwd
  @cwd = ENV['LONO_TEST'] ? File.dirname(Lono.root) : "#{Dir.pwd}/app/configsets"
end

#set_destination_rootObject

After this commands are executed with the newly created project



52
53
54
55
56
57
# File 'lib/lono/configset/new.rb', line 52

def set_destination_root
  destination_root = "#{@cwd}/#{configset_name}"
  self.destination_root = destination_root
  @old_dir = Dir.pwd # for reset_current_dir
  FileUtils.cd(self.destination_root)
end

#set_variablesObject



29
30
31
32
# File 'lib/lono/configset/new.rb', line 29

def set_variables
  @demo = @options[:demo]
  @demo = false if ENV["LONO_ORG"] # overrides --demo CLI option
end

#treeObject



73
74
75
# File 'lib/lono/configset/new.rb', line 73

def tree
  tree_structure("configset")
end

#welcome_messageObject



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/lono/configset/new.rb', line 59

def welcome_message
  puts <<~EOL
    #{"="*64}
    Congrats 🎉 You have successfully created a lono configset.

    Cd into your configset and check things out.

        cd #{configset_name}

    More info: https://lono.cloud/docs/core/configsets

  EOL
end