Class: Codebuild::Init

Inherits:
Sequence
  • Object
show all
Defined in:
lib/codebuild/init.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Sequence

source_paths

Methods included from AwsServices

#cfn, #codebuild

Methods included from AwsServices::Helpers

#are_you_sure?, #inferred_project_name, #inferred_stack_name, #project_name_convention, #stack_exists?

Class Method Details

.cli_optionsObject

Ugly, this is how I can get the options from to match with this Thor::Group



4
5
6
7
8
9
10
11
12
13
# File 'lib/codebuild/init.rb', line 4

def self.cli_options
  [
    [:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files"],
    [:name, desc: "CodeBuild project name"],
    [:template, desc: "Custom template to use"],
    [:template_mode, desc: "Template mode: replace or additive"],
    [:type, desc: "Type option creates a subfolder under .codebuild"],
    [:variables, type: :boolean, default: false, desc: "Create variables starter files"],
  ]
end

Instance Method Details

#copy_projectObject



45
46
47
48
49
50
# File 'lib/codebuild/init.rb', line 45

def copy_project
  puts "Initialize codebuild project in .codebuild"
  dest = ".codebuild"
  dest = "#{dest}/#{@options[:type]}" if @options[:type]
  directory "project", dest, exclude_pattern: /.git/
end

#copy_top_levelObject



36
37
38
39
40
41
42
43
# File 'lib/codebuild/init.rb', line 36

def copy_top_level
  puts "Initialize codebuild top-level folder"
  dest = ".codebuild"
  excludes = %w[.git]
  excludes << %w[variables] unless @options[:variables]
  pattern = Regexp.new(excludes.join('|'))
  directory "top", dest, exclude_pattern: pattern
end

#set_source_pathObject



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/codebuild/init.rb', line 22

def set_source_path
  return unless @options[:template]

  custom_template = "#{ENV['HOME']}/.codebuild/templates/#{full_repo_name}"

  if @options[:template_mode] == "replace" # replace the template entirely
    override_source_paths(custom_template)
  else # additive: modify on top of default template
    default_template = File.expand_path("../../template", __FILE__)
    puts "default_template: #{default_template}"
    override_source_paths([custom_template, default_template])
  end
end

#setup_template_repoObject



16
17
18
19
20
# File 'lib/codebuild/init.rb', line 16

def setup_template_repo
  return unless @options[:template]&.include?('/')

  sync_template_repo
end