ruby_npm 0.1.0.pre.1 → 0.1.0.pre.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e881cd3e037d19933e854ea4ded7e72a6bb69b661c78dc9fcf51e4b4645c47f
4
- data.tar.gz: dcf5758ec3746447abab1ac2e8aa880cba531c8e61b1dd24e7791a194ed9a4d8
3
+ metadata.gz: e2bfe773251ad6e3ecc36c59141e678453a331374495e5b66e6f8bf12c95e7ce
4
+ data.tar.gz: 03d9787e1482c0ee0fc340d0afde445b9c85477a7db2797b08803359d0ccf35f
5
5
  SHA512:
6
- metadata.gz: bf28ec38e38ffbcfcd9c622cd61cf846a4fc0a82b2848bd07ffc6732b111e08c463b5b6777107576b75209b3d1fc5b3ba5a1f5a1e085918c0e21d8a2e4cfadac
7
- data.tar.gz: 79cdf3fa9bf80081bb0e6fec3063c923d33ae6b6be4090e9751ffc3837b69fb89c40dbf57b62fd6bb4bdeb4fe8d91a3181d67dd4a4daba4c75c7666abc74d2a9
6
+ metadata.gz: c9321625dc5612716ee0c2e24058dfd2ef650e9ceb146937d7e861f13a02b1bb3f694dc8de201734db430ecb682b21ebdec62b6d300fee3fdb3bb9fa84f1b8a2
7
+ data.tar.gz: c047104cd3bc039ad9bb6887480d8038c204733ce6f115801f8e4c6adcee32654898b9862d0d6f667907bcf033e6cf3e1161bbc82951cd84973535d2ba881047
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ruby_npm (0.1.0.pre.1)
4
+ ruby_npm (0.1.0.pre.2)
5
5
  immutable-struct (~> 2.4)
6
6
  lino (~> 3.0)
7
7
 
@@ -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,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,81 @@
2
2
 
3
3
  module RubyNPM
4
4
  module Options
5
- DEFINITIONS = [].freeze
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, separator: ' ',
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
+ separator: ' '
37
+ )
38
+ end,
39
+
40
+ # flag options
41
+ %w[
42
+ --quiet
43
+ --silent
44
+ --verbose
45
+ ].map do |o|
46
+ definition(name: o, option_type: :flag, value_type: :boolean)
47
+ end,
48
+
49
+ # boolean options
50
+ %w[
51
+ --audit
52
+ --bin-links
53
+ --dry-run
54
+ --force
55
+ --foreground-scripts
56
+ --fund
57
+ --global
58
+ --global-style
59
+ --ignore-scripts
60
+ --include-workspace-root
61
+ --install-links
62
+ --legacy-bundling
63
+ --package-lock
64
+ --package-lock-only
65
+ --production
66
+ --save
67
+ --save-bundle
68
+ --save-dev
69
+ --save-exact
70
+ --save-optional
71
+ --save-peer
72
+ --save-prod
73
+ --strict-peer-deps
74
+ ].map do |o|
75
+ definition(
76
+ name: o, option_type: :standard, value_type: :boolean,
77
+ separator: ' '
78
+ )
79
+ end
80
+ ].flatten.freeze
6
81
  end
7
82
  end
@@ -10,7 +10,7 @@ module RubyNPM
10
10
  end
11
11
 
12
12
  def name
13
- "-#{without_prefix}"
13
+ "--#{without_prefix}"
14
14
  end
15
15
 
16
16
  alias to_s name
@@ -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/definition'
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
- Definition.new(opts)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyNPM
4
- VERSION = '0.1.0.pre.1'
4
+ VERSION = '0.1.0.pre.2'
5
5
  end
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.1
4
+ version: 0.1.0.pre.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - InfraBlocks Maintainers
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-29 00:00:00.000000000 Z
11
+ date: 2023-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: immutable-struct
@@ -298,8 +298,9 @@ files:
298
298
  - lib/ruby_npm/errors.rb
299
299
  - lib/ruby_npm/errors/execution_error.rb
300
300
  - lib/ruby_npm/options.rb
301
- - lib/ruby_npm/options/definition.rb
302
301
  - lib/ruby_npm/options/definitions.rb
302
+ - lib/ruby_npm/options/definitions/generic.rb
303
+ - lib/ruby_npm/options/definitions/workspaces.rb
303
304
  - lib/ruby_npm/options/factory.rb
304
305
  - lib/ruby_npm/options/name.rb
305
306
  - 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