Sha256: ac7352021487643cde08c30d649161a6a1f2de43c568a82fb1219f8ea027ff93

Contents?: true

Size: 1.96 KB

Versions: 12

Compression:

Stored size: 1.96 KB

Contents

class Lono::Configset
  class New < Lono::Sequence
    include Lono::Blueprint::Helper
    include Lono::Utils::Generators::Tree

    argument :configset_name

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

    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

    cli_options.each do |args|
      class_option(*args)
    end

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

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

    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

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

    # After this commands are executed with the newly created project
    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

    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

    def tree
      tree_structure("configset")
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
lono-7.5.2 lib/lono/configset/new.rb
lono-7.5.1 lib/lono/configset/new.rb
lono-7.5.0 lib/lono/configset/new.rb
lono-7.4.11 lib/lono/configset/new.rb
lono-7.4.10 lib/lono/configset/new.rb
lono-7.4.9 lib/lono/configset/new.rb
lono-7.4.8 lib/lono/configset/new.rb
lono-7.4.7 lib/lono/configset/new.rb
lono-7.4.6 lib/lono/configset/new.rb
lono-7.4.5 lib/lono/configset/new.rb
lono-7.4.4 lib/lono/configset/new.rb
lono-7.4.3 lib/lono/configset/new.rb