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

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

#build_filesObject



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

def build_files
  Lono::AppFile::Build.new(@options).run
end

#build_scriptsObject



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

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

#check_filesObject



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

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

#check_for_errorsObject



76
77
78
79
80
81
82
83
# File 'lib/lono/generate.rb', line 76

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



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

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

#generate_templatesObject



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

def generate_templates
  Lono::Template::Generator.new(@options).run
end

#param_generatorObject



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

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
30
# 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
  upload_files
  upload_scripts
end

#post_process_templateObject



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

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

#upload_filesObject



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

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

#upload_scriptsObject



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

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

#upload_templatesObject



64
65
66
# File 'lib/lono/generate.rb', line 64

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