lono 6.1.11 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (240) hide show
  1. checksums.yaml +4 -4
  2. data/.cody/acceptance.sh +19 -3
  3. data/.gitignore +2 -2
  4. data/CHANGELOG.md +16 -1
  5. data/README.md +18 -20
  6. data/Rakefile +1 -0
  7. data/lib/lono.rb +7 -5
  8. data/lib/lono/abstract_base.rb +25 -0
  9. data/lib/lono/api/client.rb +30 -0
  10. data/lib/lono/api/proxy.rb +58 -0
  11. data/lib/lono/api/repos.rb +8 -0
  12. data/lib/lono/api/verify.rb +13 -0
  13. data/lib/lono/app_file/base.rb +4 -11
  14. data/lib/lono/app_file/build.rb +1 -1
  15. data/lib/lono/app_file/upload.rb +1 -4
  16. data/lib/lono/autoloader.rb +3 -1
  17. data/lib/lono/aws_services.rb +9 -9
  18. data/lib/lono/aws_services/helper.rb +14 -0
  19. data/lib/lono/aws_services/{util.rb → stack.rb} +1 -9
  20. data/lib/lono/aws_services/stack_set.rb +41 -0
  21. data/lib/lono/blueprint.rb +2 -2
  22. data/lib/lono/blueprint/configset/loader.rb +7 -0
  23. data/lib/lono/blueprint/helper.rb +8 -2
  24. data/lib/lono/blueprint/meta.rb +4 -12
  25. data/lib/lono/blueprint/new.rb +3 -3
  26. data/lib/lono/blueprint/root.rb +6 -26
  27. data/lib/lono/bundle.rb +54 -0
  28. data/lib/lono/cfn.rb +31 -75
  29. data/lib/lono/cfn/base.rb +39 -136
  30. data/lib/lono/cfn/cancel.rb +14 -9
  31. data/lib/lono/cfn/create.rb +15 -19
  32. data/lib/lono/cfn/delete.rb +9 -9
  33. data/lib/lono/cfn/deploy.rb +4 -4
  34. data/lib/lono/cfn/download.rb +27 -9
  35. data/lib/lono/cfn/opts.rb +80 -0
  36. data/lib/lono/cfn/preview/changeset.rb +23 -23
  37. data/lib/lono/cfn/preview/codediff.rb +5 -6
  38. data/lib/lono/cfn/preview/param.rb +10 -10
  39. data/lib/lono/cfn/rollback.rb +5 -5
  40. data/lib/lono/cfn/status.rb +0 -10
  41. data/lib/lono/cfn/update.rb +22 -27
  42. data/lib/lono/clean.rb +3 -3
  43. data/lib/lono/cli.rb +69 -34
  44. data/lib/lono/code.rb +22 -0
  45. data/lib/lono/command.rb +7 -0
  46. data/lib/lono/config_location.rb +6 -13
  47. data/lib/lono/configset.rb +9 -0
  48. data/lib/lono/configset/combiner.rb +128 -0
  49. data/lib/lono/configset/evaluate_file.rb +8 -0
  50. data/lib/lono/configset/list.rb +67 -0
  51. data/lib/lono/configset/loader.rb +98 -0
  52. data/lib/lono/configset/loader/dsl.rb +9 -0
  53. data/lib/lono/configset/materializer/final.rb +10 -0
  54. data/lib/lono/configset/materializer/gems_builder.rb +81 -0
  55. data/lib/lono/configset/materializer/jade.rb +15 -0
  56. data/lib/lono/configset/materializer/source.rb +54 -0
  57. data/lib/lono/configset/meta.rb +19 -0
  58. data/lib/lono/configset/meta/dsl.rb +12 -0
  59. data/lib/lono/configset/new.rb +84 -0
  60. data/lib/lono/configset/preparer.rb +44 -0
  61. data/lib/lono/configset/register/base.rb +121 -0
  62. data/lib/lono/configset/register/blueprint.rb +16 -0
  63. data/lib/lono/configset/register/dsl.rb +15 -0
  64. data/lib/lono/configset/register/project.rb +12 -0
  65. data/lib/lono/configset/registry.rb +34 -0
  66. data/lib/lono/configset/resolver.rb +42 -0
  67. data/lib/lono/conventions.rb +18 -7
  68. data/lib/lono/core.rb +16 -20
  69. data/lib/lono/default/settings.yml +2 -3
  70. data/lib/lono/ext/bundler.rb +7 -0
  71. data/lib/lono/file_uploader.rb +8 -5
  72. data/lib/lono/finder/base.rb +140 -0
  73. data/lib/lono/finder/blueprint.rb +11 -0
  74. data/lib/lono/finder/blueprint/configset.rb +17 -0
  75. data/lib/lono/finder/configset.rb +11 -0
  76. data/lib/lono/generate.rb +93 -0
  77. data/lib/lono/help/blueprint/new.md +0 -1
  78. data/lib/lono/help/cfn/delete.md +1 -1
  79. data/lib/lono/help/cfn/deploy.md +5 -76
  80. data/lib/lono/help/cfn/status.md +0 -4
  81. data/lib/lono/help/cfn/update.md +1 -1
  82. data/lib/lono/help/code/convert.md +51 -0
  83. data/lib/lono/help/code/import.md +30 -0
  84. data/lib/lono/help/configsets.md +24 -0
  85. data/lib/lono/help/generate.md +4 -4
  86. data/lib/lono/help/new.md +1 -2
  87. data/lib/lono/help/sets/delete.md +8 -0
  88. data/lib/lono/help/sets/deploy.md +76 -0
  89. data/lib/lono/help/sets/instances/delete.md +21 -0
  90. data/lib/lono/help/sets/instances/list.md +14 -0
  91. data/lib/lono/help/sets/instances/status.md +15 -0
  92. data/lib/lono/help/sets/instances/sync.md +88 -0
  93. data/lib/lono/help/sets/status.md +23 -0
  94. data/lib/lono/help/upgrade.md +1 -0
  95. data/lib/lono/importer.rb +22 -0
  96. data/lib/lono/importer/base.rb +59 -0
  97. data/lib/lono/importer/converter.rb +19 -0
  98. data/lib/lono/importer/download.rb +46 -0
  99. data/lib/lono/importer/dsl.rb +36 -0
  100. data/lib/lono/importer/erb.rb +31 -0
  101. data/lib/lono/importer/params.rb +56 -0
  102. data/lib/lono/importer/service/coder.rb +81 -0
  103. data/lib/lono/inspector/base.rb +12 -22
  104. data/lib/lono/inspector/graph.rb +1 -1
  105. data/lib/lono/inspector/summary.rb +41 -17
  106. data/lib/lono/jade.rb +103 -0
  107. data/lib/lono/jade/circular.rb +26 -0
  108. data/lib/lono/jadespec.rb +41 -0
  109. data/lib/lono/new.rb +2 -2
  110. data/lib/lono/opts.rb +43 -0
  111. data/lib/lono/output/template.rb +48 -0
  112. data/lib/lono/param.rb +3 -5
  113. data/lib/lono/param/generator.rb +13 -33
  114. data/lib/lono/pro.rb +15 -0
  115. data/lib/lono/pro/base.rb +16 -0
  116. data/lib/lono/pro/repo.rb +27 -0
  117. data/lib/lono/project_checker.rb +4 -29
  118. data/lib/lono/registration.rb +15 -0
  119. data/lib/lono/registration/base.rb +37 -0
  120. data/lib/lono/registration/check.rb +15 -0
  121. data/lib/lono/registration/temp.rb +60 -0
  122. data/lib/lono/registration/user.rb +54 -0
  123. data/lib/lono/script/base.rb +1 -10
  124. data/lib/lono/script/upload.rb +2 -12
  125. data/lib/lono/seed.rb +2 -11
  126. data/lib/lono/seed/base.rb +55 -110
  127. data/lib/lono/sets.rb +38 -0
  128. data/lib/lono/sets/base.rb +45 -0
  129. data/lib/lono/sets/create.rb +30 -0
  130. data/lib/lono/sets/delete.rb +47 -0
  131. data/lib/lono/sets/deploy.rb +11 -0
  132. data/lib/lono/sets/instances.rb +33 -0
  133. data/lib/lono/sets/instances/base.rb +30 -0
  134. data/lib/lono/sets/instances/delete.rb +69 -0
  135. data/lib/lono/sets/instances/list.rb +13 -0
  136. data/lib/lono/sets/instances/opts.rb +29 -0
  137. data/lib/lono/sets/instances/status.rb +12 -0
  138. data/lib/lono/sets/instances/sync.rb +182 -0
  139. data/lib/lono/sets/list.rb +35 -0
  140. data/lib/lono/sets/opts.rb +18 -0
  141. data/lib/lono/sets/preview/codediff.rb +35 -0
  142. data/lib/lono/sets/preview/param.rb +32 -0
  143. data/lib/lono/sets/status.rb +116 -0
  144. data/lib/lono/sets/status/instance.rb +20 -0
  145. data/lib/lono/sets/status/instance/base.rb +120 -0
  146. data/lib/lono/sets/status/instance/completed.rb +35 -0
  147. data/lib/lono/sets/status/instance/deleted.rb +32 -0
  148. data/lib/lono/sets/status/instance/show.rb +7 -0
  149. data/lib/lono/sets/status/instances.rb +111 -0
  150. data/lib/lono/sets/summarize.rb +20 -0
  151. data/lib/lono/sets/time_spent.rb +11 -0
  152. data/lib/lono/sets/update.rb +81 -0
  153. data/lib/lono/template.rb +5 -7
  154. data/lib/lono/template/configset_injector.rb +50 -0
  155. data/lib/lono/template/context.rb +4 -4
  156. data/lib/lono/template/context/loader.rb +4 -16
  157. data/lib/lono/template/evaluate.rb +2 -1
  158. data/lib/lono/template/generator.rb +17 -15
  159. data/lib/lono/template/helper.rb +7 -7
  160. data/lib/lono/template/post_processor.rb +2 -12
  161. data/lib/lono/template/strategy/base.rb +4 -0
  162. data/lib/lono/template/{dsl.rb → strategy/dsl.rb} +4 -6
  163. data/lib/lono/template/{dsl → strategy/dsl}/builder.rb +11 -15
  164. data/lib/lono/template/{dsl → strategy/dsl}/builder/fn.rb +1 -1
  165. data/lib/lono/template/strategy/dsl/builder/helpers.rb +11 -0
  166. data/lib/lono/template/strategy/dsl/builder/helpers/core_helper.rb +14 -0
  167. data/lib/lono/template/strategy/dsl/builder/helpers/file_helper.rb +48 -0
  168. data/lib/lono/template/strategy/dsl/builder/helpers/lookup_helper.rb +27 -0
  169. data/lib/lono/template/strategy/dsl/builder/helpers/s3_helper.rb +13 -0
  170. data/lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb +39 -0
  171. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/base.rb +6 -17
  172. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/condition.rb +1 -1
  173. data/lib/lono/template/strategy/dsl/builder/section/extensions.rb +9 -0
  174. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/mapping.rb +1 -1
  175. data/lib/lono/template/{dsl/builder/section_methods.rb → strategy/dsl/builder/section/methods.rb} +9 -2
  176. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/output.rb +1 -1
  177. data/lib/lono/template/strategy/dsl/builder/section/parameter.rb +69 -0
  178. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/resource.rb +1 -1
  179. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/resource/property_mover.rb +1 -1
  180. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/section.rb +1 -1
  181. data/lib/lono/template/{dsl → strategy/dsl}/builder/squeezer.rb +1 -1
  182. data/lib/lono/template/strategy/dsl/builder/stringify.rb +15 -0
  183. data/lib/lono/template/{dsl → strategy/dsl}/builder/syntax.rb +3 -2
  184. data/lib/lono/template/strategy/dsl/finalizer.rb +12 -0
  185. data/lib/lono/template/strategy/dsl/finalizer/parameter_groups.rb +56 -0
  186. data/lib/lono/template/{erb.rb → strategy/erb.rb} +5 -5
  187. data/lib/lono/template/strategy/source.rb +8 -0
  188. data/lib/lono/template/template.rb +1 -1
  189. data/lib/lono/template/upload.rb +4 -9
  190. data/lib/lono/template/util.rb +0 -40
  191. data/lib/lono/upgrade.rb +12 -10
  192. data/lib/lono/user_data.rb +4 -4
  193. data/lib/lono/utils/pretty_time.rb +14 -0
  194. data/lib/lono/utils/sure.rb +23 -0
  195. data/lib/lono/version.rb +1 -1
  196. data/lib/lono/yamler/loader.rb +52 -0
  197. data/lib/lono/yamler/validator.rb +51 -0
  198. data/lib/templates/blueprint/%blueprint_name%.gemspec.tt +4 -0
  199. data/lib/templates/blueprint/README.md.tt +1 -1
  200. data/lib/templates/blueprint/seed/configs.rb +2 -2
  201. data/lib/templates/blueprint_types/dsl/app/templates/%blueprint_name%.rb +17 -18
  202. data/lib/templates/blueprint_types/erb/app/templates/%blueprint_name%.yml +63 -4
  203. data/lib/templates/configset/%configset_name%.gemspec.tt +41 -0
  204. data/lib/templates/configset/.gitignore +11 -0
  205. data/lib/templates/configset/CHANGELOG.md +7 -0
  206. data/lib/templates/configset/Gemfile +4 -0
  207. data/lib/templates/configset/README.md.tt +3 -0
  208. data/lib/templates/configset/Rakefile.tt +9 -0
  209. data/lib/templates/configset/lib/configset.yml +20 -0
  210. data/lib/templates/skeleton/.gitignore +1 -0
  211. data/lib/templates/skeleton/Gemfile +0 -1
  212. data/lib/templates/skeleton/README.md +4 -4
  213. data/lib/templates/skeleton/configs/settings.yml +1 -1
  214. data/lono.gemspec +1 -4
  215. metadata +146 -79
  216. data/Guardfile +0 -19
  217. data/lib/lono/app_file.rb +0 -5
  218. data/lib/lono/blueprint/find.rb +0 -90
  219. data/lib/lono/blueprint/info.rb +0 -10
  220. data/lib/lono/blueprint/list.rb +0 -14
  221. data/lib/lono/cfn/current.rb +0 -95
  222. data/lib/lono/cfn/preview.rb +0 -4
  223. data/lib/lono/cfn/suffix.rb +0 -67
  224. data/lib/lono/cfn/util.rb +0 -27
  225. data/lib/lono/help/cfn/current.md +0 -18
  226. data/lib/lono/help/upgrade4.md +0 -25
  227. data/lib/lono/inspector.rb +0 -4
  228. data/lib/lono/output_template.rb +0 -35
  229. data/lib/lono/template/base.rb +0 -13
  230. data/lib/lono/template/dsl/builder/helpers.rb +0 -8
  231. data/lib/lono/template/dsl/builder/helpers/core_helper.rb +0 -107
  232. data/lib/lono/template/dsl/builder/helpers/param_helper.rb +0 -61
  233. data/lib/lono/template/dsl/builder/parameter.rb +0 -39
  234. data/lib/lono/upgrade/upgrade4.rb +0 -175
  235. data/lib/lono/upgrade/upgrade42.rb +0 -36
  236. data/lib/lono/upgrade/upgrade5.rb +0 -55
  237. data/lib/templates/blueprint/.meta/config.yml.tt +0 -4
  238. data/lib/templates/skeleton/Guardfile +0 -12
  239. data/lib/templates/upgrade5/blueprints/main/.lono/config.yml +0 -3
  240. data/lib/templates/upgrade5/blueprints/main/.meta/config.yml +0 -3
@@ -0,0 +1,81 @@
1
+ require 'base64'
2
+ require 'json'
3
+ require 'net/http'
4
+
5
+ class Lono::Importer::Service::Coder
6
+ def initialize(template, options={})
7
+ @template, @options = template, options
8
+ end
9
+
10
+ def translate
11
+ url = "#{Lono::API}/code"
12
+ http = net_http_client(url)
13
+ req = net_http_request(url,
14
+ template: Base64.encode64(@template), # Base64 JSON for special chars that Rack::LintWrapper cannot process
15
+ lono_version: Lono::VERSION,
16
+ lono_command: lono_command,
17
+ )
18
+ res = http.request(req) # send request
19
+
20
+ if res.code == "200"
21
+ data = JSON.load(res.body)
22
+ ruby_code = print(data) # returns data["ruby_code"] / passthrough
23
+ ruby_code
24
+ else
25
+ puts "Error: Unable to convert template to Ruby code."
26
+ puts "The error has been reported."
27
+ puts "Non-successful http response status code: #{res.code}"
28
+ # puts "headers: #{res.each_header.to_h.inspect}"
29
+ exit 1
30
+ end
31
+ end
32
+
33
+ private
34
+ def print(data)
35
+ return if ENV['LONO_PRO_TEST']
36
+
37
+ if data["error"]
38
+ # Code was processed but there was this error with an HTTP 200 OK
39
+ $stderr.puts "ERROR: #{data["error"]}".color(:red)
40
+ if data["message"]
41
+ $stderr.puts data["message"]
42
+ end
43
+ return
44
+ end
45
+
46
+ validity = data["valid_ruby"] ? "valid" : "invalid"
47
+ if validity == "valid"
48
+ $stderr.puts "INFO: The generated Ruby code is has #{validity} syntax."
49
+ else
50
+ $stderr.puts "WARN: The generated Ruby code is has #{validity} syntax. Providing because it may be small errors.".color(:yellow) # note redirection disables color
51
+ end
52
+
53
+ $stderr.puts <<~EOL
54
+ Translated ruby code below:
55
+
56
+ EOL
57
+ ruby_code = data["ruby_code"]
58
+ puts ruby_code
59
+ ruby_code
60
+ end
61
+
62
+ def net_http_client(url)
63
+ uri = URI(url)
64
+ http = Net::HTTP.new(uri.host, uri.port)
65
+ http.open_timeout = http.read_timeout = 30
66
+ http.use_ssl = true if uri.scheme == 'https'
67
+ http
68
+ end
69
+
70
+ def net_http_request(url, data)
71
+ req = Net::HTTP::Post.new(url) # url includes query string and uri.path does not, must used url
72
+ text = JSON.dump(data)
73
+ req.body = text
74
+ req.content_length = text.bytesize
75
+ req
76
+ end
77
+
78
+ def lono_command
79
+ "#{$0} #{ARGV.join(' ')}"
80
+ end
81
+ end
@@ -1,30 +1,25 @@
1
1
  module Lono::Inspector
2
- class Base
3
- delegate :required_parameters, :optional_parameters, :parameters, :data,
4
- to: :output_template
5
-
2
+ class Base < Lono::AbstractBase
6
3
  extend Memoist
7
- include Lono::Blueprint::Root
8
4
 
9
- def initialize(blueprint, template, options)
10
- @blueprint, @template, @options = blueprint, template, options
5
+ def run
6
+ generate
7
+ templates = @template_name ? [@template_name] : all_templates
8
+ templates.each do |template_name|
9
+ perform(template_name)
10
+ end
11
11
  end
12
12
 
13
- def run
14
- blueprints = Lono::Blueprint::Find.one_or_all(@blueprint)
15
- blueprints.each do |blueprint|
16
- @blueprint = blueprint # intentional overwrite
13
+ def generate
14
+ if @options[:source]
15
+ Lono::Cfn::Download.new(@options).run
16
+ else
17
17
  generate_templates
18
- set_blueprint_root(blueprint)
19
- templates = @template_name ? [@template_name] : all_templates
20
- templates.each do |template_name|
21
- perform(template_name)
22
- end
23
18
  end
24
19
  end
25
20
 
26
21
  def generate_templates
27
- Lono::Template::Generator.new(@blueprint, @options.clone.merge(quiet: false)).run
22
+ Lono::Template::Generator.new(@options.merge(quiet: false)).run
28
23
  end
29
24
 
30
25
  def all_templates
@@ -33,10 +28,5 @@ module Lono::Inspector
33
28
  path.sub("#{templates_path}/", '').sub('.yml','') # template_name
34
29
  end
35
30
  end
36
-
37
- def output_template
38
- Lono::OutputTemplate.new(@blueprint, @template)
39
- end
40
- memoize :output_template
41
31
  end
42
32
  end
@@ -3,7 +3,7 @@ require "graph"
3
3
 
4
4
  module Lono::Inspector
5
5
  class Graph < Base
6
- def initialize(blueprint, template, options)
6
+ def initialize(options={})
7
7
  super
8
8
  @nodes = [] # lookup map
9
9
  end
@@ -1,5 +1,8 @@
1
1
  module Lono::Inspector
2
2
  class Summary < Base
3
+ delegate :required_parameters, :optional_parameters, :parameters, :parameter_groups, :data,
4
+ to: :output_template
5
+
3
6
  def perform(template)
4
7
  # little dirty but @template is used in data method so we dont have to pass it to the data method
5
8
  @template = template
@@ -8,34 +11,50 @@ module Lono::Inspector
8
11
  return if @options[:noop]
9
12
 
10
13
  print_parameters_summary
11
-
12
- puts "Resources:"
14
+ puts "# Resources:"
13
15
  print_resource_types
14
16
  end
15
17
 
16
18
  def print_parameters_summary
17
19
  if parameters.empty?
18
20
  puts "There are no parameters in this template."
19
- else
20
- print_parameters("Required Parameters (#{required_parameters.size})", required_parameters)
21
- print_parameters("Optional Parameters (#{optional_parameters.size})", optional_parameters)
21
+ return
22
+ end
23
+
24
+ shown = []
25
+ puts "# Parameters Total (#{parameters.size})"
26
+ parameter_groups.each do |label, parameters|
27
+ puts "# Parameter Group (#{parameters.size}): #{label}"
28
+ parameters.each do |name|
29
+ puts parameter_line(name)
30
+ shown << name
31
+ end
32
+ end if output_template.parameter_groups
33
+
34
+ parameters.each do |name, data|
35
+ puts parameter_line(name) unless shown.include?(name)
22
36
  end
23
37
  end
24
38
 
25
- def print_parameters(label, parameters)
26
- puts "#{label}:"
27
- if parameters.empty?
28
- text = label.downcase.include?("required") ? "required" : "optional"
29
- puts " There are no #{text} parameters."
39
+ def parameter_line(name)
40
+ data = parameters[name]
41
+ example = description_example(data["Description"])
42
+ if data["Default"].nil?
43
+ line = "#{name}=#{example} # (required)"
30
44
  else
31
- parameters.each do |logical_id, p|
32
- output = " #{logical_id} (#{p["Type"]})"
33
- if p["Default"]
34
- output << " Default: #{p["Default"]}"
35
- end
36
- puts output
37
- end
45
+ default = data["Default"]
46
+ line = "# #{name}=#{default}"
47
+ line = "#{line} # #{example}" if example
38
48
  end
49
+ line
50
+ end
51
+
52
+ def description_example(description)
53
+ default = ''
54
+ return default unless description
55
+ md = description.match(/(Example|IE): (.*)/)
56
+ return default unless md
57
+ md[2]
39
58
  end
40
59
 
41
60
  def resource_types
@@ -62,5 +81,10 @@ module Lono::Inspector
62
81
  end
63
82
  printf "%3s %s\n", resource_types.size, "Total"
64
83
  end
84
+
85
+ def output_template
86
+ Lono::Output::Template.new(@blueprint, @template)
87
+ end
88
+ memoize :output_template
65
89
  end
66
90
  end
@@ -0,0 +1,103 @@
1
+ module Lono
2
+ class Jade
3
+ include Circular
4
+ extend Memoist
5
+ class_attribute :tracked
6
+ self.tracked = []
7
+ class_attribute :downloaded
8
+ self.downloaded = []
9
+
10
+ delegate :template_type, :auto_camelize, :source_type, to: :jadespec
11
+
12
+ attr_accessor :dependencies, :from, :depends_ons
13
+ attr_reader :name, :type, :registry, :jadespec
14
+ def initialize(name, type, registry={})
15
+ # type: one of blueprint, configset, blueprint/configset
16
+ # registry holds either original registry from configset definition or parent jade which can be used to get the original configset defintion
17
+ @name, @type, @registry = name, type, registry
18
+ @materialized = false
19
+ @resolved = false
20
+ @depends_ons = []
21
+ self.class.tracked << self
22
+ end
23
+
24
+ def repo
25
+ @registry.options[:repo] || @name
26
+ end
27
+
28
+ # root is kind of special. root is needed for materialization but can accidentally get called too early
29
+ # before materialization. So treat it specially with an error.
30
+ def root
31
+ raise "ERROR: root is not available until jade has been materialized" unless @jadespec
32
+ @jadespec.root
33
+ end
34
+
35
+ def dependencies
36
+ @depends_ons.map do |registry|
37
+ Lono::Jade.new(registry.depends_on, registry.parent.type, registry)
38
+ end
39
+ end
40
+
41
+ def resource_from_parent
42
+ parent = registry.parent # using local variable intentionally
43
+ resource = nil
44
+ while parent # go all the way to the highest parent
45
+ resource = parent.registry.resource
46
+ parent = parent.registry.parent
47
+ end
48
+ resource
49
+ end
50
+
51
+ def materialize
52
+ @jadespec = finder.find(@name)
53
+ download unless @jadespec
54
+ # Pretty tricky. Flush memoized finder(true) since download changes filesystem. Not memoizing at all is 2x slower
55
+ @jadespec = finder(true).find(@name)
56
+ return nil unless @jadespec
57
+ if @jadespec.source_type == "materialized"
58
+ # possible "duplicated" jade instances with same name but will uniq in final materialized Gemfile
59
+ self.class.downloaded << self
60
+ end
61
+ evaluate_meta_rb
62
+ @jadespec
63
+ end
64
+ memoize :materialize
65
+
66
+ # Must return config to set @jadespec in materialize
67
+ # Only allow download of Lono::Blueprint::Configset::Jade
68
+ # Other configsets should be configured in project Gemfile.
69
+ def download
70
+ return if finder.find(@name, local_only: true) # no need to download because locally found
71
+ # 4 cases:
72
+ # 1a) blueprint/configset top-level - download
73
+ # 1b) blueprint/configset depends_on - download
74
+ # 2a) configset top-level - dont download, will report to user with validate_all!
75
+ # 2b) configset depends_on - download
76
+ return unless %w[blueprint/configset configset].include?(@type) # TODO: support materializing nested blueprints later
77
+ # only download jades that came from depends_on
78
+ return unless @registry.parent || @type == "blueprint/configset"
79
+ jade = Lono::Configset::Materializer::Jade.new(self)
80
+ jade.build
81
+ end
82
+ memoize :download
83
+
84
+ def evaluate_meta_rb
85
+ return unless %w[blueprint/configset configset].include?(@type)
86
+ meta = Lono::Configset::Meta.new(self)
87
+ meta.evaluate
88
+ end
89
+
90
+ def resolved!
91
+ @resolved = true
92
+ end
93
+
94
+ def resolved?
95
+ @resolved
96
+ end
97
+
98
+ def finder
99
+ "Lono::Finder::#{@type.camelize}".constantize.new
100
+ end
101
+ memoize :finder
102
+ end
103
+ end
@@ -0,0 +1,26 @@
1
+ class Lono::Jade
2
+ module Circular
3
+ def check_for_circular_dependency!
4
+ circular = circular_dependency?
5
+ return unless circular
6
+
7
+ puts "ERROR: configset circular dependency detected".color(:red)
8
+ puts "circular dependency: #{parent_names.join(" => ")}"
9
+ exit 1
10
+ end
11
+
12
+ def circular_dependency?
13
+ parent_names.uniq.size != parent_names.size
14
+ end
15
+
16
+ def parent_names
17
+ names = [self.name] # include initial jade name to detect circular dependency earlier
18
+ parent = registry.parent
19
+ while parent
20
+ names << parent.name
21
+ parent = parent.registry.parent
22
+ end
23
+ names
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,41 @@
1
+ require "rubygems"
2
+
3
+ module Lono
4
+ class Jadespec
5
+ extend Memoist
6
+
7
+ delegate :name, to: :gemspec
8
+
9
+ attr_accessor :from
10
+ attr_reader :root, :source_type
11
+ def initialize(root, source_type)
12
+ @root, @source_type = root, source_type
13
+ end
14
+
15
+ def exist?
16
+ !!gemspec_file
17
+ end
18
+
19
+ def gemspec
20
+ Gem::Specification::load(gemspec_file)
21
+ end
22
+ memoize :gemspec
23
+
24
+ def gemspec_file
25
+ Dir.glob("#{@root}/*.gemspec").first
26
+ end
27
+
28
+ def template_type
29
+ metadata[:template_type] || "dsl"
30
+ end
31
+
32
+ def auto_camelize
33
+ metadata[:auto_camelize] || false
34
+ end
35
+
36
+ def metadata
37
+ gemspec.metadata.deep_symbolize_keys
38
+ end
39
+ memoize :metadata
40
+ end
41
+ end
@@ -58,7 +58,7 @@ module Lono
58
58
  return unless options[:bundle]
59
59
 
60
60
  puts "=> Installing dependencies with: bundle install"
61
- Bundler.with_clean_env do
61
+ Bundler.with_unbundled_env do
62
62
  system("BUNDLE_IGNORE_CONFIG=1 bundle install")
63
63
  end
64
64
  end
@@ -88,7 +88,7 @@ module Lono
88
88
 
89
89
  To list and create additional blueprints refer to https://lono.cloud/docs/core/blueprints
90
90
 
91
- More info: http://lono.cloud/
91
+ More info: https://lono.cloud/
92
92
  EOL
93
93
  end
94
94
  end
@@ -0,0 +1,43 @@
1
+ # Note moving this under Lono::CLI::Opts messes with the zeitwerk autoloader.
2
+ # A weird workaround is calling Lono::CLI::Opts right after the autoloader and then it seems to fix itself.
3
+ # It may be because there's a custom infleciton cli => CLI. Unsure.
4
+ # Unsure if there are other side-effects with the workaround so named this:
5
+ # Lono::Opts instead of Lono::CLI::Opts
6
+ #
7
+ # Also, there's Thor Options class, so this is named Opts to avoid having to fully qualify it.
8
+ module Lono
9
+ class Opts
10
+ def initialize(cli)
11
+ @cli = cli
12
+ end
13
+
14
+ def clean
15
+ with_cli_scope do
16
+ option :clean, type: :boolean, default: true, desc: "remove all output files before generating"
17
+ end
18
+ end
19
+
20
+ def source
21
+ with_cli_scope do
22
+ option :source, desc: "url or path to file with template"
23
+ end
24
+ end
25
+
26
+ def stack
27
+ with_cli_scope do
28
+ option :stack, desc: "stack name. defaults to blueprint name."
29
+ end
30
+ end
31
+
32
+ def template
33
+ with_cli_scope do
34
+ option :template, desc: "override convention and specify the template file to use"
35
+ end
36
+ end
37
+
38
+ private
39
+ def with_cli_scope(&block)
40
+ @cli.instance_eval(&block)
41
+ end
42
+ end
43
+ end