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
# File 'lib/lono/new.rb', line 11

def self.cli_options
  [
    [:bundle, type: :boolean, default: true, desc: "Runs bundle install on the project"],
    [: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



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

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_projectObject



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

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

#create_starter_blueprintObject



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

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

#git_commitObject



64
65
66
# File 'lib/lono/new.rb', line 64

def git_commit
  run_git_commit
end

#git_initObject



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

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

#make_executableObject



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

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

#set_cwdObject

for specs



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

def set_cwd
  @cwd = Dir.pwd
end

#set_destination_rootObject

After this commands are executed with the newly created project



40
41
42
43
44
# File 'lib/lono/new.rb', line 40

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

#welcome_messageObject



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

def welcome_message
  puts <<~EOL
    #{"="*64}
    Congrats 🎉 You have successfully created a lono project.  A starter demo blueprint was created
    and is at blueprints/demo.  Check things out by going into the created infra folder.

      cd #{project_name}

    To generate the blueprint templates without launching a stack, you can run:

      lono generate demo

    The generated files are created at `output/demo/templates` and `output/demo/params`.

    To deploy the CloudFormation stack:

      lono cfn deploy my-demo --blueprint demo

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

      lono cfn deploy demo

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

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