k_director 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.builders/boot.rb +3 -3
- data/docs/CHANGELOG.md +7 -0
- data/lib/k_director/directors/base_director.rb +4 -0
- data/lib/k_director/dsls/children/package_json.rb +236 -8
- data/lib/k_director/version.rb +1 -1
- data/package-lock.json +2 -2
- data/package.json +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a7a7b652cc348b24d223f9c0df0d39443a61699e6b7221eaa65499d517f155b
|
4
|
+
data.tar.gz: 7b196d138fa1953a54562e0e381aee32754b55f43eada1981ac45db973c55209
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03cb460ca47b4c4c5ef5f355ef13882ffd1b38b9590ecba60eb4c49551efe91d067029c79c02b9e5526a12677b23cbd87accf473650c62daa1ca91de4b71be8c
|
7
|
+
data.tar.gz: 14294acc2367c38f19f7c1ccb5dcecdcbf58bd86fc754bce974de4bb75ad635a8b21b36d698362d08d5eb584e0da23c4475c81d7938f697cf30f9de0d704dc51
|
data/.builders/boot.rb
CHANGED
@@ -40,10 +40,10 @@ def dasherize
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def k_builder
|
43
|
-
@k_builder ||= KBuilder::BaseBuilder.init(
|
43
|
+
@k_builder ||= KBuilder::BaseBuilder.init(KConfig.configuration(CONFIG_KEY))
|
44
44
|
end
|
45
45
|
|
46
|
-
|
46
|
+
KConfig.configure(CONFIG_KEY) do |config|
|
47
47
|
builder_folder = Dir.pwd
|
48
48
|
base_folder = File.expand_path('../', builder_folder)
|
49
49
|
global_template = File.expand_path('~/dev/kgems/k_templates/templates')
|
@@ -58,7 +58,7 @@ KBuilder.configure(CONFIG_KEY) do |config|
|
|
58
58
|
# config.target_folders.add(:database , :data, 'database')
|
59
59
|
end
|
60
60
|
|
61
|
-
|
61
|
+
KConfig.configuration(CONFIG_KEY).debug
|
62
62
|
|
63
63
|
area = KManager.add_area(CONFIG_KEY)
|
64
64
|
resource_manager = area.resource_manager
|
data/docs/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
## [0.8.1](https://github.com/klueless-io/k_director/compare/v0.8.0...v0.8.1) (2022-02-05)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* add tests for package_json configuration ([d900065](https://github.com/klueless-io/k_director/commit/d900065bf810771841b97de03dfa9011c48c8e43))
|
7
|
+
|
1
8
|
# [0.8.0](https://github.com/klueless-io/k_director/compare/v0.7.3...v0.8.0) (2022-02-04)
|
2
9
|
|
3
10
|
|
@@ -17,14 +17,6 @@ module KDirector
|
|
17
17
|
|
18
18
|
set_package_file('package.json')
|
19
19
|
set_dependency_type(:development)
|
20
|
-
|
21
|
-
# defaults = {
|
22
|
-
# repo_name: opts[:repo_name], # || parent.builder.dom&[:PackageJson]&[:repo_name]
|
23
|
-
# username: opts[:username] || default_PackageJson_username, # || parent.builder.dom&[:PackageJson]&[:username]
|
24
|
-
# organization: opts[:organization] # || parent.builder.dom&[:PackageJson]&[:organization]
|
25
|
-
# }
|
26
|
-
|
27
|
-
# parent.builder.group_set(:PackageJson, **repo_info_hash(**defaults))
|
28
20
|
end
|
29
21
|
|
30
22
|
# ----------------------------------------------------------------------
|
@@ -44,6 +36,242 @@ module KDirector
|
|
44
36
|
|
45
37
|
self
|
46
38
|
end
|
39
|
+
|
40
|
+
# Init an NPN package
|
41
|
+
#
|
42
|
+
# run npm init -y
|
43
|
+
#
|
44
|
+
# Note: npm init does not support --silent operation
|
45
|
+
def npm_init
|
46
|
+
run_command 'npm init -y'
|
47
|
+
|
48
|
+
load
|
49
|
+
|
50
|
+
self
|
51
|
+
end
|
52
|
+
|
53
|
+
# Space separated list of packages
|
54
|
+
def npm_install(packages, options: nil)
|
55
|
+
npm_add_or_install(packages, parse_options(options))
|
56
|
+
|
57
|
+
self
|
58
|
+
end
|
59
|
+
alias npm_i npm_install
|
60
|
+
|
61
|
+
def npm_add(packages, options: nil)
|
62
|
+
npm_add_or_install(packages, parse_options(options, '--package-lock-only --no-package-lock'))
|
63
|
+
|
64
|
+
self
|
65
|
+
end
|
66
|
+
alias npm_a npm_add
|
67
|
+
|
68
|
+
def npm_add_group(key, options: nil)
|
69
|
+
group = get_group(key)
|
70
|
+
|
71
|
+
puts "Adding #{group.description}"
|
72
|
+
|
73
|
+
npm_add(group.package_names, options: options)
|
74
|
+
|
75
|
+
self
|
76
|
+
end
|
77
|
+
alias npm_ag npm_add_group
|
78
|
+
|
79
|
+
# Add a group of NPN packages which get defined in configuration
|
80
|
+
def npm_install_group(key, options: nil)
|
81
|
+
group = get_group(key)
|
82
|
+
|
83
|
+
puts "Installing #{group.description}"
|
84
|
+
|
85
|
+
npm_install(group.package_names, options: options)
|
86
|
+
|
87
|
+
self
|
88
|
+
end
|
89
|
+
|
90
|
+
# Load the existing package.json into memory
|
91
|
+
#
|
92
|
+
# ToDo: Would be useful to record the update timestamp on the package
|
93
|
+
# so that we only load if the in memory package is not the latest.
|
94
|
+
#
|
95
|
+
# The reason this can happen, is because external tools such are
|
96
|
+
# npm install are updating the package.json and after this happens
|
97
|
+
# we need to call load, but if there is any bug in the code we may
|
98
|
+
# for get to load, or we may load multiple times.
|
99
|
+
def load
|
100
|
+
raise KDirector::Error, 'package.json does not exist' unless File.exist?(package_file)
|
101
|
+
|
102
|
+
puts 'loading...'
|
103
|
+
|
104
|
+
content = File.read(package_file)
|
105
|
+
@package = JSON.parse(content)
|
106
|
+
|
107
|
+
self
|
108
|
+
end
|
109
|
+
|
110
|
+
# Write the package.json file
|
111
|
+
def write
|
112
|
+
puts 'writing...'
|
113
|
+
|
114
|
+
content = JSON.pretty_generate(@package)
|
115
|
+
|
116
|
+
File.write(package_file, content)
|
117
|
+
|
118
|
+
self
|
119
|
+
end
|
120
|
+
|
121
|
+
# Remove a script reference by key
|
122
|
+
def remove_script(key)
|
123
|
+
load
|
124
|
+
|
125
|
+
@package['scripts']&.delete(key)
|
126
|
+
|
127
|
+
write
|
128
|
+
|
129
|
+
self
|
130
|
+
end
|
131
|
+
|
132
|
+
# Add a script with key and value (command line to run)
|
133
|
+
def add_script(key, value)
|
134
|
+
load
|
135
|
+
|
136
|
+
@package['scripts'][key] = value
|
137
|
+
|
138
|
+
write
|
139
|
+
|
140
|
+
self
|
141
|
+
end
|
142
|
+
|
143
|
+
# ----------------------------------------------------------------------
|
144
|
+
# Attributes: Think getter/setter
|
145
|
+
#
|
146
|
+
# The following getter/setters can be referenced both inside and outside
|
147
|
+
# of the fluent builder fluent API. They do not implement the fluent
|
148
|
+
# interface unless prefixed by set_.
|
149
|
+
#
|
150
|
+
# set_: Only setters with the prefix _set are considered fluent.
|
151
|
+
# ----------------------------------------------------------------------
|
152
|
+
|
153
|
+
# Package
|
154
|
+
# ----------------------------------------------------------------------
|
155
|
+
|
156
|
+
# Load the package.json into a memory as object
|
157
|
+
def package
|
158
|
+
return @package if defined? @package
|
159
|
+
|
160
|
+
load
|
161
|
+
|
162
|
+
@package
|
163
|
+
end
|
164
|
+
|
165
|
+
# Package.set
|
166
|
+
# ----------------------------------------------------------------------
|
167
|
+
|
168
|
+
# Set a property value in the package
|
169
|
+
def set(key, value)
|
170
|
+
load
|
171
|
+
|
172
|
+
@package[key] = value
|
173
|
+
|
174
|
+
write
|
175
|
+
|
176
|
+
self
|
177
|
+
end
|
178
|
+
|
179
|
+
# Dependency option
|
180
|
+
# ----------------------------------------------------------------------
|
181
|
+
|
182
|
+
# Getter for dependency option
|
183
|
+
def dependency_option
|
184
|
+
dependency_type == :development ? '-D' : '-P'
|
185
|
+
end
|
186
|
+
|
187
|
+
# Dependency type
|
188
|
+
# ----------------------------------------------------------------------
|
189
|
+
|
190
|
+
# Fluent setter for target folder
|
191
|
+
# rubocop:disable Naming/AccessorMethodName
|
192
|
+
def set_dependency_type(value)
|
193
|
+
self.dependency_type = value
|
194
|
+
|
195
|
+
self
|
196
|
+
end
|
197
|
+
# rubocop:enable Naming/AccessorMethodName
|
198
|
+
|
199
|
+
# Package file
|
200
|
+
# ----------------------------------------------------------------------
|
201
|
+
|
202
|
+
# Fluent setter for package file
|
203
|
+
# rubocop:disable Naming/AccessorMethodName
|
204
|
+
def set_package_file(value)
|
205
|
+
self.package_file = value
|
206
|
+
|
207
|
+
self
|
208
|
+
end
|
209
|
+
# rubocop:enable Naming/AccessorMethodName
|
210
|
+
|
211
|
+
# Setter for package file
|
212
|
+
def package_file=(_value)
|
213
|
+
@package_file = File.join(k_builder.target_folder, 'package.json')
|
214
|
+
end
|
215
|
+
|
216
|
+
# # Getter for target folder
|
217
|
+
# def package_file
|
218
|
+
# hash['package_file']
|
219
|
+
# end
|
220
|
+
|
221
|
+
# -----------------------------------
|
222
|
+
# Helpers
|
223
|
+
# -----------------------------------
|
224
|
+
|
225
|
+
def parse_options(options = nil, required_options = nil)
|
226
|
+
options = [] if options.nil?
|
227
|
+
options = options.split if options.is_a?(String)
|
228
|
+
options.reject(&:empty?)
|
229
|
+
|
230
|
+
required_options = [] if required_options.nil?
|
231
|
+
required_options = required_options.split if required_options.is_a?(String)
|
232
|
+
|
233
|
+
options | required_options
|
234
|
+
end
|
235
|
+
|
236
|
+
def options_any?(options, *any_options)
|
237
|
+
(options & any_options).any?
|
238
|
+
end
|
239
|
+
|
240
|
+
def execute(command)
|
241
|
+
puts "RUN: #{command}"
|
242
|
+
run_command command
|
243
|
+
load
|
244
|
+
end
|
245
|
+
|
246
|
+
def npm_add_or_install(packages, options)
|
247
|
+
# if -P or -D is not in the options then use the current builder dependency option
|
248
|
+
options.push dependency_option unless options_any?(options, '-P', '-D')
|
249
|
+
packages = packages.join(' ') if packages.is_a?(Array)
|
250
|
+
command = "npm install #{options.join(' ')} #{packages}"
|
251
|
+
execute command
|
252
|
+
end
|
253
|
+
|
254
|
+
# # Debug method to open the package file in vscode
|
255
|
+
# # ToDo: Maybe remove
|
256
|
+
# def vscode
|
257
|
+
# puts "cd #{output_path}"
|
258
|
+
# puts package_file
|
259
|
+
# run_command "code #{package_file}"
|
260
|
+
# end
|
261
|
+
|
262
|
+
# private
|
263
|
+
|
264
|
+
def get_group(key)
|
265
|
+
group = configuration.package_json.package_groups[key]
|
266
|
+
|
267
|
+
raise KConfig::PackageJson::Error, "unknown package group: #{key}" if group.nil?
|
268
|
+
|
269
|
+
group
|
270
|
+
end
|
271
|
+
|
272
|
+
def run_command(command)
|
273
|
+
parent.k_builder.run_command(command)
|
274
|
+
end
|
47
275
|
end
|
48
276
|
end
|
49
277
|
end
|
data/lib/k_director/version.rb
CHANGED
data/package-lock.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "k_director",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.9.0",
|
4
4
|
"lockfileVersion": 2,
|
5
5
|
"requires": true,
|
6
6
|
"packages": {
|
7
7
|
"": {
|
8
8
|
"name": "k_director",
|
9
|
-
"version": "0.
|
9
|
+
"version": "0.9.0",
|
10
10
|
"devDependencies": {
|
11
11
|
"@klueless-js/semantic-release-rubygem": "github:klueless-js/semantic-release-rubygem",
|
12
12
|
"@semantic-release/changelog": "^6.0.1",
|
data/package.json
CHANGED