rexer 0.14.1 → 0.15.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 03a1f270989ff656e5fd97e105ecd8d21be59755e2f3112746db636c5b2a9e7c
4
- data.tar.gz: 42154270a3d8684f58ec80537cd2d5237dd0cde468bd44b3db0dd89fe7084a7c
3
+ metadata.gz: a65472e424f27d1a96fa1be7093fcb9eac2f59606dd9b93c907dfec412b8309d
4
+ data.tar.gz: b56d1515e26fd98f800c772f64511bd241c83e1e0b706f4bbdd6b2cbf734a375
5
5
  SHA512:
6
- metadata.gz: 3b7544710bb51bb0a6e5cb6de61deac2c6fbea1116d11b62f064c76a844af5664037083dbe30685421af467f7346676ba9655ceb59e2310a455e435ea7f7274b
7
- data.tar.gz: 91d31bf09b9dd719760ab4cc88c32542cc441f215ce68e7d95831e8e0789695215dbf49d70279e51d43c5a45886d6d6f6045540d0210c577153b706d3dcf0fa6
6
+ metadata.gz: bdeb0d3f7855f8fef1710f0d7918ce2b24c39004ac2cc0fa3ddd3c1e201eb5bf3afef7c08531caa539842189eb95fa99fd11166bdbcfc8fbef4ea5345541d2c8
7
+ data.tar.gz: 160d63e6239cd0d417443d2935c35a826340040cc917c28f29d3827e5e9db53bcacdc28a45c9a665f12e4087a88b436407258fe995dfd1ab08a30a25cd057783
@@ -10,8 +10,12 @@ module Rexer
10
10
  defined_envs.each.with_index do |env, i|
11
11
  puts env
12
12
 
13
- definition_with(env).then { _1.themes + _1.plugins }.each do
14
- puts " #{_1.name} (#{Source.from_definition(_1.source).info})"
13
+ themes_in(env) do
14
+ print_extension_definition(_1)
15
+ end
16
+
17
+ plugins_in(env) do
18
+ print_extension_definition(_1)
15
19
  end
16
20
 
17
21
  puts if i < defined_envs.size - 1
@@ -22,11 +26,20 @@ module Rexer
22
26
 
23
27
  attr_reader :definition
24
28
 
25
- def definition_with(env)
26
- definition.with(
27
- plugins: definition.plugins.select { _1.env == env },
28
- themes: definition.themes.select { _1.env == env }
29
- )
29
+ def print_extension_definition(extension_def)
30
+ puts " #{extension_def.name} (#{Source.from_definition(extension_def.source).info})"
31
+ end
32
+
33
+ def themes_in(env)
34
+ definition.themes.each do
35
+ yield _1 if _1.env == env
36
+ end
37
+ end
38
+
39
+ def plugins_in(env)
40
+ definition.plugins.each do
41
+ yield _1 if _1.env == env
42
+ end
30
43
  end
31
44
  end
32
45
  end
@@ -20,29 +20,27 @@ module Rexer
20
20
  attr_reader :lock_definition
21
21
 
22
22
  def print_plugins
23
- plugins = lock_definition.plugins
24
- return if plugins.empty?
23
+ plugin_defs = lock_definition.plugins
24
+ return if plugin_defs.empty?
25
25
 
26
26
  puts "\nPlugins:"
27
- plugins.each do
28
- puts " * #{_1.name} (#{source_info(_1.source)})"
27
+ plugin_defs.each do
28
+ plugin = Extension::Entity::Plugin.new(_1)
29
+ puts " * #{plugin.name} (#{plugin.source_info})"
29
30
  end
30
31
  end
31
32
 
32
33
  def print_themes
33
- themes = lock_definition.themes
34
- return if themes.empty?
34
+ theme_defs = lock_definition.themes
35
+ return if theme_defs.empty?
35
36
 
36
37
  puts "\nThemes:"
37
- themes.each do
38
- puts " * #{_1.name} (#{source_info(_1.source)})"
38
+ theme_defs.each do
39
+ theme = Extension::Entity::Theme.new(_1)
40
+ puts " * #{theme.name} (#{theme.source_info})"
39
41
  end
40
42
  end
41
43
 
42
- def source_info(definition_source)
43
- Source.from_definition(definition_source).info
44
- end
45
-
46
44
  def no_lock_file_found
47
45
  lock_definition.nil?.tap { |result|
48
46
  puts "No lock file found" if result
@@ -7,7 +7,7 @@ module Rexer
7
7
 
8
8
  def call(env)
9
9
  return if no_lock_file_found
10
- return if already_on(env)
10
+ return if already_in(env)
11
11
 
12
12
  Uninstall.new.call
13
13
  Install.new.call(env)
@@ -23,9 +23,9 @@ module Rexer
23
23
  }
24
24
  end
25
25
 
26
- def already_on(env)
26
+ def already_in(env)
27
27
  (lock_definition.env == env).tap do |result|
28
- puts "Already on #{env} environment" if result
28
+ puts "Already in #{env} environment" if result
29
29
  end
30
30
  end
31
31
  end
@@ -0,0 +1,55 @@
1
+ require "active_support/core_ext/class/attribute"
2
+
3
+ module Rexer
4
+ module Extension
5
+ module Entity
6
+ class Base
7
+ class_attribute :root_dir
8
+
9
+ def initialize(definition)
10
+ @definition = definition
11
+ @hooks = definition.hooks || {}
12
+ @name = definition.name
13
+ end
14
+
15
+ attr_reader :hooks, :name
16
+
17
+ def exist?
18
+ path.exist? && !path.empty?
19
+ end
20
+
21
+ def path
22
+ @path ||= root_dir.join(name.to_s)
23
+ end
24
+
25
+ def source_info
26
+ @source_info ||= source.info(path)
27
+ end
28
+
29
+ def source
30
+ @source ||= Source.from_definition(definition.source)
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :definition
36
+ end
37
+
38
+ class Plugin < Base
39
+ self.root_dir = Pathname.new("plugins")
40
+
41
+ def contains_db_migrations?
42
+ path.join("db", "migrate").then { _1.exist? && !_1.empty? }
43
+ end
44
+
45
+ def contains_gemfile?
46
+ path.join("Gemfile").exist?
47
+ end
48
+ end
49
+
50
+ class Theme < Base
51
+ self.root_dir = Pathname.new("themes")
52
+ end
53
+ end
54
+ end
55
+ end
@@ -9,36 +9,21 @@ module Rexer
9
9
 
10
10
  def initialize(definition)
11
11
  @definition = definition
12
- @name = definition.name
13
- @hooks = definition.hooks || {}
12
+ @plugin = Entity::Plugin.new(definition)
14
13
  end
15
14
 
16
15
  private
17
16
 
18
- attr_reader :name, :hooks, :definition
19
-
20
- def plugin_root_dir
21
- Pathname.new("plugins")
22
- end
23
-
24
- def plugin_dir
25
- @plugin_dir ||= plugin_root_dir.join(name.to_s)
26
- end
27
-
28
- def plugin_exists?
29
- plugin_dir.exist? && !plugin_dir.empty?
30
- end
17
+ attr_reader :plugin
31
18
 
32
19
  def needs_db_migration?
33
- plugin_dir.join("db", "migrate").then {
34
- _1.exist? && !_1.empty?
35
- }
20
+ plugin.contains_db_migrations?
36
21
  end
37
22
 
38
23
  def run_db_migrate(extra_envs = {})
39
24
  return unless needs_db_migration?
40
25
 
41
- envs = {"NAME" => name.to_s}.merge(extra_envs)
26
+ envs = {"NAME" => plugin.name.to_s}.merge(extra_envs)
42
27
  cmds = build_cmd("bundle", "exec", "rake", Rexer.verbosity.debug? ? nil : "-q", "redmine:plugins:migrate", envs:)
43
28
 
44
29
  broadcast(:processing, "Execute #{cmds}")
@@ -51,10 +36,6 @@ module Rexer
51
36
  end
52
37
  end
53
38
 
54
- def source
55
- @source ||= Source.from_definition(definition.source)
56
- end
57
-
58
39
  def build_cmd(*command, envs: {})
59
40
  envs_str = envs.map { [_1, _2].join("=") }
60
41
  [Rexer.config.command_prefix, *command, *envs_str].compact.join(" ")
@@ -3,9 +3,9 @@ module Rexer
3
3
  module Plugin
4
4
  class Install < Action
5
5
  def call
6
- broadcast(:started, "Install #{name}")
6
+ broadcast(:started, "Install #{plugin.name}")
7
7
 
8
- if plugin_exists?
8
+ if plugin.exist?
9
9
  broadcast(:skipped, "Already exists")
10
10
  return
11
11
  end
@@ -13,7 +13,7 @@ module Rexer
13
13
  load_from_source
14
14
  run_bundle_install
15
15
  run_db_migrate
16
- hooks[:installed]&.call
16
+ call_installed_hook
17
17
 
18
18
  broadcast(:completed)
19
19
  end
@@ -21,11 +21,11 @@ module Rexer
21
21
  private
22
22
 
23
23
  def load_from_source
24
- source.load(plugin_dir.to_s)
24
+ plugin.source.load(plugin.path.to_s)
25
25
  end
26
26
 
27
27
  def run_bundle_install
28
- return unless plugin_dir.join("Gemfile").exist?
28
+ return unless plugin.contains_gemfile?
29
29
 
30
30
  cmds = build_cmd("bundle", "install", Rexer.verbosity.debug? ? nil : "--quiet")
31
31
 
@@ -33,6 +33,10 @@ module Rexer
33
33
 
34
34
  system(cmds, exception: true)
35
35
  end
36
+
37
+ def call_installed_hook
38
+ plugin.hooks[:installed]&.call
39
+ end
36
40
  end
37
41
  end
38
42
  end
@@ -3,9 +3,9 @@ module Rexer
3
3
  module Plugin
4
4
  class ReloadSource < Action
5
5
  def call
6
- return unless plugin_exists?
6
+ return unless plugin.exist?
7
7
 
8
- broadcast(:started, "Reload #{name} source")
8
+ broadcast(:started, "Reload #{plugin.name} source")
9
9
 
10
10
  reload_source
11
11
  run_db_migrate
@@ -16,10 +16,8 @@ module Rexer
16
16
  private
17
17
 
18
18
  def reload_source
19
- plugin_dir.to_s.then { |dir|
20
- FileUtils.rm_rf(dir)
21
- source.load(dir)
22
- }
19
+ plugin.path.rmtree
20
+ plugin.source.load(plugin.path.to_s)
23
21
  end
24
22
  end
25
23
  end
@@ -3,16 +3,16 @@ module Rexer
3
3
  module Plugin
4
4
  class Uninstall < Action
5
5
  def call
6
- broadcast(:started, "Uninstall #{name}")
6
+ broadcast(:started, "Uninstall #{plugin.name}")
7
7
 
8
- unless plugin_exists?
8
+ unless plugin.exist?
9
9
  broadcast(:skipped, "Not exists")
10
10
  return
11
11
  end
12
12
 
13
13
  reset_db_migration
14
14
  remove_plugin
15
- hooks[:uninstalled]&.call
15
+ call_uninstalled_hook
16
16
 
17
17
  broadcast(:completed)
18
18
  end
@@ -24,7 +24,11 @@ module Rexer
24
24
  end
25
25
 
26
26
  def remove_plugin
27
- plugin_dir.rmtree
27
+ plugin.path.rmtree
28
+ end
29
+
30
+ def call_uninstalled_hook
31
+ plugin.hooks[:uninstalled]&.call
28
32
  end
29
33
  end
30
34
  end
@@ -3,11 +3,11 @@ module Rexer
3
3
  module Plugin
4
4
  class Update < Action
5
5
  def call
6
- return unless plugin_exists?
6
+ return unless plugin.exist?
7
7
 
8
- broadcast(:started, "Update #{name}")
8
+ broadcast(:started, "Update #{plugin.name}")
9
9
 
10
- unless source.updatable?
10
+ unless plugin.source.updatable?
11
11
  broadcast(:skipped, "Not updatable")
12
12
  return
13
13
  end
@@ -21,7 +21,7 @@ module Rexer
21
21
  private
22
22
 
23
23
  def update_source
24
- source.update(plugin_dir.to_s)
24
+ plugin.source.update(plugin.path)
25
25
  end
26
26
  end
27
27
  end
@@ -8,36 +8,12 @@ module Rexer
8
8
 
9
9
  def initialize(definition)
10
10
  @definition = definition
11
- @name = definition.name
12
- @hooks = definition.hooks || {}
11
+ @theme = Entity::Theme.new(definition)
13
12
  end
14
13
 
15
14
  private
16
15
 
17
- attr_reader :name, :hooks, :definition
18
-
19
- def theme_root_dir
20
- public_themes = Pathname.pwd.join("public", "themes")
21
-
22
- if public_themes.exist?
23
- # When Redmine version is v5.1 or older, public/themes is used.
24
- public_themes
25
- else
26
- Pathname.new("themes")
27
- end
28
- end
29
-
30
- def theme_dir
31
- @theme_dir ||= theme_root_dir.join(name.to_s)
32
- end
33
-
34
- def theme_exists?
35
- theme_dir.exist? && !theme_dir.empty?
36
- end
37
-
38
- def source
39
- @source ||= Source.from_definition(definition.source)
40
- end
16
+ attr_reader :theme
41
17
  end
42
18
  end
43
19
  end
@@ -3,15 +3,15 @@ module Rexer
3
3
  module Theme
4
4
  class Install < Action
5
5
  def call
6
- broadcast(:started, "Install #{name}")
6
+ broadcast(:started, "Install #{theme.name}")
7
7
 
8
- if theme_exists?
8
+ if theme.exist?
9
9
  broadcast(:skipped, "Already exists")
10
10
  return
11
11
  end
12
12
 
13
13
  load_from_source
14
- hooks[:installed]&.call
14
+ call_installed_hook
15
15
 
16
16
  broadcast(:completed)
17
17
  end
@@ -19,7 +19,11 @@ module Rexer
19
19
  private
20
20
 
21
21
  def load_from_source
22
- source.load(theme_dir.to_s)
22
+ theme.source.load(theme.path.to_s)
23
+ end
24
+
25
+ def call_installed_hook
26
+ theme.hooks[:installed]&.call
23
27
  end
24
28
  end
25
29
  end
@@ -3,9 +3,9 @@ module Rexer
3
3
  module Theme
4
4
  class ReloadSource < Action
5
5
  def call
6
- return unless theme_exists?
6
+ return unless theme.exist?
7
7
 
8
- broadcast(:started, "Reload #{name} source")
8
+ broadcast(:started, "Reload #{theme.name} source")
9
9
 
10
10
  reload_source
11
11
 
@@ -15,10 +15,8 @@ module Rexer
15
15
  private
16
16
 
17
17
  def reload_source
18
- theme_dir.to_s.then { |dir|
19
- FileUtils.rm_rf(dir)
20
- source.load(dir)
21
- }
18
+ theme.path.rmtree
19
+ theme.source.load(theme.path.to_s)
22
20
  end
23
21
  end
24
22
  end
@@ -3,15 +3,15 @@ module Rexer
3
3
  module Theme
4
4
  class Uninstall < Action
5
5
  def call
6
- broadcast(:started, "Uninstall #{name}")
6
+ broadcast(:started, "Uninstall #{theme.name}")
7
7
 
8
- unless theme_exists?
8
+ unless theme.exist?
9
9
  broadcast(:skipped, "Not exists")
10
10
  return
11
11
  end
12
12
 
13
13
  remove_theme
14
- hooks[:uninstalled]&.call
14
+ call_uninstalled_hook
15
15
 
16
16
  broadcast(:completed)
17
17
  end
@@ -19,7 +19,11 @@ module Rexer
19
19
  private
20
20
 
21
21
  def remove_theme
22
- theme_dir.rmtree
22
+ theme.path.rmtree
23
+ end
24
+
25
+ def call_uninstalled_hook
26
+ theme.hooks[:uninstalled]&.call
23
27
  end
24
28
  end
25
29
  end
@@ -3,9 +3,9 @@ module Rexer
3
3
  module Theme
4
4
  class Update < Action
5
5
  def call
6
- return unless theme_exists?
6
+ return unless theme.exist?
7
7
 
8
- broadcast(:started, "Update #{name}")
8
+ broadcast(:started, "Update #{theme.name}")
9
9
 
10
10
  update_source
11
11
 
@@ -15,7 +15,7 @@ module Rexer
15
15
  private
16
16
 
17
17
  def update_source
18
- source.update(theme_dir.to_s)
18
+ theme.source.update(theme.path.to_s)
19
19
  end
20
20
  end
21
21
  end
@@ -17,7 +17,7 @@ module Rexer
17
17
  end
18
18
 
19
19
  # Return the status of the source.
20
- def info = ""
20
+ def info(_work_dir = nil) = ""
21
21
  end
22
22
  end
23
23
  end
@@ -9,7 +9,6 @@ module Rexer
9
9
  @branch = branch
10
10
  @tag = tag
11
11
  @ref = ref
12
- @reference = branch || tag || ref
13
12
  end
14
13
 
15
14
  def load(path)
@@ -25,27 +24,35 @@ module Rexer
25
24
  branch || reference.nil?
26
25
  end
27
26
 
28
- def info
29
- URI.parse(url).then do |uri|
30
- "#{uri.host}#{uri.path}@#{reference_name}"
31
- end
27
+ def info(work_dir = nil)
28
+ uri = URI.parse(url).then { "#{_1.host}#{_1.path}" }
29
+ ref = reference(short_ref: true) || current_branch(work_dir)
30
+
31
+ [uri, ref].compact.join("@")
32
32
  end
33
33
 
34
34
  private
35
35
 
36
- attr_reader :url, :reference, :branch, :tag, :ref
36
+ attr_reader :url, :branch, :tag
37
37
 
38
38
  def checkout(git)
39
39
  reference&.then { git.checkout(_1) }
40
40
  end
41
41
 
42
- def reference_name
43
- branch || tag || short_ref || "main"
42
+ def reference(short_ref: false)
43
+ branch || tag || ref(short: short_ref)
44
+ end
45
+
46
+ def ref(short: false)
47
+ return nil unless @ref
48
+ return @ref unless short
49
+
50
+ @ref.match?(/^[a-z0-9]+$/) ? @ref.slice(0, 7) : @ref
44
51
  end
45
52
 
46
- def short_ref
47
- return unless ref
48
- ref.match?(/^[a-z0-9]+$/) ? ref.slice(0, 7) : ref
53
+ def current_branch(work_dir)
54
+ return nil unless work_dir
55
+ ::Git.open(work_dir).current_branch
49
56
  end
50
57
  end
51
58
  end
@@ -6,8 +6,8 @@ module Rexer
6
6
  super(url: "https://github.com/#{repo}", branch: branch, tag: tag, ref: ref)
7
7
  end
8
8
 
9
- def info
10
- "#{@repo}@#{reference_name}"
9
+ def info(work_dir = nil)
10
+ [@repo, reference(short_ref: true) || current_branch(work_dir)].compact.join("@")
11
11
  end
12
12
  end
13
13
  end
data/lib/rexer/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rexer
2
- VERSION = "0.14.1"
2
+ VERSION = "0.15.0"
3
3
  end
data/lib/rexer.rb CHANGED
@@ -1,12 +1,4 @@
1
1
  module Rexer
2
- def self.definition_file
3
- ".extensions.rb"
4
- end
5
-
6
- def self.definition_lock_file
7
- ".extensions.lock"
8
- end
9
-
10
2
  Config = Data.define(
11
3
  # The prefix of the command such as bundle install and bin/rails redmine:plugins:migrate.
12
4
  #
@@ -21,6 +13,14 @@ module Rexer
21
13
  class << self
22
14
  attr_accessor :verbosity
23
15
 
16
+ def definition_file
17
+ ".extensions.rb"
18
+ end
19
+
20
+ def definition_lock_file
21
+ ".extensions.lock"
22
+ end
23
+
24
24
  def config
25
25
  @config ||= Config.new(command_prefix: ENV["REXER_COMMAND_PREFIX"])
26
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rexer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.1
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katsuya Hidaka
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-25 00:00:00.000000000 Z
11
+ date: 2024-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -139,6 +139,7 @@ files:
139
139
  - lib/rexer/definition/diff.rb
140
140
  - lib/rexer/definition/dsl.rb
141
141
  - lib/rexer/definition/lock.rb
142
+ - lib/rexer/extension/entity.rb
142
143
  - lib/rexer/extension/plugin/action.rb
143
144
  - lib/rexer/extension/plugin/install.rb
144
145
  - lib/rexer/extension/plugin/reload_source.rb