Class: Lono::New

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

Defined Under Namespace

Modules: Helper

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Sequence

source_root

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



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

def self.cli_options
  [
    [:bundle, type: :boolean, default: true, desc: "Runs bundle install on the project"],
    [:demo, type: :boolean, default: false, desc: "Also generate demo blueprint"],
    [:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files."],
    [:git, type: :boolean, default: true, desc: "Git initialize the project"],
    [:type, default: "dsl", desc: "Blueprint type: dsl or erb"],
  ]
end

Instance Method Details

#bundle_installObject



57
58
59
60
61
62
63
64
# File 'lib/lono/new.rb', line 57

def bundle_install
  return unless options[:bundle]

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

#create_projectObject



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

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

#create_starter_blueprintObject



35
36
37
38
39
# File 'lib/lono/new.rb', line 35

def create_starter_blueprint
  return unless @options[:demo]
  # https://github.com/erikhuda/thor/wiki/Invocations
  Lono::Blueprint::New.start(["demo", "--from-new", "--type", @options[:type], "--project-name", project_name])
end

#git_commitObject



66
67
68
# File 'lib/lono/new.rb', line 66

def git_commit
  run_git_commit
end

#git_initObject



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

def git_init
  return if File.exist?(".git") # this is a clone repo
  run_git_init
end

#make_executableObject



48
49
50
# File 'lib/lono/new.rb', line 48

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

#set_cwdObject

for specs



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

def set_cwd
  @cwd = Dir.pwd
end

#set_destination_rootObject

After this commands are executed with the newly created project



42
43
44
45
46
# File 'lib/lono/new.rb', line 42

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

#welcome_messageObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/lono/new.rb', line 70

def welcome_message
  puts <<~EOL
    #{"="*64}
    Congrats 🎉 You have successfully created a lono project.  Check things out by going into the created infra folder.

        cd #{project_name}

    To create a new blueprint run:

        lono blueprint new demo

    To deploy the blueprint:

        lono cfn deploy my-demo --blueprint demo

    If you name the stack according to conventions, you can run:

        lono cfn deploy demo

    To list and create additional blueprints refer to https://lono.cloud/docs/core/blueprints

    More info: https://lono.cloud/
  EOL
end