squared 0.0.7 → 0.0.9
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 +22 -7
- data/lib/squared/common/base.rb +10 -9
- data/lib/squared/common/format.rb +2 -2
- data/lib/squared/common/task.rb +4 -3
- data/lib/squared/config.rb +30 -26
- data/lib/squared/version.rb +1 -1
- data/lib/squared/workspace/application.rb +123 -83
- data/lib/squared/workspace/project/base.rb +53 -24
- data/lib/squared/workspace/project/git.rb +73 -66
- data/lib/squared/workspace/project/node.rb +114 -83
- data/lib/squared/workspace/project/python.rb +47 -21
- data/lib/squared/workspace/project/ruby.rb +39 -51
- data/lib/squared/workspace/repo.rb +37 -23
- data/lib/squared/workspace/series.rb +64 -40
- data/lib/squared/workspace.rb +8 -2
- data/squared.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90258e1d46b51b15fcb414cddf85407968d227b5032797e76ead83befa5d302b
|
4
|
+
data.tar.gz: a01b153f7c26b7f15a24cc66a159e47e42bc117e7b0810d7146c6ca3766f3cd0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 484c0af12a637957f3ed9ddc43b6f08bee1f3dbcba50a2acdfdd0dcb7bb929b83b64d40fd8bbf17ceddc5d8177a27773e4193198cbc80f2991651bf55366b2c8
|
7
|
+
data.tar.gz: a9617a969c41e971235b98bc730fd440f6c913a2ce21b9e8acb1907ae170ac72da1bb5d72df8650c1833827599fb0d95ab4aae19e5c75249dac07c0096efe077
|
data/README.ruby.md
CHANGED
@@ -34,12 +34,14 @@ Projects from any accessible folder can be added either relative to `REPO_ROOT`
|
|
34
34
|
require "squared"
|
35
35
|
require "squared/workspace/repo" # Repo (optional)
|
36
36
|
|
37
|
+
# NODE_ENV = production
|
37
38
|
# REPO_ROOT = /workspaces
|
38
39
|
# REPO_HOME = /workspaces/squared
|
39
40
|
# rake = /workspaces/squared/Rakefile
|
40
41
|
|
41
42
|
Workspace::Application
|
42
|
-
.new("squared") #
|
43
|
+
.new(main: "squared") # Dir.pwd? (main? is implicitly basename)
|
44
|
+
.banner("group", "project", styles: %i[yellow black], border: "bold") # name | project | path | ref | group?
|
43
45
|
.repo("https://github.com/anpham6/squared-repo", "nightly", run: "build", ref: :node) # Repo (optional)
|
44
46
|
.run("rake install", ref: :ruby)
|
45
47
|
.depend(false, group: "default")
|
@@ -48,11 +50,11 @@ Workspace::Application
|
|
48
50
|
.add("pathname", run: "rake compile", copy: "rake install", test: "rake test", group: "default", ref: :ruby) # Ruby (with C extensions)
|
49
51
|
.add("optparse", doc: "rake rdoc", group: "default") # Uses bundler/gem_tasks (without C extensions)
|
50
52
|
.add("logger", copy: { from: "lib", glob: "**/*.rb", gemdir: "~/.rvm/gems/ruby-3.3.5/gems/logger-1.6.1" }, clean: ["tmp/"]) # autodetect: true
|
51
|
-
.add("android", "android-docs", run: false, doc: "make html", ref: :python) # Python
|
52
53
|
.add("emc", "e-mc", copy: { from: "publish", into: "@e-mc", also: [:pir, "squared-express/"] }, ref: :node) # Node
|
53
54
|
.add("pir", "pi-r", copy: { from: "publish", into: "@pi-r" }, clean: ["publish/**/*.js", "tmp/"]) # Trailing slash required for directories
|
54
55
|
.add("squared", log: { file: "tmp/%Y-%m-%d.log", level: "debug" }, group: "app") # Copy target (main)
|
55
|
-
.
|
56
|
+
.add("sqd", "squared/sqd", script: ["build:sqd", "prod:sqd"], depend: false, clean: ["build/sqd/"], exclude: :git) # NPM workspaces
|
57
|
+
.style("banner", 255.255) # 256 colors (fg | fg.bg | -0.bg)
|
56
58
|
.build(default: "status", parallel: ["pull", "fetch", "rebase", "copy", "clean"]) do |workspace|
|
57
59
|
workspace
|
58
60
|
.enable_aixterm
|
@@ -64,21 +66,33 @@ Workspace::Application
|
|
64
66
|
# pathname = /workspaces/pathname
|
65
67
|
# optparse = /workspaces/optparse
|
66
68
|
# log = /workspaces/logger
|
67
|
-
# android = /workspaces/android-docs
|
68
69
|
# emc = /workspaces/e-mc
|
69
70
|
# pir = /workspaces/pi-r
|
70
71
|
# squared = /workspaces/squared
|
71
72
|
|
72
73
|
Workspace::Application
|
73
|
-
.new("
|
74
|
-
.group("default", "ruby", run: "rake build", copy: "rake install", clean: "rake clean", override: {
|
75
|
-
pathname: {
|
74
|
+
.new(ENV["SQUARED_DIR"], prefix: "rb", common: false) # Local styles
|
75
|
+
.group("default", "ruby/", run: "rake build", copy: "rake install", clean: "rake clean", ref: :ruby, override: {
|
76
|
+
pathname: {
|
77
|
+
run: "rake compile" # rake rb:pathname:build
|
78
|
+
}
|
76
79
|
})
|
80
|
+
.with(:python) do # ref=Symbol | group=String
|
81
|
+
banner("path", command: false, styles: "yellow") #
|
82
|
+
doc("make html") # rake rb:doc:python
|
83
|
+
run(false) # rake rb:build:python (disabled)
|
84
|
+
exclude(%i[base git]) # Project::Git.ref (superclass)
|
85
|
+
add("android", "android-docs") # rake rb:android:doc
|
86
|
+
add("chrome", "chrome-docs") # rake rb:chrome:doc
|
87
|
+
end #
|
88
|
+
.style("inline", "bold")
|
77
89
|
.build
|
78
90
|
# default = /workspaces/ruby/*
|
79
91
|
# pathname = /workspaces/ruby/pathname
|
80
92
|
# optparse = /workspaces/ruby/optparse
|
81
93
|
# logger = /workspaces/ruby/logger
|
94
|
+
# android = /workspaces/android-docs
|
95
|
+
# chrome = /workspaces/chrome-docs
|
82
96
|
```
|
83
97
|
|
84
98
|
**NOTE**: The use of "**ref**" (class name) is only necessary when running `repo:init` for the first time into an empty directory.
|
@@ -124,6 +138,7 @@ rake clean:node # none + ["publish/**/*.js", "tmp/"] + ["build/"]
|
|
124
138
|
* header
|
125
139
|
* active
|
126
140
|
* inline
|
141
|
+
* major
|
127
142
|
|
128
143
|
## LICENSE
|
129
144
|
|
data/lib/squared/common/base.rb
CHANGED
@@ -26,7 +26,8 @@ module Squared
|
|
26
26
|
workspace: {
|
27
27
|
header: %i[bold],
|
28
28
|
active: %i[bold],
|
29
|
-
inline: %i[bold]
|
29
|
+
inline: %i[bold],
|
30
|
+
major: %i[bold]
|
30
31
|
},
|
31
32
|
project: {},
|
32
33
|
viewer: {
|
@@ -82,16 +83,16 @@ module Squared
|
|
82
83
|
args.reject(&:empty?).join(' => ') + (hint ? " (#{hint})" : '')
|
83
84
|
end
|
84
85
|
|
85
|
-
def as_a(obj, flat: nil)
|
86
|
-
if obj.nil?
|
87
|
-
|
88
|
-
|
89
|
-
[obj]
|
86
|
+
def as_a(obj, meth = nil, flat: nil, compact: false)
|
87
|
+
return [] if obj.nil?
|
88
|
+
|
89
|
+
if !obj.is_a?(::Array)
|
90
|
+
obj = [obj]
|
90
91
|
elsif flat
|
91
|
-
obj.flatten(flat == true ? nil : flat)
|
92
|
-
else
|
93
|
-
obj
|
92
|
+
obj = obj.flatten(flat == true ? nil : flat)
|
94
93
|
end
|
94
|
+
obj = obj.map(&meth) if meth
|
95
|
+
compact ? obj.compact : obj
|
95
96
|
end
|
96
97
|
end
|
97
98
|
end
|
@@ -109,7 +109,7 @@ module Squared
|
|
109
109
|
def check_style(*args, empty: true)
|
110
110
|
ret = []
|
111
111
|
colors = __get__(:colors)
|
112
|
-
as_a(args, flat: true).each do |val|
|
112
|
+
as_a(args, flat: true, compact: true).each do |val|
|
113
113
|
if !val.is_a?(Numeric)
|
114
114
|
val = val.to_sym
|
115
115
|
ret << val if colors.key?(val) || TEXT_STYLE.include?(val)
|
@@ -201,7 +201,7 @@ module Squared
|
|
201
201
|
"| #{s} |"
|
202
202
|
end
|
203
203
|
out << bord
|
204
|
-
out
|
204
|
+
out << pr.(title) << bord if title
|
205
205
|
lines.each { |line| out << pr.(line) }
|
206
206
|
out << bord
|
207
207
|
if block_given?
|
data/lib/squared/common/task.rb
CHANGED
@@ -7,12 +7,13 @@ module Squared
|
|
7
7
|
module Task
|
8
8
|
module_function
|
9
9
|
|
10
|
-
def invoke(
|
11
|
-
|
10
|
+
def invoke(series, *args, exception: true, warning: true)
|
11
|
+
series = [series] unless series.is_a?(::Array)
|
12
|
+
series.each { |name| ::Rake::Task[name].invoke(*args) }
|
12
13
|
rescue StandardError => e
|
13
14
|
raise if exception
|
14
15
|
|
15
|
-
warn e
|
16
|
+
warn e if warning
|
16
17
|
end
|
17
18
|
|
18
19
|
def invoked?(name)
|
data/lib/squared/config.rb
CHANGED
@@ -17,14 +17,15 @@ module Squared
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
attr_reader :
|
20
|
+
attr_reader :main, :name, :project, :theme
|
21
21
|
|
22
|
-
def initialize(main, name = nil, project: nil, dump: nil, opts: {}, auto: true, common: true)
|
22
|
+
def initialize(main, name = nil, project: nil, prefix: nil, dump: nil, opts: {}, auto: true, common: true)
|
23
23
|
if project
|
24
24
|
main = @project.base_path(main).to_s if (@project = __get__(:project)[project.to_sym])
|
25
25
|
@required = true
|
26
26
|
end
|
27
27
|
@name = name&.to_s || @project&.name
|
28
|
+
@prefix = prefix
|
28
29
|
@ext = File.extname(main)
|
29
30
|
@dump = dump
|
30
31
|
@mime = {}
|
@@ -59,18 +60,18 @@ module Squared
|
|
59
60
|
|
60
61
|
params = ->(args) { exist? ? [realpath, [args.keys] + args.extras] : [args.keys, args.extras] }
|
61
62
|
|
62
|
-
namespace name do
|
63
|
+
namespace(ns = task_name(name)) do
|
63
64
|
view = @command && @command != name ? @command : 'view'
|
64
65
|
namespace view do
|
65
|
-
if @mime['json'] && (exist? || !::Rake::Task.task_defined?("#{
|
66
|
-
desc format_desc(view,
|
66
|
+
if @mime['json'] && (exist? || !::Rake::Task.task_defined?("#{ns}:#{view}:json"))
|
67
|
+
desc format_desc(view, 'json')
|
67
68
|
task 'json', [:keys] do |_, args|
|
68
69
|
read_keys(JSON, 'json', *params.(args))
|
69
70
|
end
|
70
71
|
end
|
71
72
|
|
72
|
-
if @mime['yaml'] && (exist? || !::Rake::Task.task_defined?("#{
|
73
|
-
desc format_desc(view,
|
73
|
+
if @mime['yaml'] && (exist? || !::Rake::Task.task_defined?("#{ns}:#{view}:yaml"))
|
74
|
+
desc format_desc(view, 'yaml', 'yml')
|
74
75
|
task 'yaml', [:keys] do |_, args|
|
75
76
|
require 'yaml'
|
76
77
|
read_keys(YAML, 'yaml', *params.(args), ext: %w[yml yaml])
|
@@ -91,8 +92,9 @@ module Squared
|
|
91
92
|
obj = eval(parse)
|
92
93
|
ext << type if (ext = as_a(ext)).empty?
|
93
94
|
file = realpath if file.nil? && exist?
|
94
|
-
|
95
|
-
|
95
|
+
|
96
|
+
namespace task_name(name) do
|
97
|
+
desc format_desc(command, *ext, exist: exist)
|
96
98
|
namespace command do
|
97
99
|
task type, [:keys] do |_, args|
|
98
100
|
if file
|
@@ -158,7 +160,7 @@ module Squared
|
|
158
160
|
!@required || (!project.nil? && project.enabled?)
|
159
161
|
end
|
160
162
|
|
161
|
-
|
163
|
+
private
|
162
164
|
|
163
165
|
def read_keys(reader, type, file, keys, ext: [type])
|
164
166
|
if (mime = mime_type(file)) && base_path(file).exist?
|
@@ -188,19 +190,16 @@ module Squared
|
|
188
190
|
.realpath
|
189
191
|
.to_s
|
190
192
|
.sub(Regexp.new("^#{Regexp.escape(File.join(Dir.pwd, ''))}"), '')
|
191
|
-
sub = if pipe?
|
192
|
-
nil
|
193
|
-
else
|
194
|
-
styles = theme
|
193
|
+
sub = if !pipe?
|
195
194
|
[
|
196
|
-
{ pat: /^((?:[^:]|(?<! ):(?! ))+)$/, styles:
|
197
|
-
{ pat: /^(.*?)(<[^>]+>)(.+)$/m, styles:
|
198
|
-
{ pat: /^(.+)( : (?!undefined).+)$/m, styles:
|
199
|
-
{ pat: /^(.+ : )(-?[\d.]+)(\s*)$/m, styles:
|
200
|
-
{ pat: /^(.+ : ")(.+)("\s*)$/m, styles:
|
201
|
-
{ pat: /^(.+ : \{)(.+)(\}\s*)$/m, styles:
|
202
|
-
{ pat: /^(.+ : \[)(.+)(\]\s*)$/m, styles:
|
203
|
-
{ pat: /^(.+ : (?!undefined))([^"\[{].*)$/m, styles:
|
195
|
+
{ pat: /^((?:[^:]|(?<! ):(?! ))+)$/, styles: theme[:banner] },
|
196
|
+
{ pat: /^(.*?)(<[^>]+>)(.+)$/m, styles: theme[:undefined], index: 2 },
|
197
|
+
{ pat: /^(.+)( : (?!undefined).+)$/m, styles: theme[:key] },
|
198
|
+
{ pat: /^(.+ : )(-?[\d.]+)(\s*)$/m, styles: theme[:number], index: 2 },
|
199
|
+
{ pat: /^(.+ : ")(.+)("\s*)$/m, styles: theme[:string], index: 2 },
|
200
|
+
{ pat: /^(.+ : \{)(.+)(\}\s*)$/m, styles: theme[:hash], index: 2 },
|
201
|
+
{ pat: /^(.+ : \[)(.+)(\]\s*)$/m, styles: theme[:array], index: 2 },
|
202
|
+
{ pat: /^(.+ : (?!undefined))([^"\[{].*)$/m, styles: theme[:value], index: 2 }
|
204
203
|
]
|
205
204
|
end
|
206
205
|
emphasize(lines, title: title, sub: sub)
|
@@ -224,7 +223,7 @@ module Squared
|
|
224
223
|
end
|
225
224
|
end
|
226
225
|
rescue StandardError
|
227
|
-
project&.log&.warn "#{Viewer}(#{type}) => #{file
|
226
|
+
project&.log&.warn "#{Viewer}(#{type}) => #{file && "#{file} "}{#{key}: undefined}"
|
228
227
|
val = Regexp.escape($!.message)
|
229
228
|
key = key.sub(/(#{val})\.|\.(#{val})|(#{val})/) do
|
230
229
|
s = "<#{$3 || $2 || $1}>"
|
@@ -251,6 +250,10 @@ module Squared
|
|
251
250
|
project ? project.base_path(file) : Pathname.new(file).realdirpath
|
252
251
|
end
|
253
252
|
|
253
|
+
def task_name(val)
|
254
|
+
@prefix ? "#{@prefix}:#{val}" : val.to_s
|
255
|
+
end
|
256
|
+
|
254
257
|
def mime_type(file)
|
255
258
|
case (ret = File.extname(file).sub('.', '').downcase)
|
256
259
|
when 'yml'
|
@@ -262,8 +265,9 @@ module Squared
|
|
262
265
|
end
|
263
266
|
end
|
264
267
|
|
265
|
-
def format_desc(command, ext, exist: exist?)
|
266
|
-
message(
|
268
|
+
def format_desc(command, *ext, exist: exist?)
|
269
|
+
message(@prefix || '', *name.split(':'), command,
|
270
|
+
"#{ext.first}[#{exist ? '' : "file?=#{File.basename(main)}.#{ext.last},"}keys*]")
|
267
271
|
end
|
268
272
|
|
269
273
|
def realpath
|
@@ -283,7 +287,7 @@ module Squared
|
|
283
287
|
end
|
284
288
|
|
285
289
|
def warning?
|
286
|
-
project
|
290
|
+
project ? project.workspace.warning : true
|
287
291
|
end
|
288
292
|
end
|
289
293
|
end
|
data/lib/squared/version.rb
CHANGED
@@ -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 :
|
40
|
+
attr_reader :root, :home, :main, :prefix, :series, :theme
|
55
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(self)
|
62
49
|
@project = {}
|
63
50
|
@extensions = []
|
64
51
|
@script = {
|
@@ -66,42 +53,57 @@ 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 = kwargs.key?(:common) && !kwargs[:common] ? {} : __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
62
|
@warning = @verbose
|
76
|
-
|
63
|
+
if kwargs.fetch(:common, true)
|
64
|
+
@theme = __get__(:theme)[:workspace]
|
65
|
+
__set__(:no_color, true) if @pipe
|
66
|
+
else
|
67
|
+
@theme = {}
|
68
|
+
end
|
69
|
+
@banner = {}
|
77
70
|
end
|
78
71
|
|
79
72
|
def build(**kwargs)
|
73
|
+
kwargs[:parallel] = kwargs.fetch(:parallel, []).map(&:to_s)
|
80
74
|
return unless enabled?
|
81
75
|
|
82
76
|
@project.each_value do |proj|
|
83
77
|
next unless proj.enabled?
|
84
78
|
|
85
79
|
proj.populate(**kwargs)
|
86
|
-
series.
|
80
|
+
series.__populate__(proj)
|
87
81
|
end
|
88
82
|
|
89
|
-
Application.
|
83
|
+
Application.impl_project.each { |obj| obj.populate(self, **kwargs) }
|
90
84
|
@extensions.each { |ext| __send__(ext, **kwargs) }
|
91
85
|
|
86
|
+
series.__build__(**kwargs)
|
92
87
|
__build__(**kwargs)
|
93
|
-
series.build(**kwargs)
|
94
88
|
|
95
89
|
yield self if block_given?
|
96
90
|
end
|
97
91
|
|
98
|
-
def with(
|
92
|
+
def with(val, &blk)
|
99
93
|
@group = nil
|
100
94
|
@ref = nil
|
101
|
-
if
|
102
|
-
@group =
|
103
|
-
|
104
|
-
|
95
|
+
if val.is_a?(::String)
|
96
|
+
@group = val
|
97
|
+
if block_given?
|
98
|
+
instance_eval(&blk)
|
99
|
+
@group = nil
|
100
|
+
end
|
101
|
+
elsif val.is_a?(::Symbol)
|
102
|
+
@ref = val
|
103
|
+
if block_given?
|
104
|
+
instance_eval(&blk)
|
105
|
+
@ref = nil
|
106
|
+
end
|
105
107
|
end
|
106
108
|
self
|
107
109
|
end
|
@@ -126,6 +128,10 @@ module Squared
|
|
126
128
|
script_command :test, script, group, ref
|
127
129
|
end
|
128
130
|
|
131
|
+
def exclude(base, group: @group, ref: @ref)
|
132
|
+
script_command :exclude, as_a(base, :to_sym).freeze, group, ref
|
133
|
+
end
|
134
|
+
|
129
135
|
def add(name, path = nil, **kwargs)
|
130
136
|
ref = if kwargs.key?(:ref)
|
131
137
|
kwargs.delete(:ref)
|
@@ -135,10 +141,10 @@ module Squared
|
|
135
141
|
kwargs[:group] = @group if !kwargs.key?(:group) && !@group.is_a?(::Array)
|
136
142
|
path = root_path(path || name.to_s)
|
137
143
|
proj = ((if !ref.is_a?(::Class)
|
138
|
-
Application.find(path: path
|
144
|
+
Application.find(ref, path: path)
|
139
145
|
elsif ref < Project::Base
|
140
146
|
ref
|
141
|
-
end) || Project::Base).new(name, path, self, **kwargs)
|
147
|
+
end) || Project::Base).new(task_name(name), path, self, **kwargs)
|
142
148
|
@project[name = name.to_sym] = proj
|
143
149
|
__get__(:project)[name] = proj unless kwargs[:private]
|
144
150
|
self
|
@@ -165,7 +171,7 @@ module Squared
|
|
165
171
|
end
|
166
172
|
|
167
173
|
def compose(name, &blk)
|
168
|
-
namespace(name, &blk)
|
174
|
+
namespace(task_name(name), &blk)
|
169
175
|
self
|
170
176
|
end
|
171
177
|
|
@@ -177,31 +183,54 @@ module Squared
|
|
177
183
|
def style(name, *args, target: nil, empty: false)
|
178
184
|
data = nil
|
179
185
|
if target
|
180
|
-
as_a(target).each_with_index do |
|
186
|
+
as_a(target).each_with_index do |key, i|
|
181
187
|
if i == 0
|
182
|
-
break unless (data = __get__(:theme)[
|
188
|
+
break unless (data = __get__(:theme)[key.to_sym])
|
183
189
|
else
|
184
|
-
data = data[
|
190
|
+
data = data[key.to_sym] ||= {}
|
185
191
|
end
|
186
192
|
end
|
187
|
-
return unless data
|
188
193
|
end
|
189
|
-
apply_style(data || theme, name, *args, empty: empty)
|
194
|
+
apply_style(data || theme, name, *args, empty: empty) unless target && !data
|
190
195
|
self
|
191
196
|
end
|
192
197
|
|
193
|
-
def
|
198
|
+
def banner(*order, command: true, styles: [], border: [], group: nil, ref: nil)
|
199
|
+
return (group && @banner[group.to_sym]) || @banner[:"_#{ref || ''}"] if order.empty?
|
200
|
+
|
201
|
+
key = if group ||= @group
|
202
|
+
group.to_sym
|
203
|
+
else
|
204
|
+
:"_#{ref || @ref || ''}"
|
205
|
+
end
|
206
|
+
data = { command: command, order: [], styles: check_style(styles, empty: false), border: check_style(border) }
|
207
|
+
order.flatten.each do |val|
|
208
|
+
case (val = val.to_sym)
|
209
|
+
when :name, :project, :path, :ref, :group
|
210
|
+
data[:order] << val
|
211
|
+
end
|
212
|
+
end
|
213
|
+
@banner[key] = data if command || !data[:order].empty?
|
214
|
+
self
|
215
|
+
end
|
216
|
+
|
217
|
+
def script(*args, group: nil, ref: nil)
|
194
218
|
if group
|
195
219
|
@script[:group][group.to_sym]
|
196
220
|
elsif ref
|
197
221
|
@script[:ref][ref.to_sym]
|
222
|
+
elsif (val = @script[:build])
|
223
|
+
r = @script[:ref][:_]
|
224
|
+
g = @script[:group][:_]
|
225
|
+
args.empty? || (!r && !g) || (r && args.include?(r)) || (g && args.include?(g)) ? [val, @script[:env]] : []
|
198
226
|
else
|
199
|
-
|
227
|
+
[]
|
200
228
|
end
|
201
229
|
end
|
202
230
|
|
203
231
|
def env(key, default = nil, equals: nil, ignore: nil)
|
204
|
-
|
232
|
+
@env ||= main.gsub(/[^\w]+/, '_').upcase
|
233
|
+
ret = ENV.fetch("#{key}_#{@env}", ENV[key]).to_s
|
205
234
|
return ret == equals.to_s unless equals.nil?
|
206
235
|
|
207
236
|
ret.empty? || (ignore && as_a(ignore).any? { |val| ret == val.to_s }) ? default : ret
|
@@ -216,7 +245,19 @@ module Squared
|
|
216
245
|
end
|
217
246
|
|
218
247
|
def find_base(obj)
|
219
|
-
Application.
|
248
|
+
Application.impl_project.find { |proj| obj.instance_of?(proj) }
|
249
|
+
end
|
250
|
+
|
251
|
+
def task_name(val, desc: false)
|
252
|
+
ret = @prefix ? "#{@prefix}:#{val}" : val.to_s
|
253
|
+
desc ? ret.split(':').join(' => ') : ret
|
254
|
+
end
|
255
|
+
|
256
|
+
def task_namespace(val, first: false)
|
257
|
+
return nil unless (val = val.to_s).include?(':')
|
258
|
+
|
259
|
+
ret = val.split(':')
|
260
|
+
first ? ret.first : ret[0..-2].join(':')
|
220
261
|
end
|
221
262
|
|
222
263
|
def to_s
|
@@ -231,17 +272,11 @@ module Squared
|
|
231
272
|
!@extensions.empty? || @project.any? { |_, proj| proj.enabled? }
|
232
273
|
end
|
233
274
|
|
234
|
-
def
|
235
|
-
|
236
|
-
|
237
|
-
val if key == :refresh && series[:build].include?(val = "#{val.split(':').first}:build")
|
275
|
+
def task_extend?(obj, key)
|
276
|
+
series.extend?(obj, key)
|
238
277
|
end
|
239
278
|
|
240
|
-
def
|
241
|
-
TASK_EXTEND.fetch(key, []).any? { |item| obj.is_a?(item) }
|
242
|
-
end
|
243
|
-
|
244
|
-
def task_defined?(key)
|
279
|
+
def task_defined?(key, *)
|
245
280
|
::Rake::Task.task_defined?(key)
|
246
281
|
end
|
247
282
|
|
@@ -258,44 +293,49 @@ module Squared
|
|
258
293
|
private
|
259
294
|
|
260
295
|
def __build__(**kwargs)
|
261
|
-
if !task_defined?('default') && (
|
262
|
-
task default
|
263
|
-
end
|
264
|
-
return unless series.has?('build')
|
265
|
-
|
266
|
-
if (refresh = series[:refresh]).all? { |val| val.end_with?(':build') }
|
267
|
-
refresh.clear
|
296
|
+
if !task_defined?('default') && (target = kwargs[:default]) && task_defined?(target = task_name(target))
|
297
|
+
task 'default' => target
|
268
298
|
end
|
269
|
-
|
299
|
+
return unless series.some?(:build)
|
270
300
|
|
271
|
-
|
301
|
+
init = [task_name('depend'), task_name(dev? && series.some?(:refresh) ? 'refresh' : 'build')]
|
272
302
|
|
273
|
-
|
303
|
+
task 'default' => init[1] unless task_defined?('default')
|
304
|
+
return unless series.some?(:depend) && !task_defined?(key = task_name('init'))
|
274
305
|
|
275
|
-
desc
|
276
|
-
task
|
306
|
+
desc key
|
307
|
+
task key => init
|
277
308
|
end
|
278
309
|
|
279
310
|
def script_command(task, val, group, ref)
|
280
311
|
if group
|
281
312
|
label = :group
|
282
|
-
items = as_a(group)
|
313
|
+
items = as_a(group, :to_sym)
|
283
314
|
else
|
284
315
|
label = :ref
|
285
|
-
items = as_a(ref)
|
316
|
+
items = as_a(ref, :to_sym)
|
286
317
|
end
|
287
|
-
items.each { |name| (@script[label][name
|
318
|
+
items.each { |name| (@script[label][name] ||= {})[task] = val }
|
288
319
|
self
|
289
320
|
end
|
290
321
|
|
291
322
|
def script?(state, script: nil, pat: nil, ref: nil, group: nil, global: false)
|
292
|
-
|
293
|
-
|
294
|
-
if global && ((!ref && !group) || (!
|
323
|
+
r = @script[:ref][:_]
|
324
|
+
g = @script[:group][:_]
|
325
|
+
if global && ((!ref && !group) || (!r && !g) || (ref && contains?(r, ref)) || (group && contains?(g, group)))
|
295
326
|
pat = @script[state] if pat.nil?
|
296
327
|
script ||= @script[:build]
|
297
328
|
end
|
298
|
-
pat.is_a?(::Regexp)
|
329
|
+
if pat.is_a?(::Regexp)
|
330
|
+
script = script[state == :prod ? 1 : 0] if script.is_a?(::Array)
|
331
|
+
pat.match?(script)
|
332
|
+
else
|
333
|
+
pat == true
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
def contains?(data, val)
|
338
|
+
as_a(data).any? { |item| item.to_s == val.to_s }
|
299
339
|
end
|
300
340
|
end
|
301
341
|
end
|