squared 0.5.15 → 0.6.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.
@@ -3,16 +3,6 @@
3
3
  module Squared
4
4
  module Workspace
5
5
  module Repo
6
- class << self
7
- def read_manifest(path)
8
- require 'rexml/document'
9
- return unless (file = path + '.repo/manifest.xml').exist?
10
-
11
- doc = REXML::Document.new(file.read)
12
- doc.elements['manifest/include'].attributes['name']&.sub('.xml', '')
13
- end
14
- end
15
-
16
6
  attr_reader :manifest_url, :manifest
17
7
 
18
8
  def repo(url, manifest = 'latest', run: nil, script: nil, args: nil, dev: nil, prod: nil,
@@ -25,18 +15,18 @@ module Squared
25
15
  @root = nil unless path.directory?
26
16
  elsif !@root.exist?
27
17
  @root.mkpath
28
- elsif !repo_install?
29
- @root = nil unless repo_confirm
18
+ elsif !repo_install? && !repo_confirm
19
+ @root = nil
30
20
  end
21
+ raise_error Errno::EEXIST, path.cleanpath, hint: 'REPO_HOME' unless @root
31
22
  end
32
- raise_error("path invalid: #{val}", hint: 'REPO_HOME') unless @root
33
23
  path.realdirpath
34
24
  elsif (val = env('REPO_ROOT'))
35
25
  @root = Pathname.new(val).realdirpath
36
26
  if !@root.exist?
37
27
  @root.mkpath
38
- elsif !repo_install?(parent: true)
39
- raise_error("path does not exist: #{val}", hint: 'REPO_ROOT') unless repo_confirm
28
+ elsif !repo_install?(parent: true) && !repo_confirm
29
+ raise_error Errno::EEXIST, @root, hint: 'REPO_ROOT'
40
30
  end
41
31
  @root.join(main).realdirpath
42
32
  elsif repo_install?(parent: true) && (!@home.exist? || @root + main == @home)
@@ -51,9 +41,13 @@ module Squared
51
41
  @manifest = manifest
52
42
  data = scriptobj
53
43
  if repo?
44
+ sc, ru = env('REPO_BUILD', '').split(',', 2).map!(&:strip)
54
45
  if script
55
- if (val = env('REPO_BUILD'))
56
- data[:script] = case val
46
+ data[:script] = if sc.to_s.empty?
47
+ script
48
+ else
49
+ data[:env][:script] = true
50
+ case sc
57
51
  when 'verbose'
58
52
  @verbose = 1
59
53
  if script.is_a?(Array)
@@ -67,20 +61,23 @@ module Squared
67
61
  @warning = false
68
62
  script
69
63
  else
70
- val
64
+ sc
71
65
  end
72
- data[:env] = true
73
- else
74
- data[:script] = script
75
- end
66
+ end
76
67
  data[:args] = (val = env('REPO_SCRIPT')) ? shell_split(val, join: true) : args
77
- elsif (val = env('REPO_BUILD'))
78
- data[:run] = val
79
- data[:env] = true
68
+ data[:global][:script] = true
80
69
  else
81
- data[:run] = run
70
+ ru ||= sc
71
+ end
72
+ if run
73
+ data[:run] = if ru.to_s.empty?
74
+ run
75
+ else
76
+ data[:env][:run] = true
77
+ ru
78
+ end
79
+ data[:global][:run] = true
82
80
  end
83
- data[:global] = true
84
81
  data[:dev] = env_match 'REPO_DEV', dev
85
82
  data[:prod] = env_match 'REPO_PROD', prod
86
83
  if (val = env('REPO_GROUP'))
@@ -98,9 +95,8 @@ module Squared
98
95
  if script
99
96
  data[:script] = script
100
97
  data[:args] = args
101
- else
102
- data[:run] = run
103
98
  end
99
+ data[:run] = run if run
104
100
  data[:dev] = dev
105
101
  data[:prod] = prod
106
102
  script_set(data, group: group, ref: ref)
@@ -115,7 +111,7 @@ module Squared
115
111
 
116
112
  namespace task_name('repo') do |ns|
117
113
  path = ns.scope.path
118
- branch = env('REPO_MANIFEST') || Repo.read_manifest(root)
114
+ branch = env('REPO_MANIFEST') || repo_manifest
119
115
  target = branch || manifest
120
116
  stage = nil
121
117
  opts = %w[force rebase detach submodules fail no-update gc]
@@ -160,7 +156,7 @@ module Squared
160
156
  args = args.to_a
161
157
  u = env('REPO_URL') || manifest_url
162
158
  m = args.first && !opts.include?(args.first) ? args.shift : target
163
- g = args.first && !opts.include?(args.first) ? args.shift : nil
159
+ g = (args.shift if args.first && !opts.include?(args.first))
164
160
  g = case (val = env('REPO_GROUPS'))
165
161
  when '', NilClass
166
162
  g
@@ -216,7 +212,7 @@ module Squared
216
212
  end
217
213
  end
218
214
 
219
- series.sync.append(
215
+ series.sync.push(
220
216
  task_join(path, 'all'),
221
217
  task_join(path, 'init'),
222
218
  task_join(path, 'sync')
@@ -224,11 +220,19 @@ module Squared
224
220
  end
225
221
  end
226
222
 
223
+ def repo_manifest(path = root)
224
+ return unless (file = path + '.repo/manifest.xml').exist?
225
+
226
+ require 'rexml/document'
227
+ doc = REXML::Document.new(file.read)
228
+ doc.elements['manifest/include'].attributes['name']&.sub('.xml', '')
229
+ end
230
+
227
231
  def repo_confirm
228
232
  return false unless root.directory?
229
233
 
230
234
  path = sub_style(root, styles: theme[:inline])
231
- @repo_override = Common::Prompt.confirm(
235
+ @repo_override = env('REPO_Y', equals: '1') || Common::Prompt.confirm(
232
236
  "#{log_title(:warn)} \"#{path}\" is not empty. Continue with installation?",
233
237
  'N',
234
238
  timeout: env('REPO_TIMEOUT', 15, ignore: '0')
@@ -247,7 +251,7 @@ module Squared
247
251
  def repo_opts(*args)
248
252
  return args unless (n = ARGV.index('--'))
249
253
 
250
- ARGV[(n + 1)..-1].concat(args)
254
+ ARGV[n.succ..-1].concat(args)
251
255
  end
252
256
 
253
257
  def repo?
@@ -199,9 +199,7 @@ module Squared
199
199
  end
200
200
 
201
201
  def batch?(obj, key)
202
- return false unless (data = batch_get(key))
203
-
204
- data.keys.any? { |ref| obj.ref?(ref) }
202
+ (data = batch_get(key)) ? data.keys.any? { |ref| obj.ref?(ref) } : false
205
203
  end
206
204
 
207
205
  def chain?(val)
@@ -240,9 +238,11 @@ module Squared
240
238
  end
241
239
 
242
240
  def already_invoked?(list, val)
243
- return Rake::Task.tasks.any? { |obj| obj.already_invoked && list.include?(obj.name) } unless val
244
-
245
- list.include?(val) && !invoked_get(val).nil?
241
+ if val
242
+ list.include?(val) && !invoked_get(val).nil?
243
+ else
244
+ Rake::Task.tasks.any? { |obj| obj.already_invoked && list.include?(obj.name) }
245
+ end
246
246
  end
247
247
  end
248
248
 
@@ -3,30 +3,9 @@
3
3
  module Squared
4
4
  module Workspace
5
5
  module Support
6
- class << self
7
- def hashobj
8
- Hash.new { |data, key| data[key] = {} }
9
- end
10
-
11
- def hashlist
12
- Hash.new { |data, key| data[key] = [] }
13
- end
14
-
15
- def hashdup(data, pass: {})
16
- ret = {}
17
- data.each do |key, val|
18
- ret[key] = case val
19
- when Hash
20
- pass[val] ||= hashdup(val, pass: pass)
21
- when Proc, Method
22
- val
23
- else
24
- val.dup
25
- end
26
- end
27
- ret
28
- end
29
- end
6
+ RunData = Struct.new('RunData', :run, :block)
7
+ ChainData = Struct.new('ChainData', :action, :step, :with, :before, :after, :sync)
8
+ BannerData = Struct.new('BannerData', :command, :order, :styles, :border)
30
9
  end
31
10
  end
32
11
  end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Squared
4
+ module Workspace
5
+ module Support
6
+ module Variables
7
+ private
8
+
9
+ def hashobj
10
+ Hash.new { |data, key| data[key] = {} }
11
+ end
12
+
13
+ def hashlist
14
+ Hash.new { |data, key| data[key] = [] }
15
+ end
16
+
17
+ def hashdup(data, compact: false, freeze: false, target: {}, pass: {})
18
+ data.each do |key, val|
19
+ next if val.nil? && compact
20
+
21
+ target[key] = case val
22
+ when Hash
23
+ if pass.key?(val)
24
+ pass[val]
25
+ else
26
+ hashdup(val, compact: compact, freeze: freeze, target: pass[val] = {}, pass: pass)
27
+ end
28
+ when Enumerable
29
+ compact ? val.compact : val.dup
30
+ when Proc, Method
31
+ val
32
+ else
33
+ val.dup
34
+ end
35
+ target[key].freeze if freeze && val.frozen?
36
+ end
37
+ target
38
+ end
39
+ end
40
+
41
+ class << Support
42
+ include Variables
43
+
44
+ public(*Variables.private_instance_methods(false))
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'support/base'
4
- require_relative 'support/data'
4
+ require_relative 'support/variables'
@@ -6,7 +6,7 @@ module Squared
6
6
  include Common
7
7
 
8
8
  def resolve(*args)
9
- ret = args.map do |id|
9
+ ret = args.map! do |id|
10
10
  if id.is_a?(Symbol)
11
11
  project id
12
12
  else
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squared
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.15
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - An Pham
@@ -101,7 +101,7 @@ files:
101
101
  - lib/squared/workspace/series.rb
102
102
  - lib/squared/workspace/support.rb
103
103
  - lib/squared/workspace/support/base.rb
104
- - lib/squared/workspace/support/data.rb
104
+ - lib/squared/workspace/support/variables.rb
105
105
  - squared.gemspec
106
106
  homepage: https://github.com/anpham6/squared-ruby
107
107
  licenses:
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  requirements: []
127
- rubygems_version: 3.6.9
127
+ rubygems_version: 3.7.2
128
128
  specification_version: 4
129
129
  summary: Rake task generator for managing multi-language workspaces.
130
130
  test_files: []
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Squared
4
- module Workspace
5
- module Support
6
- RunData = Struct.new('RunData', :run, :block)
7
- ChainData = Struct.new('ChainData', :action, :step, :with, :before, :after, :sync)
8
- BannerData = Struct.new('BannerData', :command, :order, :styles, :border)
9
- end
10
- end
11
- end