squared 0.0.6 → 0.0.8
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 +4 -4
- data/README.ruby.md +48 -13
- data/lib/squared/common/base.rb +22 -16
- data/lib/squared/common/class.rb +5 -1
- data/lib/squared/common/format.rb +48 -45
- data/lib/squared/common/shell.rb +3 -3
- data/lib/squared/common/system.rb +35 -3
- data/lib/squared/common/task.rb +3 -11
- data/lib/squared/config.rb +21 -18
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +136 -128
- data/lib/squared/workspace/project/base.rb +131 -72
- data/lib/squared/workspace/project/git.rb +73 -73
- data/lib/squared/workspace/project/node.rb +88 -63
- data/lib/squared/workspace/project/python.rb +48 -33
- data/lib/squared/workspace/project/ruby.rb +196 -64
- data/lib/squared/workspace/project.rb +4 -0
- data/lib/squared/workspace/repo.rb +41 -28
- data/lib/squared/workspace/series.rb +54 -43
- data/lib/squared/workspace.rb +11 -3
- data/squared.gemspec +1 -0
- metadata +16 -2
@@ -7,58 +7,45 @@ module Squared
|
|
7
7
|
include Format
|
8
8
|
include ::Rake::DSL
|
9
9
|
|
10
|
-
TASK_BASE = {
|
11
|
-
build: [],
|
12
|
-
refresh: [],
|
13
|
-
depend: [],
|
14
|
-
outdated: [],
|
15
|
-
doc: [],
|
16
|
-
test: [],
|
17
|
-
copy: [],
|
18
|
-
clean: []
|
19
|
-
}
|
20
|
-
TASK_EXTEND = {}
|
21
|
-
WORKSPACE_KEYS = TASK_BASE.keys.freeze
|
22
|
-
private_constant :TASK_BASE, :TASK_EXTEND
|
23
|
-
|
24
10
|
class << self
|
25
11
|
def implement(*objs)
|
26
12
|
objs.each do |obj|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
obj
|
31
|
-
|
32
|
-
(TASK_EXTEND[val] ||= []).push(obj)
|
13
|
+
if obj < Project::Base
|
14
|
+
@impl_project.unshift(obj)
|
15
|
+
obj.tasks&.each { |task| @impl_series.add(task, obj) }
|
16
|
+
elsif obj < Workspace::Series
|
17
|
+
@impl_series = obj
|
33
18
|
end
|
34
19
|
end
|
35
20
|
end
|
36
21
|
|
37
|
-
def find(
|
38
|
-
if ref
|
39
|
-
ret
|
40
|
-
|
22
|
+
def find(ref = nil, path: nil)
|
23
|
+
if ref && (ret = impl_project.find { |proj| proj.ref == ref.to_sym })
|
24
|
+
ret
|
25
|
+
elsif path
|
26
|
+
impl_project.find { |proj| proj.is_a?(path) }
|
41
27
|
end
|
42
|
-
project_kind.find { |proj| proj.is_a?(path) } if path
|
43
28
|
end
|
44
29
|
|
45
30
|
def to_s
|
46
31
|
super.to_s.match(/[^:]+$/)[0]
|
47
32
|
end
|
48
33
|
|
49
|
-
attr_reader :
|
34
|
+
attr_reader :impl_project, :impl_series
|
50
35
|
end
|
51
36
|
|
52
|
-
@
|
37
|
+
@impl_project = []
|
38
|
+
@impl_series = Workspace::Series
|
53
39
|
|
54
|
-
attr_reader :
|
55
|
-
attr_accessor :exception, :pipe, :verbose
|
40
|
+
attr_reader :root, :home, :main, :prefix, :series, :theme
|
41
|
+
attr_accessor :exception, :warning, :pipe, :verbose
|
56
42
|
|
57
|
-
def initialize(
|
58
|
-
@
|
59
|
-
@
|
43
|
+
def initialize(home = Dir.pwd, *, main: nil, prefix: nil, exception: false, pipe: false, verbose: nil, **kwargs)
|
44
|
+
@home = (home = Pathname.new(home)).realdirpath
|
45
|
+
@main = (main || home.basename).to_s
|
60
46
|
@root = @home.parent
|
61
|
-
@
|
47
|
+
@prefix = prefix
|
48
|
+
@series = Application.impl_series.new(prefix)
|
62
49
|
@project = {}
|
63
50
|
@extensions = []
|
64
51
|
@script = {
|
@@ -66,97 +53,118 @@ module Squared
|
|
66
53
|
ref: {},
|
67
54
|
build: nil,
|
68
55
|
dev: nil,
|
69
|
-
prod: nil
|
56
|
+
prod: nil,
|
57
|
+
env: false
|
70
58
|
}
|
71
|
-
@theme = common && @verbose ? __get__(:theme)[:workspace] : {}
|
72
59
|
@exception = exception.is_a?(String) ? !env(exception, ignore: '0').nil? : exception
|
73
60
|
@pipe = pipe.is_a?(String) ? !env(pipe, ignore: '0').nil? : pipe
|
74
61
|
@verbose = verbose.nil? ? !@pipe : verbose
|
75
|
-
@warning =
|
62
|
+
@warning = @verbose
|
63
|
+
if kwargs.fetch(:common, true)
|
64
|
+
@theme = __get__(:theme)[:workspace]
|
65
|
+
__set__(:no_color, true) if @pipe
|
66
|
+
else
|
67
|
+
@theme = {}
|
68
|
+
end
|
76
69
|
end
|
77
70
|
|
78
71
|
def build(**kwargs)
|
72
|
+
kwargs[:parallel] = kwargs.fetch(:parallel, []).map(&:to_s)
|
79
73
|
return unless enabled?
|
80
74
|
|
81
75
|
@project.each_value do |proj|
|
82
76
|
next unless proj.enabled?
|
83
77
|
|
84
|
-
series.populate(proj)
|
85
78
|
proj.populate(**kwargs)
|
79
|
+
series.__populate__(proj)
|
86
80
|
end
|
87
81
|
|
88
|
-
Application.
|
82
|
+
Application.impl_project.each { |obj| obj.populate(self, **kwargs) }
|
89
83
|
@extensions.each { |ext| __send__(ext, **kwargs) }
|
90
84
|
|
91
|
-
series
|
85
|
+
series.__build__(**kwargs)
|
86
|
+
__build__(**kwargs)
|
92
87
|
|
93
|
-
|
94
|
-
|
95
|
-
if series.has?('build')
|
96
|
-
init = ['depend', dev? && series.has?('refresh') ? 'refresh' : 'build']
|
97
|
-
|
98
|
-
task default: init[1] unless task_defined?('default')
|
88
|
+
yield self if block_given?
|
89
|
+
end
|
99
90
|
|
100
|
-
|
101
|
-
|
102
|
-
|
91
|
+
def with(group: nil, ref: nil, &blk)
|
92
|
+
@group = nil
|
93
|
+
@ref = nil
|
94
|
+
if group
|
95
|
+
@group = group
|
96
|
+
if block_given?
|
97
|
+
instance_eval(&blk)
|
98
|
+
@group = nil
|
99
|
+
end
|
100
|
+
elsif ref
|
101
|
+
@ref = ref
|
102
|
+
if block_given?
|
103
|
+
instance_eval(&blk)
|
104
|
+
@ref = nil
|
103
105
|
end
|
104
106
|
end
|
105
|
-
|
106
|
-
|
107
|
-
yield self if block_given?
|
107
|
+
self
|
108
108
|
end
|
109
109
|
|
110
|
-
def run(script, group:
|
110
|
+
def run(script, group: @group, ref: @ref)
|
111
111
|
script_command :run, script, group, ref
|
112
112
|
end
|
113
113
|
|
114
|
-
def depend(script, group:
|
114
|
+
def depend(script, group: @group, ref: @ref)
|
115
115
|
script_command :depend, script, group, ref
|
116
116
|
end
|
117
117
|
|
118
|
-
def clean(script, group:
|
118
|
+
def clean(script, group: @group, ref: @ref)
|
119
119
|
script_command :clean, script, group, ref
|
120
120
|
end
|
121
121
|
|
122
|
-
def doc(script, group:
|
122
|
+
def doc(script, group: @group, ref: @ref)
|
123
123
|
script_command :doc, script, group, ref
|
124
124
|
end
|
125
125
|
|
126
|
-
def test(script, group:
|
126
|
+
def test(script, group: @group, ref: @ref)
|
127
127
|
script_command :test, script, group, ref
|
128
128
|
end
|
129
129
|
|
130
|
-
def
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
130
|
+
def exclude(base, group: @group, ref: @ref)
|
131
|
+
script_command :exclude, as_a(base, :to_sym).freeze, group, ref
|
132
|
+
end
|
133
|
+
|
134
|
+
def add(name, path = nil, **kwargs)
|
135
|
+
ref = if kwargs.key?(:ref)
|
136
|
+
kwargs.delete(:ref)
|
137
|
+
elsif !@ref.is_a?(::Array)
|
138
|
+
@ref
|
139
|
+
end
|
140
|
+
kwargs[:group] = @group if !kwargs.key?(:group) && !@group.is_a?(::Array)
|
141
|
+
path = root_path(path || name.to_s)
|
142
|
+
proj = ((if !ref.is_a?(::Class)
|
143
|
+
Application.find(ref, path: path)
|
144
|
+
elsif ref < Project::Base
|
145
|
+
ref
|
146
|
+
end) || Project::Base).new(prefix ? "#{prefix}:#{name}" : name, path, self, **kwargs)
|
147
|
+
@project[name = name.to_sym] = proj
|
148
|
+
__get__(:project)[name] = proj unless kwargs[:private]
|
140
149
|
self
|
141
150
|
end
|
142
151
|
|
143
|
-
def group(name, path, **kwargs)
|
152
|
+
def group(name, path, override: {}, **kwargs)
|
144
153
|
root_path(path).children.map do |ent|
|
145
154
|
next unless (dir = Pathname.new(ent)).directory?
|
146
155
|
|
147
156
|
index = 0
|
148
157
|
basename = dir.basename.to_s.to_sym
|
149
|
-
override = kwargs.delete(basename)
|
150
158
|
while @project[basename]
|
151
159
|
index += 1
|
152
160
|
basename = :"#{basename}-#{index}"
|
153
161
|
end
|
154
|
-
[basename, dir, override]
|
162
|
+
[basename, dir, override[basename]]
|
155
163
|
end
|
156
|
-
.each do |basename, dir,
|
157
|
-
|
158
|
-
|
159
|
-
add(basename, dir, group: name, **
|
164
|
+
.each do |basename, dir, opts|
|
165
|
+
args = kwargs.dup
|
166
|
+
args.merge!(opts) if opts
|
167
|
+
add(basename, dir, group: name, **args)
|
160
168
|
end
|
161
169
|
self
|
162
170
|
end
|
@@ -174,29 +182,35 @@ module Squared
|
|
174
182
|
def style(name, *args, target: nil, empty: false)
|
175
183
|
data = nil
|
176
184
|
if target
|
177
|
-
as_a(target).each_with_index do |
|
185
|
+
as_a(target).each_with_index do |key, i|
|
178
186
|
if i == 0
|
179
|
-
break unless (data = __get__(:theme)[
|
187
|
+
break unless (data = __get__(:theme)[key.to_sym])
|
180
188
|
else
|
181
|
-
data = data[
|
189
|
+
data = data[key.to_sym] ||= {}
|
182
190
|
end
|
183
191
|
end
|
184
|
-
return unless data
|
185
192
|
end
|
186
|
-
apply_style(data || theme, name, *args, empty: empty)
|
193
|
+
apply_style(data || theme, name, *args, empty: empty) unless target && !data
|
187
194
|
self
|
188
195
|
end
|
189
196
|
|
190
|
-
def script(group: nil, ref: nil)
|
191
|
-
if group
|
192
|
-
|
197
|
+
def script(*args, group: nil, ref: nil)
|
198
|
+
if group
|
199
|
+
@script[:group][group.to_sym]
|
200
|
+
elsif ref
|
201
|
+
@script[:ref][ref.to_sym]
|
202
|
+
elsif (val = @script[:build])
|
203
|
+
r = @script[:ref][:_]
|
204
|
+
g = @script[:group][:_]
|
205
|
+
args.empty? || (!r && !g) || (r && args.include?(r)) || (g && args.include?(g)) ? [val, @script[:env]] : []
|
193
206
|
else
|
194
|
-
|
207
|
+
[]
|
195
208
|
end
|
196
209
|
end
|
197
210
|
|
198
|
-
def env(key,
|
199
|
-
|
211
|
+
def env(key, default = nil, equals: nil, ignore: nil)
|
212
|
+
@env ||= main.gsub(/[^\w]+/, '_').upcase
|
213
|
+
ret = ENV.fetch("#{key}_#{@env}", ENV[key]).to_s
|
200
214
|
return ret == equals.to_s unless equals.nil?
|
201
215
|
|
202
216
|
ret.empty? || (ignore && as_a(ignore).any? { |val| ret == val.to_s }) ? default : ret
|
@@ -211,7 +225,7 @@ module Squared
|
|
211
225
|
end
|
212
226
|
|
213
227
|
def find_base(obj)
|
214
|
-
Application.
|
228
|
+
Application.impl_project.find { |proj| obj.instance_of?(proj) }
|
215
229
|
end
|
216
230
|
|
217
231
|
def to_s
|
@@ -229,78 +243,72 @@ module Squared
|
|
229
243
|
def task_base?(key, val)
|
230
244
|
return val if task_defined?(key)
|
231
245
|
|
232
|
-
val if key == :refresh && series
|
246
|
+
val if key == :refresh && series.build.include?(val = "#{val.split(':').first}:build")
|
233
247
|
end
|
234
248
|
|
235
|
-
def
|
236
|
-
|
249
|
+
def task_extend?(obj, key)
|
250
|
+
series.extend?(obj, key)
|
237
251
|
end
|
238
252
|
|
239
|
-
def task_defined?(key)
|
253
|
+
def task_defined?(key, *)
|
240
254
|
::Rake::Task.task_defined?(key)
|
241
255
|
end
|
242
256
|
|
243
|
-
def dev?(
|
244
|
-
|
257
|
+
def dev?(global: nil, **kwargs)
|
258
|
+
script?(:dev, global: global.nil? ? kwargs[:pat].nil? : global, **kwargs)
|
245
259
|
end
|
246
260
|
|
247
|
-
def prod?(
|
261
|
+
def prod?(global: false, **kwargs)
|
248
262
|
return false if global && (@script[:dev] == true || !@script[:prod])
|
249
263
|
|
250
|
-
|
251
|
-
end
|
252
|
-
|
253
|
-
protected
|
254
|
-
|
255
|
-
def confirm(msg, agree: 'Y', cancel: 'N', default: nil, attempts: 5, timeout: 15)
|
256
|
-
require 'readline'
|
257
|
-
require 'timeout'
|
258
|
-
agree = /^#{agree}$/i if agree.is_a?(String)
|
259
|
-
cancel = /^#{cancel}$/i if cancel.is_a?(String)
|
260
|
-
Timeout.timeout(timeout) do
|
261
|
-
begin
|
262
|
-
while (ch = Readline.readline(msg, true))
|
263
|
-
ch = ch.chomp
|
264
|
-
ch = default if ch.empty?
|
265
|
-
case ch
|
266
|
-
when agree
|
267
|
-
return true
|
268
|
-
when cancel
|
269
|
-
return false
|
270
|
-
end
|
271
|
-
attempts -= 1
|
272
|
-
exit 1 unless attempts >= 0
|
273
|
-
end
|
274
|
-
rescue Interrupt
|
275
|
-
puts
|
276
|
-
exit 0
|
277
|
-
else
|
278
|
-
false
|
279
|
-
end
|
280
|
-
end
|
264
|
+
script?(:prod, global: global, **kwargs)
|
281
265
|
end
|
282
266
|
|
283
267
|
private
|
284
268
|
|
269
|
+
def __build__(**kwargs)
|
270
|
+
if !task_defined?('default') && (default = kwargs[:default]) && series.has?(default)
|
271
|
+
task 'default' => default
|
272
|
+
end
|
273
|
+
return unless series.has?(:build)
|
274
|
+
|
275
|
+
series.refresh.clear unless series.refresh.any? { |val| val.end_with?(':refresh') }
|
276
|
+
|
277
|
+
init = [:depend, dev? && series.has?(:refresh) ? :refresh : :build]
|
278
|
+
|
279
|
+
task 'default' => init[1] unless task_defined?('default')
|
280
|
+
|
281
|
+
return if task_defined?('init') || !series.has?(init[0])
|
282
|
+
|
283
|
+
desc 'init'
|
284
|
+
task 'init' => init
|
285
|
+
end
|
286
|
+
|
285
287
|
def script_command(task, val, group, ref)
|
286
288
|
if group
|
287
289
|
label = :group
|
288
|
-
items = as_a(group)
|
290
|
+
items = as_a(group, :to_sym)
|
289
291
|
else
|
290
292
|
label = :ref
|
291
|
-
items = as_a(ref)
|
293
|
+
items = as_a(ref, :to_sym)
|
292
294
|
end
|
293
|
-
items.each { |name| (@script[label][name
|
295
|
+
items.each { |name| (@script[label][name] ||= {})[task] = val }
|
294
296
|
self
|
295
297
|
end
|
296
298
|
|
297
|
-
def
|
298
|
-
|
299
|
+
def script?(state, script: nil, pat: nil, ref: nil, group: nil, global: false)
|
300
|
+
r = @script[:ref][:_]
|
301
|
+
g = @script[:group][:_]
|
302
|
+
if global && ((!ref && !group) || (!r && !g) || (ref && contains?(r, ref)) || (group && contains?(g, group)))
|
299
303
|
pat = @script[state] if pat.nil?
|
300
304
|
script ||= @script[:build]
|
301
305
|
end
|
302
306
|
pat.is_a?(::Regexp) ? pat.match?(script) : pat == true
|
303
307
|
end
|
308
|
+
|
309
|
+
def contains?(data, val)
|
310
|
+
as_a(data).any? { |item| item.to_s == val.to_s }
|
311
|
+
end
|
304
312
|
end
|
305
313
|
end
|
306
314
|
end
|