squared 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.ruby.md +26 -3
- data/lib/squared/common/base.rb +91 -0
- data/lib/squared/common/class.rb +1 -1
- data/lib/squared/common/format.rb +16 -9
- data/lib/squared/common/shell.rb +9 -9
- data/lib/squared/common/system.rb +4 -1
- data/lib/squared/common/task.rb +6 -2
- data/lib/squared/common.rb +1 -78
- data/lib/squared/config.rb +10 -10
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +306 -0
- data/lib/squared/{repo → workspace}/project/base.rb +86 -86
- data/lib/squared/{repo → workspace}/project/git.rb +98 -80
- data/lib/squared/{repo → workspace}/project/node.rb +22 -26
- data/lib/squared/workspace/project/python.rb +150 -0
- data/lib/squared/{repo → workspace}/project/ruby.rb +33 -28
- data/lib/squared/{repo → workspace}/project.rb +1 -1
- data/lib/squared/workspace/repo.rb +201 -0
- data/lib/squared/workspace/series.rb +125 -0
- data/lib/squared/{repo.rb → workspace.rb} +6 -3
- data/lib/squared.rb +9 -8
- metadata +13 -10
- data/lib/squared/repo/project/python.rb +0 -123
- data/lib/squared/repo/workspace.rb +0 -501
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 60e2da1ce8ec4439d4180db0c0f806d9984046ef5f12b34008563edd7b40b938
|
4
|
+
data.tar.gz: 6eb7ef1c8273d10747cb79c1a113dae53210cebd167969f4a1546a9fc07162f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75f989753670bd5854a8dccc6a3bf8d3d7397d2a373a50d46eaa7add861ff8d1f24cffb1c9ac00d48756d89abb50728c35368beb62649b3d704f3d7b059b449a
|
7
|
+
data.tar.gz: 6387222860eb65bd57cd14ba86b77b39d47a64d5a03940a5b6f6ac0ccea6368f0ab8df0a1886d5f6e6eec83f89887397b72f57a647a4ad06efa632020c1a5938
|
data/README.ruby.md
CHANGED
@@ -28,19 +28,26 @@ gem install squared
|
|
28
28
|
|
29
29
|
## Example - Rakefile
|
30
30
|
|
31
|
+
Projects from any accessible folder can be added either relative to `REPO_ROOT` or absolutely. The same Rakefile can also manage other similarly cloned repositories remotely by setting the `REPO_ROOT` environment variable to the location. Missing projects will simply be excluded from the task runner.
|
32
|
+
|
31
33
|
```ruby
|
32
34
|
require "squared"
|
35
|
+
require "squared/workspace/repo" # Repo (optional)
|
33
36
|
|
34
|
-
|
37
|
+
# REPO_ROOT = /workspaces
|
38
|
+
# REPO_HOME = /workspaces/squared
|
39
|
+
# rake = /workspaces/squared/Rakefile
|
40
|
+
|
41
|
+
Workspace::Application
|
35
42
|
.new("squared") # REPO_HOME
|
36
|
-
.repo("https://github.com/anpham6/squared-repo", "nightly", run:
|
43
|
+
.repo("https://github.com/anpham6/squared-repo", "nightly", run: "build") # Repo (optional)
|
37
44
|
.run("rake install", ref: :ruby)
|
38
45
|
.clean("rake clean", group: "default") # depend test doc
|
39
46
|
.clean(["build/"], group: "app")
|
40
47
|
.add("pathname", run: "rake compile", copy: "rake install", test: "rake test", group: "default", ref: :ruby) # Ruby (with C extensions)
|
41
48
|
.add("optparse", doc: "rake rdoc", group: "default") # Uses bundler/gem_tasks (without C extensions)
|
42
49
|
.add("logger", copy: { from: "lib", glob: "**/*.rb", gemdir: "~/.rvm/gems/ruby-3.3.5/gems/logger-1.6.1" }, clean: ["tmp/"]) # autodetect: true
|
43
|
-
.add("android", "android-docs", run: false, doc: "make html", ref: :python) #
|
50
|
+
.add("android", "android-docs", run: false, doc: "make html", ref: :python) # Python
|
44
51
|
.add("emc", "e-mc", copy: { from: "publish", into: "@e-mc", also: [:pir, "squared-express/"] }, ref: :node) # Node
|
45
52
|
.add("pir", "pi-r", copy: { from: "publish", into: "@pi-r" }, clean: ["publish/**/*.js", "tmp/"]) # Trailing slash required for directories
|
46
53
|
.add("squared", log: { file: "tmp/%Y-%m-%d.log", level: "debug" }, group: "app") # Copy target (main)
|
@@ -51,6 +58,22 @@ Repo::Workspace
|
|
51
58
|
.style(:banner, "bright_cyan", "bold", "bright_black!")
|
52
59
|
.finalize! # Optional
|
53
60
|
end
|
61
|
+
# pathname = /workspaces/pathname
|
62
|
+
# optparse = /workspaces/optparse
|
63
|
+
# log = /workspaces/logger
|
64
|
+
# android = /workspaces/android-docs
|
65
|
+
# emc = /workspaces/e-mc
|
66
|
+
# pir = /workspaces/pi-r
|
67
|
+
# squared = /workspaces/squared
|
68
|
+
|
69
|
+
Repo::Workspace
|
70
|
+
.new("squared")
|
71
|
+
.group("default", "ruby", run: "rake build", copy: "rake install", clean: "rake clean", pathname: { run: "rake compile" })
|
72
|
+
.build
|
73
|
+
# default = /workspaces/ruby/*
|
74
|
+
# pathname = /workspaces/ruby/pathname
|
75
|
+
# optparse = /workspaces/ruby/optparse
|
76
|
+
# logger = /workspaces/ruby/logger
|
54
77
|
```
|
55
78
|
|
56
79
|
**NOTE**: The use of "**ref**" (class name) is only necessary when running `repo:init` for the first time into an empty directory.
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Squared
|
4
|
+
module Common
|
5
|
+
VAR = {
|
6
|
+
project: {},
|
7
|
+
colors: {
|
8
|
+
black: '30',
|
9
|
+
red: '31',
|
10
|
+
green: '32',
|
11
|
+
yellow: '33',
|
12
|
+
blue: '34',
|
13
|
+
magenta: '35',
|
14
|
+
cyan: '36',
|
15
|
+
white: '37',
|
16
|
+
black!: '40',
|
17
|
+
red!: '41',
|
18
|
+
green!: '42',
|
19
|
+
yellow!: '43',
|
20
|
+
blue!: '44',
|
21
|
+
magenta!: '45',
|
22
|
+
cyan!: '46',
|
23
|
+
white!: '47'
|
24
|
+
},
|
25
|
+
theme: {
|
26
|
+
workspace: {},
|
27
|
+
project: {},
|
28
|
+
viewer: {
|
29
|
+
banner: %i[blue bold],
|
30
|
+
key: %i[bold],
|
31
|
+
value: %i[green],
|
32
|
+
string: %i[yellow],
|
33
|
+
hash: %i[green black!],
|
34
|
+
array: %i[blue black!],
|
35
|
+
number: %i[magenta],
|
36
|
+
undefined: %i[red italic]
|
37
|
+
},
|
38
|
+
logger: {
|
39
|
+
unknown: %i[cyan],
|
40
|
+
fatal: %i[white bold red!],
|
41
|
+
error: %i[red bold],
|
42
|
+
warn: %i[yellow bold],
|
43
|
+
info: %i[blue],
|
44
|
+
debug: %i[green]
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}.compare_by_identity
|
48
|
+
private_constant :VAR
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def __get__(key)
|
53
|
+
VAR[key.is_a?(::String) ? key.to_sym : key]
|
54
|
+
end
|
55
|
+
|
56
|
+
def __set__(key, val)
|
57
|
+
return if VAR.frozen?
|
58
|
+
|
59
|
+
VAR[key.is_a?(::String) ? key.to_sym : key] = val
|
60
|
+
end
|
61
|
+
|
62
|
+
def env(key, equals: nil, ignore: nil, default: nil, **)
|
63
|
+
ret = ENV.fetch(key, '')
|
64
|
+
return ret == equals.to_s unless equals.nil?
|
65
|
+
|
66
|
+
ret.empty? || (ignore && as_a(ignore).any? { |val| ret == val.to_s }) ? default : ret
|
67
|
+
end
|
68
|
+
|
69
|
+
def message(*args, hint: nil)
|
70
|
+
args.reject(&:empty?).join(' => ') + (hint ? " (#{hint})" : '')
|
71
|
+
end
|
72
|
+
|
73
|
+
def as_a(obj, flat: nil)
|
74
|
+
if obj.nil?
|
75
|
+
[]
|
76
|
+
elsif !obj.is_a?(::Array)
|
77
|
+
[obj]
|
78
|
+
elsif flat
|
79
|
+
obj.flatten(flat == true ? nil : flat)
|
80
|
+
else
|
81
|
+
obj
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def finalize!
|
86
|
+
VAR.each_value(&:freeze)
|
87
|
+
VAR[:theme].each_value(&:freeze)
|
88
|
+
VAR.freeze
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/lib/squared/common/class.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
require_relative 'base'
|
6
|
+
|
3
7
|
module Squared
|
4
8
|
module Common
|
5
9
|
module Format
|
@@ -33,6 +37,8 @@ module Squared
|
|
33
37
|
block_given? ? yield(self) : self
|
34
38
|
end
|
35
39
|
|
40
|
+
private
|
41
|
+
|
36
42
|
def emphasize(val, title: nil, cols: nil, sub: nil, pipe: nil)
|
37
43
|
n = 0
|
38
44
|
if title
|
@@ -66,14 +72,12 @@ module Squared
|
|
66
72
|
yield out
|
67
73
|
elsif pipe.respond_to?(:puts)
|
68
74
|
pipe.puts out
|
69
|
-
elsif err
|
70
|
-
defined?(__warn__) == 'method' ? __warn__(out) : warn(out)
|
71
75
|
else
|
72
|
-
|
76
|
+
err ? warn(out) : puts(out)
|
73
77
|
end
|
74
78
|
end
|
75
79
|
|
76
|
-
def sub_style(val, *args,
|
80
|
+
def sub_style(val, *args, styles: nil, pat: nil, index: 1)
|
77
81
|
return val unless ENV['NO_COLOR'].to_s.empty?
|
78
82
|
|
79
83
|
if pat && index != 0
|
@@ -168,6 +172,10 @@ module Squared
|
|
168
172
|
end
|
169
173
|
end
|
170
174
|
|
175
|
+
def raise_error(*args, hint: nil, kind: ArgumentError)
|
176
|
+
raise kind, message(*args, hint: hint)
|
177
|
+
end
|
178
|
+
|
171
179
|
def log_title(level, color: true)
|
172
180
|
level = if level.is_a?(::Numeric)
|
173
181
|
case level
|
@@ -188,13 +196,12 @@ module Squared
|
|
188
196
|
level.to_s.downcase.to_sym
|
189
197
|
end
|
190
198
|
theme = __get__(:theme)[:logger]
|
191
|
-
|
192
|
-
|
193
|
-
case level
|
199
|
+
styles = theme[level] || theme[level = :unknown]
|
200
|
+
case (ret = +level.to_s.upcase)
|
194
201
|
when 'WARN', 'ERROR', 'FATAL'
|
195
|
-
|
202
|
+
ret += '!'
|
196
203
|
end
|
197
|
-
color ? sub_style(
|
204
|
+
color ? sub_style(ret, *styles) : ret
|
198
205
|
end
|
199
206
|
|
200
207
|
def log_message(level, *args, subject: nil, hint: nil, color: true)
|
data/lib/squared/common/shell.rb
CHANGED
@@ -1,24 +1,28 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'shellwords'
|
4
|
+
require 'rake'
|
5
|
+
|
3
6
|
module Squared
|
4
7
|
module Common
|
5
8
|
module Shell
|
6
|
-
|
7
|
-
|
9
|
+
private
|
10
|
+
|
11
|
+
def shell_escape(val, quote: false)
|
12
|
+
return (quote ? shell_quote(val, force: false) : val) if ::Rake::Win32.windows?
|
8
13
|
|
9
|
-
require 'shellwords'
|
10
14
|
Shellwords.escape(val)
|
11
15
|
end
|
12
16
|
|
13
17
|
def shell_quote(val, force: true)
|
14
18
|
ret = val.to_s.strip
|
15
|
-
return ret if (!force && !ret.include?(' ')) || ret
|
19
|
+
return ret if (!force && !ret.include?(' ')) || ret =~ /(?:^|=)(["']).+\1$/m
|
16
20
|
|
17
21
|
::Rake::Win32.windows? ? "\"#{double_quote(ret)}\"" : "'#{single_quote(ret)}'"
|
18
22
|
end
|
19
23
|
|
20
24
|
def fill_option(val)
|
21
|
-
return "-#{val}" if val.size == 1 || val
|
25
|
+
return "-#{val}" if val.size == 1 || val =~ /^[a-z]\d+$/i
|
22
26
|
|
23
27
|
val = "--#{val}" unless val.start_with?('-')
|
24
28
|
shell_escape(val).sub('\\=', '=')
|
@@ -36,10 +40,6 @@ module Squared
|
|
36
40
|
val.split(/\s*(?<!\\)#{char}\s*/)
|
37
41
|
end
|
38
42
|
|
39
|
-
def trailing_slash(val)
|
40
|
-
val.to_s.chomp(::File::SEPARATOR) + ::File::SEPARATOR
|
41
|
-
end
|
42
|
-
|
43
43
|
def sanitize_args(*opts)
|
44
44
|
opts.map { |val| val.include?(' ') ? shell_quote(val) : shell_escape(val) }.join(' ')
|
45
45
|
end
|
@@ -1,12 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'pathname'
|
4
|
+
require 'fileutils'
|
4
5
|
|
5
6
|
module Squared
|
6
7
|
module Common
|
7
8
|
module System
|
9
|
+
private
|
10
|
+
|
8
11
|
def shell(*cmd, **kwargs)
|
9
|
-
if /^2\.[0-5]
|
12
|
+
if RUBY_VERSION =~ /^2\.[0-5]\./
|
10
13
|
exception = kwargs.delete(:exception)
|
11
14
|
ret = system(*cmd, **kwargs)
|
12
15
|
raise $?.to_s if !ret && exception
|
data/lib/squared/common/task.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'rake'
|
4
|
+
|
3
5
|
module Squared
|
4
6
|
module Common
|
5
7
|
module Task
|
8
|
+
private
|
9
|
+
|
6
10
|
def collect_args(args, *keys)
|
7
11
|
ret = []
|
8
12
|
return ret unless args.is_a?(::Rake::TaskArguments)
|
9
13
|
|
10
|
-
keys.each { |key| ret << args
|
14
|
+
keys.each { |key| ret << args.fetch(key) if args.key?(key) }
|
11
15
|
ret += args.extras
|
12
16
|
end
|
13
17
|
|
@@ -16,7 +20,7 @@ module Squared
|
|
16
20
|
rescue StandardError => e
|
17
21
|
raise if exception
|
18
22
|
|
19
|
-
|
23
|
+
warn e
|
20
24
|
end
|
21
25
|
|
22
26
|
def invoked?(name)
|
data/lib/squared/common.rb
CHANGED
@@ -1,86 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'pathname'
|
4
|
-
require 'logger'
|
5
4
|
require 'rake'
|
6
5
|
|
7
|
-
|
8
|
-
module Common
|
9
|
-
VAR = {
|
10
|
-
project: {},
|
11
|
-
colors: {
|
12
|
-
black: '30',
|
13
|
-
red: '31',
|
14
|
-
green: '32',
|
15
|
-
yellow: '33',
|
16
|
-
blue: '34',
|
17
|
-
magenta: '35',
|
18
|
-
cyan: '36',
|
19
|
-
white: '37',
|
20
|
-
black!: '40',
|
21
|
-
red!: '41',
|
22
|
-
green!: '42',
|
23
|
-
yellow!: '43',
|
24
|
-
blue!: '44',
|
25
|
-
magenta!: '45',
|
26
|
-
cyan!: '46',
|
27
|
-
white!: '47'
|
28
|
-
},
|
29
|
-
theme: {
|
30
|
-
workspace: {},
|
31
|
-
project: {},
|
32
|
-
viewer: {
|
33
|
-
banner: %i[blue bold],
|
34
|
-
key: %i[bold],
|
35
|
-
value: %i[green],
|
36
|
-
string: %i[yellow],
|
37
|
-
hash: %i[green black!],
|
38
|
-
array: %i[blue black!],
|
39
|
-
number: %i[magenta],
|
40
|
-
undefined: %i[red italic]
|
41
|
-
},
|
42
|
-
logger: {
|
43
|
-
unknown: %i[cyan],
|
44
|
-
fatal: %i[white bold red!],
|
45
|
-
error: %i[red bold],
|
46
|
-
warn: %i[yellow bold],
|
47
|
-
info: %i[blue],
|
48
|
-
debug: %i[green]
|
49
|
-
}
|
50
|
-
}
|
51
|
-
}.compare_by_identity
|
52
|
-
private_constant :VAR
|
53
|
-
|
54
|
-
def __get__(key)
|
55
|
-
VAR[key.is_a?(::String) ? key.to_sym : key]
|
56
|
-
end
|
57
|
-
|
58
|
-
def __set__(key, val)
|
59
|
-
return if VAR.frozen?
|
60
|
-
|
61
|
-
VAR[key.is_a?(::String) ? key.to_sym : key] = val
|
62
|
-
end
|
63
|
-
|
64
|
-
def finalize!
|
65
|
-
VAR.each_value(&:freeze)
|
66
|
-
VAR[:theme].each_value(&:freeze)
|
67
|
-
VAR.freeze
|
68
|
-
end
|
69
|
-
|
70
|
-
def message(*args, hint: nil)
|
71
|
-
args.reject(&:empty?).join(' => ') + (hint ? " (#{hint})" : '')
|
72
|
-
end
|
73
|
-
|
74
|
-
def as_a(obj, flat: nil)
|
75
|
-
return [] if obj.nil?
|
76
|
-
return [obj] unless obj.is_a?(::Array)
|
77
|
-
return obj unless flat
|
78
|
-
|
79
|
-
obj.flatten(flat == true ? nil : flat)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
6
|
+
require_relative 'common/base'
|
84
7
|
require_relative 'common/class'
|
85
8
|
require_relative 'common/format'
|
86
9
|
require_relative 'common/shell'
|
data/lib/squared/config.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'json'
|
4
4
|
|
5
|
+
require_relative 'common'
|
6
|
+
|
5
7
|
module Squared
|
6
8
|
module Config
|
7
9
|
class Viewer
|
@@ -12,7 +14,7 @@ module Squared
|
|
12
14
|
|
13
15
|
class << self
|
14
16
|
def to_s
|
15
|
-
/[^:]
|
17
|
+
super.to_s.match(/[^:]+$/)[0]
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
@@ -63,14 +65,14 @@ module Squared
|
|
63
65
|
namespace view do
|
64
66
|
if @mime['json'] && (exist? || !::Rake::Task.task_defined?("#{name}:#{view}:json"))
|
65
67
|
desc format_desc(view, %w[json])
|
66
|
-
task
|
68
|
+
task 'json', [:keys] do |_, args|
|
67
69
|
read_keys(JSON, 'json', *params.(args))
|
68
70
|
end
|
69
71
|
end
|
70
72
|
|
71
73
|
if @mime['yaml'] && (exist? || !::Rake::Task.task_defined?("#{name}:#{view}:yaml"))
|
72
74
|
desc format_desc(view, %w[yaml yml])
|
73
|
-
task
|
75
|
+
task 'yaml', [:keys] do |_, args|
|
74
76
|
require 'yaml'
|
75
77
|
read_keys(YAML, 'yaml', *params.(args), ext: %w[yml yaml])
|
76
78
|
end
|
@@ -161,7 +163,7 @@ module Squared
|
|
161
163
|
|
162
164
|
def read_keys(reader, type, file, keys, ext: [type])
|
163
165
|
if (mime = mime_type(file)) && base_path(file).exist?
|
164
|
-
|
166
|
+
raise_error(file, mime, hint: 'invalid') unless ext.include?(mime)
|
165
167
|
else
|
166
168
|
if ext.include?(mime)
|
167
169
|
alt = file
|
@@ -172,11 +174,9 @@ module Squared
|
|
172
174
|
alt = base_path("#{main}.{#{ext.join(',')}}")
|
173
175
|
file = Dir[alt].first
|
174
176
|
end
|
175
|
-
unless file
|
176
|
-
raise ArgumentError, message(reader.name, "#{File.basename(alt, '.*')}.#{ext.first}", hint: 'not found')
|
177
|
-
end
|
177
|
+
raise_error(reader.name, "#{File.basename(alt, '.*')}.#{ext.first}", hint: 'not found') unless file
|
178
178
|
end
|
179
|
-
project&.info "#{Viewer}(#{type}) => #{file} {#{keys.join(', ')}}"
|
179
|
+
project&.log&.info "#{Viewer}(#{type}) => #{file} {#{keys.join(', ')}}"
|
180
180
|
doc = if reader.respond_to?(:load_file)
|
181
181
|
reader.load_file(file, **@mime[type])
|
182
182
|
else
|
@@ -225,7 +225,7 @@ module Squared
|
|
225
225
|
end
|
226
226
|
end
|
227
227
|
rescue StandardError
|
228
|
-
project&.warn "#{Viewer}(#{type}) => #{file ? "#{file} " : ''}{#{key}: undefined}"
|
228
|
+
project&.log&.warn "#{Viewer}(#{type}) => #{file ? "#{file} " : ''}{#{key}: undefined}"
|
229
229
|
val = Regexp.escape($!.message)
|
230
230
|
key = key.sub(/(#{val})\.|\.(#{val})|(#{val})/) do
|
231
231
|
s = "<#{$3 || $2 || $1}>"
|
@@ -284,7 +284,7 @@ module Squared
|
|
284
284
|
end
|
285
285
|
|
286
286
|
def warning?
|
287
|
-
project ? project.warning : true
|
287
|
+
project && defined?(project.warning) == 'method' ? project.warning : true
|
288
288
|
end
|
289
289
|
end
|
290
290
|
end
|
data/lib/squared/version.rb
CHANGED