nanoc-webpack.rb 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +7 -8
- data/lib/nanoc/webpack/filter.rb +52 -67
- data/lib/nanoc/webpack/spawn.rb +19 -0
- data/lib/nanoc/webpack/version.rb +1 -1
- data/lib/nanoc/webpack.rb +4 -4
- data/spec/filter_spec.rb +5 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18e7707c0d80e1bb53739670f0a914aadb99117e3888847c7994c02467916401
|
4
|
+
data.tar.gz: 2fab4baa367a41c9e3c12fe076ca1b494504871ac70f775d540d8dc529378969
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 446b7975cad4fc591237fc5189fae9ac46e65a3544047227cf7e2fdf4130df7ff10251a506cf65519ca76a06e832ce66042f4d45bf629ee8237a601d3fe2ef08
|
7
|
+
data.tar.gz: f97f315d4a5d8fcc788fc88d41730ec2e1704b6a36304edb48128f196a12aaf066734fc9e1e9991ebd673dc92d1238b0f8b022364738791cb3605e88da0a3b65
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -5,7 +5,7 @@ nanoc-webpack.rb is a
|
|
5
5
|
filter that integrates
|
6
6
|
[webpack](https://webpack.js.org/)
|
7
7
|
into nanoc. <br>
|
8
|
-
The filter acts as a
|
8
|
+
The filter acts as a bridge that connects nanoc,
|
9
9
|
and the JavaScript, TypeScript, and nodejs ecosystems.
|
10
10
|
|
11
11
|
## Examples
|
@@ -56,19 +56,18 @@ compile "/js/main/App.tsx" do
|
|
56
56
|
end
|
57
57
|
```
|
58
58
|
|
59
|
-
**Option:
|
59
|
+
**Option: argv**
|
60
60
|
|
61
|
-
The `
|
61
|
+
The `argv` option forwards command-line options directly
|
62
62
|
to the webpack executable. <br>
|
63
|
-
[Nanoc::Webpack.
|
64
|
-
returns the default options
|
65
|
-
forward to webpack:
|
63
|
+
[Nanoc::Webpack.default_argv](https://0x1eef.github.io/x/nanoc-webpack.rb/Nanoc/Webpack.html#default_argv-class_method)
|
64
|
+
returns the default command-line options forwarded to webpack:
|
66
65
|
|
67
66
|
```ruby
|
68
67
|
# Rules
|
69
68
|
require "nanoc-webpack"
|
70
69
|
compile "/js/main/App.tsx" do
|
71
|
-
filter(:webpack,
|
70
|
+
filter(:webpack, argv: ["--node-env", "production"])
|
72
71
|
write("/js/main/app.js")
|
73
72
|
end
|
74
73
|
```
|
@@ -77,7 +76,7 @@ end
|
|
77
76
|
|
78
77
|
**Rubygems.org**
|
79
78
|
|
80
|
-
nanoc-webpack.rb can
|
79
|
+
nanoc-webpack.rb can be installed via rubygems.org.
|
81
80
|
|
82
81
|
gem install nanoc-webpack.rb
|
83
82
|
|
data/lib/nanoc/webpack/filter.rb
CHANGED
@@ -2,81 +2,66 @@
|
|
2
2
|
|
3
3
|
##
|
4
4
|
# Compiles a nanoc item with webpack.
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
module Nanoc::Webpack
|
6
|
+
class Filter < Nanoc::Filter
|
7
|
+
require_relative "filter/dependable"
|
8
|
+
require_relative "spawn"
|
9
|
+
include Dependable
|
10
|
+
include Spawn
|
11
|
+
include FileUtils
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
+
identifier :webpack
|
14
|
+
type :text
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
@default_options ||= {"--cache-type" => "filesystem"}
|
24
|
-
end
|
16
|
+
##
|
17
|
+
# @example
|
18
|
+
# Nanoc::Webpack.default_argv.replace ["--cache-type", "memory"]
|
19
|
+
#
|
20
|
+
# @return [Hash]
|
21
|
+
# The default command-line options forwarded to webpack.
|
22
|
+
def self.default_argv
|
23
|
+
@default_argv ||= ["--cache-type", "filesystem"]
|
24
|
+
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
26
|
+
##
|
27
|
+
# @param [String] content
|
28
|
+
# The contents of a file.
|
29
|
+
#
|
30
|
+
# @param [Hash] options
|
31
|
+
# A hash of options.
|
32
|
+
#
|
33
|
+
# @return [void]
|
34
|
+
def run(content, options = {})
|
35
|
+
options = Ryo.from(options)
|
36
|
+
path = temporary_file(content).path
|
37
|
+
depend_on dependable(paths: options.depend_on, reject: options.reject)
|
38
|
+
.map { items[_1] }
|
39
|
+
spawn "node",
|
40
|
+
["./node_modules/webpack/bin/webpack.js",
|
41
|
+
"--entry", File.join(Dir.getwd, item.attributes[:content_filename]),
|
42
|
+
"--output-path", File.dirname(path),
|
43
|
+
"--output-filename", File.basename(path),
|
44
|
+
*default_argv, *(options.argv || [])],
|
45
|
+
log: File.join(tmpdir, "webpack.log")
|
46
|
+
ensure
|
47
|
+
rm(path)
|
48
|
+
end
|
41
49
|
|
42
|
-
|
50
|
+
private
|
43
51
|
|
44
|
-
|
45
|
-
|
46
|
-
"./node_modules/webpack/bin/webpack.js",
|
47
|
-
"--entry", File.join(Dir.getwd, item.attributes[:content_filename]),
|
48
|
-
"--output-path", File.dirname(file.path),
|
49
|
-
"--output-filename", File.basename(file.path),
|
50
|
-
*webpack_args(cli)
|
51
|
-
if $?.success?
|
52
|
-
File.read(file.path).tap { file.tap(&:unlink).close }
|
53
|
-
else
|
54
|
-
rm_f Dir.glob(File.join(File.dirname(file.path), "*"))
|
55
|
-
file.close
|
56
|
-
raise Error, "webpack.js exited unsuccessfully (exit code: #{$?.exitstatus})", []
|
52
|
+
def default_argv
|
53
|
+
self.class.default_argv
|
57
54
|
end
|
58
|
-
end
|
59
55
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
ary.concat [key, value.to_s]
|
66
|
-
end
|
56
|
+
def temporary_file(content)
|
57
|
+
mkdir_p(tmpdir)
|
58
|
+
file = Tempfile.new(File.basename(item.identifier.to_s), tmpdir)
|
59
|
+
file.write(content)
|
60
|
+
file.tap(&:flush)
|
67
61
|
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def temporary_file(content)
|
71
|
-
dir = File.join(Dir.getwd, "tmp", "nanoc-webpack.rb")
|
72
|
-
mkdir_p(dir) unless Dir.exist?(dir)
|
73
|
-
file = Tempfile.new(File.basename(@item.identifier.to_s), dir)
|
74
|
-
file.write(content)
|
75
|
-
file.tap(&:flush)
|
76
|
-
end
|
77
62
|
|
78
|
-
|
79
|
-
|
80
|
-
|
63
|
+
def tmpdir
|
64
|
+
File.join(Dir.getwd, "tmp", "webpack")
|
65
|
+
end
|
81
66
|
end
|
82
67
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Nanoc::Webpack
|
2
|
+
module Spawn
|
3
|
+
Error = Class.new(RuntimeError)
|
4
|
+
def spawn(exe, argv, log:)
|
5
|
+
Kernel.spawn(
|
6
|
+
exe, *argv, { STDOUT => log, STDERR => log }
|
7
|
+
)
|
8
|
+
Process.wait
|
9
|
+
unless $?.success?
|
10
|
+
raise Error,
|
11
|
+
"#{File.basename(exe)} exited unsuccessfully " \
|
12
|
+
"(exit code: #{$?.exitstatus}, " \
|
13
|
+
"item: #{item.identifier}, " \
|
14
|
+
"log: #{log.gsub(Dir.getwd, '')[1..]})",
|
15
|
+
[]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/nanoc/webpack.rb
CHANGED
@@ -5,9 +5,9 @@ module Nanoc::Webpack
|
|
5
5
|
require "ryo"
|
6
6
|
require_relative "webpack/filter"
|
7
7
|
##
|
8
|
-
# @example (see Nanoc::Webpack::Filter.
|
9
|
-
# @return (see Nanoc::Webpack::Filter.
|
10
|
-
def self.
|
11
|
-
Nanoc::Webpack::Filter.
|
8
|
+
# @example (see Nanoc::Webpack::Filter.default_argv)
|
9
|
+
# @return (see Nanoc::Webpack::Filter.default_argv)
|
10
|
+
def self.default_argv
|
11
|
+
Nanoc::Webpack::Filter.default_argv
|
12
12
|
end
|
13
13
|
end
|
data/spec/filter_spec.rb
CHANGED
@@ -136,7 +136,8 @@ RSpec.describe Nanoc::Webpack::Filter do
|
|
136
136
|
|
137
137
|
context "with default arguments" do
|
138
138
|
it "executes nodejs" do
|
139
|
-
expect(
|
139
|
+
expect(Kernel).to receive(:spawn).with(*cmdline, instance_of(Hash))
|
140
|
+
expect(Process).to receive(:wait)
|
140
141
|
filter.run(item)
|
141
142
|
end
|
142
143
|
end
|
@@ -145,8 +146,9 @@ RSpec.describe Nanoc::Webpack::Filter do
|
|
145
146
|
let(:cmdline) { super().concat(["--no-cache"]) }
|
146
147
|
|
147
148
|
it "executes nodejs with an argument" do
|
148
|
-
expect(
|
149
|
-
|
149
|
+
expect(Kernel).to receive(:spawn).with(*cmdline, instance_of(Hash))
|
150
|
+
expect(Process).to receive(:wait)
|
151
|
+
filter.run(item, argv: ["--no-cache"])
|
150
152
|
end
|
151
153
|
end
|
152
154
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nanoc-webpack.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- '0x1eef'
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ryo.rb
|
@@ -114,6 +114,7 @@ files:
|
|
114
114
|
- lib/nanoc/webpack.rb
|
115
115
|
- lib/nanoc/webpack/filter.rb
|
116
116
|
- lib/nanoc/webpack/filter/dependable.rb
|
117
|
+
- lib/nanoc/webpack/spawn.rb
|
117
118
|
- lib/nanoc/webpack/version.rb
|
118
119
|
- nanoc-webpack.rb.gemspec
|
119
120
|
- spec/filter_spec.rb
|