squared 0.0.10 → 0.0.11
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 +45 -26
- data/lib/squared/app.rb +10 -0
- data/lib/squared/common/base.rb +7 -13
- data/lib/squared/common/class.rb +20 -3
- data/lib/squared/common/format.rb +59 -15
- data/lib/squared/common/prompt.rb +38 -0
- data/lib/squared/common/system.rb +6 -36
- data/lib/squared/common/task.rb +3 -2
- data/lib/squared/common/utils.rb +25 -16
- data/lib/squared/common.rb +1 -0
- data/lib/squared/config.rb +18 -16
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +224 -110
- data/lib/squared/workspace/project/base.rb +258 -163
- data/lib/squared/workspace/project/git.rb +66 -76
- data/lib/squared/workspace/project/node.rb +220 -73
- data/lib/squared/workspace/project/python.rb +22 -16
- data/lib/squared/workspace/project/ruby.rb +76 -60
- data/lib/squared/workspace/project.rb +0 -3
- data/lib/squared/workspace/repo.rb +25 -12
- data/lib/squared/workspace/series.rb +80 -52
- data/lib/squared/workspace.rb +5 -4
- data/lib/squared.rb +1 -11
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d000551aa00185dae3ea1bc7e3a61c64af96dce7d717339483d8cb572ca12d43
|
4
|
+
data.tar.gz: 229f06052512ee06d16e43688602753a867025e8cf39b6b1c6dfafa69805fdbc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5efe60578369457075929b95ba8ea628d39d7324d40f84c397e07606c8c5fe48f07f797b940d7ca34a80321bb3f1435494c36afcd95432cbe8924e4353099f56
|
7
|
+
data.tar.gz: daf832c4fbcf0e80459317be7b91781cfea9b653b3368cdbc090101d67ca59aff8b38940c2803100e322ca14bd25f45ccf37ef27bb348312b724c45babeb3393
|
data/README.ruby.md
CHANGED
@@ -34,7 +34,14 @@ Projects from any accessible folder can be added either relative to `REPO_ROOT`
|
|
34
34
|
|
35
35
|
```ruby
|
36
36
|
require "squared"
|
37
|
-
|
37
|
+
|
38
|
+
require "squared/workspace"
|
39
|
+
require "squared/workspace/repo" # Optional
|
40
|
+
require "squared/workspace/project/node" #
|
41
|
+
require "squared/workspace/project/python" #
|
42
|
+
require "squared/workspace/project/ruby" #
|
43
|
+
# OR
|
44
|
+
require "squared/app" # All workspace related modules
|
38
45
|
|
39
46
|
# NODE_ENV = production
|
40
47
|
# REPO_ROOT = /workspaces
|
@@ -52,7 +59,7 @@ require "squared/workspace/repo" # Repo (optional)
|
|
52
59
|
|
53
60
|
Workspace::Application
|
54
61
|
.new(Dir.pwd, main: "squared") # Dir.pwd? (main? is implicitly basename)
|
55
|
-
.banner("group", "project", styles: %i[yellow black], border: "bold") # name | project | path | ref | group?
|
62
|
+
.banner("group", "project", styles: %i[yellow black], border: "bold") # name | project | path | ref | group? | parent? | version?
|
56
63
|
.repo("https://github.com/anpham6/squared-repo", "nightly", script: ["build:dev", "build:prod"], ref: :node) # Repo (optional)
|
57
64
|
.run("rake install", ref: :ruby)
|
58
65
|
.depend(false, group: "default")
|
@@ -63,13 +70,17 @@ Workspace::Application
|
|
63
70
|
"CFLAGS" => "-fPIC -O1"
|
64
71
|
})
|
65
72
|
.add("optparse", doc: "rake rdoc", group: "default") # Uses bundler/gem_tasks (without C extensions)
|
66
|
-
.add("logger", copy: { from: "lib", glob: "**/*.rb",
|
67
|
-
.add("e-mc", "emc", copy: { from: "publish",
|
68
|
-
.add("pi-r", "pir", copy: { from: "publish",
|
73
|
+
.add("logger", copy: { from: "lib", glob: "**/*.rb", into: "~/.rvm/gems/ruby-3.3.5/gems/logger-1.6.1" }, clean: ["tmp/"]) # autodetect: true
|
74
|
+
.add("e-mc", "emc", copy: { from: "publish", scope: "@e-mc", also: [:pir, "squared-express/"] }, ref: :node) # Node
|
75
|
+
.add("pi-r", "pir", copy: { from: "publish", scope: "@pi-r" }, clean: ["publish/**/*.js", "tmp/"]) # Trailing slash required for directories
|
69
76
|
.add("squared", script: ["build:stage1", "build:stage2"], group: "app") do # Copy target (main)
|
70
|
-
add("publish/sqd-cli", "cli", exclude: [:git])
|
71
|
-
add("publish/sqd-serve")
|
77
|
+
add("publish/sqd-cli", "cli", exclude: [:git]) # rake cli:build
|
78
|
+
add("publish/sqd-serve") # rake sqd-serve:build
|
72
79
|
add("publish/sqd-admin", group: "sqd", exclude: [:base])
|
80
|
+
# OR
|
81
|
+
with(exclude: [:base]) { add("publish/*", "packages") } # rake packages:sqd-serve:build
|
82
|
+
# OR
|
83
|
+
add(["publish/sqd-cli", "publish/sqd-serve", "publish/sqd-admin"], true, exclude: [:base]) # rake squared:sqd-serve:build
|
73
84
|
end
|
74
85
|
.add("squared/sqd", exclude: [:git]) do
|
75
86
|
variable_set :script, "build:sqd" # Override detection
|
@@ -77,7 +88,7 @@ Workspace::Application
|
|
77
88
|
variable_set :clean, ["build/sqd/"]
|
78
89
|
end
|
79
90
|
.style("banner", 255.255) # 256 colors (fg | fg.bg | -0.bg)
|
80
|
-
.build(default: "status", parallel: ["pull", "fetch", "rebase", "copy", "clean"]) do |workspace|
|
91
|
+
.build(default: "status", parallel: ["pull", "fetch", "rebase", "copy", "clean", "outdated:ruby"]) do |workspace|
|
81
92
|
workspace
|
82
93
|
.enable_aixterm
|
83
94
|
.style({
|
@@ -97,28 +108,28 @@ Workspace::Application
|
|
97
108
|
.new(ENV["SQUARED_HOME"], prefix: "rb", common: false) # Local styles
|
98
109
|
.group("ruby", "default", run: "rake build", copy: "rake install", clean: "rake clean", ref: :ruby, override: {
|
99
110
|
pathname: {
|
100
|
-
run: "rake compile"
|
111
|
+
run: "rake compile" # rake rb:pathname:build
|
101
112
|
}
|
102
113
|
})
|
103
|
-
.with(:python) do
|
104
|
-
banner(
|
105
|
-
doc("make html")
|
106
|
-
run(false)
|
107
|
-
exclude(%i[base git])
|
108
|
-
add("android-docs", "android")
|
109
|
-
add("chrome-docs", "chrome")
|
110
|
-
end
|
114
|
+
.with(:python) do # ref=Symbol | group=String
|
115
|
+
banner([:name, ': ', :version], "path") # chrome-docs: 0.1.0 | /workspaces/chrome-docs
|
116
|
+
doc("make html") # rake rb:doc:python
|
117
|
+
run(false) # rake rb:build:python (disabled)
|
118
|
+
exclude(%i[base git]) # Project::Git.ref (superclass)
|
119
|
+
add("android-docs", "android") # rake rb:android:doc
|
120
|
+
add("chrome-docs", "chrome") # rake rb:chrome:doc
|
121
|
+
end #
|
111
122
|
.style("inline", "bold")
|
112
123
|
.build
|
113
124
|
```
|
114
125
|
|
115
|
-
**NOTE**: The use of "**ref**" (class name) is only necessary when
|
126
|
+
**NOTE**: The use of "**ref**" (class name) is only necessary when initializing an empty directory (e.g. *rake repo:init*).
|
116
127
|
|
117
128
|
## Usage
|
118
129
|
|
119
130
|
```sh
|
120
|
-
rake -T
|
121
|
-
rake
|
131
|
+
rake -T # List tasks
|
132
|
+
rake # rake status (usually "build")
|
122
133
|
|
123
134
|
# GIT_OPTIONS=rebase
|
124
135
|
rake pull # All except "default" + "app"
|
@@ -145,6 +156,7 @@ rake build:app # squared + cli + sqd-serve
|
|
145
156
|
rake squared:build:workspace # cli + sqd-serve
|
146
157
|
rake pull:sqd # sqd-admin
|
147
158
|
rake squared:pull:workspace # sqd-serve + sqd-admin
|
159
|
+
rake squared:outdated:workspace # cli + sqd-serve + sqd-admin
|
148
160
|
```
|
149
161
|
|
150
162
|
## Methods
|
@@ -179,14 +191,21 @@ Non-task:
|
|
179
191
|
### Build
|
180
192
|
|
181
193
|
```ruby
|
194
|
+
# :env :run :opts
|
182
195
|
# LD_LIBRARY_PATH="path/to/lib" CFLAGS="-Wall" gcc a.c -o a.o -c
|
183
196
|
BUILD_${NAME} # gcc a.c -o a.o
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
#
|
188
|
-
|
189
|
-
BUILD_${NAME}
|
197
|
+
BUILD_OPTS_${NAME} # -c
|
198
|
+
BUILD_ENV_${NAME} # {"LD_LIBRARY_PATH":"path/to/lib","CFLAGS":"-Wall"} (hash/json)
|
199
|
+
|
200
|
+
# :env :opts :script
|
201
|
+
# NODE_ENV="production" NO_COLOR="1" npm run --loglevel=error --workspaces=false build:dev
|
202
|
+
BUILD_${NAME} # build:dev
|
203
|
+
BUILD_OPTS_${NAME} # --loglevel=error --workspaces=false
|
204
|
+
BUILD_ENV_${NAME} # {"NODE_ENV":"production","NO_COLOR":"1"} (hash/json)
|
205
|
+
BUILD_DEV_${NAME} # pattern,0,1 (:dev)
|
206
|
+
BUILD_PROD_${NAME} # pattern,0,1 (:prod)
|
207
|
+
|
208
|
+
BUILD_${NAME}=0 # skip project
|
190
209
|
```
|
191
210
|
|
192
211
|
These options also support the project specific suffix `${NAME}`. (e.g. LOG_FILE_SQUARED)
|
data/lib/squared/app.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'workspace'
|
4
|
+
require_relative 'workspace/repo'
|
5
|
+
require_relative 'workspace/project/node'
|
6
|
+
require_relative 'workspace/project/python'
|
7
|
+
require_relative 'workspace/project/ruby'
|
8
|
+
require_relative 'config'
|
9
|
+
|
10
|
+
Common = Squared::Common
|
data/lib/squared/common/base.rb
CHANGED
@@ -2,10 +2,14 @@
|
|
2
2
|
|
3
3
|
module Squared
|
4
4
|
module Common
|
5
|
-
|
5
|
+
ARG = {
|
6
6
|
PIPE: 1,
|
7
|
+
OUT: nil,
|
7
8
|
FAIL: false,
|
8
|
-
COMMON: true
|
9
|
+
COMMON: true,
|
10
|
+
BANNER: true,
|
11
|
+
SPACE: ' => ',
|
12
|
+
COLOR: ENV.fetch('NO_COLOR', '').empty?
|
9
13
|
}
|
10
14
|
VAR = {
|
11
15
|
project: {},
|
@@ -70,6 +74,7 @@ module Squared
|
|
70
74
|
end
|
71
75
|
|
72
76
|
def __freeze__
|
77
|
+
ARG.freeze
|
73
78
|
VAR.each_value(&:freeze)
|
74
79
|
VAR[:theme].each_value(&:freeze)
|
75
80
|
VAR.freeze
|
@@ -77,17 +82,6 @@ module Squared
|
|
77
82
|
|
78
83
|
module_function
|
79
84
|
|
80
|
-
def env(key, default = nil, equals: nil, ignore: nil, **)
|
81
|
-
ret = ENV.fetch(key, '')
|
82
|
-
return ret == equals.to_s unless equals.nil?
|
83
|
-
|
84
|
-
ret.empty? || (ignore && as_a(ignore).any? { |val| ret == val.to_s }) ? default : ret
|
85
|
-
end
|
86
|
-
|
87
|
-
def message(*args, hint: nil)
|
88
|
-
args.reject(&:empty?).join(' => ') + (hint ? " (#{hint})" : '')
|
89
|
-
end
|
90
|
-
|
91
85
|
def as_a(obj, meth = nil, flat: nil, compact: false)
|
92
86
|
return [] if obj.nil?
|
93
87
|
|
data/lib/squared/common/class.rb
CHANGED
@@ -1,14 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'set'
|
4
|
+
require 'forwardable'
|
4
5
|
|
5
6
|
module Squared
|
6
7
|
module Common
|
7
|
-
class
|
8
|
-
|
9
|
-
|
8
|
+
class SymSet
|
9
|
+
extend Forwardable
|
10
|
+
|
11
|
+
def_delegators :@data, :each, :each_with_index, :entries, :to_a, :include?
|
12
|
+
|
13
|
+
def initialize(data = [])
|
14
|
+
@data = Set.new(data)
|
10
15
|
end
|
11
16
|
|
17
|
+
def add(val)
|
18
|
+
@data.add(val.to_sym)
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
@data.to_s.sub('Set', SymSet.to_s)
|
23
|
+
end
|
24
|
+
|
25
|
+
alias inspect to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
class JoinSet < ::Set
|
12
29
|
def initialize(data = [], delim: ' ')
|
13
30
|
super(data.compact)
|
14
31
|
@delim = delim
|
@@ -40,7 +40,7 @@ module Squared
|
|
40
40
|
private
|
41
41
|
|
42
42
|
def sub_style(val, *args, styles: nil, pat: nil, index: 1)
|
43
|
-
return val unless
|
43
|
+
return val unless ARG[:COLOR]
|
44
44
|
|
45
45
|
if pat && index != 0
|
46
46
|
return val unless (data = pat.match(val))
|
@@ -106,7 +106,7 @@ module Squared
|
|
106
106
|
out
|
107
107
|
end
|
108
108
|
|
109
|
-
def check_style(
|
109
|
+
def check_style(args, empty: true)
|
110
110
|
ret = []
|
111
111
|
colors = __get__(:colors)
|
112
112
|
as_a(args, flat: true, compact: true).each do |val|
|
@@ -123,7 +123,7 @@ module Squared
|
|
123
123
|
ret if empty || !ret.empty?
|
124
124
|
end
|
125
125
|
|
126
|
-
def apply_style(data, key,
|
126
|
+
def apply_style(data, key, args, empty: true)
|
127
127
|
return if data.is_a?(::Symbol) && (data = __get__(:theme)[data]).nil?
|
128
128
|
|
129
129
|
set = ->(k, v) { data[k] = check_style(v, empty: empty) }
|
@@ -155,7 +155,7 @@ module Squared
|
|
155
155
|
end
|
156
156
|
end
|
157
157
|
|
158
|
-
def log_title(level, color:
|
158
|
+
def log_title(level, color: ARG[:COLOR])
|
159
159
|
theme = __get__(:theme)[:logger]
|
160
160
|
styles = theme[level = log_sym(level)] || theme[level = :unknown]
|
161
161
|
case (ret = +level.to_s.upcase)
|
@@ -165,7 +165,7 @@ module Squared
|
|
165
165
|
color ? sub_style(ret, *styles) : ret
|
166
166
|
end
|
167
167
|
|
168
|
-
def log_message(level, *args, subject: nil, hint: nil, color:
|
168
|
+
def log_message(level, *args, subject: nil, hint: nil, color: ARG[:COLOR])
|
169
169
|
args = args.map(&:to_s)
|
170
170
|
if args.size > 1
|
171
171
|
title = log_title(level, color: false)
|
@@ -183,20 +183,38 @@ module Squared
|
|
183
183
|
end
|
184
184
|
end
|
185
185
|
|
186
|
-
def
|
187
|
-
|
186
|
+
def puts_oe(*args, pipe: 1)
|
187
|
+
if pipe.is_a?(::Pathname)
|
188
|
+
begin
|
189
|
+
File.open(pipe, 'a') do |f|
|
190
|
+
br = File::SEPARATOR == '\\' ? "\r\n" : "\n"
|
191
|
+
args.flatten.each { |val| f.write("#{strip_style(val.chomp)}#{br}") }
|
192
|
+
end
|
193
|
+
return
|
194
|
+
rescue StandardError
|
195
|
+
pipe = 2
|
196
|
+
end
|
197
|
+
end
|
198
|
+
(pipe == 2 ? $stderr : $stdout).puts(*args)
|
188
199
|
end
|
189
200
|
|
190
201
|
module_function
|
191
202
|
|
192
|
-
def
|
203
|
+
def message(*args, hint: nil, empty: false)
|
204
|
+
(empty ? args.reject { |val| val.nil? || val.empty? } : args).join(ARG[:SPACE]) + (hint ? " (#{hint})" : '')
|
205
|
+
end
|
206
|
+
|
207
|
+
def emphasize(val, title: nil, footer: nil, cols: nil, sub: nil, border: nil, pipe: nil)
|
193
208
|
n = 0
|
194
|
-
|
195
|
-
|
196
|
-
n =
|
209
|
+
set = lambda do |l|
|
210
|
+
ret = as_a(l, :to_s)
|
211
|
+
n = ret.max_by(&:size).size
|
212
|
+
ret
|
197
213
|
end
|
214
|
+
title = set.(title) if title
|
215
|
+
footer = set.(footer) if footer
|
198
216
|
if val.is_a?(::Array)
|
199
|
-
lines = val
|
217
|
+
lines = val.map(&:to_s)
|
200
218
|
else
|
201
219
|
lines = val.to_s.lines.map(&:chomp)
|
202
220
|
lines[0] = "#{val.class}: #{lines.first}" if (err = val.is_a?(::StandardError))
|
@@ -208,24 +226,50 @@ module Squared
|
|
208
226
|
end
|
209
227
|
out = []
|
210
228
|
bord = '-' * (n + 4)
|
229
|
+
bord = sub_style(bord, styles: border) if border
|
211
230
|
sub = [sub] if sub && !sub.is_a?(::Array)
|
212
231
|
pr = lambda do |line|
|
213
232
|
s = line.ljust(n)
|
214
233
|
sub&.each { |h| s = sub_style(s, **h) }
|
215
|
-
"| #{s} |"
|
234
|
+
s = "| #{s} |"
|
235
|
+
if border
|
236
|
+
s = sub_style(s, pat: /^(\|)(.+)$/m, styles: border)
|
237
|
+
s = sub_style(s, pat: /^(.+)(\|)$/m, styles: border, index: 2)
|
238
|
+
end
|
239
|
+
s
|
216
240
|
end
|
217
241
|
out << bord
|
218
|
-
|
242
|
+
if title
|
243
|
+
out += title.map { |t| pr.(t) }
|
244
|
+
out << bord
|
245
|
+
end
|
219
246
|
lines.each { |line| out << pr.(line) }
|
220
247
|
out << bord
|
248
|
+
out += footer if footer
|
221
249
|
if block_given?
|
222
250
|
yield out
|
223
|
-
elsif pipe
|
251
|
+
elsif pipe
|
252
|
+
case pipe
|
253
|
+
when 0
|
254
|
+
pipe = $stdin
|
255
|
+
when 2
|
256
|
+
pipe = $stderr
|
257
|
+
else
|
258
|
+
pipe = $stdout unless pipe.respond_to?(:puts)
|
259
|
+
end
|
224
260
|
pipe.puts out
|
225
261
|
else
|
226
262
|
err ? warn(out) : puts(out)
|
227
263
|
end
|
228
264
|
end
|
265
|
+
|
266
|
+
def strip_style(val)
|
267
|
+
val.gsub(/\x1B\[(\d+;?)+m/, '')
|
268
|
+
end
|
269
|
+
|
270
|
+
def raise_error(*args, hint: nil, kind: ArgumentError)
|
271
|
+
raise kind, message(*args, hint: hint, empty: true)
|
272
|
+
end
|
229
273
|
end
|
230
274
|
end
|
231
275
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'readline'
|
4
|
+
|
5
|
+
module Squared
|
6
|
+
module Common
|
7
|
+
module Prompt
|
8
|
+
module_function
|
9
|
+
|
10
|
+
def confirm(msg, default = nil, agree: 'Y', cancel: 'N', attempts: 5, timeout: 15)
|
11
|
+
require 'timeout'
|
12
|
+
agree = /^#{agree}$/i if agree.is_a?(::String)
|
13
|
+
cancel = /^#{cancel}$/i if cancel.is_a?(::String)
|
14
|
+
Timeout.timeout(timeout) do
|
15
|
+
begin
|
16
|
+
while (ch = Readline.readline(msg, true))
|
17
|
+
ch = ch.chomp
|
18
|
+
ch = default if ch.empty?
|
19
|
+
case ch
|
20
|
+
when agree
|
21
|
+
return true
|
22
|
+
when cancel
|
23
|
+
return false
|
24
|
+
end
|
25
|
+
attempts -= 1
|
26
|
+
exit 1 unless attempts >= 0
|
27
|
+
end
|
28
|
+
rescue Interrupt
|
29
|
+
puts
|
30
|
+
exit 0
|
31
|
+
else
|
32
|
+
false
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -8,43 +8,15 @@ module Squared
|
|
8
8
|
module System
|
9
9
|
module_function
|
10
10
|
|
11
|
-
def shell(*
|
11
|
+
def shell(*args, **kwargs)
|
12
12
|
if RUBY_VERSION =~ /^2\.[0-5]\./
|
13
13
|
exception = kwargs.delete(:exception)
|
14
|
-
ret = system(*
|
14
|
+
ret = system(*args, **kwargs)
|
15
15
|
raise $?.to_s if !ret && exception
|
16
16
|
|
17
17
|
ret
|
18
18
|
else
|
19
|
-
system(*
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def confirm(msg, default = nil, agree: 'Y', cancel: 'N', attempts: 5, timeout: 15)
|
24
|
-
require 'readline'
|
25
|
-
require 'timeout'
|
26
|
-
agree = /^#{agree}$/i if agree.is_a?(::String)
|
27
|
-
cancel = /^#{cancel}$/i if cancel.is_a?(::String)
|
28
|
-
Timeout.timeout(timeout) do
|
29
|
-
begin
|
30
|
-
while (ch = Readline.readline(msg, true))
|
31
|
-
ch = ch.chomp
|
32
|
-
ch = default if ch.empty?
|
33
|
-
case ch
|
34
|
-
when agree
|
35
|
-
return true
|
36
|
-
when cancel
|
37
|
-
return false
|
38
|
-
end
|
39
|
-
attempts -= 1
|
40
|
-
exit 1 unless attempts >= 0
|
41
|
-
end
|
42
|
-
rescue Interrupt
|
43
|
-
puts
|
44
|
-
exit 0
|
45
|
-
else
|
46
|
-
false
|
47
|
-
end
|
19
|
+
system(*args, **kwargs)
|
48
20
|
end
|
49
21
|
end
|
50
22
|
|
@@ -56,8 +28,7 @@ module Squared
|
|
56
28
|
subdir = []
|
57
29
|
files = 0
|
58
30
|
dest.mkpath if create
|
59
|
-
glob
|
60
|
-
glob.each do |val|
|
31
|
+
(glob.is_a?(::Array) ? glob : [glob]).each do |val|
|
61
32
|
Dir.glob(src.join(val)) do |path|
|
62
33
|
ent = Pathname.new(path)
|
63
34
|
next if ent.directory?
|
@@ -72,13 +43,12 @@ module Squared
|
|
72
43
|
files += 1
|
73
44
|
end
|
74
45
|
end
|
75
|
-
puts [dest.realpath, subdir.size.to_s, files.to_s].join(
|
46
|
+
puts [dest.realpath, subdir.size.to_s, files.to_s].join(Common::ARG[:SPACE]) if verbose
|
76
47
|
end
|
77
48
|
|
78
49
|
def copy_f(src, dest, overwrite: true, verbose: false)
|
79
50
|
unless overwrite
|
80
|
-
path = Pathname.new(dest)
|
81
|
-
if path.directory?
|
51
|
+
if (path = Pathname.new(dest)).directory?
|
82
52
|
src = [src] unless src.is_a?(::Array)
|
83
53
|
src = src.reject { |val| path.join(File.basename(val)).exist? }
|
84
54
|
elsif path.exist?
|
data/lib/squared/common/task.rb
CHANGED
@@ -16,8 +16,9 @@ module Squared
|
|
16
16
|
warn e if warning
|
17
17
|
end
|
18
18
|
|
19
|
-
def invoked?(name)
|
20
|
-
|
19
|
+
def invoked?(*name)
|
20
|
+
val = name.size > 1 ? name.join(':') : name.first.to_s
|
21
|
+
::Rake::Task.tasks.any? { |obj| obj.already_invoked && obj.name == val }
|
21
22
|
end
|
22
23
|
end
|
23
24
|
end
|
data/lib/squared/common/utils.rb
CHANGED
@@ -5,17 +5,18 @@ module Squared
|
|
5
5
|
module Utils
|
6
6
|
module_function
|
7
7
|
|
8
|
-
def
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
ENV.fetch(key, '')
|
8
|
+
def env(key, default = nil, suffix: @envname, equals: nil, ignore: nil)
|
9
|
+
ret = env_value(key, suffix: suffix)
|
10
|
+
return ret == equals.to_s unless equals.nil?
|
11
|
+
|
12
|
+
ret.empty? || (ignore && as_a(ignore).any? { |val| ret == val.to_s }) ? default : ret
|
14
13
|
end
|
15
14
|
|
16
|
-
def
|
17
|
-
|
15
|
+
def env_value(key, default = '', suffix: nil)
|
16
|
+
suffix && (ret = ENV["#{key}_#{suffix}"]) ? ret : ENV.fetch(key, default)
|
17
|
+
end
|
18
18
|
|
19
|
+
def env_bool(key, default = false, suffix: nil)
|
19
20
|
if key.is_a?(::String)
|
20
21
|
case env_value(key, suffix: suffix)
|
21
22
|
when ''
|
@@ -26,21 +27,29 @@ module Squared
|
|
26
27
|
true
|
27
28
|
end
|
28
29
|
else
|
29
|
-
key
|
30
|
+
key.nil? ? default : key
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
33
|
-
def env_pipe(key, default = 1, suffix: nil)
|
34
|
-
if
|
34
|
+
def env_pipe(key, default = 1, suffix: nil, root: nil)
|
35
|
+
if default.is_a?(String)
|
36
|
+
begin
|
37
|
+
default = (root ? root.join(default) : Pathname.new(default)).realdirpath
|
38
|
+
rescue StandardError => e
|
39
|
+
default = 1
|
40
|
+
warn e
|
41
|
+
end
|
42
|
+
end
|
43
|
+
case key
|
44
|
+
when ::String
|
35
45
|
case (ret = env_value(key, suffix: suffix))
|
36
46
|
when '0', '1', '2'
|
37
|
-
ret.to_i
|
38
|
-
else
|
39
|
-
default
|
47
|
+
return ret.to_i
|
40
48
|
end
|
41
|
-
|
42
|
-
key
|
49
|
+
when ::Numeric
|
50
|
+
return key if key >= 0 && key <= 2
|
43
51
|
end
|
52
|
+
default
|
44
53
|
end
|
45
54
|
|
46
55
|
def env_match(key, default = nil, suffix: nil, options: 0, timeout: nil)
|
data/lib/squared/common.rb
CHANGED