nanoc-webpack.rb 0.5.6 → 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 +28 -58
- data/lib/nanoc/webpack/filter.rb +53 -60
- data/lib/nanoc/webpack/spawn.rb +19 -0
- data/lib/nanoc/webpack/version.rb +1 -1
- data/lib/nanoc/webpack.rb +4 -4
- data/nanoc-webpack.rb.gemspec +1 -1
- data/spec/filter_spec.rb +5 -3
- metadata +5 -4
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
@@ -2,50 +2,44 @@
|
|
2
2
|
|
3
3
|
nanoc-webpack.rb is a
|
4
4
|
[nanoc](https://nanoc.app)
|
5
|
-
filter
|
6
|
-
that integrates
|
5
|
+
filter that integrates
|
7
6
|
[webpack](https://webpack.js.org/)
|
8
|
-
into nanoc
|
9
|
-
|
7
|
+
into nanoc. <br>
|
8
|
+
The filter acts as a bridge that connects nanoc,
|
9
|
+
and the JavaScript, TypeScript, and nodejs ecosystems.
|
10
10
|
|
11
11
|
## Examples
|
12
12
|
|
13
|
-
|
13
|
+
**Defaults**
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
The following example forwards the entry point `/js/main/App.tsx` to webpack,
|
18
|
-
and then writes the result to `/js/app.js`. This example and all the other
|
19
|
-
examples assume that the files `webpack.config.js`, `tsconfig.json`, and
|
20
|
-
`package.json` already exist at the root of the project:
|
15
|
+
The following example forwards the entry point `/js/main/App.tsx`
|
16
|
+
to webpack. <br> The result is then written to `/js/main/app.js`:
|
21
17
|
|
22
18
|
``` ruby
|
23
19
|
# Rules
|
24
20
|
require "nanoc-webpack"
|
25
21
|
compile "/js/main/App.tsx" do
|
26
22
|
filter(:webpack)
|
27
|
-
write("/js/app.js")
|
23
|
+
write("/js/main/app.js")
|
28
24
|
end
|
29
25
|
```
|
30
26
|
|
31
|
-
|
32
|
-
|
33
|
-
#### Option: "depend_on"
|
27
|
+
**Option: depend_on**
|
34
28
|
|
35
|
-
|
36
|
-
|
37
|
-
|
29
|
+
When a file or directory tracked by the `depend_on` option
|
30
|
+
is observed to have changed, nanoc will initiate a recompilation
|
31
|
+
of the entry point:
|
38
32
|
|
39
33
|
```ruby
|
40
34
|
# Rules
|
41
35
|
require "nanoc-webpack"
|
42
36
|
compile "/js/main/App.tsx" do
|
43
37
|
filter(:webpack, depend_on: ["/js/lib", "/js/components", "/js/hooks"])
|
44
|
-
write("/js/app.js")
|
38
|
+
write("/js/main/app.js")
|
45
39
|
end
|
46
40
|
```
|
47
41
|
|
48
|
-
|
42
|
+
**Option: reject**
|
49
43
|
|
50
44
|
The `depend_on` option can be combined with the `reject` option to exclude
|
51
45
|
certain files or directories from being tracked. For example, maybe you want
|
@@ -58,63 +52,39 @@ compile "/js/main/App.tsx" do
|
|
58
52
|
filter :webpack,
|
59
53
|
depend_on: ["/js/lib", "/js/components", "/js/hooks"],
|
60
54
|
reject: proc { |path| path.start_with?("/js/lib/foo/") }
|
61
|
-
write("/js/app.js")
|
55
|
+
write("/js/main/app.js")
|
62
56
|
end
|
63
57
|
```
|
64
58
|
|
65
|
-
|
59
|
+
**Option: argv**
|
66
60
|
|
67
|
-
The `
|
68
|
-
to the webpack executable.
|
69
|
-
|
70
|
-
|
71
|
-
and
|
72
|
-
[Nanoc::Webpack.default_options](https://0x1eef.github.io/x/nanoc-webpack.rb/Nanoc/Webpack.html#default_options-class_method)
|
73
|
-
returns the default options nanoc-webpack.rb will forward to webpack:
|
61
|
+
The `argv` option forwards command-line options directly
|
62
|
+
to the webpack executable. <br>
|
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:
|
74
65
|
|
75
66
|
```ruby
|
76
67
|
# Rules
|
77
68
|
require "nanoc-webpack"
|
78
69
|
compile "/js/main/App.tsx" do
|
79
|
-
filter
|
80
|
-
write("/js/app.js")
|
70
|
+
filter(:webpack, argv: ["--node-env", "production"])
|
71
|
+
write("/js/main/app.js")
|
81
72
|
end
|
82
73
|
```
|
83
74
|
|
84
|
-
|
85
|
-
## Requirements
|
86
|
-
|
87
|
-
nanoc-webpack.rb assumes that:
|
88
|
-
|
89
|
-
* A "node" executable is available in $PATH.
|
90
|
-
* "webpack" / "webpack-cli" exist as dependencies in package.json.
|
91
|
-
|
92
|
-
## Sources
|
93
|
-
|
94
|
-
* [Source code (GitHub)](https://github.com/0x1eef/nanoc-webpack.rb)
|
95
|
-
* [Source code (GitLab)](https://gitlab.com/0x1eef/nanoc-webpack.rb)
|
96
|
-
|
97
75
|
## <a id='install'>Install</a>
|
98
76
|
|
99
|
-
**Git**
|
100
|
-
|
101
|
-
nanoc-webpack.rb is distributed as a RubyGem through its git repositories. <br>
|
102
|
-
[GitHub](https://github.com/0x1eef/nanoc-webpack.rb),
|
103
|
-
and
|
104
|
-
[GitLab](https://gitlab.com/0x1eef/nanoc-webpack.rb)
|
105
|
-
are available as sources.
|
106
|
-
|
107
|
-
```ruby
|
108
|
-
# Gemfile
|
109
|
-
gem "nanoc-webpack.rb", github: "0x1eef/nanoc-webpack.rb", tag: "v0.5.6"
|
110
|
-
```
|
111
|
-
|
112
77
|
**Rubygems.org**
|
113
78
|
|
114
|
-
nanoc-webpack.rb can
|
79
|
+
nanoc-webpack.rb can be installed via rubygems.org.
|
115
80
|
|
116
81
|
gem install nanoc-webpack.rb
|
117
82
|
|
83
|
+
## Sources
|
84
|
+
|
85
|
+
* [GitHub](https://github.com/0x1eef/nanoc-webpack.rb#readme)
|
86
|
+
* [GitLab](https://gitlab.com/0x1eef/nanoc-webpack.rb#about)
|
87
|
+
|
118
88
|
## License
|
119
89
|
|
120
90
|
[BSD Zero Clause](https://choosealicense.com/licenses/0bsd/).
|
data/lib/nanoc/webpack/filter.rb
CHANGED
@@ -1,74 +1,67 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
##
|
4
|
-
# Compiles a
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
# Compiles a nanoc item with webpack.
|
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
|
-
|
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
|
33
49
|
|
34
|
-
|
50
|
+
private
|
35
51
|
|
36
|
-
|
37
|
-
|
38
|
-
"./node_modules/webpack/bin/webpack.js",
|
39
|
-
"--entry", File.join(Dir.getwd, item.attributes[:content_filename]),
|
40
|
-
"--output-path", File.dirname(file.path),
|
41
|
-
"--output-filename", File.basename(file.path),
|
42
|
-
*webpack_args(args)
|
43
|
-
if $?.success?
|
44
|
-
File.read(file.path).tap { file.tap(&:unlink).close }
|
45
|
-
else
|
46
|
-
rm_f Dir.glob(File.join(File.dirname(file.path), "*"))
|
47
|
-
file.close
|
48
|
-
raise Error, "webpack.js exited unsuccessfully (exit code: #{$?.exitstatus})", []
|
52
|
+
def default_argv
|
53
|
+
self.class.default_argv
|
49
54
|
end
|
50
|
-
end
|
51
55
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
ary.concat [key, value.to_s]
|
58
|
-
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)
|
59
61
|
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def temporary_file_for(content)
|
63
|
-
dir = File.join(Dir.getwd, "tmp", "nanoc-webpack.rb")
|
64
|
-
mkdir_p(dir) unless Dir.exist?(dir)
|
65
|
-
file = Tempfile.new(File.basename(@item.identifier.to_s), dir)
|
66
|
-
file.write(content)
|
67
|
-
file.tap(&:flush)
|
68
|
-
end
|
69
62
|
|
70
|
-
|
71
|
-
|
72
|
-
|
63
|
+
def tmpdir
|
64
|
+
File.join(Dir.getwd, "tmp", "webpack")
|
65
|
+
end
|
73
66
|
end
|
74
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/nanoc-webpack.rb.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.require_paths = ["lib"]
|
13
13
|
gem.summary = "nanoc-webpack.rb integrates webpack into nanoc."
|
14
14
|
gem.description = gem.summary
|
15
|
-
gem.add_runtime_dependency "ryo.rb", "~> 0.
|
15
|
+
gem.add_runtime_dependency "ryo.rb", "~> 0.5"
|
16
16
|
gem.add_development_dependency "yard", "~> 0.9"
|
17
17
|
gem.add_development_dependency "redcarpet", "~> 3.5"
|
18
18
|
gem.add_development_dependency "rspec", "~> 3.10"
|
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-
|
11
|
+
date: 2024-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ryo.rb
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: yard
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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
|