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 generate_only?
  pre_generate
  generate_templates # generates with some placeholders for build_files IE: file://app/files/my.rb
  post_generate
  upload unless generate_only?

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

#build_filesObject



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

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



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

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

#check_filesObject



103
104
105
106
107
108
109
# File 'lib/lono/generate.rb', line 103

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

#check_for_errorsObject



94
95
96
97
98
99
100
101
# File 'lib/lono/generate.rb', line 94

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



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

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

#generate_only?Boolean

Returns:

  • (Boolean)


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

def generate_only?
  ENV['LONO_GENERATE_ONLY'] || @options[:generate_only]
end

#generate_templatesObject



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

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

#inject_configsetsObject



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

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



35
36
37
38
39
40
41
42
# File 'lib/lono/generate.rb', line 35

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

#post_generateObject



27
28
29
30
31
32
33
# File 'lib/lono/generate.rb', line 27

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



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

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

#pre_generateObject



23
24
25
# File 'lib/lono/generate.rb', line 23

def pre_generate
  build_scripts
end

#uploadObject



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

def upload
  upload_files
  upload_scripts
  upload_templates
end

#upload_filesObject



89
90
91
92
# File 'lib/lono/generate.rb', line 89

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

#upload_scriptsObject



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

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

#upload_templatesObject



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

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