pdk 1.13.0 → 1.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +25 -0
- data/README.md +41 -0
- data/lib/pdk.rb +0 -13
- data/lib/pdk/analytics.rb +18 -2
- data/lib/pdk/analytics/client/google_analytics.rb +3 -0
- data/lib/pdk/answer_file.rb +4 -1
- data/lib/pdk/cli.rb +7 -2
- data/lib/pdk/cli/build.rb +2 -2
- data/lib/pdk/cli/bundle.rb +7 -1
- data/lib/pdk/cli/console.rb +148 -0
- data/lib/pdk/cli/convert.rb +2 -2
- data/lib/pdk/cli/exec.rb +14 -14
- data/lib/pdk/cli/exec/command.rb +16 -11
- data/lib/pdk/cli/exec/interactive_command.rb +4 -0
- data/lib/pdk/cli/exec_group.rb +5 -5
- data/lib/pdk/cli/module/build.rb +0 -2
- data/lib/pdk/cli/module/generate.rb +1 -2
- data/lib/pdk/cli/new.rb +1 -1
- data/lib/pdk/cli/new/defined_type.rb +2 -0
- data/lib/pdk/cli/new/provider.rb +2 -0
- data/lib/pdk/cli/new/task.rb +2 -0
- data/lib/pdk/cli/new/{unit_test.rb → test.rb} +16 -12
- data/lib/pdk/cli/new/transport.rb +2 -0
- data/lib/pdk/cli/test/unit.rb +5 -3
- data/lib/pdk/cli/update.rb +2 -3
- data/lib/pdk/cli/util.rb +45 -14
- data/lib/pdk/cli/util/spinner.rb +2 -2
- data/lib/pdk/cli/validate.rb +6 -2
- data/lib/pdk/config.rb +20 -8
- data/lib/pdk/config/analytics_schema.json +26 -0
- data/lib/pdk/config/json.rb +14 -3
- data/lib/pdk/config/json_schema_namespace.rb +143 -0
- data/lib/pdk/config/json_schema_setting.rb +53 -0
- data/lib/pdk/config/json_with_schema.rb +50 -0
- data/lib/pdk/config/namespace.rb +84 -76
- data/lib/pdk/config/setting.rb +132 -0
- data/lib/pdk/config/yaml.rb +15 -3
- data/lib/pdk/config/yaml_with_schema.rb +59 -0
- data/lib/pdk/generate.rb +0 -2
- data/lib/pdk/generate/module.rb +29 -16
- data/lib/pdk/generate/puppet_object.rb +31 -28
- data/lib/pdk/module.rb +2 -2
- data/lib/pdk/module/build.rb +21 -8
- data/lib/pdk/module/convert.rb +64 -7
- data/lib/pdk/module/metadata.rb +5 -1
- data/lib/pdk/module/templatedir.rb +24 -7
- data/lib/pdk/module/update.rb +5 -1
- data/lib/pdk/module/update_manager.rb +21 -13
- data/lib/pdk/report.rb +4 -3
- data/lib/pdk/report/event.rb +5 -3
- data/lib/pdk/tests/unit.rb +36 -7
- data/lib/pdk/util.rb +20 -8
- data/lib/pdk/util/bundler.rb +14 -6
- data/lib/pdk/util/filesystem.rb +5 -0
- data/lib/pdk/util/git.rb +6 -0
- data/lib/pdk/util/puppet_strings.rb +24 -2
- data/lib/pdk/util/puppet_version.rb +25 -10
- data/lib/pdk/util/ruby_version.rb +13 -1
- data/lib/pdk/util/template_uri.rb +23 -2
- data/lib/pdk/util/vendored_file.rb +28 -24
- data/lib/pdk/util/version.rb +5 -5
- data/lib/pdk/validate/base_validator.rb +5 -4
- data/lib/pdk/validate/metadata/metadata_json_lint.rb +0 -4
- data/lib/pdk/validate/metadata/metadata_syntax.rb +5 -3
- data/lib/pdk/validate/metadata_validator.rb +0 -2
- data/lib/pdk/validate/puppet/puppet_epp.rb +4 -4
- data/lib/pdk/validate/puppet/puppet_lint.rb +0 -3
- data/lib/pdk/validate/puppet/puppet_syntax.rb +4 -4
- data/lib/pdk/validate/puppet_validator.rb +0 -2
- data/lib/pdk/validate/ruby/rubocop.rb +0 -5
- data/lib/pdk/validate/ruby_validator.rb +0 -2
- data/lib/pdk/validate/tasks/metadata_lint.rb +9 -5
- data/lib/pdk/validate/tasks/name.rb +4 -2
- data/lib/pdk/validate/tasks_validator.rb +0 -2
- data/lib/pdk/validate/yaml/syntax.rb +4 -4
- data/lib/pdk/validate/yaml_validator.rb +0 -2
- data/lib/pdk/version.rb +1 -1
- data/locales/pdk.pot +351 -311
- metadata +11 -7
- data/lib/pdk/config/validator.rb +0 -31
- data/lib/pdk/config/value.rb +0 -94
data/lib/pdk/module.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'pathspec'
|
2
|
-
|
3
1
|
module PDK
|
4
2
|
module Module
|
5
3
|
DEFAULT_IGNORED = [
|
@@ -13,6 +11,8 @@ module PDK
|
|
13
11
|
].freeze
|
14
12
|
|
15
13
|
def default_ignored_pathspec(ignore_dotfiles = true)
|
14
|
+
require 'pathspec'
|
15
|
+
|
16
16
|
PathSpec.new(DEFAULT_IGNORED).tap do |ps|
|
17
17
|
ps.add('.*') if ignore_dotfiles
|
18
18
|
end
|
data/lib/pdk/module/build.rb
CHANGED
@@ -1,11 +1,3 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'minitar'
|
3
|
-
require 'zlib'
|
4
|
-
require 'pathspec'
|
5
|
-
require 'find'
|
6
|
-
require 'pdk/module'
|
7
|
-
require 'pdk/tests/unit'
|
8
|
-
|
9
1
|
module PDK
|
10
2
|
module Module
|
11
3
|
class Build
|
@@ -26,6 +18,8 @@ module PDK
|
|
26
18
|
#
|
27
19
|
# @return [Hash{String => Object}] The hash of metadata values.
|
28
20
|
def metadata
|
21
|
+
require 'pdk/module/metadata'
|
22
|
+
|
29
23
|
@metadata ||= PDK::Module::Metadata.from_file(File.join(module_dir, 'metadata.json')).data
|
30
24
|
end
|
31
25
|
|
@@ -71,6 +65,8 @@ module PDK
|
|
71
65
|
#
|
72
66
|
# If the directory already exists, remove it first.
|
73
67
|
def create_build_dir
|
68
|
+
require 'fileutils'
|
69
|
+
|
74
70
|
cleanup_build_dir
|
75
71
|
|
76
72
|
FileUtils.mkdir_p(build_dir)
|
@@ -80,6 +76,8 @@ module PDK
|
|
80
76
|
#
|
81
77
|
# @return nil.
|
82
78
|
def cleanup_build_dir
|
79
|
+
require 'fileutils'
|
80
|
+
|
83
81
|
FileUtils.rm_rf(build_dir, secure: true)
|
84
82
|
end
|
85
83
|
|
@@ -99,6 +97,8 @@ module PDK
|
|
99
97
|
#
|
100
98
|
# @return nil
|
101
99
|
def stage_module_in_build_dir
|
100
|
+
require 'find'
|
101
|
+
|
102
102
|
Find.find(module_dir) do |path|
|
103
103
|
next if path == module_dir
|
104
104
|
|
@@ -112,6 +112,9 @@ module PDK
|
|
112
112
|
#
|
113
113
|
# @return nil.
|
114
114
|
def stage_path(path)
|
115
|
+
require 'pathname'
|
116
|
+
require 'fileutils'
|
117
|
+
|
115
118
|
relative_path = Pathname.new(path).relative_path_from(Pathname.new(module_dir))
|
116
119
|
dest_path = File.join(build_dir, relative_path)
|
117
120
|
|
@@ -149,6 +152,8 @@ module PDK
|
|
149
152
|
#
|
150
153
|
# @return nil.
|
151
154
|
def warn_symlink(path)
|
155
|
+
require 'pathname'
|
156
|
+
|
152
157
|
symlink_path = Pathname.new(path)
|
153
158
|
module_path = Pathname.new(module_dir)
|
154
159
|
|
@@ -217,6 +222,11 @@ module PDK
|
|
217
222
|
#
|
218
223
|
# @return nil.
|
219
224
|
def build_package
|
225
|
+
require 'fileutils'
|
226
|
+
require 'zlib'
|
227
|
+
require 'minitar'
|
228
|
+
require 'find'
|
229
|
+
|
220
230
|
FileUtils.rm_f(package_file)
|
221
231
|
|
222
232
|
Dir.chdir(target_dir) do
|
@@ -268,6 +278,9 @@ module PDK
|
|
268
278
|
#
|
269
279
|
# @return [PathSpec] The populated ignore path matcher.
|
270
280
|
def ignored_files
|
281
|
+
require 'pdk/module'
|
282
|
+
require 'pathspec'
|
283
|
+
|
271
284
|
@ignored_files ||=
|
272
285
|
begin
|
273
286
|
ignored = if ignore_file.nil?
|
data/lib/pdk/module/convert.rb
CHANGED
@@ -1,8 +1,3 @@
|
|
1
|
-
require 'pdk/generate/module'
|
2
|
-
require 'pdk/module/update_manager'
|
3
|
-
require 'pdk/util'
|
4
|
-
require 'pdk/report'
|
5
|
-
|
6
1
|
module PDK
|
7
2
|
module Module
|
8
3
|
class Convert
|
@@ -24,7 +19,14 @@ module PDK
|
|
24
19
|
stage_changes!
|
25
20
|
|
26
21
|
unless update_manager.changes?
|
27
|
-
|
22
|
+
if adding_tests?
|
23
|
+
add_tests!
|
24
|
+
else
|
25
|
+
require 'pdk/report'
|
26
|
+
|
27
|
+
PDK::Report.default_target.puts(_('No changes required.'))
|
28
|
+
end
|
29
|
+
|
28
30
|
return
|
29
31
|
end
|
30
32
|
|
@@ -35,6 +37,8 @@ module PDK
|
|
35
37
|
return if noop?
|
36
38
|
|
37
39
|
unless force?
|
40
|
+
require 'pdk/cli/util'
|
41
|
+
|
38
42
|
PDK.logger.info _(
|
39
43
|
'Module conversion is a potentially destructive action. ' \
|
40
44
|
'Ensure that you have committed your module to a version control ' \
|
@@ -52,7 +56,12 @@ module PDK
|
|
52
56
|
|
53
57
|
update_manager.sync_changes!
|
54
58
|
|
55
|
-
|
59
|
+
if needs_bundle_update?
|
60
|
+
require 'pdk/util/bundler'
|
61
|
+
PDK::Util::Bundler.ensure_bundle!
|
62
|
+
end
|
63
|
+
|
64
|
+
add_tests! if adding_tests?
|
56
65
|
|
57
66
|
print_result 'Convert completed'
|
58
67
|
end
|
@@ -65,11 +74,45 @@ module PDK
|
|
65
74
|
options[:force]
|
66
75
|
end
|
67
76
|
|
77
|
+
def add_tests?
|
78
|
+
options[:'add-tests']
|
79
|
+
end
|
80
|
+
|
81
|
+
def adding_tests?
|
82
|
+
add_tests? && missing_tests?
|
83
|
+
end
|
84
|
+
|
85
|
+
def missing_tests?
|
86
|
+
test_generators.any? { |gen| gen.can_run? }
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_generators
|
90
|
+
return @test_generators unless @test_generators.nil?
|
91
|
+
require 'pdk/util/puppet_strings'
|
92
|
+
|
93
|
+
test_gens = PDK::Util::PuppetStrings.all_objects.map do |generator, objects|
|
94
|
+
(objects || []).map do |obj|
|
95
|
+
generator.new(Dir.pwd, obj['name'], spec_only: true)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
@test_generators = test_gens.flatten
|
100
|
+
end
|
101
|
+
|
102
|
+
def add_tests!
|
103
|
+
test_generators.each do |gen|
|
104
|
+
gen.run if gen.can_run?
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
68
108
|
def needs_bundle_update?
|
69
109
|
update_manager.changed?('Gemfile')
|
70
110
|
end
|
71
111
|
|
72
112
|
def stage_changes!
|
113
|
+
require 'pdk/module/templatedir'
|
114
|
+
require 'pdk/util/filesystem'
|
115
|
+
|
73
116
|
metadata_path = 'metadata.json'
|
74
117
|
|
75
118
|
PDK::Module::TemplateDir.new(template_uri, nil, true) do |templates|
|
@@ -108,14 +151,22 @@ module PDK
|
|
108
151
|
end
|
109
152
|
|
110
153
|
def update_manager
|
154
|
+
require 'pdk/module/update_manager'
|
155
|
+
|
111
156
|
@update_manager ||= PDK::Module::UpdateManager.new
|
112
157
|
end
|
113
158
|
|
114
159
|
def template_uri
|
160
|
+
require 'pdk/util/template_uri'
|
161
|
+
|
115
162
|
@template_uri ||= PDK::Util::TemplateURI.new(options)
|
116
163
|
end
|
117
164
|
|
118
165
|
def update_metadata(metadata_path, template_metadata)
|
166
|
+
require 'pdk/generate/module'
|
167
|
+
require 'pdk/util/filesystem'
|
168
|
+
require 'pdk/module/metadata'
|
169
|
+
|
119
170
|
if PDK::Util::Filesystem.file?(metadata_path)
|
120
171
|
unless PDK::Util::Filesystem.readable?(metadata_path)
|
121
172
|
raise PDK::CLI::ExitWithError, _('Unable to update module metadata; %{path} exists but it is not readable.') % {
|
@@ -172,6 +223,8 @@ module PDK
|
|
172
223
|
end
|
173
224
|
|
174
225
|
def print_summary
|
226
|
+
require 'pdk/report'
|
227
|
+
|
175
228
|
footer = false
|
176
229
|
|
177
230
|
summary.keys.each do |category|
|
@@ -186,12 +239,16 @@ module PDK
|
|
186
239
|
end
|
187
240
|
|
188
241
|
def print_result(banner_text)
|
242
|
+
require 'pdk/report'
|
243
|
+
|
189
244
|
PDK::Report.default_target.puts(_("\n%{banner}") % { banner: generate_banner(banner_text, 40) })
|
190
245
|
summary_to_print = summary.map { |k, v| "#{v.length} files #{k}" unless v.empty? }.compact
|
191
246
|
PDK::Report.default_target.puts(_("\n%{summary}\n\n") % { summary: "#{summary_to_print.join(', ')}." })
|
192
247
|
end
|
193
248
|
|
194
249
|
def full_report(path)
|
250
|
+
require 'pdk/report'
|
251
|
+
|
195
252
|
File.open(path, 'w') do |f|
|
196
253
|
f.write("/* Report generated by PDK at #{Time.now} */")
|
197
254
|
update_manager.changes[:modified].each do |_, diff|
|
data/lib/pdk/module/metadata.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'json'
|
2
1
|
require 'pdk/util/filesystem'
|
3
2
|
|
4
3
|
module PDK
|
@@ -102,6 +101,7 @@ module PDK
|
|
102
101
|
raise ArgumentError, _("Unable to open '%{file}' for reading.") % { file: metadata_json_path }
|
103
102
|
end
|
104
103
|
|
104
|
+
require 'json'
|
105
105
|
begin
|
106
106
|
data = JSON.parse(PDK::Util::Filesystem.read_file(metadata_json_path))
|
107
107
|
rescue JSON::JSONError => e
|
@@ -120,6 +120,8 @@ module PDK
|
|
120
120
|
end
|
121
121
|
|
122
122
|
def to_json
|
123
|
+
require 'json'
|
124
|
+
|
123
125
|
JSON.pretty_generate(@data.dup.delete_if { |_key, value| value.nil? })
|
124
126
|
end
|
125
127
|
|
@@ -132,6 +134,8 @@ module PDK
|
|
132
134
|
end
|
133
135
|
|
134
136
|
def interview_for_forge!
|
137
|
+
require 'pdk/generate/module'
|
138
|
+
|
135
139
|
PDK::Generate::Module.module_interview(self, only_ask: missing_fields)
|
136
140
|
end
|
137
141
|
|
@@ -1,10 +1,3 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
require 'deep_merge'
|
3
|
-
require 'pdk/util'
|
4
|
-
require 'pdk/util/git'
|
5
|
-
require 'pdk/cli/errors'
|
6
|
-
require 'pdk/template_file'
|
7
|
-
|
8
1
|
module PDK
|
9
2
|
module Module
|
10
3
|
class TemplateDir
|
@@ -39,6 +32,10 @@ module PDK
|
|
39
32
|
#
|
40
33
|
# @api public
|
41
34
|
def initialize(uri, module_metadata = {}, init = false)
|
35
|
+
require 'pdk/analytics'
|
36
|
+
require 'pdk/util/template_uri'
|
37
|
+
require 'pdk/util/git'
|
38
|
+
|
42
39
|
unless block_given?
|
43
40
|
raise ArgumentError, _('%{class_name} must be initialized with a block.') % { class_name: self.class.name }
|
44
41
|
end
|
@@ -83,6 +80,7 @@ module PDK
|
|
83
80
|
# If we cloned a git repo to get the template, remove the clone once
|
84
81
|
# we're done with it.
|
85
82
|
if temp_dir_clone
|
83
|
+
require 'fileutils'
|
86
84
|
FileUtils.remove_dir(@path)
|
87
85
|
end
|
88
86
|
end
|
@@ -96,6 +94,8 @@ module PDK
|
|
96
94
|
#
|
97
95
|
# @api public
|
98
96
|
def metadata
|
97
|
+
require 'pdk/util/version'
|
98
|
+
|
99
99
|
{
|
100
100
|
'pdk-version' => PDK::Util::Version.version_string,
|
101
101
|
'template-url' => uri.metadata_format,
|
@@ -117,6 +117,8 @@ module PDK
|
|
117
117
|
#
|
118
118
|
# @api public
|
119
119
|
def render
|
120
|
+
require 'pdk/template_file'
|
121
|
+
|
120
122
|
PDK::Module::TemplateDir.files_in_template(@dirs).each do |template_file, template_loc|
|
121
123
|
template_file = template_file.to_s
|
122
124
|
PDK.logger.debug(_("Rendering '%{template}'...") % { template: template_file })
|
@@ -207,6 +209,8 @@ module PDK
|
|
207
209
|
def validate_module_template!
|
208
210
|
# rubocop:disable Style/GuardClause
|
209
211
|
unless File.directory?(@path)
|
212
|
+
require 'pdk/util'
|
213
|
+
|
210
214
|
if PDK::Util.package_install? && File.fnmatch?(File.join(PDK::Util.package_cachedir, '*'), @path)
|
211
215
|
raise ArgumentError, _('The built-in template has substantially changed. Please run "pdk convert" on your module to continue.')
|
212
216
|
else
|
@@ -260,11 +264,15 @@ module PDK
|
|
260
264
|
#
|
261
265
|
# @api private
|
262
266
|
def config_for(dest_path, sync_config_path = nil)
|
267
|
+
require 'pdk/util'
|
268
|
+
require 'pdk/analytics'
|
269
|
+
|
263
270
|
module_root = PDK::Util.module_root
|
264
271
|
sync_config_path ||= File.join(module_root, '.sync.yml') unless module_root.nil?
|
265
272
|
config_path = File.join(@path, 'config_defaults.yml')
|
266
273
|
|
267
274
|
if @config.nil?
|
275
|
+
require 'deep_merge'
|
268
276
|
conf_defaults = read_config(config_path)
|
269
277
|
@sync_config = read_config(sync_config_path) unless sync_config_path.nil?
|
270
278
|
@config = conf_defaults
|
@@ -302,6 +310,8 @@ module PDK
|
|
302
310
|
# @api private
|
303
311
|
def read_config(loc)
|
304
312
|
if File.file?(loc) && File.readable?(loc)
|
313
|
+
require 'yaml'
|
314
|
+
|
305
315
|
begin
|
306
316
|
YAML.safe_load(File.read(loc), [], [], true)
|
307
317
|
rescue Psych::SyntaxError => e
|
@@ -329,6 +339,9 @@ module PDK
|
|
329
339
|
# @todo When switching this over to using rugged, cache the cloned
|
330
340
|
# template repo in `%AppData%` or `$XDG_CACHE_DIR` and update before
|
331
341
|
# use.
|
342
|
+
require 'pdk/util'
|
343
|
+
require 'pdk/util/git'
|
344
|
+
|
332
345
|
temp_dir = PDK::Util.make_tmpdir_name('pdk-templates')
|
333
346
|
origin_repo = uri.git_remote
|
334
347
|
git_ref = uri.git_ref
|
@@ -348,6 +361,8 @@ module PDK
|
|
348
361
|
|
349
362
|
# @api private
|
350
363
|
def checkout_template_ref(path, ref)
|
364
|
+
require 'pdk/util/git'
|
365
|
+
|
351
366
|
if PDK::Util::Git.work_dir_clean?(path)
|
352
367
|
Dir.chdir(path) do
|
353
368
|
full_ref = PDK::Util::Git.ls_remote(path, ref)
|
@@ -365,6 +380,8 @@ module PDK
|
|
365
380
|
end
|
366
381
|
|
367
382
|
def cache_template_ref(path, ref = nil)
|
383
|
+
require 'pdk/util/git'
|
384
|
+
|
368
385
|
@template_ref ||= PDK::Util::Git.describe(File.join(path, '.git'), ref)
|
369
386
|
end
|
370
387
|
end
|
data/lib/pdk/module/update.rb
CHANGED
@@ -41,7 +41,11 @@ module PDK
|
|
41
41
|
|
42
42
|
update_manager.sync_changes!
|
43
43
|
|
44
|
-
|
44
|
+
if needs_bundle_update?
|
45
|
+
require 'pdk/util/bundler'
|
46
|
+
|
47
|
+
PDK::Util::Bundler.ensure_bundle!
|
48
|
+
end
|
45
49
|
|
46
50
|
print_result 'Update completed'
|
47
51
|
end
|
@@ -1,16 +1,11 @@
|
|
1
|
-
require 'diff/lcs'
|
2
|
-
require 'diff/lcs/hunk'
|
3
|
-
require 'English'
|
4
|
-
require 'fileutils'
|
5
|
-
require 'set'
|
6
|
-
require 'pdk/util/filesystem'
|
7
|
-
|
8
1
|
module PDK
|
9
2
|
module Module
|
10
3
|
class UpdateManager
|
11
4
|
# Initialises a blank UpdateManager object, which is used to store and
|
12
5
|
# process file additions/removals/modifications.
|
13
6
|
def initialize
|
7
|
+
require 'set'
|
8
|
+
|
14
9
|
@modified_files = Set.new
|
15
10
|
@added_files = Set.new
|
16
11
|
@removed_files = Set.new
|
@@ -45,11 +40,13 @@ module PDK
|
|
45
40
|
# @raise (see #calculate_diffs)
|
46
41
|
# @return [Hash{Symbol => Set,Hash}] the summary of the pending changes.
|
47
42
|
def changes
|
43
|
+
require 'pdk/util/filesystem'
|
44
|
+
|
48
45
|
calculate_diffs
|
49
46
|
|
50
47
|
{
|
51
48
|
added: @added_files,
|
52
|
-
removed: @removed_files.select { |f|
|
49
|
+
removed: @removed_files.select { |f| PDK::Util::Filesystem.exist?(f) },
|
53
50
|
modified: @diff_cache.reject { |_, value| value.nil? },
|
54
51
|
}
|
55
52
|
end
|
@@ -106,9 +103,11 @@ module PDK
|
|
106
103
|
#
|
107
104
|
# @raise [PDK::CLI::ExitWithError] if the file could not be removed.
|
108
105
|
def unlink_file(path)
|
109
|
-
|
106
|
+
require 'pdk/util/filesystem'
|
107
|
+
|
108
|
+
if PDK::Util::Filesystem.file?(path)
|
110
109
|
PDK.logger.debug(_("unlinking '%{path}'") % { path: path })
|
111
|
-
|
110
|
+
PDK::Util::Filesystem.rm(path)
|
112
111
|
else
|
113
112
|
PDK.logger.debug(_("'%{path}': already gone") % { path: path })
|
114
113
|
end
|
@@ -127,14 +126,16 @@ module PDK
|
|
127
126
|
# @raise [PDK::CLI::ExitWithError] if a file being modified isn't
|
128
127
|
# readable.
|
129
128
|
def calculate_diffs
|
129
|
+
require 'pdk/util/filesystem'
|
130
|
+
|
130
131
|
@modified_files.each do |file|
|
131
132
|
next if @diff_cache.key?(file[:path])
|
132
133
|
|
133
|
-
unless
|
134
|
+
unless PDK::Util::Filesystem.readable?(file[:path])
|
134
135
|
raise PDK::CLI::ExitWithError, _("Unable to open '%{path}' for reading") % { path: file[:path] }
|
135
136
|
end
|
136
137
|
|
137
|
-
old_content =
|
138
|
+
old_content = PDK::Util::Filesystem.read_file(file[:path])
|
138
139
|
file_diff = unified_diff(file[:path], old_content, file[:content])
|
139
140
|
@diff_cache[file[:path]] = file_diff
|
140
141
|
end
|
@@ -147,7 +148,9 @@ module PDK
|
|
147
148
|
#
|
148
149
|
# @raise [PDK::CLI::ExitWithError] if the file is not writeable.
|
149
150
|
def write_file(path, content)
|
150
|
-
|
151
|
+
require 'pdk/util/filesystem'
|
152
|
+
|
153
|
+
PDK::Util::Filesystem.mkdir_p(File.dirname(path))
|
151
154
|
PDK.logger.debug(_("writing '%{path}'") % { path: path })
|
152
155
|
PDK::Util::Filesystem.write_file(path, content)
|
153
156
|
rescue Errno::EACCES
|
@@ -167,6 +170,9 @@ module PDK
|
|
167
170
|
#
|
168
171
|
# @return [String] The unified diff of the pending changes to the file.
|
169
172
|
def unified_diff(path, old_content, new_content, lines_of_context = 3)
|
173
|
+
require 'diff/lcs'
|
174
|
+
require 'English'
|
175
|
+
|
170
176
|
output = []
|
171
177
|
|
172
178
|
old_lines = old_content.split($INPUT_RECORD_SEPARATOR).map(&:chomp)
|
@@ -176,6 +182,8 @@ module PDK
|
|
176
182
|
|
177
183
|
return if diffs.empty?
|
178
184
|
|
185
|
+
require 'diff/lcs/hunk'
|
186
|
+
|
179
187
|
file_mtime = File.stat(path).mtime.localtime.strftime('%Y-%m-%d %H:%M:%S.%N %z')
|
180
188
|
now = Time.now.localtime.strftime('%Y-%m-%d %H:%M:%S.%N %z')
|
181
189
|
|