Class: Lono::Generate

Inherits:
AbstractBase show all
Defined in:
lib/lono/generate.rb

Constant Summary collapse

@@parameters =

Use class variable to cache this only runs once across all classes. base.rb, diff.rb, preview.rb

nil

Instance Method Summary collapse

Methods inherited from AbstractBase

#initialize, #reinitialize, #template_path

Methods included from Blueprint::Root

#find_blueprint_root, #set_blueprint_root

Constructor Details

This class inherits a constructor from Lono::AbstractBase

Instance Method Details

#allObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/lono/generate.rb', line 5

def all
  return @@parameters if @@parameters

  ensure_s3_bucket_exist unless @options[:generate_only]
  pre_generate
  generate_templates # generates with some placeholders for build_files IE: file://app/files/my.rb
  post_generate
  upload unless @options[:generate_only]

  @@parameters = param_generator.generate  # Writes the json file in CamelCase keys format
  check_for_errors
  @@parameters
end

#build_filesObject



51
52
53
54
# File 'lib/lono/generate.rb', line 51

def build_files
  Lono::AppFile::Build.new(@options).run
  Lono::Configset::S3File::Build.new(@options).run # copies files to the output folder
end

#build_scriptsObject



47
48
49
# File 'lib/lono/generate.rb', line 47

def build_scripts
  Lono::Script::Build.new(@options).run
end

#check_filesObject



99
100
101
102
103
104
105
# File 'lib/lono/generate.rb', line 99

def check_files
  errors = []
  unless File.exist?(template_path)
    errors << "Template file missing: could not find #{template_path}"
  end
  errors
end

#check_for_errorsObject



90
91
92
93
94
95
96
97
# File 'lib/lono/generate.rb', line 90

def check_for_errors
  errors = check_files
  unless errors.empty?
    puts "Please double check the command you ran.  There were some errors."
    puts "ERROR: #{errors.join("\n")}".color(:red)
    exit
  end
end

#ensure_s3_bucket_existObject



41
42
43
44
45
# File 'lib/lono/generate.rb', line 41

def ensure_s3_bucket_exist
  bucket = Lono::S3::Bucket.new
  return if bucket.exist?
  bucket.deploy
end

#generate_templatesObject



56
57
58
59
# File 'lib/lono/generate.rb', line 56

def generate_templates
  Lono::Template::Generator.new(@options).run # write templates to disk
  inject_configsets
end

#inject_configsetsObject



61
62
63
64
65
# File 'lib/lono/generate.rb', line 61

def inject_configsets
  # The inject_configsets reads it back from disk. Leaving as-is instead of reading all in memory in case there's a reason.
  Lono::Configset::Preparer.new(@options).run # register and materialize gems
  Lono::Template::ConfigsetInjector.new(@options).run
end

#param_generatorObject



31
32
33
34
35
36
37
38
# File 'lib/lono/generate.rb', line 31

def param_generator
  o = {
    regenerate: true,
    allow_not_exists: true,
  }.merge(@options)
  o = HashWithIndifferentAccess.new(o)
  Lono::Param::Generator.new(o)
end

#post_generateObject



23
24
25
26
27
28
29
# File 'lib/lono/generate.rb', line 23

def post_generate
  return if @options[:noop]
  return if @options[:source]

  build_files # builds app/files to output/BLUEPRINT/files
  post_process_template
end

#post_process_templateObject



67
68
69
# File 'lib/lono/generate.rb', line 67

def post_process_template
  Lono::Template::PostProcessor.new(@options).run
end

#pre_generateObject



19
20
21
# File 'lib/lono/generate.rb', line 19

def pre_generate
  build_scripts
end

#uploadObject



71
72
73
74
75
# File 'lib/lono/generate.rb', line 71

def upload
  upload_files
  upload_scripts
  upload_templates
end

#upload_filesObject



85
86
87
88
# File 'lib/lono/generate.rb', line 85

def upload_files
  Lono::AppFile::Upload.new(@options).upload
  Lono::Configset::S3File::Upload.new(@options).upload
end

#upload_scriptsObject



81
82
83
# File 'lib/lono/generate.rb', line 81

def upload_scripts
  Lono::Script::Upload.new(@options).run
end

#upload_templatesObject



77
78
79
# File 'lib/lono/generate.rb', line 77

def upload_templates
  Lono::Template::Upload.new(@options).run
end