nanoc-webpack.rb 0.5.6 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22ee6ae13d75181d02e95948c6f00446a7f92effe96fcc87c8e017f95c707a3e
4
- data.tar.gz: bccc782d822fe1b6f843204a45b6eff75f677979bc7f4c68c853a71351f649ce
3
+ metadata.gz: 6089712cbc312cd503ad06f0a1d54e27351901f86b870460f1c6d3c205566d4c
4
+ data.tar.gz: 8c932b943c81803365dcd2e9a7c46b5cfec2790fb05964c73b60e557fcf1461a
5
5
  SHA512:
6
- metadata.gz: 6dc66a6c40e1cadcdd50de9acd480ec69d80364bcd1b61e31345fdf4ab817fa7bb51c31fdd0790971b6915cbcce80c372b600b932cb450fac4caf947aa113579
7
- data.tar.gz: 6509714bfa75b8d55b7030736a94f8ea66226bd7a86ceecc958c1749d08abc58618940a4cb1c009924bc76a172dedab0ccb6956facfb9e77145c222c6de73211
6
+ metadata.gz: 9b9f6f1cc40ada346daac98c1b401dc613c327e41c5bf48b1bf4c6ecad8b50c267b3a46164336e677dd8c28415f2c7262b28cab9ff4ea897c7f6a96491cc3c2a
7
+ data.tar.gz: 62595779fdff296640fa1ddd0030ab3d97e580378f0129c5a5d9260fe13b92e9a08a006316c8ad5de420133557d7f9542a776f7d2c909c2e37642d1c788a8996
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-powered websites. The filter provides a bridge that
9
- connects nanoc, and the JavaScript, TypeScript, and nodejs ecosystems.
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
- ### Defaults
13
+ **Defaults**
14
14
 
15
- #### /js/main/App.tsx
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
- ### Options
32
-
33
- #### Option: "depend_on"
27
+ **Option: depend_on**
34
28
 
35
- The `depend_on` option tells nanoc what files an entry point imports or requires.
36
- When a file being tracked by the `depend_on` option undergoes a change, nanoc
37
- will initiate a recompilation of the entry point:
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
- #### Option: "reject"
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,40 @@ 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
- #### Option: "args"
59
+ **Option: cli**
66
60
 
67
- The `args` option can be used to forward command-line options directly
68
- to the webpack executable.
69
- <br>
70
- `$ webpack build --help verbose` provides a list of all available options,
71
- and
61
+ The `cli` option forwards command-line options directly
62
+ to the webpack executable. <br>
72
63
  [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:
64
+ returns the default options nanoc-webpack.rb will
65
+ forward to webpack:
74
66
 
75
67
  ```ruby
76
68
  # Rules
77
69
  require "nanoc-webpack"
78
70
  compile "/js/main/App.tsx" do
79
- filter :webpack, args: {"--no-stats" => true}
80
- write("/js/app.js")
71
+ filter(:webpack, cli: {"--no-stats" => true})
72
+ write("/js/main/app.js")
81
73
  end
82
74
  ```
83
75
 
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
76
  ## <a id='install'>Install</a>
98
77
 
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
78
  **Rubygems.org**
113
79
 
114
80
  nanoc-webpack.rb can also be installed via rubygems.org.
115
81
 
116
82
  gem install nanoc-webpack.rb
117
83
 
84
+ ## Sources
85
+
86
+ * [GitHub](https://github.com/0x1eef/nanoc-webpack.rb#readme)
87
+ * [GitLab](https://gitlab.com/0x1eef/nanoc-webpack.rb#about)
88
+
118
89
  ## License
119
90
 
120
91
  [BSD Zero Clause](https://choosealicense.com/licenses/0bsd/).
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  ##
4
- # Compiles a textual nanoc item with webpack.
4
+ # Compiles a nanoc item with webpack.
5
5
  class Nanoc::Webpack::Filter < Nanoc::Filter
6
6
  require_relative "filter/dependable"
7
- Error = Class.new(RuntimeError)
8
7
  include FileUtils
9
8
  include Dependable
9
+ Error = Class.new(RuntimeError)
10
10
 
11
11
  identifier :webpack
12
12
  type :text
@@ -18,28 +18,36 @@ class Nanoc::Webpack::Filter < Nanoc::Filter
18
18
  # )
19
19
  #
20
20
  # @return [Hash]
21
- # Returns the default command-line options given to webpack.
21
+ # Returns the default command-line options forwarded to webpack.
22
22
  def self.default_options
23
23
  @default_options ||= {"--cache-type" => "filesystem"}
24
24
  end
25
25
 
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]
26
34
  def run(content, options = {})
27
- args = options[:args] || options["args"] || {}
28
- depend_on dependable(paths: options[:depend_on], reject: options[:reject])
35
+ options = Ryo.from(options)
36
+ depend_on dependable(paths: options.depend_on, reject: options.reject)
29
37
  .map { items[_1] }
30
- webpack temporary_file_for(content),
31
- args: self.class.default_options.merge(args)
38
+ webpack temporary_file(content),
39
+ cli: self.class.default_options.merge(options.cli || {})
32
40
  end
33
41
 
34
42
  private
35
43
 
36
- def webpack(file, args: {})
44
+ def webpack(file, cli:)
37
45
  sh "node",
38
46
  "./node_modules/webpack/bin/webpack.js",
39
47
  "--entry", File.join(Dir.getwd, item.attributes[:content_filename]),
40
48
  "--output-path", File.dirname(file.path),
41
49
  "--output-filename", File.basename(file.path),
42
- *webpack_args(args)
50
+ *webpack_args(cli)
43
51
  if $?.success?
44
52
  File.read(file.path).tap { file.tap(&:unlink).close }
45
53
  else
@@ -59,7 +67,7 @@ class Nanoc::Webpack::Filter < Nanoc::Filter
59
67
  end
60
68
  end
61
69
 
62
- def temporary_file_for(content)
70
+ def temporary_file(content)
63
71
  dir = File.join(Dir.getwd, "tmp", "nanoc-webpack.rb")
64
72
  mkdir_p(dir) unless Dir.exist?(dir)
65
73
  file = Tempfile.new(File.basename(@item.identifier.to_s), dir)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Nanoc
4
4
  module Webpack
5
- VERSION = "0.5.6"
5
+ VERSION = "0.7.0"
6
6
  end
7
7
  end
@@ -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.4"
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
@@ -146,7 +146,7 @@ RSpec.describe Nanoc::Webpack::Filter do
146
146
 
147
147
  it "executes nodejs with an argument" do
148
148
  expect(filter).to receive(:system).with(*cmdline)
149
- filter.run(item, args: {"--no-cache" => true})
149
+ filter.run(item, cli: {"--no-cache" => true})
150
150
  end
151
151
  end
152
152
  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.5.6
4
+ version: 0.7.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-02-09 00:00:00.000000000 Z
11
+ date: 2024-03-25 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.4'
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.4'
26
+ version: '0.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: yard
29
29
  requirement: !ruby/object:Gem::Requirement