Class: Terraspace::CLI::New::Project

Inherits:
Sequence
  • Object
show all
Defined in:
lib/terraspace/cli/new/project.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Sequence

base_options, component_options

Methods included from Util::Logging

#logger

Class Method Details

.project_optionsObject



3
4
5
6
7
8
9
10
# File 'lib/terraspace/cli/new/project.rb', line 3

def self.project_options
  [
    [:bundle, type: :boolean, default: true, desc: "Runs bundle install on the project"],
    [:config, type: :boolean, default: true, desc: "Whether or not to generate config files."],
    [:force, aliases: %w[y], type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files."],
    [:quiet, type: :boolean, desc: "Quiet output."],
  ]
end

Instance Method Details

#bundle_installObject



30
31
32
33
34
35
36
37
38
# File 'lib/terraspace/cli/new/project.rb', line 30

def bundle_install
  return if @options[:bundle] == false
  log "=> Installing dependencies with: bundle install"
  Bundler.with_unbundled_env do
    bundle = "BUNDLE_IGNORE_CONFIG=1 bundle install"
    bundle << " > /dev/null 2>&1" if @options[:quiet]
    system(bundle, chdir: name)
  end
end

#create_baseObject



25
26
27
28
# File 'lib/terraspace/cli/new/project.rb', line 25

def create_base
  plugin_template_source("base", "project")
  directory ".", "#{name}"
end

#create_projectObject

Will generate config folder from

1. terraspace code lang templates or
2. example lang templates from provider gems


45
46
47
48
49
50
51
52
53
54
# File 'lib/terraspace/cli/new/project.rb', line 45

def create_project
  plugin_template_source(@options[:lang], "project") # IE: plugin_template_source("hcl", "project")

  options = @options[:config] == false ? {exclude_pattern: "config" } : {}
  directory ".", "#{name}", options

  if @options[:config] == false
    empty_directory("#{name}/config")
  end
end

#create_starter_moduleObject



62
63
64
65
# File 'lib/terraspace/cli/new/project.rb', line 62

def create_starter_module
  return unless @options[:examples]
  Module.start(component_args("example", name))
end

#create_starter_stackObject



67
68
69
70
# File 'lib/terraspace/cli/new/project.rb', line 67

def create_starter_stack
  return unless @options[:examples]
  Stack.start(component_args("demo", name))
end

#creating_messagingObject



21
22
23
# File 'lib/terraspace/cli/new/project.rb', line 21

def creating_messaging
  log "=> Creating new project called #{name}"
end

#empty_dirsObject



56
57
58
59
60
# File 'lib/terraspace/cli/new/project.rb', line 56

def empty_dirs
  return if @options[:examples]
  empty_directory("#{name}/app/modules")
  empty_directory("#{name}/app/stacks")
end

#welcome_message_examplesObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/terraspace/cli/new/project.rb', line 72

def welcome_message_examples
  return unless options[:examples]
  log <<~EOL
    #{"="*64}
    Congrats! You have successfully created a terraspace project.
    Check out the created files. Adjust to the examples and then deploy with:

        cd #{name}
        terraspace up demo -y   # to deploy
        terraspace down demo -y # to destroy

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

#welcome_message_no_examplesObject



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/terraspace/cli/new/project.rb', line 87

def welcome_message_no_examples
  return if options[:examples]
  log <<~EOL
    #{"="*64}
    Congrats! You have successfully created a terraspace project.
    Check out the created files.

        cd #{name}

    You can create starter modules and stacks with their generators:

        terraspace new module example
        terraspace new stack demo

    Add your code to them, and deploy when you are ready:

        terraspace up demo -y   # to deploy

    Destroy with:

        terraspace down demo -y # to destroy

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