webpack_driver 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/README.md +8 -7
- data/lib/status-plugin.js +78 -0
- data/lib/webpack_driver/compile.rb +3 -2
- data/lib/webpack_driver/configuration/{base.rb → example.rb} +11 -9
- data/lib/webpack_driver/configuration/generated.rb +22 -0
- data/lib/webpack_driver/configuration.rb +51 -6
- data/lib/webpack_driver/dev_server.rb +3 -21
- data/lib/webpack_driver/process.rb +37 -15
- data/lib/webpack_driver/version.rb +1 -1
- data/lib/webpack_driver.rb +0 -14
- data/templates/generated.config.js.tt +10 -0
- metadata +7 -5
- data/lib/webpack_driver/config_options.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f323c56cf0e293177fec824035df08310a3ee7c
|
4
|
+
data.tar.gz: d4c5a165ca89887ee598ff1d7cf30fe299e7c94b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b08b2724c2db81e8c84a88d8389951be28d6dfb7b60e090a40ec70339a813f9070f3495cc2ace7827ffcfa643c924c82deaeaad4340a22490795115089d7a54
|
7
|
+
data.tar.gz: fe31afa752611b232bf55b1ea5cbd49cc8ec1a1703ac60e0a409b50c6b9b1600cb2b6858182d1619f998f7b2a8d1e7169e30f5daad32eab079d9bf2596178d3d
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -13,7 +13,7 @@ It runs the dev server in the background using the `childprocess` gem and monito
|
|
13
13
|
Add this line to your application's Gemfile:
|
14
14
|
|
15
15
|
```ruby
|
16
|
-
gem '
|
16
|
+
gem 'webpack_driver'
|
17
17
|
```
|
18
18
|
|
19
19
|
And then execute:
|
@@ -22,17 +22,18 @@ And then execute:
|
|
22
22
|
|
23
23
|
Or install it yourself as:
|
24
24
|
|
25
|
-
$ gem install
|
25
|
+
$ gem install webpack_driver
|
26
26
|
|
27
27
|
## Usage
|
28
28
|
|
29
|
-
Initialization
|
29
|
+
Initialization will create a `package.json`, `yarn.lock`, a bare-bones `webpack.config.js` and then run yarn install (via the [Knitter](https://github.com/nathanstitt/knitter) gem).
|
30
30
|
|
31
31
|
```ruby
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
|
33
|
+
config = WebpackDriver::Configuration.new(
|
34
|
+
WebpackDriver::Configuration.new('/path/to/my/webpack.config.js')
|
35
|
+
)
|
36
|
+
config.generate!
|
36
37
|
```
|
37
38
|
|
38
39
|
Production compilation (TODO):
|
@@ -0,0 +1,78 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var webpack = require("webpack");
|
4
|
+
|
5
|
+
function WebpackDriverStatusPlugin(options) {
|
6
|
+
this.options = options;
|
7
|
+
}
|
8
|
+
|
9
|
+
function log(type, value) {
|
10
|
+
console.log('STATUS:', JSON.stringify({type, value}));
|
11
|
+
}
|
12
|
+
|
13
|
+
WebpackDriverStatusPlugin.prototype.apply = function(compiler) {
|
14
|
+
var timer;
|
15
|
+
|
16
|
+
if ( compiler.options.devServer ) {
|
17
|
+
let {port, host, outputPath} = compiler.options.devServer;
|
18
|
+
log("dev-server", { port, host, outputPath });
|
19
|
+
}
|
20
|
+
|
21
|
+
// compiler.apply(new webpack.ProgressPlugin(function (percent, msg) {
|
22
|
+
// log("compile", {
|
23
|
+
// "progress": percent,
|
24
|
+
// "operation": msg,
|
25
|
+
// "ms": Date.now() - timer
|
26
|
+
// });
|
27
|
+
// }));
|
28
|
+
|
29
|
+
compiler.plugin("compile", function() {
|
30
|
+
timer = Date.now();
|
31
|
+
log("compile", {
|
32
|
+
"progress": 0,
|
33
|
+
"operation": "idle"
|
34
|
+
})
|
35
|
+
});
|
36
|
+
|
37
|
+
compiler.plugin("invalid", function() {
|
38
|
+
log("status", "invalid");
|
39
|
+
});
|
40
|
+
|
41
|
+
compiler.plugin("failed-module", function(module) {
|
42
|
+
log("failed-module", module);
|
43
|
+
});
|
44
|
+
compiler.plugin("done", function(stats) {
|
45
|
+
if (stats.compilation.errors && stats.compilation.errors.length){
|
46
|
+
log("status", "invalid");
|
47
|
+
for(var i = 0; i < stats.compilation.errors.length; i++){
|
48
|
+
var err = stats.compilation.errors[i];
|
49
|
+
log("error", {
|
50
|
+
name: err.name, message: err.message,
|
51
|
+
resource: err.module ? err.module.resource : ''
|
52
|
+
});
|
53
|
+
}
|
54
|
+
} else {
|
55
|
+
log("status", "success");
|
56
|
+
}
|
57
|
+
});
|
58
|
+
|
59
|
+
compiler.plugin("failed", function() {
|
60
|
+
log("status", "failed");
|
61
|
+
});
|
62
|
+
|
63
|
+
compiler.plugin("valid", function() {
|
64
|
+
log("status", "valid");
|
65
|
+
});
|
66
|
+
|
67
|
+
compiler.plugin("after-emit", function(compilation, callback) {
|
68
|
+
for (var k in compilation.assets){
|
69
|
+
if(!compilation.assets[k].parents){
|
70
|
+
log("asset", {name: k, size: compilation.assets[k].size()});
|
71
|
+
}
|
72
|
+
}
|
73
|
+
callback();
|
74
|
+
});
|
75
|
+
|
76
|
+
}
|
77
|
+
|
78
|
+
module.exports = WebpackDriverStatusPlugin;
|
@@ -3,23 +3,28 @@ require 'knitter'
|
|
3
3
|
|
4
4
|
module WebpackDriver
|
5
5
|
|
6
|
-
|
6
|
+
class Configuration
|
7
7
|
|
8
|
-
class
|
8
|
+
class Example < Thor::Group
|
9
9
|
include Thor::Actions
|
10
10
|
|
11
|
+
class_option :config
|
12
|
+
|
13
|
+
attr_reader :yarn
|
14
|
+
|
11
15
|
def self.source_root
|
12
|
-
Pathname.new(__FILE__)
|
16
|
+
Pathname.new(__FILE__)
|
17
|
+
.dirname.join('..', '..', '..', 'templates')
|
13
18
|
end
|
14
19
|
|
15
20
|
def set_destination_root
|
16
|
-
self.destination_root =
|
21
|
+
self.destination_root = options[:config].file.dirname
|
22
|
+
@yarn = Knitter::Yarn.new(destination_root)
|
17
23
|
end
|
18
24
|
|
19
25
|
def install_using_yarn
|
20
|
-
yarn = Knitter::Yarn.new(WebpackDriver.config.directory)
|
21
26
|
yarn.init unless yarn.valid?
|
22
|
-
%w
|
27
|
+
%w(webpack webpack-dev-server).each do |package|
|
23
28
|
package = Knitter::Package.new(package, yarn: yarn)
|
24
29
|
unless package.installed?
|
25
30
|
package.dependency_type = :development
|
@@ -30,11 +35,8 @@ module WebpackDriver
|
|
30
35
|
|
31
36
|
def generate
|
32
37
|
template("webpack.config.js", verbose: false)
|
33
|
-
template("status-plugin.js", verbose: false, force: true)
|
34
38
|
template("index.js", verbose: false, force: true)
|
35
39
|
end
|
36
40
|
end
|
37
|
-
|
38
41
|
end
|
39
|
-
|
40
42
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "thor"
|
2
|
+
|
3
|
+
module WebpackDriver
|
4
|
+
|
5
|
+
class Configuration
|
6
|
+
|
7
|
+
class Generated < Thor::Group
|
8
|
+
include Thor::Actions
|
9
|
+
|
10
|
+
class_option :config
|
11
|
+
|
12
|
+
def self.source_root
|
13
|
+
Pathname.new(__FILE__).dirname.join("..","..","..","templates")
|
14
|
+
end
|
15
|
+
|
16
|
+
def output
|
17
|
+
template("generated.config.js", options[:config].path, verbose: false, force: true)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,15 +1,60 @@
|
|
1
|
-
require_relative 'configuration/
|
1
|
+
require_relative 'configuration/generated'
|
2
|
+
require_relative 'configuration/example'
|
2
3
|
|
3
4
|
module WebpackDriver
|
4
5
|
|
5
|
-
|
6
|
+
class Configuration
|
6
7
|
|
7
|
-
|
8
|
+
attr_accessor :port
|
9
|
+
attr_accessor :logger
|
10
|
+
attr_accessor :compile_script
|
11
|
+
attr_accessor :directory
|
12
|
+
attr_accessor :cmd_line_flags
|
13
|
+
attr_writer :environment
|
8
14
|
|
9
|
-
|
10
|
-
|
11
|
-
|
15
|
+
attr_reader :file
|
16
|
+
attr_reader :generated
|
17
|
+
attr_accessor :logger
|
12
18
|
|
19
|
+
ROOT = Pathname.new(__FILE__).dirname.join('..', '..')
|
20
|
+
|
21
|
+
def initialize(file = './webpack.config.js', options = {})
|
22
|
+
options.each { |k, v| send("#{k}=", v) }
|
23
|
+
@directory ||= '.'
|
24
|
+
@file = Pathname.new(file)
|
25
|
+
@generated = Tempfile.new(['webpack.config', '.js'])
|
26
|
+
Generated.new([], config: self).invoke_all
|
27
|
+
end
|
28
|
+
|
29
|
+
def generate!
|
30
|
+
Example.new([], config: self).invoke_all
|
31
|
+
end
|
32
|
+
|
33
|
+
def present?
|
34
|
+
file.exist?
|
35
|
+
end
|
36
|
+
|
37
|
+
def path
|
38
|
+
@generated.path
|
39
|
+
end
|
40
|
+
|
41
|
+
def gem_root
|
42
|
+
ROOT
|
43
|
+
end
|
44
|
+
|
45
|
+
def environment
|
46
|
+
@environment ||= { NODE_ENV: 'development' }
|
47
|
+
end
|
48
|
+
|
49
|
+
def flags
|
50
|
+
opts = ['--config', path]
|
51
|
+
opts += ['--port', port] if port
|
52
|
+
opts += cmd_line_flags if cmd_line_flags
|
53
|
+
opts
|
54
|
+
end
|
55
|
+
|
56
|
+
def logger
|
57
|
+
@logger ||= Logger.new(STDOUT)
|
13
58
|
end
|
14
59
|
|
15
60
|
end
|
@@ -1,35 +1,18 @@
|
|
1
1
|
module WebpackDriver
|
2
2
|
|
3
|
-
|
3
|
+
# A wrapper around an instance of `webpak-dev-server`
|
4
4
|
class DevServer < Process
|
5
5
|
|
6
6
|
attr_reader :port, :host, :path
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
def initialize(*flags)
|
11
|
-
|
12
|
-
config = WebpackDriver.config
|
13
|
-
flags = ['--port', config.port] if config.port
|
14
|
-
super(config.dev_server_script, *flags)
|
8
|
+
def initialize(config)
|
9
|
+
super('webpack-dev-server', config)
|
15
10
|
end
|
16
11
|
|
17
|
-
|
18
12
|
def valid?
|
19
13
|
alive? && super
|
20
14
|
end
|
21
15
|
|
22
|
-
# def detected_url
|
23
|
-
# match = URL.match(output)
|
24
|
-
# match ? match[0] : nil
|
25
|
-
# end
|
26
|
-
|
27
|
-
# def detected_port
|
28
|
-
|
29
|
-
# match = URL.match(output)
|
30
|
-
# match ? match[3].to_i : nil
|
31
|
-
# end
|
32
|
-
|
33
16
|
private
|
34
17
|
|
35
18
|
def record_message(msg)
|
@@ -41,5 +24,4 @@ module WebpackDriver
|
|
41
24
|
super
|
42
25
|
end
|
43
26
|
end
|
44
|
-
|
45
27
|
end
|
@@ -10,18 +10,24 @@ module WebpackDriver
|
|
10
10
|
|
11
11
|
extend Forwardable
|
12
12
|
|
13
|
-
|
13
|
+
def_delegators :@proc, :alive?, :environment, :wait
|
14
14
|
|
15
|
-
|
15
|
+
attr_reader :assets, :messages
|
16
|
+
attr_reader :config
|
17
|
+
|
18
|
+
def initialize(script, config)
|
16
19
|
self.reset!
|
17
|
-
|
20
|
+
@config = config
|
21
|
+
args = ["./node_modules/.bin/#{script}"] + config.flags
|
22
|
+
|
18
23
|
@proc = ::ChildProcess.build(*args)
|
19
|
-
@proc.environment['NODE_ENV'] = WebpackDriver.config.environment
|
20
|
-
@proc.cwd = WebpackDriver.config.directory
|
21
|
-
end
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
+
@proc.environment.merge!(
|
26
|
+
config.environment
|
27
|
+
)
|
28
|
+
puts "ENV"
|
29
|
+
p config.environment
|
30
|
+
@proc.cwd = config.directory
|
25
31
|
end
|
26
32
|
|
27
33
|
def start
|
@@ -34,8 +40,8 @@ module WebpackDriver
|
|
34
40
|
end
|
35
41
|
|
36
42
|
def stop
|
37
|
-
@output.close unless @output.closed?
|
38
43
|
@proc.stop
|
44
|
+
@output.close unless @output.closed?
|
39
45
|
@listener.join
|
40
46
|
end
|
41
47
|
|
@@ -47,28 +53,44 @@ module WebpackDriver
|
|
47
53
|
|
48
54
|
def reset!
|
49
55
|
@assets = Concurrent::Map.new
|
50
|
-
@
|
56
|
+
@messages = Concurrent::Array.new
|
51
57
|
end
|
52
58
|
|
53
59
|
def last_compilation_message
|
54
|
-
msg = @
|
60
|
+
msg = @messages.reverse_each.detect{ |l| l['type'] == 'compile' }
|
55
61
|
msg ? msg['value'] : {}
|
56
62
|
end
|
57
63
|
|
64
|
+
def record_error(error)
|
65
|
+
config.logger.error(
|
66
|
+
"#{error['name']}: #{error['resource']}\n#{error['message']}"
|
67
|
+
)
|
68
|
+
end
|
69
|
+
|
58
70
|
def record_message(msg)
|
59
|
-
|
71
|
+
case msg['type']
|
72
|
+
when 'asset'
|
60
73
|
name = msg['value']['name']
|
61
74
|
@assets[name] = Asset.new(name, msg['value']['size'])
|
75
|
+
when 'error'
|
76
|
+
record_error(msg['value'])
|
77
|
+
else
|
78
|
+
config.logger.debug(msg)
|
62
79
|
end
|
63
|
-
@
|
80
|
+
@messages << msg
|
64
81
|
end
|
65
82
|
|
66
83
|
|
67
84
|
def listen_for_status_updates
|
68
85
|
Thread.new do
|
69
86
|
@output.each_line do | l |
|
70
|
-
match = l.match(
|
71
|
-
|
87
|
+
match = l.match(/^STATUS: (.*)/)
|
88
|
+
if match
|
89
|
+
record_message(JSON.parse(match[1]))
|
90
|
+
config.logger.debug(l.chomp)
|
91
|
+
else
|
92
|
+
config.logger.info(l.chomp)
|
93
|
+
end
|
72
94
|
end
|
73
95
|
end
|
74
96
|
end
|
data/lib/webpack_driver.rb
CHANGED
@@ -1,21 +1,7 @@
|
|
1
1
|
require_relative "webpack_driver/version"
|
2
|
-
require_relative "webpack_driver/config_options"
|
3
2
|
require_relative "webpack_driver/configuration"
|
4
3
|
require_relative "webpack_driver/asset"
|
5
4
|
require_relative 'webpack_driver/process'
|
6
5
|
require_relative "webpack_driver/dev_server"
|
7
6
|
require_relative "webpack_driver/compile"
|
8
7
|
require_relative "webpack_driver/errors"
|
9
|
-
|
10
|
-
module WebpackDriver
|
11
|
-
|
12
|
-
def self.config
|
13
|
-
@config ||= WebpackDriver::ConfigOptions.new
|
14
|
-
if block_given?
|
15
|
-
yield @config
|
16
|
-
@config.after_configuration
|
17
|
-
end
|
18
|
-
@config
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
var config = require('<%= options[:config].file %>');
|
2
|
+
var WebpackDriverStatusPlugin = require('<%= options[:config].gem_root %>/lib/status-plugin.js');
|
3
|
+
|
4
|
+
config.plugins = (config.plugins || []);
|
5
|
+
|
6
|
+
config.plugins.push(
|
7
|
+
new WebpackDriverStatusPlugin()
|
8
|
+
);
|
9
|
+
|
10
|
+
module.exports = config;
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webpack_driver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Stitt
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: knitter
|
@@ -141,16 +141,18 @@ files:
|
|
141
141
|
- bin/console
|
142
142
|
- bin/setup
|
143
143
|
- lib/config.rb
|
144
|
+
- lib/status-plugin.js
|
144
145
|
- lib/webpack_driver.rb
|
145
146
|
- lib/webpack_driver/asset.rb
|
146
147
|
- lib/webpack_driver/compile.rb
|
147
|
-
- lib/webpack_driver/config_options.rb
|
148
148
|
- lib/webpack_driver/configuration.rb
|
149
|
-
- lib/webpack_driver/configuration/
|
149
|
+
- lib/webpack_driver/configuration/example.rb
|
150
|
+
- lib/webpack_driver/configuration/generated.rb
|
150
151
|
- lib/webpack_driver/dev_server.rb
|
151
152
|
- lib/webpack_driver/errors.rb
|
152
153
|
- lib/webpack_driver/process.rb
|
153
154
|
- lib/webpack_driver/version.rb
|
155
|
+
- templates/generated.config.js.tt
|
154
156
|
- templates/index.js.tt
|
155
157
|
- templates/status-plugin.js.tt
|
156
158
|
- templates/webpack.config.js.tt
|
@@ -176,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
178
|
version: '0'
|
177
179
|
requirements: []
|
178
180
|
rubyforge_project:
|
179
|
-
rubygems_version: 2.
|
181
|
+
rubygems_version: 2.5.1
|
180
182
|
signing_key:
|
181
183
|
specification_version: 4
|
182
184
|
summary: Run webpack-dev-server in a sub process
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module WebpackDriver
|
2
|
-
|
3
|
-
class ConfigOptions
|
4
|
-
|
5
|
-
attr_accessor :port
|
6
|
-
attr_accessor :directory
|
7
|
-
attr_accessor :environment
|
8
|
-
attr_accessor :compile_script
|
9
|
-
attr_accessor :dev_server_script
|
10
|
-
|
11
|
-
def initialize
|
12
|
-
@directory = Pathname.new(Dir.pwd)
|
13
|
-
@environment = 'development'
|
14
|
-
@compile_script = 'node_modules/webpack/bin/webpack.js'
|
15
|
-
@dev_server_script = 'node_modules/webpack-dev-server/bin/webpack-dev-server.js' end
|
16
|
-
|
17
|
-
def after_configuration
|
18
|
-
@directory = Pathname.new(@directory)
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|