ruby_npm 0.1.0.pre.1 → 0.1.0.pre.3
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/Gemfile.lock +13 -13
- data/lib/ruby_npm/commands/base.rb +1 -1
- data/lib/ruby_npm/commands/install.rb +49 -0
- data/lib/ruby_npm/commands/run_script.rb +45 -0
- data/lib/ruby_npm/commands.rb +1 -0
- data/lib/ruby_npm/options/definitions/generic.rb +177 -0
- data/lib/ruby_npm/options/definitions/workspaces.rb +73 -0
- data/lib/ruby_npm/options/definitions.rb +77 -1
- data/lib/ruby_npm/options/name.rb +1 -1
- data/lib/ruby_npm/options.rb +7 -2
- data/lib/ruby_npm/version.rb +1 -1
- metadata +5 -3
- data/lib/ruby_npm/options/definition.rb +0 -174
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 237ebd0f181a703bb4eab351730cebbda23dcb98925fa807b07e34d35e2f3252
|
|
4
|
+
data.tar.gz: c27b634150d240bb86034e7c69a582b00426f9e7d1aae732a1464293711dea40
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 70d379c15bc4163adccdeb05fd083a57ce80808ae4d73da8025bf70ffe219e425d6d0747c52b88db2d765c72b6346451f03860c721d15d9aded0c2fc43167428
|
|
7
|
+
data.tar.gz: b142252fd0bcdc4a5608352d265302c2f75975e8e116a6b7997d493c9e4df4821b6d342295392a9cf3241c1e54e18ce47d0ed53b03f92651355a174b58ec82c2
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
ruby_npm (0.1.0.pre.
|
|
4
|
+
ruby_npm (0.1.0.pre.3)
|
|
5
5
|
immutable-struct (~> 2.4)
|
|
6
6
|
lino (~> 3.0)
|
|
7
7
|
|
|
@@ -59,12 +59,12 @@ GEM
|
|
|
59
59
|
rb-inotify (~> 0.9, >= 0.9.10)
|
|
60
60
|
lumberjack (1.2.8)
|
|
61
61
|
method_source (1.0.0)
|
|
62
|
-
minitest (5.
|
|
62
|
+
minitest (5.17.0)
|
|
63
63
|
nenv (0.3.0)
|
|
64
64
|
notiffany (0.1.3)
|
|
65
65
|
nenv (~> 0.1)
|
|
66
66
|
shellany (~> 0.0)
|
|
67
|
-
octokit (
|
|
67
|
+
octokit (6.0.1)
|
|
68
68
|
faraday (>= 1, < 3)
|
|
69
69
|
sawyer (~> 0.9)
|
|
70
70
|
open4 (1.3.4)
|
|
@@ -85,15 +85,15 @@ GEM
|
|
|
85
85
|
rake_factory (0.31.0)
|
|
86
86
|
activesupport (>= 4)
|
|
87
87
|
rake (~> 13.0)
|
|
88
|
-
rake_github (0.
|
|
88
|
+
rake_github (0.11.0)
|
|
89
89
|
colored2 (~> 3.1)
|
|
90
|
-
octokit (
|
|
90
|
+
octokit (>= 4.16, < 7.0)
|
|
91
91
|
rake_factory (~> 0.23)
|
|
92
92
|
sshkey (~> 2.0)
|
|
93
|
-
rake_gpg (0.
|
|
94
|
-
rake_factory (
|
|
95
|
-
ruby_gpg2 (
|
|
96
|
-
rake_ssh (0.
|
|
93
|
+
rake_gpg (0.18.0)
|
|
94
|
+
rake_factory (~> 0.23)
|
|
95
|
+
ruby_gpg2 (~> 0.6)
|
|
96
|
+
rake_ssh (0.8.0)
|
|
97
97
|
colored2 (~> 3.1)
|
|
98
98
|
rake_factory (~> 0.23)
|
|
99
99
|
sshkey (~> 2.0)
|
|
@@ -115,17 +115,17 @@ GEM
|
|
|
115
115
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
116
116
|
rspec-support (~> 3.12.0)
|
|
117
117
|
rspec-support (3.12.0)
|
|
118
|
-
rubocop (1.
|
|
118
|
+
rubocop (1.42.0)
|
|
119
119
|
json (~> 2.3)
|
|
120
120
|
parallel (~> 1.10)
|
|
121
121
|
parser (>= 3.1.2.1)
|
|
122
122
|
rainbow (>= 2.2.2, < 4.0)
|
|
123
123
|
regexp_parser (>= 1.8, < 3.0)
|
|
124
124
|
rexml (>= 3.2.5, < 4.0)
|
|
125
|
-
rubocop-ast (>= 1.
|
|
125
|
+
rubocop-ast (>= 1.24.1, < 2.0)
|
|
126
126
|
ruby-progressbar (~> 1.7)
|
|
127
127
|
unicode-display_width (>= 1.4.0, < 3.0)
|
|
128
|
-
rubocop-ast (1.24.
|
|
128
|
+
rubocop-ast (1.24.1)
|
|
129
129
|
parser (>= 3.1.1.0)
|
|
130
130
|
rubocop-rake (0.6.0)
|
|
131
131
|
rubocop (~> 1.0)
|
|
@@ -182,4 +182,4 @@ DEPENDENCIES
|
|
|
182
182
|
yard
|
|
183
183
|
|
|
184
184
|
BUNDLED WITH
|
|
185
|
-
2.4.
|
|
185
|
+
2.4.2
|
|
@@ -74,7 +74,7 @@ module RubyNPM
|
|
|
74
74
|
.for_command(@binary)
|
|
75
75
|
.with_environment_variables(environment)
|
|
76
76
|
.with_options_after_subcommands
|
|
77
|
-
.with_option_separator('
|
|
77
|
+
.with_option_separator(' ')
|
|
78
78
|
.with_appliables(@options.resolve(options, parameters))
|
|
79
79
|
.with_subcommands(subcommands)
|
|
80
80
|
.with_arguments(arguments(parameters).compact.flatten).build
|
|
@@ -9,6 +9,55 @@ module RubyNPM
|
|
|
9
9
|
def subcommands
|
|
10
10
|
%w[install]
|
|
11
11
|
end
|
|
12
|
+
|
|
13
|
+
# @!visibility private
|
|
14
|
+
# rubocop:disable Metrics/MethodLength
|
|
15
|
+
def options
|
|
16
|
+
%w[
|
|
17
|
+
--audit
|
|
18
|
+
--bin-links
|
|
19
|
+
--color
|
|
20
|
+
--dry-run
|
|
21
|
+
--force
|
|
22
|
+
--foreground-scripts
|
|
23
|
+
--fund
|
|
24
|
+
--global
|
|
25
|
+
--global-style
|
|
26
|
+
--ignore-scripts
|
|
27
|
+
--include
|
|
28
|
+
--include-workspace-root
|
|
29
|
+
--install-links
|
|
30
|
+
--install-strategy
|
|
31
|
+
--legacy-bundling
|
|
32
|
+
--loglevel
|
|
33
|
+
--logs-dir
|
|
34
|
+
--logs-max
|
|
35
|
+
--omit
|
|
36
|
+
--package-lock
|
|
37
|
+
--package-lock-only
|
|
38
|
+
--production
|
|
39
|
+
--quiet
|
|
40
|
+
--save
|
|
41
|
+
--save-bundle
|
|
42
|
+
--save-dev
|
|
43
|
+
--save-exact
|
|
44
|
+
--save-optional
|
|
45
|
+
--save-peer
|
|
46
|
+
--save-prod
|
|
47
|
+
--script-shell
|
|
48
|
+
--silent
|
|
49
|
+
--strict-peer-deps
|
|
50
|
+
--tag
|
|
51
|
+
--verbose
|
|
52
|
+
--workspace
|
|
53
|
+
--workspaces
|
|
54
|
+
] + super
|
|
55
|
+
end
|
|
56
|
+
# rubocop:enable Metrics/MethodLength
|
|
57
|
+
|
|
58
|
+
def arguments(parameters)
|
|
59
|
+
[parameters[:packages]]
|
|
60
|
+
end
|
|
12
61
|
end
|
|
13
62
|
end
|
|
14
63
|
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'base'
|
|
4
|
+
|
|
5
|
+
module RubyNPM
|
|
6
|
+
module Commands
|
|
7
|
+
class RunScript < Base
|
|
8
|
+
# @!visibility private
|
|
9
|
+
def subcommands
|
|
10
|
+
%w[run-script]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# @!visibility private
|
|
14
|
+
# rubocop:disable Metrics/MethodLength
|
|
15
|
+
def options
|
|
16
|
+
%w[
|
|
17
|
+
--color
|
|
18
|
+
--foreground-scripts
|
|
19
|
+
--if-present
|
|
20
|
+
--ignore-scripts
|
|
21
|
+
--include-workspace-root
|
|
22
|
+
--json
|
|
23
|
+
--loglevel
|
|
24
|
+
--logs-dir
|
|
25
|
+
--logs-max
|
|
26
|
+
--parseable
|
|
27
|
+
--quiet
|
|
28
|
+
--script-shell
|
|
29
|
+
--silent
|
|
30
|
+
--verbose
|
|
31
|
+
--workspace
|
|
32
|
+
--workspaces
|
|
33
|
+
] + super
|
|
34
|
+
end
|
|
35
|
+
# rubocop:enable Metrics/MethodLength
|
|
36
|
+
|
|
37
|
+
def arguments(parameters)
|
|
38
|
+
script_arguments =
|
|
39
|
+
parameters[:arguments] ? ['--'] + parameters[:arguments] : []
|
|
40
|
+
|
|
41
|
+
[parameters[:script]] + script_arguments
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
data/lib/ruby_npm/commands.rb
CHANGED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'immutable-struct'
|
|
4
|
+
|
|
5
|
+
require_relative '../name'
|
|
6
|
+
require_relative '../types'
|
|
7
|
+
require_relative '../values'
|
|
8
|
+
|
|
9
|
+
module RubyNPM
|
|
10
|
+
module Options
|
|
11
|
+
module Definitions
|
|
12
|
+
# rubocop:disable Metrics/ClassLength
|
|
13
|
+
class Generic < ImmutableStruct.new(
|
|
14
|
+
:name,
|
|
15
|
+
:option_type,
|
|
16
|
+
:value_type,
|
|
17
|
+
:override_keys,
|
|
18
|
+
:extra_keys,
|
|
19
|
+
:separator,
|
|
20
|
+
:placement,
|
|
21
|
+
:repeatable?
|
|
22
|
+
)
|
|
23
|
+
# rubocop:disable Metrics/MethodLength
|
|
24
|
+
def initialize(opts)
|
|
25
|
+
raise 'Missing name.' unless opts[:name]
|
|
26
|
+
|
|
27
|
+
super(
|
|
28
|
+
name: Name.new(opts[:name]),
|
|
29
|
+
option_type: Types.resolve(opts[:option_type]) || Types::Standard,
|
|
30
|
+
value_type: Values.resolve(opts[:value_type]) || Values::String,
|
|
31
|
+
repeatable: opts[:repeatable] || false,
|
|
32
|
+
separator: opts[:separator],
|
|
33
|
+
placement: opts[:placement],
|
|
34
|
+
extra_keys:
|
|
35
|
+
{ singular: [], plural: [] }
|
|
36
|
+
.merge(opts[:extra_keys] || {}),
|
|
37
|
+
override_keys:
|
|
38
|
+
{ singular: nil, plural: nil }
|
|
39
|
+
.merge(opts[:override_keys] || {})
|
|
40
|
+
)
|
|
41
|
+
end
|
|
42
|
+
# rubocop:enable Metrics/MethodLength
|
|
43
|
+
|
|
44
|
+
def matches?(name)
|
|
45
|
+
@name == Name.new(name)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def build(parameters)
|
|
49
|
+
build_singular_options(parameters) + build_plural_options(parameters)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
private
|
|
53
|
+
|
|
54
|
+
def resolved_singular_key
|
|
55
|
+
if override_keys[:singular] == false
|
|
56
|
+
nil
|
|
57
|
+
else
|
|
58
|
+
override_keys[:singular] || name.as_singular_key
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def all_singular_keys
|
|
63
|
+
([resolved_singular_key] + extra_keys[:singular]).compact
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def resolved_plural_key
|
|
67
|
+
if override_keys[:plural] == false
|
|
68
|
+
nil
|
|
69
|
+
else
|
|
70
|
+
override_keys[:plural] || name.as_plural_key
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def all_plural_keys
|
|
75
|
+
([resolved_plural_key] + extra_keys[:plural]).compact
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def too_many_values?(values)
|
|
79
|
+
!repeatable? && values.length > 1
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def values(parameters, keys)
|
|
83
|
+
keys.map { |k| parameters[k] }.compact
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def needs_plural?(value)
|
|
87
|
+
repeatable? && !value.nil?
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def only_singular?(value)
|
|
91
|
+
!needs_plural?(value)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def key_valued?(value)
|
|
95
|
+
value.respond_to?(:keys)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def multi_valued?(value)
|
|
99
|
+
value.respond_to?(:each)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def build_option(value)
|
|
103
|
+
option_type.new(name, value, separator: separator,
|
|
104
|
+
placement: placement)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def build_value(value)
|
|
108
|
+
value_type.new(value)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def build_key_value(key, value)
|
|
112
|
+
Values::KeyValue.new(key, build_value(value))
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def build_singular(value)
|
|
116
|
+
build_single_option(value)
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def build_singulars(values)
|
|
120
|
+
values.map { |p| build_singular(p) }.flatten
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def build_singular_options(parameters)
|
|
124
|
+
keys = all_singular_keys
|
|
125
|
+
values = values(parameters, keys)
|
|
126
|
+
|
|
127
|
+
if too_many_values?(values)
|
|
128
|
+
raise "Multiple values provided for '#{name}' " \
|
|
129
|
+
"(with keys #{keys}) and option not repeatable."
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
build_singulars(values)
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def build_plural(value)
|
|
136
|
+
if only_singular?(value)
|
|
137
|
+
build_no_options
|
|
138
|
+
elsif key_valued?(value)
|
|
139
|
+
build_key_value_options(value)
|
|
140
|
+
elsif multi_valued?(value)
|
|
141
|
+
build_multiple_options(value)
|
|
142
|
+
else
|
|
143
|
+
build_single_option(value)
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def build_plurals(values)
|
|
148
|
+
values.map { |p| build_plural(p) }.flatten
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def build_plural_options(parameters)
|
|
152
|
+
keys = all_plural_keys
|
|
153
|
+
values = values(parameters, keys)
|
|
154
|
+
|
|
155
|
+
build_plurals(values)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def build_key_value_options(value)
|
|
159
|
+
value.map { |k, v| build_option(build_key_value(k, v)) }
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def build_multiple_options(value)
|
|
163
|
+
value.map { |v| build_option(build_value(v)) }
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
def build_single_option(value)
|
|
167
|
+
[build_option(build_value(value))]
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def build_no_options
|
|
171
|
+
[]
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
# rubocop:enable Metrics/ClassLength
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative '../name'
|
|
4
|
+
require_relative '../types'
|
|
5
|
+
require_relative '../values'
|
|
6
|
+
|
|
7
|
+
module RubyNPM
|
|
8
|
+
module Options
|
|
9
|
+
module Definitions
|
|
10
|
+
class Workspaces
|
|
11
|
+
attr_reader :workspace_name, :workspaces_name
|
|
12
|
+
|
|
13
|
+
def initialize
|
|
14
|
+
@workspace_name = Name.new('--workspace')
|
|
15
|
+
@workspaces_name = Name.new('--workspaces')
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def matches?(name)
|
|
19
|
+
workspaces_name == Name.new(name)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def build(parameters)
|
|
23
|
+
build_workspace_options(parameters) +
|
|
24
|
+
build_workspaces_option(parameters)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
def build_workspace_options(parameters)
|
|
30
|
+
workspaces = parameters[:workspaces]
|
|
31
|
+
|
|
32
|
+
return build_no_options if workspaces.nil? || boolean?(workspaces)
|
|
33
|
+
|
|
34
|
+
if workspaces.is_a?(Array)
|
|
35
|
+
return workspaces.map do |v|
|
|
36
|
+
build_string_option(workspace_name, v)
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
[build_string_option(workspace_name, workspaces)]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def build_workspaces_option(parameters)
|
|
44
|
+
workspaces = parameters[:workspaces]
|
|
45
|
+
|
|
46
|
+
return build_no_options if workspaces.nil? || !boolean?(workspaces)
|
|
47
|
+
|
|
48
|
+
[build_boolean_option(workspaces_name, workspaces)]
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def build_no_options
|
|
52
|
+
[]
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def build_string_option(name, value)
|
|
56
|
+
Options.types.standard(
|
|
57
|
+
name, Options.values.string(value), separator: ' '
|
|
58
|
+
)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def build_boolean_option(name, value)
|
|
62
|
+
Options.types.standard(
|
|
63
|
+
name, Options.values.boolean(value), separator: ' '
|
|
64
|
+
)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def boolean?(value)
|
|
68
|
+
[true, false].include?(value)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -2,6 +2,82 @@
|
|
|
2
2
|
|
|
3
3
|
module RubyNPM
|
|
4
4
|
module Options
|
|
5
|
-
DEFINITIONS = [
|
|
5
|
+
DEFINITIONS = [
|
|
6
|
+
# concrete definitions
|
|
7
|
+
[
|
|
8
|
+
workspaces
|
|
9
|
+
],
|
|
10
|
+
|
|
11
|
+
# string repeatable options
|
|
12
|
+
{
|
|
13
|
+
omit: '--omit',
|
|
14
|
+
include: '--include'
|
|
15
|
+
}.map do |key, name|
|
|
16
|
+
definition(
|
|
17
|
+
name: name, option_type: :standard, value_type: :string,
|
|
18
|
+
repeatable: true,
|
|
19
|
+
override_keys: { singular: false, plural: key }
|
|
20
|
+
)
|
|
21
|
+
end,
|
|
22
|
+
|
|
23
|
+
# string options
|
|
24
|
+
%w[
|
|
25
|
+
--color
|
|
26
|
+
--install-strategy
|
|
27
|
+
--loglevel
|
|
28
|
+
--logs-dir
|
|
29
|
+
--logs-max
|
|
30
|
+
--script-shell
|
|
31
|
+
--tag
|
|
32
|
+
--workspace
|
|
33
|
+
].map do |o|
|
|
34
|
+
definition(
|
|
35
|
+
name: o, option_type: :standard, value_type: :string
|
|
36
|
+
)
|
|
37
|
+
end,
|
|
38
|
+
|
|
39
|
+
# flag options
|
|
40
|
+
%w[
|
|
41
|
+
--quiet
|
|
42
|
+
--silent
|
|
43
|
+
--verbose
|
|
44
|
+
].map do |o|
|
|
45
|
+
definition(name: o, option_type: :flag, value_type: :boolean)
|
|
46
|
+
end,
|
|
47
|
+
|
|
48
|
+
# boolean options
|
|
49
|
+
%w[
|
|
50
|
+
--audit
|
|
51
|
+
--bin-links
|
|
52
|
+
--dry-run
|
|
53
|
+
--force
|
|
54
|
+
--foreground-scripts
|
|
55
|
+
--fund
|
|
56
|
+
--global
|
|
57
|
+
--global-style
|
|
58
|
+
--if-present
|
|
59
|
+
--ignore-scripts
|
|
60
|
+
--include-workspace-root
|
|
61
|
+
--install-links
|
|
62
|
+
--json
|
|
63
|
+
--legacy-bundling
|
|
64
|
+
--package-lock
|
|
65
|
+
--package-lock-only
|
|
66
|
+
--parseable
|
|
67
|
+
--production
|
|
68
|
+
--save
|
|
69
|
+
--save-bundle
|
|
70
|
+
--save-dev
|
|
71
|
+
--save-exact
|
|
72
|
+
--save-optional
|
|
73
|
+
--save-peer
|
|
74
|
+
--save-prod
|
|
75
|
+
--strict-peer-deps
|
|
76
|
+
].map do |o|
|
|
77
|
+
definition(
|
|
78
|
+
name: o, option_type: :standard, value_type: :boolean
|
|
79
|
+
)
|
|
80
|
+
end
|
|
81
|
+
].flatten.freeze
|
|
6
82
|
end
|
|
7
83
|
end
|
data/lib/ruby_npm/options.rb
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
require_relative 'options/name'
|
|
4
4
|
require_relative 'options/types'
|
|
5
5
|
require_relative 'options/values'
|
|
6
|
-
require_relative 'options/
|
|
6
|
+
require_relative 'options/definitions/generic'
|
|
7
|
+
require_relative 'options/definitions/workspaces'
|
|
7
8
|
require_relative 'options/factory'
|
|
8
9
|
require_relative 'options/sets'
|
|
9
10
|
|
|
@@ -14,7 +15,11 @@ module RubyNPM
|
|
|
14
15
|
end
|
|
15
16
|
|
|
16
17
|
def self.definition(opts)
|
|
17
|
-
|
|
18
|
+
Definitions::Generic.new(opts)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.workspaces
|
|
22
|
+
Definitions::Workspaces.new
|
|
18
23
|
end
|
|
19
24
|
|
|
20
25
|
def self.types
|
data/lib/ruby_npm/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby_npm
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.0.pre.
|
|
4
|
+
version: 0.1.0.pre.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- InfraBlocks Maintainers
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2023-01-01 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: immutable-struct
|
|
@@ -295,11 +295,13 @@ files:
|
|
|
295
295
|
- lib/ruby_npm/commands.rb
|
|
296
296
|
- lib/ruby_npm/commands/base.rb
|
|
297
297
|
- lib/ruby_npm/commands/install.rb
|
|
298
|
+
- lib/ruby_npm/commands/run_script.rb
|
|
298
299
|
- lib/ruby_npm/errors.rb
|
|
299
300
|
- lib/ruby_npm/errors/execution_error.rb
|
|
300
301
|
- lib/ruby_npm/options.rb
|
|
301
|
-
- lib/ruby_npm/options/definition.rb
|
|
302
302
|
- lib/ruby_npm/options/definitions.rb
|
|
303
|
+
- lib/ruby_npm/options/definitions/generic.rb
|
|
304
|
+
- lib/ruby_npm/options/definitions/workspaces.rb
|
|
303
305
|
- lib/ruby_npm/options/factory.rb
|
|
304
306
|
- lib/ruby_npm/options/name.rb
|
|
305
307
|
- lib/ruby_npm/options/sets.rb
|
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'immutable-struct'
|
|
4
|
-
|
|
5
|
-
require_relative 'name'
|
|
6
|
-
require_relative 'types'
|
|
7
|
-
require_relative 'values'
|
|
8
|
-
|
|
9
|
-
module RubyNPM
|
|
10
|
-
module Options
|
|
11
|
-
# rubocop:disable Metrics/ClassLength
|
|
12
|
-
class Definition < ImmutableStruct.new(
|
|
13
|
-
:name,
|
|
14
|
-
:option_type,
|
|
15
|
-
:value_type,
|
|
16
|
-
:override_keys,
|
|
17
|
-
:extra_keys,
|
|
18
|
-
:separator,
|
|
19
|
-
:placement,
|
|
20
|
-
:repeatable?
|
|
21
|
-
)
|
|
22
|
-
# rubocop:disable Metrics/MethodLength
|
|
23
|
-
def initialize(opts)
|
|
24
|
-
raise 'Missing name.' unless opts[:name]
|
|
25
|
-
|
|
26
|
-
super(
|
|
27
|
-
name: Name.new(opts[:name]),
|
|
28
|
-
option_type: Types.resolve(opts[:option_type]) || Types::Standard,
|
|
29
|
-
value_type: Values.resolve(opts[:value_type]) || Values::String,
|
|
30
|
-
repeatable: opts[:repeatable] || false,
|
|
31
|
-
separator: opts[:separator],
|
|
32
|
-
placement: opts[:placement],
|
|
33
|
-
extra_keys:
|
|
34
|
-
{ singular: [], plural: [] }
|
|
35
|
-
.merge(opts[:extra_keys] || {}),
|
|
36
|
-
override_keys:
|
|
37
|
-
{ singular: nil, plural: nil }
|
|
38
|
-
.merge(opts[:override_keys] || {})
|
|
39
|
-
)
|
|
40
|
-
end
|
|
41
|
-
# rubocop:enable Metrics/MethodLength
|
|
42
|
-
|
|
43
|
-
def matches?(name)
|
|
44
|
-
@name == Name.new(name)
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def build(parameters)
|
|
48
|
-
build_singular_options(parameters) + build_plural_options(parameters)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
private
|
|
52
|
-
|
|
53
|
-
def resolved_singular_key
|
|
54
|
-
if override_keys[:singular] == false
|
|
55
|
-
nil
|
|
56
|
-
else
|
|
57
|
-
override_keys[:singular] || name.as_singular_key
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def all_singular_keys
|
|
62
|
-
([resolved_singular_key] + extra_keys[:singular]).compact
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def resolved_plural_key
|
|
66
|
-
if override_keys[:plural] == false
|
|
67
|
-
nil
|
|
68
|
-
else
|
|
69
|
-
override_keys[:plural] || name.as_plural_key
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def all_plural_keys
|
|
74
|
-
([resolved_plural_key] + extra_keys[:plural]).compact
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
def too_many_values?(values)
|
|
78
|
-
!repeatable? && values.length > 1
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def values(parameters, keys)
|
|
82
|
-
keys.map { |k| parameters[k] }.compact
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
def needs_plural?(value)
|
|
86
|
-
repeatable? && !value.nil?
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def only_singular?(value)
|
|
90
|
-
!needs_plural?(value)
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def key_valued?(value)
|
|
94
|
-
value.respond_to?(:keys)
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
def multi_valued?(value)
|
|
98
|
-
value.respond_to?(:each)
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
def build_option(value)
|
|
102
|
-
option_type.new(name, value, separator: separator, placement: placement)
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def build_value(value)
|
|
106
|
-
value_type.new(value)
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def build_key_value(key, value)
|
|
110
|
-
Values::KeyValue.new(key, build_value(value))
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
def build_singular(value)
|
|
114
|
-
build_single_option(value)
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
def build_singulars(values)
|
|
118
|
-
values.map { |p| build_singular(p) }.flatten
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
def build_singular_options(parameters)
|
|
122
|
-
keys = all_singular_keys
|
|
123
|
-
values = values(parameters, keys)
|
|
124
|
-
|
|
125
|
-
if too_many_values?(values)
|
|
126
|
-
raise "Multiple values provided for '#{name}' " \
|
|
127
|
-
"(with keys #{keys}) and option not repeatable."
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
build_singulars(values)
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
def build_plural(value)
|
|
134
|
-
if only_singular?(value)
|
|
135
|
-
build_no_options
|
|
136
|
-
elsif key_valued?(value)
|
|
137
|
-
build_key_value_options(value)
|
|
138
|
-
elsif multi_valued?(value)
|
|
139
|
-
build_multiple_options(value)
|
|
140
|
-
else
|
|
141
|
-
build_single_option(value)
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
def build_plurals(values)
|
|
146
|
-
values.map { |p| build_plural(p) }.flatten
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
def build_plural_options(parameters)
|
|
150
|
-
keys = all_plural_keys
|
|
151
|
-
values = values(parameters, keys)
|
|
152
|
-
|
|
153
|
-
build_plurals(values)
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
def build_key_value_options(value)
|
|
157
|
-
value.map { |k, v| build_option(build_key_value(k, v)) }
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
def build_multiple_options(value)
|
|
161
|
-
value.map { |v| build_option(build_value(v)) }
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
def build_single_option(value)
|
|
165
|
-
[build_option(build_value(value))]
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
def build_no_options
|
|
169
|
-
[]
|
|
170
|
-
end
|
|
171
|
-
end
|
|
172
|
-
# rubocop:enable Metrics/ClassLength
|
|
173
|
-
end
|
|
174
|
-
end
|