lono 8.0.0.pre.rc2 → 8.0.0.pre.rc3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -2
  3. data/Gemfile +1 -3
  4. data/lib/lono/app/callable_option/concern.rb +12 -0
  5. data/lib/lono/app/callable_option.rb +56 -0
  6. data/lib/lono/app.rb +22 -23
  7. data/lib/lono/autoloader.rb +1 -0
  8. data/lib/lono/aws_services/helper.rb +0 -2
  9. data/lib/lono/blueprint.rb +1 -18
  10. data/lib/lono/builder/allow/base.rb +54 -0
  11. data/lib/lono/builder/allow/env.rb +17 -0
  12. data/lib/lono/builder/allow/region.rb +20 -0
  13. data/lib/lono/builder/allow.rb +8 -0
  14. data/lib/lono/builder/configset/combiner.rb +145 -0
  15. data/lib/lono/builder/configset/definition/base.rb +47 -0
  16. data/lib/lono/builder/configset/definition/context.rb +29 -0
  17. data/lib/lono/{configset/strategy/helpers/dsl → builder/configset/definition/dsl/syntax}/auth.rb +1 -1
  18. data/lib/lono/{configset/strategy/helpers/dsl/core.rb → builder/configset/definition/dsl/syntax/content.rb} +12 -4
  19. data/lib/lono/{configset/strategy/helpers/dsl/syntax.rb → builder/configset/definition/dsl/syntax/core.rb} +15 -9
  20. data/lib/lono/{configset/strategy/helpers/dsl → builder/configset/definition/dsl/syntax}/package.rb +1 -1
  21. data/lib/lono/builder/configset/definition/dsl/syntax.rb +5 -0
  22. data/lib/lono/{configset/strategy → builder/configset/definition}/dsl.rb +10 -14
  23. data/lib/lono/{configset/strategy → builder/configset/definition}/erb.rb +13 -16
  24. data/lib/lono/builder/configset/definition.rb +18 -0
  25. data/lib/lono/builder/configset/evaluator.rb +10 -0
  26. data/lib/lono/builder/configset/registration.rb +35 -0
  27. data/lib/lono/builder/context.rb +40 -0
  28. data/lib/lono/builder/dsl/evaluator.rb +6 -55
  29. data/lib/lono/builder/dsl/finalizer/base.rb +8 -0
  30. data/lib/lono/builder/dsl/finalizer/configsets.rb +7 -28
  31. data/lib/lono/builder/dsl/finalizer/files/base.rb +4 -0
  32. data/lib/lono/builder/dsl/finalizer/files/build.rb +58 -0
  33. data/lib/lono/builder/dsl/finalizer/files/replace.rb +31 -0
  34. data/lib/lono/builder/dsl/finalizer/files.rb +9 -0
  35. data/lib/lono/builder/dsl/finalizer/parameter_groups.rb +4 -3
  36. data/lib/lono/builder/dsl/finalizer.rb +4 -2
  37. data/lib/lono/builder/dsl/helpers/files.rb +7 -0
  38. data/lib/lono/builder/dsl/helpers/partials.rb +48 -53
  39. data/lib/lono/builder/dsl/helpers/s3.rb +1 -1
  40. data/lib/lono/builder/dsl/helpers/ssm/fetcher.rb +3 -1
  41. data/lib/lono/builder/dsl/helpers/template_file.rb +18 -6
  42. data/lib/lono/builder/dsl/helpers.rb +1 -11
  43. data/lib/lono/builder/dsl/syntax/core/resource/property_mover.rb +11 -1
  44. data/lib/lono/builder/dsl/syntax/core/squeezer.rb +16 -2
  45. data/lib/lono/builder/dsl.rb +1 -1
  46. data/lib/lono/builder/param.rb +4 -1
  47. data/lib/lono/builder/template/upload.rb +2 -15
  48. data/lib/lono/cfn/cancel.rb +5 -5
  49. data/lib/lono/cfn/deploy/iam.rb +1 -1
  50. data/lib/lono/cfn/deploy.rb +32 -3
  51. data/lib/lono/cfn/download.rb +0 -1
  52. data/lib/lono/cfn/plan/changeset.rb +2 -2
  53. data/lib/lono/cfn/plan/diff/data.rb +11 -1
  54. data/lib/lono/cfn/plan/param.rb +1 -1
  55. data/lib/lono/cfn/plan/template.rb +2 -2
  56. data/lib/lono/cfn/plan.rb +1 -0
  57. data/lib/lono/cli/abstract.rb +0 -6
  58. data/lib/lono/cli/base.rb +5 -3
  59. data/lib/lono/cli/build.rb +16 -60
  60. data/lib/lono/cli/clean.rb +3 -2
  61. data/lib/lono/cli/code.rb +12 -12
  62. data/lib/lono/cli/help/new/helper/blueprint.md +17 -0
  63. data/lib/lono/cli/help/new/helper/project.md +16 -0
  64. data/lib/lono/cli/list.rb +3 -6
  65. data/lib/lono/cli/new/blueprint.rb +3 -7
  66. data/lib/lono/cli/new/configset.rb +11 -44
  67. data/lib/lono/cli/new/helper/blueprint.rb +26 -0
  68. data/lib/lono/cli/new/helper/project.rb +24 -0
  69. data/lib/lono/cli/new/helper.rb +8 -27
  70. data/lib/lono/cli/new/sequence.rb +6 -1
  71. data/lib/lono/cli/new.rb +8 -12
  72. data/lib/lono/cli/status.rb +18 -0
  73. data/lib/lono/cli.rb +6 -9
  74. data/lib/lono/command.rb +0 -1
  75. data/lib/lono/component.rb +29 -0
  76. data/lib/lono/concerns/aws_info.rb +14 -0
  77. data/lib/lono/concerns/names.rb +9 -0
  78. data/lib/lono/configset.rb +17 -0
  79. data/lib/lono/core.rb +1 -1
  80. data/lib/lono/ext/bundler.rb +7 -0
  81. data/lib/lono/ext/core/module.rb +31 -0
  82. data/lib/lono/ext/core/object.rb +32 -0
  83. data/lib/lono/ext/core/string.rb +9 -0
  84. data/lib/lono/ext.rb +4 -0
  85. data/lib/lono/files/base.rb +12 -0
  86. data/lib/lono/files/builder.rb +37 -0
  87. data/lib/lono/files/compressor.rb +53 -0
  88. data/lib/lono/files/concerns/post_processing.rb +35 -0
  89. data/lib/lono/files/concerns/registration.rb +13 -0
  90. data/lib/lono/files/registry.rb +6 -0
  91. data/lib/lono/files.rb +37 -0
  92. data/lib/lono/importer/base.rb +1 -1
  93. data/lib/lono/inspector/summary.rb +0 -3
  94. data/lib/lono/layering/layer.rb +3 -17
  95. data/lib/lono/logger.rb +1 -3
  96. data/lib/lono/names.rb +1 -1
  97. data/lib/lono/s3/uploader.rb +29 -28
  98. data/lib/lono/seeder.rb +18 -27
  99. data/lib/lono/user_data.rb +3 -1
  100. data/lib/lono/version.rb +1 -1
  101. data/lib/lono/yamler/validator.rb +7 -22
  102. data/lib/lono.rb +8 -0
  103. data/lib/templates/configset/configset.rb +2 -16
  104. data/lib/templates/examples/configset/configset.rb +16 -0
  105. data/lib/templates/helper/%underscore_name%_helper.rb.tt +1 -1
  106. data/lono.gemspec +1 -1
  107. metadata +52 -39
  108. data/lib/lono/app_file/base.rb +0 -28
  109. data/lib/lono/app_file/build/lambda_layer/ruby_packager.rb +0 -153
  110. data/lib/lono/app_file/build/lambda_layer.rb +0 -20
  111. data/lib/lono/app_file/build.rb +0 -79
  112. data/lib/lono/app_file/registry/item.rb +0 -24
  113. data/lib/lono/app_file/registry.rb +0 -16
  114. data/lib/lono/app_file/upload.rb +0 -12
  115. data/lib/lono/builder/context/generic.rb +0 -11
  116. data/lib/lono/builder/context/loaders/load_files.rb +0 -23
  117. data/lib/lono/builder/context/loaders.rb +0 -35
  118. data/lib/lono/builder/context/params.rb +0 -6
  119. data/lib/lono/builder/context/template.rb +0 -4
  120. data/lib/lono/configset/builder.rb +0 -59
  121. data/lib/lono/configset/combiner.rb +0 -164
  122. data/lib/lono/configset/evaluate_file.rb +0 -8
  123. data/lib/lono/configset/meta/dsl.rb +0 -12
  124. data/lib/lono/configset/meta.rb +0 -19
  125. data/lib/lono/configset/s3_file/build.rb +0 -34
  126. data/lib/lono/configset/s3_file/item.rb +0 -38
  127. data/lib/lono/configset/s3_file/registry.rb +0 -12
  128. data/lib/lono/configset/s3_file/upload.rb +0 -12
  129. data/lib/lono/configset/strategy/base.rb +0 -83
  130. data/lib/lono/configset/strategy/helpers/dsl.rb +0 -8
  131. data/lib/lono/configset/strategy/helpers/erb.rb +0 -9
  132. data/lib/lono/lookup.rb +0 -12
  133. data/lib/lono/seeder/service_role.rb +0 -11
  134. data/lib/lono/utils/contexts.rb +0 -15
  135. data/lib/lono/utils/item/file_methods.rb +0 -29
  136. data/lib/lono/utils/item/zip.rb +0 -42
@@ -1,56 +1,27 @@
1
1
  class Lono::CLI::New
2
2
  class Configset < Sequence
3
- argument :configset_name
4
-
5
- def self.source_root
6
- templates = File.expand_path("../../templates", File.dirname(__FILE__))
7
- "#{templates}/configset"
8
- end
9
-
3
+ argument :name
10
4
  def self.cli_options
11
5
  [
12
- [:demo, type: :boolean, default: true, desc: "Include demo template"],
13
- [:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files."],
6
+ [:examples, type: :boolean, desc: "Whether not to generate examples"],
7
+ [:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files"],
14
8
  ]
15
9
  end
16
-
17
10
  cli_options.each do |args|
18
11
  class_option(*args)
19
12
  end
20
13
 
21
- # for specs
22
- def set_cwd
23
- @cwd = ENV['LONO_TEST'] ? File.dirname(Lono.root) : "#{Dir.pwd}/app/configsets"
24
- end
25
-
26
- def set_variables
27
- @demo = @options[:demo]
28
- @demo = false if ENV["LONO_ORG"] # overrides --demo CLI option
29
- end
30
-
31
- def create_project
32
- puts "=> Creating new configset called #{configset_name}."
33
- if @demo
34
- options = {}
14
+ def set_source
15
+ if @options[:examples]
16
+ set_template_source "examples/configset"
35
17
  else
36
- create_file "#{@cwd}/#{configset_name}/lib/configset.rb"
37
- options = {exclude_pattern: %r{configset\.rb}}
18
+ set_template_source "configset"
38
19
  end
39
-
40
- directory ".", "#{@cwd}/#{configset_name}", options
41
- end
42
-
43
- def create_license
44
- return unless ENV['LONO_LICENSE_FILE']
45
- copy_file ENV['LONO_LICENSE_FILE'], "#{@cwd}/#{configset_name}/LICENSE.txt"
46
20
  end
47
21
 
48
- # After this commands are executed with the newly created project
49
- def set_destination_root
50
- destination_root = "#{@cwd}/#{configset_name}"
51
- self.destination_root = destination_root
52
- @old_dir = Dir.pwd # for reset_current_dir
53
- FileUtils.cd(self.destination_root)
22
+ def create_configset
23
+ dest = "#{Lono.root}/app/configsets"
24
+ directory ".", "#{dest}/#{name}"
54
25
  end
55
26
 
56
27
  def welcome_message
@@ -58,11 +29,7 @@ class Lono::CLI::New
58
29
  #{"="*64}
59
30
  Congrats 🎉 You have successfully created a lono configset.
60
31
 
61
- Cd into your configset and check things out.
62
-
63
- cd #{configset_name}
64
-
65
- More info: https://lono.cloud/docs/core/configsets
32
+ More info: https://lono.cloud/docs/configsets
66
33
 
67
34
  EOL
68
35
  end
@@ -0,0 +1,26 @@
1
+ class Lono::CLI::New::Helper
2
+ class Blueprint < Lono::CLI::New::Sequence
3
+ def self.cli_options
4
+ # required for name => underscore_name => app/blueprints/demo/helpers/%underscore_name%_helper.rb.tt
5
+ argument :name, default: "custom", desc: "Helper name"
6
+
7
+ [
8
+ [:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files"],
9
+ [:blueprint, required: true, desc: "Blueprint name"],
10
+ ]
11
+ end
12
+ cli_options.each do |args|
13
+ class_option(*args)
14
+ end
15
+
16
+ def set_source
17
+ set_template_source "helper"
18
+ end
19
+
20
+ def create_blueprint
21
+ @blueprint = @options[:blueprint] # allows %underscore_name%_helper.rb.tt to access @blueprint
22
+ logger.info "=> Generating #{underscore_name}_helper.rb"
23
+ directory ".", "app/blueprints/#{@blueprint}/helpers"
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,24 @@
1
+ class Lono::CLI::New::Helper
2
+ class Project < Lono::CLI::New::Sequence
3
+ def self.cli_options
4
+ # required for name => underscore_name => app/blueprints/demo/helpers/%underscore_name%_helper.rb.tt
5
+ argument :name, default: "custom", desc: "Helper name"
6
+
7
+ [
8
+ [:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files"],
9
+ ]
10
+ end
11
+ cli_options.each do |args|
12
+ class_option(*args)
13
+ end
14
+
15
+ def set_source
16
+ set_template_source "helper"
17
+ end
18
+
19
+ def create_blueprint
20
+ logger.info "=> Generating #{underscore_name}_helper.rb"
21
+ directory ".", "app/helpers/#{underscore_name}"
22
+ end
23
+ end
24
+ end
@@ -1,32 +1,13 @@
1
1
  class Lono::CLI::New
2
- class Helper < Sequence
3
- def self.cli_options
4
- [
5
- [:force, type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files"],
6
- [:blueprint, required: true, desc: "Blueprint name"],
7
- [:name, default: "custom", desc: "Helper name"],
8
- ]
9
- end
10
- cli_options.each do |args|
11
- class_option(*args)
12
- end
2
+ class Helper < Lono::Command
3
+ Help = Lono::CLI::Help
13
4
 
14
- def set_source
15
- set_template_source "helper"
16
- end
5
+ long_desc Help.text("new/helper/blueprint")
6
+ Blueprint.cli_options.each { |args| option(*args) }
7
+ register(Blueprint, "blueprint", "blueprint HELPER_NAME --blueprint", "Generates new blueprint helper")
17
8
 
18
- def set_vars
19
- @blueprint = @options[:blueprint]
20
- @name = @options[:name]
21
- end
22
-
23
- def create_blueprint
24
- puts "underscore_name #{underscore_name}"
25
- logger.info "=> Generating helper: #{@name}"
26
- directory ".", "app/blueprints/#{@blueprint}/helpers"
27
- end
28
-
29
- private
30
- attr_reader :name # required for templates/helper/%name%_helper.rb.tt
9
+ long_desc Help.text("new/helper/project")
10
+ Project.cli_options.each { |args| option(*args) }
11
+ register(Project, "project", "project HELPER_NAME", "Generates new project helper")
31
12
  end
32
13
  end
@@ -12,7 +12,8 @@ class Lono::CLI::New
12
12
 
13
13
  private
14
14
  def self.set_template_source(folder)
15
- source_root File.expand_path("../../../templates/#{folder}", __dir__)
15
+ path = File.expand_path("../../../templates/#{folder}", __dir__)
16
+ source_root path
16
17
  end
17
18
 
18
19
  def set_template_source(*paths)
@@ -47,5 +48,9 @@ class Lono::CLI::New
47
48
  puts "=> Initialize git repo"
48
49
  run("git init")
49
50
  end
51
+
52
+ def env
53
+ Lono.env # allows for seed/vars/%env%.rb.tt
54
+ end
50
55
  end
51
56
  end
data/lib/lono/cli/new.rb CHANGED
@@ -2,27 +2,23 @@ class Lono::CLI
2
2
  class New < Lono::Command
3
3
  long_desc Help.text("new/blueprint")
4
4
  Blueprint.cli_options.each { |args| option(*args) }
5
- register(Blueprint, "blueprint", "blueprint NAME", "Generates new blueprint.")
5
+ register(Blueprint, "blueprint", "blueprint NAME", "Generate new blueprint")
6
6
 
7
7
  long_desc Help.text("new/configset")
8
8
  Configset.cli_options.each { |args| option(*args) }
9
- register(Configset, "configset", "configset NAME", "Generates new configset.")
10
-
11
- long_desc Help.text("new/extension")
12
- Extension.cli_options.each { |args| option(*args) }
13
- register(Extension, "extension", "extension NAME", "Generates new extension.")
14
-
15
- long_desc Help.text("new/helper")
16
- Helper.cli_options.each { |args| option(*args) }
17
- register(Helper, "helper", "helper NAME", "Generates new helper.")
9
+ register(Configset, "configset", "configset NAME", "Generate new configset")
18
10
 
19
11
  long_desc Help.text("new/project")
20
12
  Project.cli_options.each { |args| option(*args) }
21
- register(Project, "project", "project NAME", "Generates new project.")
13
+ register(Project, "project", "project NAME", "Generate new project")
22
14
 
23
15
  long_desc Help.text("new/shim")
24
16
  Shim.cli_options.each { |args| option(*args) }
25
- register(Shim, "shim", "shim NAME", "Generates new shim.")
17
+ register(Shim, "shim", "shim NAME", "Generate new shim")
18
+
19
+ desc "helper SUBCOMMAND", "helper subcommands"
20
+ long_desc Help.text(:helper)
21
+ subcommand "helper", Helper
26
22
 
27
23
  desc "test SUBCOMMAND", "test subcommands"
28
24
  long_desc Help.text(:test)
@@ -0,0 +1,18 @@
1
+ class Lono::CLI
2
+ class Status < Lono::CLI::Base
3
+ include Lono::AwsServices
4
+
5
+ def run
6
+ names = Lono::Names.new(@options)
7
+ stack = find_stack(@stack)
8
+ if stack
9
+ status = Lono::Cfn::Status.new(@stack, @options)
10
+ success = status.run
11
+ exit 1 unless success
12
+ else
13
+ logger.error "ERROR: stack #{@stack} not found".color(:red)
14
+ exit 1
15
+ end
16
+ end
17
+ end
18
+ end
data/lib/lono/cli.rb CHANGED
@@ -5,7 +5,7 @@ module Lono
5
5
  opts = Opts.new(self)
6
6
  cfn_opts = Lono::CLI::Cfn::Opts.new(self)
7
7
 
8
- desc "build BLUEPRINT", "Build both CloudFormation template and parameters files"
8
+ desc "build BLUEPRINT", "Build template"
9
9
  long_desc Help.text(:build)
10
10
  option :quiet, type: :boolean, desc: "silence the output"
11
11
  opts.clean
@@ -25,14 +25,14 @@ module Lono
25
25
  Clean.new(options).run
26
26
  end
27
27
 
28
- desc "down BLUEPRINT", "Delete CloudFormation blueprint"
28
+ desc "down BLUEPRINT", "Delete stack"
29
29
  long_desc Help.text(:down)
30
30
  cfn_opts.delete
31
31
  def down(blueprint)
32
32
  Lono::Cfn::Delete.new(options.merge(blueprint: blueprint)).run
33
33
  end
34
34
 
35
- desc "list", "List blueprints, configsets, extensions, etc"
35
+ desc "list", "List blueprints"
36
36
  long_desc Help.text(:list)
37
37
  option :type, aliases: :t, desc: "Type: IE: blueprint, configset, extension. Defaults to all"
38
38
  def list
@@ -46,7 +46,7 @@ module Lono
46
46
  Lono::Cfn::Output.new(options.merge(blueprint: blueprint)).run
47
47
  end
48
48
 
49
- desc "plan BLUEPRINT", "Plan or preview of the deploy"
49
+ desc "plan BLUEPRINT", "Preview deploy"
50
50
  long_desc Help.text(:plan)
51
51
  option :out, aliases: :o, desc: "Write Change Set info to path"
52
52
  def plan(blueprint)
@@ -71,10 +71,7 @@ module Lono
71
71
  desc "status BLUEPRINT", "Shows current status of blueprint."
72
72
  long_desc Help.text(:status)
73
73
  def status(blueprint)
74
- names = Lono::Names.new(blueprint: blueprint)
75
- status = Lono::Cfn::Status.new(names.stack, options)
76
- success = status.run
77
- exit 3 unless success
74
+ Status.new(options.merge(blueprint: blueprint)).run
78
75
  end
79
76
 
80
77
  desc "summary BLUEPRINT", "Prints summary of CloudFormation template"
@@ -89,7 +86,7 @@ module Lono
89
86
  Test.new(options).run
90
87
  end
91
88
 
92
- desc "up BLUEPRINT", "Deploy CloudFormation stack"
89
+ desc "up BLUEPRINT", "Deploy stack"
93
90
  long_desc Help.text(:up)
94
91
  cfn_opts.deploy
95
92
  def up(blueprint)
data/lib/lono/command.rb CHANGED
@@ -48,7 +48,6 @@ module Lono
48
48
  # as well thor's normal way:
49
49
  #
50
50
  # lono help command
51
- help_flags = Thor::HELP_MAPPINGS + ["help"]
52
51
  if args.length > 1 && !(args & help_flags).empty?
53
52
  args -= help_flags
54
53
  args.insert(-2, "help")
@@ -0,0 +1,29 @@
1
+ module Lono
2
+ class Component
3
+ attr_reader :name
4
+ def initialize(options={})
5
+ @options = options
6
+ @name = options[:name]
7
+ end
8
+
9
+ def type
10
+ self.class.name.to_s.split('::').last.underscore # IE: blueprint
11
+ end
12
+
13
+ def exist?
14
+ !root.nil?
15
+ end
16
+
17
+ def type_dir
18
+ type.pluralize # IE: blueprints
19
+ end
20
+
21
+ def root
22
+ paths = Dir.glob("#{Lono.root}/{app,vendor}/#{type_dir}/*")
23
+ paths.find do |path|
24
+ found = path.sub(%r{.*/(app|vendor)/}, '')
25
+ found == "#{type_dir}/#{@name}" # exact match
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,14 @@
1
+ # Dont name AwsData. Think prefer AwsInfo vs AwsConcern
2
+ module Lono::Concerns
3
+ module AwsInfo
4
+ extend Memoist
5
+ delegate :region, to: :aws_data
6
+ alias_method :aws_region, :region
7
+ alias_method :current_region, :region
8
+
9
+ def aws_data
10
+ AwsData.new
11
+ end
12
+ memoize :aws_data
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ module Lono::Concerns
2
+ module Names
3
+ extend Memoist
4
+ def names
5
+ Lono::Names.new(@options)
6
+ end
7
+ memoize :names
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ module Lono
2
+ class Configset < Component
3
+ attr_reader :resource
4
+ attr_accessor :metadata
5
+ def initialize(options={})
6
+ super
7
+ @resource = options[:resource]
8
+ end
9
+
10
+ def path
11
+ return unless root
12
+ exts = %w[rb yml json] # rb highest precedence
13
+ paths = exts.map { |ext| "#{root}/configset.#{ext}" }
14
+ paths.find { |p| File.exist?(p) }
15
+ end
16
+ end
17
+ end
data/lib/lono/core.rb CHANGED
@@ -37,7 +37,7 @@ module Lono
37
37
  App.instance.configure(&block)
38
38
  end
39
39
 
40
- # Generally, use the Terraspace.config instead of App.instance.config since it guarantees the load_project_config call
40
+ # Generally, use the Lono.config instead of App.instance.config since it guarantees the load_project_config call
41
41
  def config
42
42
  App.instance.load_project_config
43
43
  App.instance.config
@@ -0,0 +1,7 @@
1
+ # Bundler 2.0 does yet not have with_unbundled_env
2
+ # Bundler 2.1 deprecates with_clean_env for with_unbundled_env
3
+
4
+ require "bundler"
5
+ def Bundler.with_unbundled_env(&block)
6
+ with_clean_env(&block)
7
+ end unless Bundler.respond_to?(:with_unbundled_env)
@@ -0,0 +1,31 @@
1
+ class Module
2
+ # Include all modules within the relative folder. IE: for dsl/syntax/mod/*
3
+ #
4
+ # include Common
5
+ # include Provider
6
+ # # etc
7
+ #
8
+ # Caller lines are different for OSes:
9
+ #
10
+ # windows: "C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/lono-1.1.1/lib/lono/builder.rb:34:in `build'"
11
+ # linux: "/home/ec2-user/.rvm/gems/ruby-3.0.3/gems/lono-1.1.1/lib/lono/compiler/dsl/syntax/mod.rb:4:in `<module:Mod>'"
12
+ #
13
+ def include_modules(dir)
14
+ caller_line = caller[0]
15
+ parts = caller_line.split(':')
16
+ calling_file = caller_line.match(/^[a-zA-Z]:/) ? parts[1] : parts[0]
17
+ parent_dir = File.dirname(calling_file)
18
+
19
+ full_dir = "#{parent_dir}/#{dir}"
20
+ paths = Dir.glob("#{full_dir}/**/*.rb")
21
+ if paths.empty?
22
+ raise "Empty include_modules full_dir: #{full_dir}"
23
+ end
24
+ paths.each do |path|
25
+ regexp = Regexp.new(".*/lib/")
26
+ mod = path.sub(regexp, '').sub('.rb','').camelize
27
+ c = mod.constantize
28
+ include c if c.class == Module
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,32 @@
1
+ class Object
2
+ # Load custom helper methods from project
3
+ def load_helper_files(dir, type: :blueprint)
4
+ paths = Dir.glob("#{dir}/**/*.rb")
5
+ paths.sort_by! { |p| p.size } # so namespaces are loaded first
6
+ paths.each do |path|
7
+ next unless File.file?(path)
8
+
9
+ filename = if type == :project
10
+ path.sub(%r{.*/helpers/[a-zA-Z\-_]+/},'').sub('.rb','')
11
+ else # blueprint, configset
12
+ path.sub(%r{.*/helpers/},'').sub('.rb','')
13
+ end
14
+ module_name = filename.camelize
15
+
16
+ # Prepend a period so require works when LONO_ROOT is set to a relative path without a period.
17
+ # Example: LONO_ROOT=tmp/lono_project
18
+ first_char = path[0..0]
19
+ path = "./#{path}" unless %w[. /].include?(first_char)
20
+
21
+ # Examples:
22
+ # project:
23
+ # path: app/helpers/custom/custom_helper.rb
24
+ # module_name: CustomHelper
25
+ # blueprint:
26
+ # path: app/blueprints/demo/helpers/outputs.rb
27
+ # module_name: Outputs
28
+ require path
29
+ self.class.send :include, module_name.constantize
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,9 @@
1
+ module Lono
2
+ refine String do
3
+ def camelcase
4
+ self.underscore.camelize
5
+ end
6
+ end
7
+ end
8
+
9
+ using Lono
data/lib/lono/ext.rb ADDED
@@ -0,0 +1,4 @@
1
+ require_relative "ext/bundler"
2
+ require_relative "ext/core/module"
3
+ require_relative "ext/core/object"
4
+ require_relative "ext/core/string"
@@ -0,0 +1,12 @@
1
+ class Lono::Files
2
+ class Base < Lono::CLI::Base
3
+ delegate :full_path, :output_path, :zip_name, :zip_path, to: :files
4
+ attr_reader :files
5
+ def initialize(options={})
6
+ super
7
+ # @files is reference to Lono::Files self instance
8
+ # IE: Lono::Files instance is the caller
9
+ @files = options[:files]
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,37 @@
1
+ class Lono::Files
2
+ class Builder < Base
3
+ extend Memoist
4
+ include Lono::Builder::Context
5
+ include Lono::Builder::Dsl::Syntax
6
+ # Tricky must define files again to avoid conflict with files from loading the Dsl::Syntax
7
+ attr_reader :files
8
+
9
+ def run
10
+ load_context
11
+ if File.directory?(full_path)
12
+ directory(@files)
13
+ else
14
+ template(@files)
15
+ end
16
+ end
17
+
18
+ def template(files)
19
+ sequence.send(:set_template_paths, @blueprint.root)
20
+ src = files.path
21
+ dest = files.output_path
22
+ sequence.template(src, dest)
23
+ end
24
+
25
+ def directory(files)
26
+ src = files.full_path
27
+ sequence.send(:set_template_paths, src)
28
+ sequence.destination_root = @files.output_path
29
+ sequence.directory(".", verbose: false, force: true, context: binding) # Thor::Action
30
+ end
31
+
32
+ def sequence
33
+ Lono::CLI::New::Sequence.new(@options)
34
+ end
35
+ memoize :sequence
36
+ end
37
+ end
@@ -0,0 +1,53 @@
1
+ require 'fileutils'
2
+
3
+ class Lono::Files
4
+ class Compressor < Base
5
+ def run
6
+ if File.directory?(output_path)
7
+ zip_directory
8
+ else
9
+ zip_file
10
+ end
11
+ end
12
+
13
+ def zip_file
14
+ logger.debug "Zipping file to #{pretty_path(zip_path)}"
15
+ # create zipfile at same level of file
16
+ command = "cd #{File.dirname(output_path)} && zip -q #{zip_name} #{File.basename(output_path)}"
17
+ execute_zip(command)
18
+ end
19
+
20
+ def zip_directory
21
+ logger.debug "Zipping folder to #{zip_path}"
22
+ command = "cd #{output_path} && zip --symlinks -rq #{zip_name} ." # create zipfile witih directory
23
+ execute_zip(command)
24
+ FileUtils.mv("#{output_path}/#{zip_name}", "#{File.dirname(output_path)}/#{zip_name}") # move zip back to the parent directory
25
+ end
26
+
27
+ private
28
+ def execute_zip(command)
29
+ check_zip_installed!
30
+ logger.debug "=> #{command}".color(:green)
31
+ `#{command}`
32
+ return if $?.success?
33
+ logger.info "ERROR: Fail trying to zip files".color(:red)
34
+ logger.info "Command: #{command}".color(:red)
35
+ exit 1
36
+ end
37
+
38
+ @@zip_installed = false
39
+ def check_zip_installed!
40
+ @@zip_installed = system("type zip > /dev/null 2>&1")
41
+ if @@zip_installed
42
+ @@zip_installed = true
43
+ return
44
+ end
45
+ logger.error "ERROR: The command 'zip' is not installed.".color(:red)
46
+ logger.error <<~EOL
47
+ The file helper requires the zip command.
48
+ Please install the zip command on this system.
49
+ EOL
50
+ exit 1
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,35 @@
1
+ module Lono::Files::Concerns
2
+ module PostProcessing
3
+ extend Memoist
4
+
5
+ def build
6
+ Lono::Files::Builder.new(@options.merge(files: self)).run
7
+ end
8
+
9
+ def compress
10
+ Lono::Files::Compressor.new(@options.merge(files: self)).run
11
+ end
12
+
13
+ def upload
14
+ uploader.upload # Lono::S3::Uploader#upload
15
+ end
16
+
17
+ delegate :s3_path, :s3_key, to: :uploader
18
+ def uploader
19
+ Lono::S3::Uploader.new(zip_path)
20
+ end
21
+ memoize :uploader
22
+
23
+ def zip_name
24
+ "#{File.basename(full_path)}-#{Lono::Md5.sum(full_path)}.zip"
25
+ end
26
+
27
+ def zip_path
28
+ "#{File.dirname(output_path)}/#{zip_name}"
29
+ end
30
+
31
+ def output_path
32
+ "#{Lono.root}/output/#{@blueprint.name}/#{path}"
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,13 @@
1
+ module Lono::Files::Concerns
2
+ module Registration
3
+ def call_line
4
+ @caller.find do |line|
5
+ line.include?(Lono.root.to_s)
6
+ end
7
+ end
8
+
9
+ def marker
10
+ "LONO://#{@path}"
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,6 @@
1
+ class Lono::Files
2
+ class Registry
3
+ class_attribute :files
4
+ self.files = []
5
+ end
6
+ end