squared 0.1.9 → 0.1.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.
@@ -79,7 +79,7 @@ module Squared
79
79
  def __freeze__
80
80
  ARG.freeze
81
81
  VAR.each_value(&:freeze)
82
- VAR[:theme].each_value(&:freeze)
82
+ VAR[:theme].each_value { |val| val.freeze.each_value(&:freeze) }
83
83
  VAR.freeze
84
84
  end
85
85
 
@@ -127,11 +127,11 @@ module Squared
127
127
  def apply_style(data, key, args, empty: true)
128
128
  return if data.is_a?(::Symbol) && (data = __get__(:theme)[data]).nil?
129
129
 
130
- set = ->(k, v) { data[k] = check_style(v, empty: empty) }
130
+ set = ->(k, v) { data[k.to_sym] = check_style(v, empty: empty) }
131
131
  if key.is_a?(::Hash)
132
132
  key.each { |k, v| set.(k, v || args) }
133
133
  else
134
- set.(key.to_sym, args)
134
+ set.(key, args)
135
135
  end
136
136
  end
137
137
 
@@ -24,7 +24,7 @@ module Squared
24
24
  else
25
25
  return Kernel.send(name, *args, **kwargs)
26
26
  end
27
- return ret if ret || !e
27
+ return ret unless e && !ret && name == :system
28
28
 
29
29
  raise $?.to_s
30
30
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Squared
4
- VERSION = '0.1.9'
4
+ VERSION = '0.1.11'
5
5
  end
@@ -393,20 +393,19 @@ module Squared
393
393
  end
394
394
 
395
395
  def script_get(*args, group: nil, ref: nil)
396
- if group
397
- @script[:group][group.to_sym]
398
- elsif ref.is_a?(Array)
399
- ref = ref.each
400
- end
401
- if ref.instance_of?(Enumerator)
402
- ref.each do |key|
403
- next unless (ret = @script[:ref][key])
396
+ if group && (ret = @script[:group][group.to_sym])
397
+ ret
398
+ elsif ref
399
+ if ref.is_a?(Enumerable)
400
+ ref.each do |key|
401
+ next unless (ret = @script[:ref][key])
404
402
 
405
- return ret if args.empty? || args.any? { |val| ret.key?(val) }
403
+ return ret if args.empty? || args.any? { |val| ret.key?(val) }
404
+ end
405
+ nil
406
+ else
407
+ @script[:ref][ref]
406
408
  end
407
- nil
408
- elsif ref
409
- @script[:ref][ref]
410
409
  end
411
410
  end
412
411
 
@@ -495,9 +494,14 @@ module Squared
495
494
  private
496
495
 
497
496
  def __build__(default: nil, **)
498
- return unless default && task_defined?(out = task_name(default))
499
-
500
- task Rake.application.default_task_name => out
497
+ unless task_defined?('squared:version')
498
+ task 'squared:version' do
499
+ puts Squared::VERSION
500
+ end
501
+ end
502
+ if default && task_defined?(out = task_name(default))
503
+ task Rake.application.default_task_name => out
504
+ end
501
505
  end
502
506
 
503
507
  def puts(*args)
@@ -15,7 +15,7 @@ module Squared
15
15
  include Rake::DSL
16
16
 
17
17
  VAR_SET = %i[parent global envname dependfile theme run script env].freeze
18
- SEM_VER = /\b(\d+)(?:(\.)(\d+))?(?:(\.)(\d+)(\S+)?)?\b/.freeze
18
+ SEM_VER = /\b(\d+)(?:(\.)(\d+))?(?:(\.)(\d+))?[-.]?(\S+)?\b/.freeze
19
19
  private_constant :VAR_SET, :SEM_VER
20
20
 
21
21
  class << self
@@ -238,7 +238,7 @@ module Squared
238
238
  flags.each do |flag|
239
239
  case action
240
240
  when :graph
241
- next unless graph?
241
+ break unless graph?
242
242
 
243
243
  check = lambda do |args|
244
244
  next args if (args = args.to_a).empty?
@@ -904,6 +904,29 @@ module Squared
904
904
  fill ? semver(ret) : ret
905
905
  end
906
906
 
907
+ def semcmp(val, other)
908
+ return 0 if val == other
909
+
910
+ a, b = [val, other].map! { |ver| ver.scan(SEM_VER) }
911
+ return -1 if b.empty?
912
+ return 1 if a.empty?
913
+
914
+ a, b = [a.first, b.first].map! do |c|
915
+ begin
916
+ d = Integer(c[5]).to_s
917
+ rescue StandardError
918
+ d = c[5] ? '-1' : '0'
919
+ end
920
+ [c[0], c[2], c[4] || '0', d]
921
+ end
922
+ a.each_with_index do |c, index|
923
+ next if c == (d = b[index])
924
+
925
+ return c.to_i < d.to_i ? 1 : -1
926
+ end
927
+ 0
928
+ end
929
+
907
930
  def indexitem(val)
908
931
  [$1.to_i, $2 && $2[1..-1]] if val =~ /\A#{Regexp.escape(indexchar)}(\d+)(:.+)?\z/
909
932
  end
@@ -443,15 +443,18 @@ module Squared
443
443
  when :major
444
444
  if seg[0] != '0' || seg[2].nil?
445
445
  seg[0] = seg[0].succ
446
+ seg[2] = '0'
446
447
  else
447
448
  seg[2] = seg[2].succ
448
449
  end
450
+ seg[4] = '0'
449
451
  when :minor
450
452
  if seg[0] == '0'
451
453
  seg[4] &&= seg[4].succ
452
454
  else
453
455
  seg[2] = seg[2].succ
454
456
  end
457
+ seg[4] = '0'
455
458
  else
456
459
  seg[4] &&= seg[4].succ
457
460
  end
@@ -619,7 +622,7 @@ module Squared
619
622
  def read_packagemanager(version: nil)
620
623
  if @pm[:_].nil?
621
624
  doc = JSON.parse(dependfile.read)
622
- @pm[:_] = (val = doc['packageManager']) ? val[0..((val.index('+') || 0) - 1)] : false
625
+ @pm[:_] = (val = doc['packageManager']) ? val[0, val.index('+') || val.size] : false
623
626
  @pm[:name] = doc['name']
624
627
  @pm[:scripts] = doc['scripts']
625
628
  @pm[:version] = doc['version']
@@ -630,7 +633,9 @@ module Squared
630
633
  @pm[:_] = false
631
634
  nil
632
635
  else
633
- !(ret = @pm[:_]) || (version && ret[(ret.index('@') + 1)..-1] < version) ? nil : ret
636
+ if (ret = @pm[:_]) && !(version && semcmp(ret[(ret.index('@') + 1)..-1], version) == 1)
637
+ ret
638
+ end
634
639
  end
635
640
 
636
641
  def read_install
data/squared.gemspec CHANGED
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "lib/squared/version"
3
+ version = File.read(File.join(__dir__, "lib/squared/version.rb"))[/\bVERSION = '(.+)'$/, 1]
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "squared"
7
- spec.version = Squared::VERSION
7
+ spec.version = version
8
8
  spec.authors = ["An Pham"]
9
9
  spec.email = ["anpham6@gmail.com"]
10
10
 
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.metadata["documentation_uri"] = "https://squared.readthedocs.io"
20
20
 
21
21
  spec.files = Dir["lib/**/*"] +
22
- %w[CHANGELOG.md LICENSE README.md README.ruby.md squared.gemspec]
22
+ %w[CHANGELOG.md LICENSE README.md squared.gemspec]
23
23
  spec.bindir = "exe"
24
24
  spec.executables = []
25
25
  spec.require_paths = ["lib"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squared
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - An Pham
@@ -75,7 +75,6 @@ files:
75
75
  - CHANGELOG.md
76
76
  - LICENSE
77
77
  - README.md
78
- - README.ruby.md
79
78
  - lib/squared.rb
80
79
  - lib/squared/app.rb
81
80
  - lib/squared/common.rb
@@ -120,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
119
  - !ruby/object:Gem::Version
121
120
  version: '0'
122
121
  requirements: []
123
- rubygems_version: 3.6.7
122
+ rubygems_version: 3.6.9
124
123
  specification_version: 4
125
124
  summary: Rake task generator for managing multi-language workspaces.
126
125
  test_files: []
data/README.ruby.md DELETED
@@ -1,304 +0,0 @@
1
- # squared 0.1
2
-
3
- * [source](https://github.com/anpham6/squared)
4
- * [manifest](https://github.com/anpham6/squared-repo)
5
- * [docs](https://squared.readthedocs.io)
6
-
7
- ## Version Compatibility
8
-
9
- | Date | squared | Ruby 2 | Ruby 3 |
10
- | :------: | ------: | -----: | -----: |
11
- | 12-07-24 | 0.1.0 | 2.4.0 | 3.0.0 |
12
-
13
- ## Installation
14
-
15
- ```sh
16
- gem install squared
17
- ```
18
-
19
- ### Optional
20
-
21
- * [Repo](https://source.android.com/docs/setup/reference/repo)
22
- * Python 3.6
23
- * Not compatible with Windows
24
-
25
- ```sh
26
- mkdir -p ~/.bin
27
- PATH="${HOME}/.bin:${PATH}"
28
- curl https://storage.googleapis.com/git-repo-downloads/repo > ~/.bin/repo
29
- chmod a+rx ~/.bin/repo
30
- ```
31
-
32
- ## Example - Rakefile
33
-
34
- Projects from any accessible folder can be added relative to the parent directory (e.g. *REPO_ROOT*) or absolutely. The same Rakefile can also manage other similarly cloned `Repo` repositories remotely by setting the `REPO_ROOT` environment variable to the location. Missing projects will simply be excluded from the task runner.
35
-
36
- ```ruby
37
- require "squared"
38
-
39
- require "squared/workspace"
40
- require "squared/workspace/repo" # Optional
41
- require "squared/workspace/project/node" #
42
- require "squared/workspace/project/python" #
43
- require "squared/workspace/project/ruby" #
44
- # OR
45
- require "squared/app" # All workspace related modules
46
-
47
- # NODE_ENV = production
48
-
49
- # REPO_ROOT = /workspaces #
50
- # REPO_HOME = /workspaces/squared # Dir.pwd
51
- # rake = /workspaces/squared/Rakefile # main?
52
- # OR
53
- # REPO_ROOT = /workspaces # Dir.pwd
54
- # rake = /workspaces/Rakefile #
55
- # REPO_HOME = /workspaces/squared # main: "squared"
56
-
57
- # pathname = /workspaces/pathname
58
- # optparse = /workspaces/optparse
59
- # log = /workspaces/logger
60
- # emc = /workspaces/e-mc
61
- # pir = /workspaces/pi-r
62
- # squared = /workspaces/squared
63
- # cli = /workspaces/squared/publish/sqd-cli
64
- # sqd-serve = /workspaces/squared/publish/sqd-serve
65
- # sqd = /workspaces/squared/sqd
66
-
67
- Workspace::Application
68
- .new(Dir.pwd, main: "squared") # Dir.pwd? (main? is implicitly basename)
69
- .banner("group", "project", styles: ["yellow", "black"], border: "bold") # name | project | path | ref | group? | parent? | version?
70
- .repo("https://github.com/anpham6/squared-repo", "nightly", script: ["build:dev", "build:prod"], ref: :node) # Repo (optional)
71
- .run("rake install", ref: :ruby)
72
- .depend(false, group: "default")
73
- .clean("rake clean", group: "default")
74
- .clean(["build/"], group: "app")
75
- .log({ file: "tmp/%Y-%m-%d.log", level: "debug" }, group: "app")
76
- .add("pathname", run: "rake compile", copy: "rake install", test: "rake test", group: "default", env: { # Ruby (with C extensions)
77
- "CFLAGS" => "-fPIC -O1"
78
- })
79
- .add("optparse", doc: "rake rdoc", group: "default") # Uses bundler/gem_tasks (without C extensions)
80
- .add("logger", copy: { from: "lib", glob: "**/*.rb", into: "~/.rvm/gems/ruby-3.3.5/gems/logger-1.6.1" }, clean: ["tmp/"]) # autodetect: true
81
- .add("e-mc", "emc", copy: { from: "publish", scope: "@e-mc", also: [:pir, "squared-express/"] }, ref: :node) # Node
82
- .add("pi-r", "pir", copy: { from: "publish", scope: "@pi-r" }, clean: ["publish/**/*.js", "tmp/"]) # Trailing slash required for directories
83
- .add("squared", script: ["build:stage1", "build:stage2"], group: "app") do # Copy target (main)
84
- add("publish/sqd-cli", "cli", exclude: [:git]) # rake cli:build
85
- add("publish/sqd-serve") # rake sqd-serve:build
86
- add("publish/sqd-admin", group: "sqd", exclude: [:base])
87
- # OR
88
- with(exclude: [:base]) { add("publish/*", "packages") } # rake packages:sqd-serve:build
89
- # OR
90
- add(["publish/sqd-cli", "publish/sqd-serve", "publish/sqd-admin"], true, exclude: [:base]) # rake squared:sqd-serve:build
91
- end
92
- .add("squared/sqd", exclude: [:git]) do
93
- variable_set :script, "build:sqd" # Override detection
94
- variable_set :depend, false
95
- variable_set :clean, ["build/sqd/"]
96
- end
97
- .style("banner", 255.255) # 256 colors (fg | fg.bg | -0.bg)
98
- .build(default: "build", parallel: ["pull", "fetch", "rebase", "copy", "clean", /^outdated:/]) do |workspace|
99
- workspace
100
- .enable_aixterm
101
- .style({
102
- banner: ["bright_cyan", "bold", "bright_black!"],
103
- border: "bright_white"
104
- })
105
- end
106
-
107
- # default = /workspaces/ruby/*
108
- # pathname = /workspaces/ruby/pathname
109
- # optparse = /workspaces/ruby/optparse
110
- # logger = /workspaces/ruby/logger
111
- # android = /workspaces/android-docs
112
- # chrome = /workspaces/chrome-docs
113
-
114
- Workspace::Application
115
- .new(ENV["SQUARED_HOME"], prefix: "rb", common: false) # Local styles
116
- .group("ruby", "default", run: "rake build", copy: "rake install", clean: "rake clean", ref: :ruby, override: {
117
- pathname: {
118
- run: "rake compile" # rake rb:pathname:build
119
- }
120
- })
121
- .with(:python) do # ref=Symbol | group=String
122
- banner([:name, ": ", :version], "path") # chrome-docs: 0.1.0 | /workspaces/chrome-docs
123
- doc("make html") # rake rb:doc:python
124
- run(false) # rake rb:build:python (disabled)
125
- exclude(%i[base git]) # Project::Git.ref (superclass)
126
- add("android-docs", "android") # rake rb:android:doc
127
- add("chrome-docs", "chrome") # rake rb:chrome:doc
128
- end #
129
- .style("inline", "bold")
130
- .build
131
- ```
132
-
133
- **NOTE**: The use of "**ref**" (class name) is only necessary when initializing an empty directory (e.g. *rake repo:init*).
134
-
135
- ### Graph
136
-
137
- ```ruby
138
- Workspace::Application
139
- .new(main: "squared")
140
- .graph(["depend"], ref: :git) # Optional
141
- .with(:python) do
142
- add("android-docs", "android")
143
- add("chrome-docs", "chrome", graph: "android")
144
- end
145
- .with(:node) do
146
- graph(["build", "copy"]) # Overrides "git"
147
- add("e-mc", "emc")
148
- add("pi-r", "pir", graph: "emc")
149
- add("squared-express", "express", graph: "pir")
150
- add("squared", graph: ["chrome", "express"])
151
- end
152
- .with(:ruby) do
153
- add("pathname")
154
- add("fileutils", graph: "pathname")
155
- add("optparse")
156
- add("rake", graph: ["fileutils", "optparse"])
157
- end
158
- .build
159
- ```
160
-
161
- ```sh
162
- rake pir:graph # emc + pir
163
- rake express:graph # emc + pir + express
164
- rake chrome:graph # android + chrome
165
- rake graph:python # same
166
- rake squared:graph # android + chrome + emc + pir + express + squared
167
- rake graph:node # same
168
- rake rake:graph # pathname + fileutils + optparse + rake
169
- rake graph:ruby # same
170
- rake graph # graph:node + graph:ruby
171
- ```
172
-
173
- ### Batch
174
-
175
- ```ruby
176
- Workspace::Series.batch(:ruby, :node, {
177
- stage: %i[graph test],
178
- reset: %i[stash pull]
179
- })
180
- ```
181
-
182
- ### Rename
183
-
184
- ```ruby
185
- Workspace::Series.rename("depend", "install")
186
- ```
187
-
188
- ## Usage
189
-
190
- ```sh
191
- rake -T # List tasks
192
- rake # rake status (usually "build")
193
-
194
- # GIT_OPTIONS=rebase
195
- rake pull # All except "default" + "app"
196
- rake pull:ruby # pathname + optparse + logger
197
- rake pull:default # pathname + optparse
198
- rake pull:app # squared
199
- rake pull:node # emc + pir + squared
200
-
201
- rake build # All except "android"
202
- rake doc # optparse + android
203
- rake depend # All except "default"
204
-
205
- rake build:ruby # rake compile + rake install + rake install
206
-
207
- rake clean # All except "default" + "app"
208
- rake clean:ruby # rake clean + rake clean + ["tmp/"]
209
- rake clean:default # rake clean + rake clean + skip
210
- rake clean:app # none + skip + ["build/"]
211
- rake clean:node # none + ["publish/**/*.js", "tmp/"] + ["build/"]
212
- ```
213
-
214
- ```sh
215
- rake build:app # squared + cli + sqd-serve
216
- rake squared:build:workspace # cli + sqd-serve
217
- rake pull:sqd # sqd-admin
218
- rake squared:pull:workspace # sqd-serve + sqd-admin
219
- rake squared:outdated:workspace # cli + sqd-serve + sqd-admin
220
- ```
221
-
222
- ## Methods
223
-
224
- Task:
225
-
226
- * run
227
- * depend
228
- * graph
229
- * test
230
- * doc
231
- * clean
232
-
233
- Non-task:
234
-
235
- * log
236
- * exclude
237
-
238
- ## Styles
239
-
240
- * banner
241
- * border
242
- * header
243
- * active
244
- * inline
245
- * major
246
- * red
247
- * yellow
248
- * green
249
-
250
- ## Environment
251
-
252
- ### Build
253
-
254
- ```ruby
255
- # :env :run :opts
256
- # LD_LIBRARY_PATH="path/to/lib" CFLAGS="-Wall" gcc a.c -o a.o -c
257
- BUILD_${NAME} # gcc a.c -o a.o
258
- BUILD_${NAME}_OPTS # -c
259
- BUILD_${NAME}_ENV # {"LD_LIBRARY_PATH":"path/to/lib","CFLAGS":"-Wall"} (hash/json)
260
-
261
- # :env :opts :script
262
- # NODE_ENV="production" NO_COLOR="1" npm run --loglevel=error --workspaces=false build:dev
263
- BUILD_${NAME} # build:dev
264
- BUILD_${NAME}_OPTS # --loglevel=error --workspaces=false
265
- BUILD_${NAME}_ENV # {"NODE_ENV":"production","NO_COLOR":"1"} (hash/json)
266
- BUILD_${NAME}_DEV # pattern,0,1 (:dev)
267
- BUILD_${NAME}_PROD # pattern,0,1 (:prod)
268
-
269
- BUILD_${NAME}=0 # skip project
270
- ```
271
-
272
- These options also support the project specific suffix `${NAME}`. (e.g. LOG_FILE_SQUARED)
273
-
274
- ### Logger
275
-
276
- ```ruby
277
- LOG_FILE # %Y-%m-%d.log
278
- # OR
279
- LOG_AUTO # year,y,month,m,day,d,1
280
- # Optional
281
- LOG_DIR # exist?
282
- LOG_LEVEL # See gem "logger"
283
- LOG_COLUMNS # terminal width (default: 80)
284
- ```
285
-
286
- ### Repo
287
-
288
- ```ruby
289
- REPO_ROOT # parent dir
290
- REPO_HOME # project dir (main)
291
- REPO_BUILD # run,script
292
- REPO_GROUP # string
293
- REPO_REF # e.g. ruby,node
294
- REPO_DEV # pattern,0,1
295
- REPO_PROD # pattern,0,1
296
- REPO_WARN # 0,1
297
- REPO_SYNC # 0,1
298
- REPO_MANIFEST # e.g. latest,nightly,prod
299
- REPO_TIMEOUT # confirm dialog (seconds)
300
- ```
301
-
302
- ## LICENSE
303
-
304
- BSD 3-Clause