squared 0.0.1
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 +7 -0
- data/LICENSE +11 -0
- data/README.md +1347 -0
- data/README.ruby.md +50 -0
- data/lib/squared/common/class.rb +18 -0
- data/lib/squared/common/format.rb +151 -0
- data/lib/squared/common/shell.rb +40 -0
- data/lib/squared/common/system.rb +55 -0
- data/lib/squared/common/task.rb +27 -0
- data/lib/squared/common.rb +66 -0
- data/lib/squared/config.rb +240 -0
- data/lib/squared/repo/project/base.rb +357 -0
- data/lib/squared/repo/project/git.rb +521 -0
- data/lib/squared/repo/project/node.rb +394 -0
- data/lib/squared/repo/project/python.rb +104 -0
- data/lib/squared/repo/project/ruby.rb +277 -0
- data/lib/squared/repo/project.rb +49 -0
- data/lib/squared/repo/workspace.rb +427 -0
- data/lib/squared/repo.rb +39 -0
- data/lib/squared/version.rb +5 -0
- data/lib/squared.rb +13 -0
- data/squared.gemspec +29 -0
- metadata +95 -0
@@ -0,0 +1,277 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Squared
|
4
|
+
module Repo
|
5
|
+
module Project
|
6
|
+
class Ruby < Git
|
7
|
+
GEMFILE = %w[Gemfile Gemfile.lock gem.deps.rb Isolate].freeze
|
8
|
+
OPT_INSTALL = %w[no-cache force quiet verbose].freeze
|
9
|
+
OPT_UPDATE = %w[redownload local strict conservative quiet verbose].freeze
|
10
|
+
private_constant :GEMFILE, :OPT_INSTALL, :OPT_UPDATE
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def tasks
|
14
|
+
nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_sym
|
18
|
+
:ruby
|
19
|
+
end
|
20
|
+
|
21
|
+
def is_a?(path)
|
22
|
+
if path.is_a?(::String) || path.is_a?(::Pathname)
|
23
|
+
base = Pathname.new(path)
|
24
|
+
[*GEMFILE, 'Rakefile', 'README.rdoc'].any? { |file| base.join(file).exist? }
|
25
|
+
else
|
26
|
+
super
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
@@tasks[:ruby] = {
|
32
|
+
install: %i[redownload local prefer-local with-g without-g],
|
33
|
+
update: %i[all patch minor major],
|
34
|
+
pristine: %i[version extensions]
|
35
|
+
}.freeze
|
36
|
+
|
37
|
+
def initialize(name, project, workspace, **kwargs)
|
38
|
+
super
|
39
|
+
if env('BUILD', suffix: 'DEV', equals: '0')
|
40
|
+
@dev = false
|
41
|
+
else
|
42
|
+
@dev = kwargs.delete(:dev)
|
43
|
+
if env('BUILD', suffix: 'DEV')
|
44
|
+
@dev = true
|
45
|
+
elsif @dev.nil?
|
46
|
+
@dev = @workspace.dev?
|
47
|
+
end
|
48
|
+
end
|
49
|
+
@version = env('BUILD', suffix: 'VERSION', strict: true) || kwargs.delete(:version)
|
50
|
+
@autodetect = kwargs.key?(:autodetect) ? kwargs.delete(:autodetect) : false
|
51
|
+
@gemdir = nil
|
52
|
+
return unless @output[0].nil? && @copy.nil? && !@version && !@autodetect && !doc? && (file = rakefile)
|
53
|
+
|
54
|
+
begin
|
55
|
+
pat = %r{\brequire\s+(["'])bundler/gem_tasks\1}
|
56
|
+
File.foreach(file) do |line|
|
57
|
+
next unless pat.match?(line)
|
58
|
+
|
59
|
+
@output[0] = 'bundle exec rake build'
|
60
|
+
@copy = 'bundle exec rake install'
|
61
|
+
@clean ||= 'bundle exec rake clean'
|
62
|
+
break
|
63
|
+
end
|
64
|
+
rescue StandardError => e
|
65
|
+
warn e
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def populate(*)
|
70
|
+
super
|
71
|
+
return unless outdated?
|
72
|
+
|
73
|
+
namespace @name do
|
74
|
+
@@tasks[:ruby].each do |action, flags|
|
75
|
+
namespace action do
|
76
|
+
flags.each do |flag|
|
77
|
+
case action
|
78
|
+
when :install
|
79
|
+
case flag
|
80
|
+
when :'with-g', :'without-g'
|
81
|
+
desc format_desc(action, flag, 'group+')
|
82
|
+
task flag, [:group] do |_, args|
|
83
|
+
install(flag, group: collect_args(args, :group))
|
84
|
+
end
|
85
|
+
else
|
86
|
+
desc format_desc(action, flag, OPT_INSTALL)
|
87
|
+
task flag, [:opts] do |_, args|
|
88
|
+
install(flag, opts: collect_args(args, :opts))
|
89
|
+
end
|
90
|
+
end
|
91
|
+
when :update
|
92
|
+
desc format_desc(action, flag, OPT_UPDATE)
|
93
|
+
task flag, [:opts] do |_, args|
|
94
|
+
update(flag, opts: collect_args(args, :opts))
|
95
|
+
end
|
96
|
+
when :pristine
|
97
|
+
desc format_desc(action, flag, 'version?')
|
98
|
+
task flag, [:version] do |_, args|
|
99
|
+
pristine(flag, version: args.version)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def depend(flag = nil, opts: [], group: [])
|
109
|
+
if @depend
|
110
|
+
super
|
111
|
+
else
|
112
|
+
case flag
|
113
|
+
when :redownload, :local, :'prefer-local'
|
114
|
+
cmd = bundle_session 'install'
|
115
|
+
cmd << "--#{flag}"
|
116
|
+
if (val = env('BUNDLE_TRUST_POLICY'))
|
117
|
+
cmd << "--trust-policy=#{case val
|
118
|
+
when '0'
|
119
|
+
'NoSecurity'
|
120
|
+
when '1'
|
121
|
+
'AlmostNoSecurity'
|
122
|
+
when '2'
|
123
|
+
'LowSecurity'
|
124
|
+
when '3'
|
125
|
+
'MediumSecurity'
|
126
|
+
when '4'
|
127
|
+
'HighSecurity'
|
128
|
+
else
|
129
|
+
val
|
130
|
+
end}"
|
131
|
+
end
|
132
|
+
append_opts opts, OPT_INSTALL
|
133
|
+
when :'with-g', :'without-g'
|
134
|
+
guard_params('install', flag, args: group)
|
135
|
+
cmd = gem_session 'install', '-g'
|
136
|
+
opt = flag.to_s.sub('-g', '')
|
137
|
+
group.each { |s| cmd << "--#{opt}=#{shell_escape(s)}" }
|
138
|
+
else
|
139
|
+
cmd = bundle_session 'install'
|
140
|
+
end
|
141
|
+
run(banner: banner?, exception: @workspace.exception)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def copy(from: 'lib', glob: '**/*', basedir: @gemdir, override: false)
|
146
|
+
if @copy && !override
|
147
|
+
return super if @copy.is_a?(::String)
|
148
|
+
|
149
|
+
from = @copy[:from] if @copy.key?(:from)
|
150
|
+
glob = @copy[:glob] if @copy.key?(:glob)
|
151
|
+
basedir = @copy[:basedir] if @copy.key?(:basedir)
|
152
|
+
end
|
153
|
+
return unless basedir
|
154
|
+
|
155
|
+
dest = Pathname.new(basedir).realpath
|
156
|
+
print_item unless @output[0]
|
157
|
+
glob = as_a(glob)
|
158
|
+
as_a(from).each_with_index do |val, i|
|
159
|
+
a = base_path(val)
|
160
|
+
b = dest.join(val)
|
161
|
+
c = glob[i] || '**/*'
|
162
|
+
warn "cp #{a.join(c)} #{b}"
|
163
|
+
copy_d(a, b, glob: c, verbose: verbose?)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def outdated(*); end
|
168
|
+
|
169
|
+
def update(flag, opts: [])
|
170
|
+
cmd = bundle_session 'update'
|
171
|
+
case flag
|
172
|
+
when :all, :major, :patch, :minor
|
173
|
+
cmd << "--#{flag}"
|
174
|
+
end
|
175
|
+
append_opts opts, OPT_UPDATE
|
176
|
+
run(banner: banner?, exception: @workspace.exception)
|
177
|
+
end
|
178
|
+
|
179
|
+
def pristine(flag, version: nil)
|
180
|
+
cmd = gem_session 'pristine', @project
|
181
|
+
case flag
|
182
|
+
when :extensions
|
183
|
+
cmd << '--extensions'
|
184
|
+
when :version
|
185
|
+
guard_params version, 'version'
|
186
|
+
end
|
187
|
+
cmd << "--version=#{version}" if version
|
188
|
+
run(banner: banner?, exception: @workspace.exception)
|
189
|
+
end
|
190
|
+
|
191
|
+
def rakefile
|
192
|
+
file = ::Rake::Application::DEFAULT_RAKEFILES.find { |val| base_path(val).exist? }
|
193
|
+
base_path(file) if file
|
194
|
+
end
|
195
|
+
|
196
|
+
def copy?
|
197
|
+
return true if @copy && (@copy.is_a?(::String) || @copy.fetch(:gemdir, nil))
|
198
|
+
return gemdir? if @gemdir
|
199
|
+
|
200
|
+
gem_path = -> { "gems#{::File::SEPARATOR}#{@project}-#{@version}" }
|
201
|
+
if @version && (val = ENV['GEM_HOME'])
|
202
|
+
@gemdir = Pathname.new(val).join(gem_path.())
|
203
|
+
return true if gemdir?
|
204
|
+
end
|
205
|
+
return false unless @autodetect
|
206
|
+
|
207
|
+
error = ->(hint) { raise ArgumentError, message('failed to parse', hint: hint) }
|
208
|
+
begin
|
209
|
+
out = `gem -C #{shell_quote(@path)} list --local -d #{@project}`
|
210
|
+
data = /#{Regexp.escape(@project)} \(([^)]+)\)/.match(out)
|
211
|
+
error.('version') unless data
|
212
|
+
ver = data[1].split(/\s*,\s*/)
|
213
|
+
if @version
|
214
|
+
ver.unshift(@version)
|
215
|
+
ver.uniq!
|
216
|
+
end
|
217
|
+
ver.each do |v|
|
218
|
+
data = /\(#{Regexp.escape(v)}(?:,[^)]+|\b)\):([^\n]+)/.match(out)
|
219
|
+
next unless data
|
220
|
+
|
221
|
+
warn "using version #{v} (given #{@version})" if @version && @version != v
|
222
|
+
@version = v
|
223
|
+
break
|
224
|
+
end
|
225
|
+
error.('path') unless data
|
226
|
+
@gemdir = Pathname.new(data[1].strip).join(gem_path.())
|
227
|
+
rescue StandardError => e
|
228
|
+
warn e
|
229
|
+
@version = nil
|
230
|
+
@gemdir = nil
|
231
|
+
@autodetect = false
|
232
|
+
else
|
233
|
+
gemdir?
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def depend?
|
238
|
+
!@depend.nil? || outdated?
|
239
|
+
end
|
240
|
+
|
241
|
+
def outdated?
|
242
|
+
GEMFILE.any? { |file| base_path(file).exist? }
|
243
|
+
end
|
244
|
+
|
245
|
+
def dev?
|
246
|
+
@dev
|
247
|
+
end
|
248
|
+
|
249
|
+
private
|
250
|
+
|
251
|
+
def append_opts(opts, list = [])
|
252
|
+
if (val = env('BUNDLE_JOBS')).to_i > 0
|
253
|
+
@session << "-j#{val}"
|
254
|
+
end
|
255
|
+
list.each { |flag| @session << "--#{flag}" if opts.include?(flag) }
|
256
|
+
end
|
257
|
+
|
258
|
+
def gem_session(*cmd)
|
259
|
+
session('gem', *cmd)
|
260
|
+
end
|
261
|
+
|
262
|
+
def bundle_session(*cmd)
|
263
|
+
session('bundle', *cmd)
|
264
|
+
append_nocolor
|
265
|
+
end
|
266
|
+
|
267
|
+
def banner?
|
268
|
+
!@session.include?('--quiet')
|
269
|
+
end
|
270
|
+
|
271
|
+
def gemdir?
|
272
|
+
@gemdir.exist? && !@gemdir.empty?
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Squared
|
4
|
+
module Repo
|
5
|
+
module Project
|
6
|
+
class << self
|
7
|
+
include Common::Format
|
8
|
+
|
9
|
+
attr_accessor :line_width
|
10
|
+
|
11
|
+
def banner(*lines, styles: nil, pad: 0, first: false)
|
12
|
+
n = max_width(lines)
|
13
|
+
ch = ' ' * pad
|
14
|
+
index = -1
|
15
|
+
out = lines.map do |val|
|
16
|
+
index += 1
|
17
|
+
val = ch + val.ljust(n - (pad * 2)) + ch
|
18
|
+
if styles && (!first || index == 0)
|
19
|
+
sub_style(val, *styles)
|
20
|
+
else
|
21
|
+
val
|
22
|
+
end
|
23
|
+
end
|
24
|
+
out << ('-' * n)
|
25
|
+
out.join("\n")
|
26
|
+
end
|
27
|
+
|
28
|
+
def footer(*lines)
|
29
|
+
n = max_width(lines)
|
30
|
+
['-' * n, *lines.map { |val| val.ljust(n) }].join("\n")
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def max_width(lines)
|
36
|
+
[lines.max_by(&:size).size, line_width].max
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
@line_width = ENV.fetch('LOG_COLUMNS', 80).to_i
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
require_relative 'project/base'
|
46
|
+
require_relative 'project/git'
|
47
|
+
require_relative 'project/node'
|
48
|
+
require_relative 'project/python'
|
49
|
+
require_relative 'project/ruby'
|