npm-rails 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 531ae45eee201ef671482c29382cd0d1a5f32912
4
- data.tar.gz: ec7de754048db5cdc81de420c379f44e547e5bd6
3
+ metadata.gz: c32cc65625bf1da90f6aa9e1c6ebd49798857cde
4
+ data.tar.gz: 53418cb5e60aadc395693ea90ec76ad8253509fb
5
5
  SHA512:
6
- metadata.gz: ae8bf4bb16d8f73a14112c619458319f7f84bf556f5c0aa5500a638da7c8e7c2f50dcc131bb7d60193299c522369e980c956260f609a1da4f8be1469a89e1482
7
- data.tar.gz: c87489e1d5ab28dfa5856c06e26d1e4a7c8ac2b29ba8408ac0441885b6088f4c86e72de4bc2a42a9d26a32934a1f2578269ee68afa4ec6d2faa47ad913bafdb7
6
+ metadata.gz: 07b2fd711a6d4c1f35de14426fdbb96e8c135014f60f3c20907d54a1b42b12e7524736009eaa06673f6f37d777188b71bfecd21027ee20f3d49c62837df73d65
7
+ data.tar.gz: 26e4b27eb5c1a9571c098057d085f0bca80d2179d6301f2b297383d912562a7d416dddfc59c8c7d62fa6672b45ed86660e92b3b061224b5e9de0541969cae0a7
data/README.md CHANGED
@@ -63,15 +63,15 @@ npm 'browserify', require: false
63
63
  The following options are available for configuration in your application or environment-level
64
64
  config files (`config/application.rb`, `config/environments/development.rb`, etc.):
65
65
 
66
- | Configuration Option | Description |
67
- |---------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------- |
68
- | `config.npm.package_file` | Specificies a package file. Default value: `npm_packages` |
69
- | `config.npm.output_file` | Specifies a file where to bundle npm packages. Default value: `vendor/assets/javascripts/npm-dependencies.js`. |
70
- | `config.npm.browserify_options` | Sets options for browserify command. See all available options in [Browserify documentation](https://github.com/substack/node-browserify#usage) |
66
+ | Configuration Option | Description |
67
+ |-------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------- |
68
+ | `config.npm.package_file` | Specificies a package file. Default value: `npm_packages` |
69
+ | `config.npm.output_file` | Specifies a file where to bundle npm packages. Default value for production: `vendor/assets/javascripts/npm-rails/production/npm-dependencies.js`. Default value for other environments: `vendor/assets/javascripts/npm-rails/development/npm-dependencies.js` |
70
+ | `config.npm.browserify_options` | Sets options for browserify command. See all available options in [Browserify documentation](https://github.com/substack/node-browserify#usage) |
71
+ | `config.npm.run_berofe_assets_precompile` | If set to `true` then run `rake npm:install` before assets precompilation. Default value: `false` |
71
72
 
72
73
  ## How it works
73
74
 
74
- The generator creates `npm_packages` file. This file contains a list of packages. Rake uses NPM to install the packages and Browserify to bundle them and output the bundled results to `vendor/assets/javascripts/npm-dependencies.js`, which are then loaded by sprockets. These generated bundle file have been added to your `.gitignore` for your convenience. All packages attached to `window`.
75
-
75
+ The generator creates `npm_packages` file. This file contains a list of packages. Rake uses NPM to install the packages and Browserify to bundle them. Browserify output the bundled results to `output_file`(see configuration options), which are then loaded by sprockets. All packages attached to `window` by `build_name`, which by default is the camelize package name.
76
76
 
77
77
 
@@ -12,7 +12,6 @@ module NpmRails
12
12
  <<-EOF.strip_heredoc
13
13
  # Added by npm-rails
14
14
  /node_modules
15
- /vendor/assets/javascripts/npm-dependencies.js
16
15
  EOF
17
16
  end
18
17
  end
@@ -5,3 +5,4 @@ require 'npm/rails/package_manager'
5
5
  require 'npm/rails/errors'
6
6
  require 'npm/rails/package_file_parser'
7
7
  require 'npm/rails/package'
8
+ require 'npm/rails/task_helpers'
@@ -25,7 +25,7 @@ module Npm
25
25
  private
26
26
 
27
27
  def create_build_name_from_name
28
- @name.gsub("-", "_").camelize
28
+ @name.tr("-", "_").camelize
29
29
  end
30
30
  end
31
31
  end
@@ -24,7 +24,7 @@ module Npm
24
24
 
25
25
  def npm(package_name, *args)
26
26
  options = args.last.is_a?(Hash) ? args.pop : {}
27
- options.merge!(development: @development)
27
+ options = { development: @development }.merge(options)
28
28
  version = args.empty? ? "latest" : args.pop
29
29
 
30
30
  @packages << Npm::Rails::Package.new(package_name, version, options)
@@ -6,7 +6,18 @@ module Npm
6
6
  class Railtie < ::Rails::Railtie
7
7
  config.npm = ActiveSupport::OrderedOptions.new
8
8
  config.npm.package_file = "npm_packages"
9
- config.npm.output_file = "vendor/assets/javascripts/npm-dependencies.js"
9
+ config.npm.run_before_assets_precompile = false
10
+
11
+ output_path = "vendor/assets/javascripts/npm-rails"
12
+ if ::Rails.env.production?
13
+ config.npm.output_path = output_path << "/production"
14
+ else
15
+ config.npm.output_path = output_path << "/development"
16
+ end
17
+
18
+ initializer "npm_rails.add_assets_path", after: :engines_blank_point, group: :all do |app|
19
+ app.config.assets.paths << app.config.npm.output_path
20
+ end
10
21
 
11
22
  rake_tasks do
12
23
  load "tasks/npm.rake"
@@ -0,0 +1,29 @@
1
+ require "mkmf"
2
+ require 'fileutils'
3
+
4
+ module Npm
5
+ module Rails
6
+ module TaskHelpers
7
+
8
+ def self.find_browserify(npm_directory)
9
+ browserify = find_executable0("browserify") ||
10
+ find_executable0("#{ npm_directory }/.bin/browserify")
11
+
12
+ if browserify.nil?
13
+ raise Npm::Rails::BrowserifyNotFound, "Browserify not found! You can install Browserify using npm: npm install browserify -g"
14
+ else
15
+ browserify
16
+ end
17
+ end
18
+
19
+ def self.create_file(path, file)
20
+ unless File.directory?(path)
21
+ FileUtils.mkdir_p(path)
22
+ end
23
+
24
+ file_path = path.join(file)
25
+ FileUtils.touch(file_path)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,5 +1,5 @@
1
1
  module Npm
2
2
  module Rails
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -1,29 +1,24 @@
1
1
  require 'fileutils'
2
- require "mkmf"
3
2
 
4
3
  namespace :npm do
5
4
  desc "Install npm packages"
6
5
  task :install do
7
6
  package_file = ::Rails.configuration.npm.package_file
8
- output_file_path = ::Rails.root.join(::Rails.configuration.npm.output_file)
9
7
  browserify_options = ::Rails.configuration.npm.browserify_options
8
+ output_path = ::Rails.root.join(::Rails.configuration.npm.output_path)
9
+ output_file = "npm-dependencies.js"
10
+ output_file_path = output_path.join(output_file)
11
+
12
+ Npm::Rails::TaskHelpers.create_file(output_path, output_file) unless File.exist?(output_file_path)
10
13
 
11
14
  Npm::Rails::PackageBundler.bundle(::Rails.root, package_file, ::Rails.env) do |packages, bundle_file_path|
12
- FileUtils.touch(output_file_path) unless File.exist?(output_file_path)
13
15
  sh "cd #{ ::Rails.root }"
14
16
  sh "npm install --loglevel error #{ packages }"
15
17
 
16
- browserify = find_executable0("browserify") ||
17
- find_executable0("#{ ::Rails.root }/node_modules/.bin/browserify")
18
-
19
- if browserify.nil?
20
- raise Npm::Rails::BrowserifyNotFound, "Browserify not found! You can install Browserify using npm: npm install browserify -g"
21
- end
22
-
18
+ browserify = Npm::Rails::TaskHelpers.find_browserify(::Rails.root.join("node_modules"))
19
+ browserify_command = "#{ browserify } #{ browserify_options } #{ bundle_file_path } > #{ output_file_path }"
23
20
  if Rails.env.production?
24
- browserify_command = "NODE_ENV=production #{ browserify } #{ browserify_options } #{ bundle_file_path } > #{ output_file_path }"
25
- else
26
- browserify_command = "#{ browserify } #{ browserify_options } #{ bundle_file_path } > #{ output_file_path }"
21
+ browserify_command = "NODE_ENV=production #{ browserify_command }"
27
22
  end
28
23
 
29
24
  sh browserify_command
@@ -31,4 +26,6 @@ namespace :npm do
31
26
  end
32
27
  end
33
28
 
34
- task "assets:precompile" => ["npm:install"]
29
+ if ::Rails.configuration.npm.run_before_assets_precompile
30
+ task "assets:precompile" => ["npm:install"]
31
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: npm-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stepan Lusnikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-05 00:00:00.000000000 Z
11
+ date: 2016-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -98,6 +98,7 @@ files:
98
98
  - lib/npm/rails/package_file_parser.rb
99
99
  - lib/npm/rails/package_manager.rb
100
100
  - lib/npm/rails/railtie.rb
101
+ - lib/npm/rails/task_helpers.rb
101
102
  - lib/npm/rails/version.rb
102
103
  - lib/tasks/npm.rake
103
104
  homepage: https://github.com/endenwer/npm-rails