class Lono::Blueprint::New

Public Class Methods

cli_options() click to toggle source
# File lib/lono/blueprint/new.rb, line 13
def self.cli_options
  [
    [:bundle, type: :boolean, default: true, desc: "Runs bundle install on the project"],
    [:demo, type: :boolean, default: true, desc: "Include demo template"],
    [:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files."],
    [:from_new, type: :boolean, desc: "Called from `lono new` command."],
    [:import, type: :boolean, desc: "Flag for lono code import"],
    [:project_name, default: '', desc: "Only used with from_new internally"],
    [:type, default: "dsl", desc: "Blueprint type: dsl or erb"],
  ]
end
source_root() click to toggle source
# File lib/lono/blueprint/new.rb, line 8
def self.source_root
  templates = File.expand_path("../../templates", File.dirname(__FILE__))
  "#{templates}/blueprint"
end

Public Instance Methods

create_app_folder() click to toggle source
# File lib/lono/blueprint/new.rb, line 58
def create_app_folder
  return if @options[:import]

  if @demo
    directory "../blueprint_types/#{@options[:type]}", "#{@cwd}/#{blueprint_name}"
  else
    empty_directory "#{@cwd}/#{blueprint_name}/app/templates"
    create_file "#{@cwd}/#{blueprint_name}/app/templates/#{blueprint_name}.rb"
  end
end
create_empty_directories() click to toggle source
# File lib/lono/blueprint/new.rb, line 69
def create_empty_directories
  # Note: Not using Lono::Core::Config::PATHS.keys to create all of them because
  # think it is more common to not have all the folders. Instead create them explicitly.
  empty_directory "#{@cwd}/#{blueprint_name}/app/templates"
end
create_license() click to toggle source
# File lib/lono/blueprint/new.rb, line 75
def create_license
  return unless ENV['LONO_LICENSE_FILE']
  copy_file ENV['LONO_LICENSE_FILE'], "#{@cwd}/#{blueprint_name}/LICENSE.txt"
end
create_project() click to toggle source
# File lib/lono/blueprint/new.rb, line 53
def create_project
  puts "=> Creating new blueprint called #{blueprint_name}."
  directory ".", "#{@cwd}/#{blueprint_name}", directory_options
end
create_readme() click to toggle source
# File lib/lono/blueprint/new.rb, line 80
def create_readme
  return unless ENV['LONO_README_FILE']
  template ENV['LONO_README_FILE'], "#{@cwd}/#{blueprint_name}/README.md"
end
reset_current_dir() click to toggle source

Reason: So `lono code import` prints out the params values with relative paths when the config files are generated.

# File lib/lono/blueprint/new.rb, line 114
def reset_current_dir
  FileUtils.cd(@old_dir)
end
set_cwd() click to toggle source

for specs

# File lib/lono/blueprint/new.rb, line 30
def set_cwd
  @cwd = "#{Lono.root}/app/blueprints"

  if options[:from_new]
    # At this point @cwd will have the project_name from `lono new`
    # Yup, it's confusing.  Here's an example to explain:
    #
    #   lono new my-infra - sets @cwd = my-infra
    #
    # Then within the new Thor::Group this is called
    #
    #   Lono::Blueprint::New.start(["ec2", "--from-new"])
    #
    # So @cwd = my-infra/blueprints
    @cwd = "#{options[:project_name]}/app/blueprints"
  end
end
set_destination_root() click to toggle source

After this commands are executed with the newly created project

# File lib/lono/blueprint/new.rb, line 86
def set_destination_root
  destination_root = "#{@cwd}/#{blueprint_name}"
  self.destination_root = destination_root
  @old_dir = Dir.pwd # for reset_current_dir
  FileUtils.cd(self.destination_root)
end
set_variables() click to toggle source
# File lib/lono/blueprint/new.rb, line 48
def set_variables
  @demo = @options[:demo]
  @demo = false if ENV["LONO_ORG"] # overrides --demo CLI option
end
tree() click to toggle source
# File lib/lono/blueprint/new.rb, line 108
def tree
  tree_structure("blueprint")
end
welcome_message() click to toggle source
# File lib/lono/blueprint/new.rb, line 93
    def welcome_message
      return if options[:from_new] || options[:import]
      puts <<~EOL
        #{"="*64}
        Congrats 🎉 You have successfully created a lono blueprint.

        Cd into your blueprint and check things out.

            cd #{blueprint_name}

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

      EOL
    end

Private Instance Methods

directory_options() click to toggle source
# File lib/lono/blueprint/new.rb, line 119
def directory_options
  if ENV['LONO_README_FILE']
    {exclude_pattern: /README/}
  else
    {}
  end
end