Class: Lono::New

Inherits:
Sequence show all
Includes:
Helper, Message
Defined in:
lib/lono/new.rb

Defined Under Namespace

Modules: Helper, Message

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Sequence

source_root, template_name

Class Method Details

.cli_optionsObject

Ugly, but when the class_option is only defined in the Thor::Group class it doesnt show up with cli-template new help :( If anyone knows how to fix this let me know. Also options from the cli can be pass through to here



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

def self.cli_options
  [
    [:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files."],
    [:bundle, type: :boolean, default: true, desc: "Runs bundle install on the project"],
    [:git, type: :boolean, default: true, desc: "Git initialize the project"],
  ]
end

Instance Method Details

#bundle_installObject



60
61
62
63
64
65
66
67
# File 'lib/lono/new.rb', line 60

def bundle_install
  return unless options[:bundle]

  puts "=> Installing dependencies with: bundle install"
  Bundler.with_clean_env do
    system("BUNDLE_IGNORE_CONFIG=1 bundle install")
  end
end

#create_empty_directoriesObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/lono/new.rb', line 36

def create_empty_directories
  meths = Lono::Core::Config::PATHS.keys
  meths.each do |meth|
    path = "#{@cwd}/#{project_name}/#{Lono.config.send(meth)}"
    next if File.exist?(path)
    if ENV['TEST']
      empty_directory Lono.config.send(meth)
    else
      empty_directory path
    end
  end
end

#create_projectObject



31
32
33
34
# File 'lib/lono/new.rb', line 31

def create_project
  puts "=> Creating new project called #{project_name}."
  directory ".", "#{@cwd}/#{project_name}"
end

#final_messageObject



80
81
82
# File 'lib/lono/new.rb', line 80

def final_message
  puts welcome_message
end

#git_initObject



69
70
71
72
73
74
75
76
77
78
# File 'lib/lono/new.rb', line 69

def git_init
  return if !options[:git]
  return unless git_installed?
  return if File.exist?(".git") # this is a clone repo

  puts "=> Initialize git repo"
  run("git init")
  run("git add .")
  run("git commit -m 'first commit'")
end

#make_executableObject



56
57
58
# File 'lib/lono/new.rb', line 56

def make_executable
  chmod("exe", 0755 & ~File.umask, verbose: false) if File.exist?("exe")
end

#set_cwdObject

for specs



27
28
29
# File 'lib/lono/new.rb', line 27

def set_cwd
  @cwd = ENV['TEST'] ? File.dirname(Lono.root) : Dir.pwd
end

#set_destination_rootObject

After this commands are executed with the newly created project



50
51
52
53
54
# File 'lib/lono/new.rb', line 50

def set_destination_root
  destination_root = "#{@cwd}/#{project_name}"
  self.destination_root = destination_root
  FileUtils.cd(self.destination_root)
end