nanoc-tidy.rb 0.5.5 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nanoc/tidy/filter.rb +2 -1
- data/lib/nanoc/tidy/spawn.rb +31 -5
- data/lib/nanoc/tidy/version.rb +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: f2a117a2fa83b551326ed6ba05761c1744f182144b2980cd8246757853c67ecc
|
4
|
+
data.tar.gz: 362656c6f68fe0791665ecffaa9606cebeb2950eabe08db6f98f3fe8c1f32d84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c19227fa2c5b0386bfeb148b6ecbc664d42847dc1267370228e68139318749ad53c3ec0b6429f175eb77c04540caa388510ecb4920c50e6846c82c40921389d
|
7
|
+
data.tar.gz: aa0327d39187dee54a4cc3dd356345b2ebaafd4167e46a83698b275c2e0eaffb4cb6d406dba49ec07490a89f6bc7c6b7c76a63a3609b7762a5f351f76f8bcdb3
|
data/lib/nanoc/tidy/filter.rb
CHANGED
@@ -26,7 +26,8 @@ module Nanoc::Tidy
|
|
26
26
|
path = temporary_file(content).path
|
27
27
|
spawn tidy,
|
28
28
|
[*default_argv, *(options[:argv] || []), "-modify", path],
|
29
|
-
|
29
|
+
err: File.join(tmpdir, "stderr"),
|
30
|
+
out: File.join(tmpdir, "stdout")
|
30
31
|
File.read(path).tap { rm(path) }
|
31
32
|
end
|
32
33
|
|
data/lib/nanoc/tidy/spawn.rb
CHANGED
@@ -1,9 +1,31 @@
|
|
1
1
|
module Nanoc::Tidy
|
2
2
|
module Spawn
|
3
|
+
require "securerandom"
|
4
|
+
require "fileutils"
|
3
5
|
Error = Class.new(RuntimeError)
|
4
|
-
|
6
|
+
|
7
|
+
##
|
8
|
+
# Spawns a process
|
9
|
+
#
|
10
|
+
# @param [String] exe
|
11
|
+
# The path to an executable
|
12
|
+
#
|
13
|
+
# @param [Array<String>] argv
|
14
|
+
# An array of command line arguments
|
15
|
+
#
|
16
|
+
# @param [String] err
|
17
|
+
# A path where stderr is redirected to
|
18
|
+
#
|
19
|
+
# @param [String] out
|
20
|
+
# A path where stdout is redirected to
|
21
|
+
#
|
22
|
+
# @return [void]
|
23
|
+
def spawn(exe, argv, err:, out:)
|
24
|
+
hex = SecureRandom.hex
|
25
|
+
err = "#{err}-ID#{hex}"
|
26
|
+
out = "#{out}-ID#{hex}"
|
5
27
|
Kernel.spawn(
|
6
|
-
exe, *argv, {
|
28
|
+
exe, *argv, { STDERR => err, STDOUT => out }
|
7
29
|
)
|
8
30
|
Process.wait
|
9
31
|
status = $?
|
@@ -14,15 +36,19 @@ module Nanoc::Tidy
|
|
14
36
|
# * 2: has errors
|
15
37
|
return if [0, 1].include?(status.exitstatus)
|
16
38
|
|
39
|
+
msgs = [err, out].map do
|
40
|
+
FileUtils.touch(_1)
|
41
|
+
[_1.gsub(Dir.getwd, ''), ":", File.binread(_1)].join
|
42
|
+
ensure
|
43
|
+
FileUtils.rm(_1)
|
44
|
+
end.join("\n")
|
17
45
|
raise Error,
|
18
46
|
"#{File.basename(exe)} exited unsuccessfully " \
|
19
47
|
"(" \
|
20
48
|
"exit code: #{status.exitstatus}, " \
|
21
49
|
"item: #{item.identifier}" \
|
22
50
|
")" \
|
23
|
-
"\n"
|
24
|
-
"#{log.gsub(Dir.getwd, '')[1..]}:" \
|
25
|
-
"#{File.binread(log)}" \
|
51
|
+
"\n#{msgs}",
|
26
52
|
[]
|
27
53
|
end
|
28
54
|
end
|
data/lib/nanoc/tidy/version.rb
CHANGED