afterlife 1.1.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad1fcadc1d4fa02e309f7fbffe6e10f1538844dd956381aec84dca99c075b336
4
- data.tar.gz: 4885395894cd313ddf440595c5c635733ce3a772d80f2d21756d2a15f424a551
3
+ metadata.gz: 4a748ce7d12a9ee07b9811468a33b25852ab857dc26e35af99ace77826f150c3
4
+ data.tar.gz: d969d2522b6cf783cb43426d3f8556ac5049f009fad5fba08b16065a91fd15cc
5
5
  SHA512:
6
- metadata.gz: '082b695c397a910107fea5a286e6d6179be4495670a96f550b881e831cee537726d9655be034e77fd4b9f4bb489f071d5974279ac4b80fcdb3aeb905218a98cc'
7
- data.tar.gz: 3301a025549f4a02582ac27151a33193447137d80809c90122031cd1f0727d3bf3bb8e197a0bb0480acdee4e8c2900a6bdf409e1efa358f3b6db9d8af9c9f54d
6
+ metadata.gz: 873c5cfa91704940ccbc7fff7a70d339c9f73271c63ba60e2f2b7011e61d58b601595982027f26e94f006ece37f2abd4061ac05179ba0a0f7ed444ce21dfc735
7
+ data.tar.gz: 1e064e211cd77e8ae137e047eaa877b9174ba6098296c8723aa05d2a9f6bf7bc9268ffa8e43ea877e25b05613499588548e3ee09120e5702133ba380c1e04156
data/lib/afterlife/cli.rb CHANGED
@@ -22,21 +22,8 @@ module Afterlife
22
22
  log_success 'afterlife is ready!'
23
23
  end
24
24
 
25
- desc 'config <path>', 'get config options'
26
- def config(path) # rubocop:disable Metrics/MethodLength
27
- path = path.split('.').map(&:to_sym)
28
- result = repo.conf.dig(*path)
29
- case result
30
- when Hash
31
- say JSON.generate(result)
32
- when Array
33
- result.each do |item|
34
- say item
35
- end
36
- else
37
- say result
38
- end
39
- end
25
+ desc 'config', 'Repo configuration options'
26
+ subcommand 'config', Config::Cli
40
27
 
41
28
  desc 'cdn', 'CDN stuff'
42
29
  subcommand 'cdn', Cdn::Cli
@@ -49,6 +36,8 @@ module Afterlife
49
36
  option :yes, type: :boolean
50
37
  def deploy(stage)
51
38
  invoke Deploy::Cli, :call, [stage], options
39
+ rescue Deploy::Error
40
+ fatal!(e.message)
52
41
  rescue Interrupt
53
42
  log_interrupted
54
43
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Afterlife
4
+ module Config
5
+ class Cli < Thor
6
+ include BaseCli
7
+ def self.exit_on_failure?
8
+ true
9
+ end
10
+
11
+ desc 'get <path>', 'get config path'
12
+ def get(path)
13
+ Repo::Config.read(path) do |value|
14
+ say value
15
+ end
16
+ rescue Repo::Config::Error => e
17
+ fatal!(e.message)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Afterlife
4
+ module Config
5
+ class Provider
6
+ def self.file
7
+ Afterlife.local_path.join('config.yml')
8
+ end
9
+
10
+ def respond_to_missing?(sym, include_all)
11
+ config.key?(sym) || super
12
+ end
13
+
14
+ def method_missing(sym, *args, &block)
15
+ config.key?(sym) ? config[sym] : super
16
+ end
17
+
18
+ def stages
19
+ @stages ||= config.delete(:stages)&.to_h do |name, val|
20
+ [name, Stage.new(val.merge(name: name.to_s))]
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def config
27
+ @config ||= YAML.load_file(Provider.file).deep_symbolize_keys
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,29 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Afterlife
4
- class Config
5
- def self.file
6
- Afterlife.local_path.join('config.yml')
7
- end
8
-
9
- def respond_to_missing?(sym, include_all)
10
- config.key?(sym) || super
11
- end
12
-
13
- def method_missing(sym, *args, &block)
14
- config.key?(sym) ? config[sym] : super
15
- end
16
-
17
- def stages
18
- @stages ||= config.delete(:stages)&.to_h do |name, val|
19
- [name, Stage.new(val.merge(name: name.to_s))]
20
- end
21
- end
22
-
23
- private
24
-
25
- def config
26
- @config ||= YAML.load_file(Config.file).deep_symbolize_keys
27
- end
4
+ module Config
28
5
  end
29
6
  end
@@ -48,18 +48,23 @@ module Afterlife
48
48
  --exclude '*.ts'
49
49
  --exclude '*.tsx'
50
50
  --size-only
51
- --cache-control 'no-cache'
51
+ --cache-control 'public, max-age=31540000'
52
52
  BASH
53
53
  end
54
54
 
55
55
  def revision
56
56
  <<-BASH
57
- echo "#{repo.current_revision}" | aws s3 cp --content-type text/plain --cache-control 'no-cache' - %<S3_FULL_PATH>s/revision
57
+ echo "#{repo.current_revision}" |
58
+ aws s3 cp --content-type text/plain --cache-control 'no-cache' - #{s3_revision_path}
58
59
  BASH
59
60
  end
60
61
 
62
+ def s3_revision_path
63
+ "s3://#{Afterlife.current_stage.bucket}/#{repo.full_name}/revision"
64
+ end
65
+
61
66
  def s3_full_path
62
- "s3://#{Afterlife.current_stage.bucket}/#{repo.full_name}"
67
+ "s3://#{Afterlife.current_stage.bucket}/#{repo.full_name}/#{repo.current_revision}"
63
68
  end
64
69
  end
65
70
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Afterlife
4
+ module Deploy
5
+ class CdnStenciljsDeployment < CdnDeployment
6
+ private
7
+
8
+ def commands
9
+ [
10
+ add_revision_command,
11
+ repo_command || javascripts,
12
+ revision,
13
+ ]
14
+ end
15
+
16
+ def add_revision_command
17
+ Dir["#{repo.dist_path}/*.esm.js"].map do |file|
18
+ next if file.include?(repo.current_revision)
19
+
20
+ new_name = file.gsub('.esm.js', "-#{repo.current_revision}.esm.js")
21
+ "mv #{file} #{new_name}"
22
+ end
23
+ end
24
+
25
+ def s3_full_path
26
+ "s3://#{Afterlife.current_stage.bucket}/#{repo.full_name}"
27
+ end
28
+ end
29
+ end
30
+ end
@@ -8,7 +8,7 @@ module Afterlife
8
8
  end
9
9
 
10
10
  def repo_command
11
- Array(repo.conf.dig(:deploy, :command))
11
+ Array(repo.conf.dig(:deploy, :command)).presence
12
12
  end
13
13
 
14
14
  def setup; end
@@ -16,12 +16,10 @@ module Afterlife
16
16
  end
17
17
 
18
18
  def klass
19
- case current_type
20
- when 'cdn'
21
- CdnDeployment
22
- else
23
- CustomDeployment
24
- end
19
+ klass = "#{current_type.gsub('-', '_')}_deployment".classify
20
+ fail Error, "deployment type '#{current_type}' is invalid" unless const_defined?(klass)
21
+
22
+ const_get(klass)
25
23
  end
26
24
 
27
25
  def current_type
@@ -32,8 +30,9 @@ module Afterlife
32
30
 
33
31
  def setup_stage(stage)
34
32
  unless Afterlife.config.stages.key?(stage.to_sym)
35
- fatal!("invalid stage '#{stage}'. Possible values: #{Afterlife.config.stages.keys.map(&:to_s)}")
33
+ fail Error, "invalid stage '#{stage}'. Possible values: #{Afterlife.config.stages.keys.map(&:to_s)}"
36
34
  end
35
+
37
36
  Afterlife.current_stage = Afterlife.config.stages[stage.to_sym]
38
37
  end
39
38
 
@@ -12,7 +12,7 @@ module Afterlife
12
12
  end
13
13
 
14
14
  def self.parse(arg, env)
15
- Array(arg).map do |command|
15
+ Array(arg.flatten.compact).flatten.map do |command|
16
16
  format(command, env.symbolize_keys)
17
17
  end
18
18
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Afterlife
4
+ class Repo
5
+ class Config
6
+ Error = Class.new StandardError
7
+
8
+ attr_reader :path
9
+
10
+ def self.read(path, &block)
11
+ new(path).read(&block)
12
+ end
13
+
14
+ def initialize(path)
15
+ @path = path.split('.').map(&:to_sym)
16
+ end
17
+
18
+ def read(&block) # rubocop:disable Metrics/MethodLength
19
+ case from_yml
20
+ when Hash
21
+ yield(JSON.generate(from_yml))
22
+ when Array
23
+ from_yml.each(&block)
24
+ when String, Symbol
25
+ yield(from_yml)
26
+ else
27
+ fail Error, "No config with path '#{path.join('.')}'" unless repo_method?
28
+
29
+ yield(repo.public_send(repo_method))
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def repo_method?
36
+ path.count == 1 && repo.public_methods(false).include?(repo_method)
37
+ end
38
+
39
+ def repo_method
40
+ @repo_method ||= path.first.to_s.gsub('-', '_').to_sym
41
+ end
42
+
43
+ def repo
44
+ Afterlife.current_repo
45
+ end
46
+
47
+ def from_yml
48
+ return @from_yml if defined?(@from_yml)
49
+
50
+ @from_yml ||= repo.conf.dig(*path)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Afterlife
4
+ class Repo
5
+ class Provider
6
+ CONFIG_NAME = '.afterlife.yml'
7
+
8
+ attr_reader :full_path
9
+
10
+ def initialize(full_path)
11
+ @full_path = full_path
12
+ end
13
+
14
+ def config
15
+ return @config if defined?(@config)
16
+
17
+ if config_file.exist?
18
+ @config = base_config
19
+ @config = parent.deep_merge(base_config) if parent
20
+ end
21
+
22
+ @config ||= {}
23
+ end
24
+
25
+ private
26
+
27
+ def parent
28
+ return @parent if defined?(@parent)
29
+
30
+ inherit_from = base_config.delete(:inherit_from)
31
+ return @parent = nil unless inherit_from
32
+
33
+ @parent = Provider.new(full_path.join(inherit_from)).config
34
+ @parent[:cdn]&.delete(:packages)
35
+ @parent
36
+ end
37
+
38
+ def base_config
39
+ @base_config ||= YAML.load_file(config_file).deep_symbolize_keys
40
+ end
41
+
42
+ def config_file
43
+ @config_file ||= full_path.join(CONFIG_NAME)
44
+ end
45
+ end
46
+ end
47
+ end
@@ -74,6 +74,10 @@ module Afterlife
74
74
  @current_revision ||= `git rev-parse HEAD`.chomp
75
75
  end
76
76
 
77
+ def current_revision_short
78
+ @current_revision_short ||= `git rev-parse --short HEAD`.chomp
79
+ end
80
+
77
81
  def name
78
82
  full_name.split('/').last.gsub('-', '_')
79
83
  end
@@ -110,49 +114,7 @@ module Afterlife
110
114
  end
111
115
 
112
116
  def conf
113
- @conf ||= Config.new(full_path).config
114
- end
115
-
116
- class Config
117
- CONFIG_NAME = '.afterlife.yml'
118
-
119
- attr_reader :full_path
120
-
121
- def initialize(full_path)
122
- @full_path = full_path
123
- end
124
-
125
- def config
126
- return @config if defined?(@config)
127
-
128
- if config_file.exist?
129
- @config = base_config
130
- @config = parent.deep_merge(base_config) if parent
131
- end
132
-
133
- @config ||= {}
134
- end
135
-
136
- private
137
-
138
- def parent
139
- return @parent if defined?(@parent)
140
-
141
- inherit_from = base_config.delete(:inherit_from)
142
- return @parent = nil unless inherit_from
143
-
144
- @parent = Config.new(full_path.join(inherit_from)).config
145
- @parent[:cdn]&.delete(:packages)
146
- @parent
147
- end
148
-
149
- def base_config
150
- @base_config ||= YAML.load_file(config_file).deep_symbolize_keys
151
- end
152
-
153
- def config_file
154
- @config_file ||= full_path.join(CONFIG_NAME)
155
- end
117
+ @conf ||= Provider.new(full_path).config
156
118
  end
157
119
  end
158
120
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Afterlife
4
- VERSION = '1.1.0'
4
+ VERSION = '1.2.1'
5
5
  end
data/lib/afterlife.rb CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  require 'zeitwerk'
4
4
  require 'git'
5
- require 'pry'
6
5
  require 'yaml'
7
6
  require 'pathname'
8
7
  require 'active_support'
@@ -26,7 +25,7 @@ module Afterlife
26
25
  end
27
26
 
28
27
  def self.config
29
- @config ||= Config.new
28
+ @config ||= Config::Provider.new
30
29
  end
31
30
 
32
31
  def self.current_repo
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: afterlife
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genaro Madrid
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-08 00:00:00.000000000 Z
11
+ date: 2023-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -122,8 +122,11 @@ files:
122
122
  - lib/afterlife/cdn/server.rb
123
123
  - lib/afterlife/cli.rb
124
124
  - lib/afterlife/config.rb
125
+ - lib/afterlife/config/cli.rb
126
+ - lib/afterlife/config/provider.rb
125
127
  - lib/afterlife/deploy.rb
126
128
  - lib/afterlife/deploy/cdn_deployment.rb
129
+ - lib/afterlife/deploy/cdn_stenciljs_deployment.rb
127
130
  - lib/afterlife/deploy/cli.rb
128
131
  - lib/afterlife/deploy/custom_deployment.rb
129
132
  - lib/afterlife/deploy/deployment.rb
@@ -136,6 +139,8 @@ files:
136
139
  - lib/afterlife/release/helper.rb
137
140
  - lib/afterlife/release/pre_helper.rb
138
141
  - lib/afterlife/repo.rb
142
+ - lib/afterlife/repo/config.rb
143
+ - lib/afterlife/repo/provider.rb
139
144
  - lib/afterlife/stage.rb
140
145
  - lib/afterlife/version.rb
141
146
  - logs/.keep