lib/lono/param/generator.rb in lono-3.4.1 vs lib/lono/param/generator.rb in lono-3.5.0
- old
+ new
@@ -1,13 +1,12 @@
class Lono::Param::Generator
include Lono::CurrentRegion
def self.generate_all(options)
puts "Generating params files"
- project_root = options[:project_root] || '.'
- params = param_names(project_root, "base") + param_names(project_root, LONO_ENV)
+ params = param_names("base") + param_names(Lono.env)
params.uniq.each do |name|
param = Lono::Param::Generator.new(name, options)
param.generate
end
end
@@ -16,23 +15,22 @@
# Example:
# Given params:
# params/base/a.txt params/base/b.txt params/base/c.txt
# Returns:
# param_names("base") => ["a", "b", "c"]
- def self.param_names(project_root, folder)
- base_folder = "#{project_root}/params/#{folder}" # Example: "./params/base"
+ def self.param_names(folder)
+ base_folder = "#{Lono.root}/params/#{folder}" # Example: "./params/base"
Dir.glob("#{base_folder}/**/*.txt").map do |path|
path.sub("#{base_folder}/", '').sub('.txt','')
end
end
def initialize(name, options)
- @_name = "#{LONO_ENV}/#{name}"
+ @_name = "#{Lono.env}/#{name}"
@_options = options
- @_project_root = options[:project_root] || '.'
- @_env_path = options[:path] || "#{@_project_root}/params/#{@_name}.txt"
- @_base_path = @_env_path.sub("/#{LONO_ENV}/", "/base/")
+ @_env_path = options[:path] || "#{Lono.root}/params/#{@_name}.txt"
+ @_base_path = @_env_path.sub("/#{Lono.env}/", "/base/")
end
def generate
# useful option for lono cfn
return if @_options[:allow_no_file] && !source_exist?
@@ -42,11 +40,11 @@
data = convert_to_cfn_format(contents)
json = JSON.pretty_generate(data)
write_output(json)
# Example: @_name = stag/ecs/private
# pretty_name = ecs/private
- pretty_name = @_name.sub("#{LONO_ENV}/", '')
+ pretty_name = @_name.sub("#{Lono.env}/", '')
puts "Params file generated for #{pretty_name} at #{output_path}" unless @_options[:mute]
else
puts "#{@_base_path} or #{@_env_path} could not be found? Are you sure it exist?"
exit 1
end
@@ -177,11 +175,11 @@
end
params
end
def output_path
- "#{@_project_root}/output/params/#{@_name}.json".sub(/\.\//,'')
+ "#{Lono.root}/output/params/#{@_name}.json".sub(/\.\//,'')
end
def write_output(json)
dir = File.dirname(output_path)
FileUtils.mkdir_p(dir) unless File.exist?(dir)
@@ -189,11 +187,11 @@
end
def load_variables
load_variables_folder("base")
- load_variables_folder(LONO_ENV)
+ load_variables_folder(Lono.env)
end
# Load the variables defined in config/variables/* to make available the params/*.txt files
#
# Example:
@@ -203,10 +201,10 @@
#
# `params/ecs/private.txt`:
# AmiId=<%= @ami %>
#
def load_variables_folder(folder)
- paths = Dir.glob("#{@_project_root}/config/variables/#{folder}/**/*")
+ paths = Dir.glob("#{Lono.root}/config/variables/#{folder}/**/*")
paths.select{ |e| File.file? e }.each do |path|
instance_eval(IO.read(path))
end
end
end