lib/webpack_driver/configuration.rb in webpack_driver-0.1.1 vs lib/webpack_driver/configuration.rb in webpack_driver-0.2.0
- old
+ new
@@ -1,16 +1,61 @@
-require_relative 'configuration/base'
+require_relative 'configuration/generated'
+require_relative 'configuration/example'
module WebpackDriver
- module Configuration
+ class Configuration
- class << self
+ attr_accessor :port
+ attr_accessor :logger
+ attr_accessor :compile_script
+ attr_accessor :directory
+ attr_accessor :cmd_line_flags
+ attr_writer :environment
- def generate
- Base.start
- end
+ attr_reader :file
+ attr_reader :generated
+ attr_accessor :logger
+ ROOT = Pathname.new(__FILE__).dirname.join('..', '..')
+
+ def initialize(file = './webpack.config.js', options = {})
+ options.each { |k, v| send("#{k}=", v) }
+ @directory ||= '.'
+ @file = Pathname.new(file)
+ @generated = Tempfile.new(['webpack.config', '.js'])
+ Generated.new([], config: self).invoke_all
+ end
+
+ def generate!
+ Example.new([], config: self).invoke_all
+ end
+
+ def present?
+ file.exist?
+ end
+
+ def path
+ @generated.path
+ end
+
+ def gem_root
+ ROOT
+ end
+
+ def environment
+ @environment ||= { NODE_ENV: 'development' }
+ end
+
+ def flags
+ opts = ['--config', path]
+ opts += ['--port', port] if port
+ opts += cmd_line_flags if cmd_line_flags
+ opts
+ end
+
+ def logger
+ @logger ||= Logger.new(STDOUT)
end
end
end