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 +4 -4
- data/README.md +7 -7
- data/lib/generators/npm_rails/initialize_generator.rb +0 -1
- data/lib/npm/rails.rb +1 -0
- data/lib/npm/rails/package.rb +1 -1
- data/lib/npm/rails/package_file_parser.rb +1 -1
- data/lib/npm/rails/railtie.rb +12 -1
- data/lib/npm/rails/task_helpers.rb +29 -0
- data/lib/npm/rails/version.rb +1 -1
- data/lib/tasks/npm.rake +11 -14
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c32cc65625bf1da90f6aa9e1c6ebd49798857cde
|
4
|
+
data.tar.gz: 53418cb5e60aadc395693ea90ec76ad8253509fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
67
|
-
|
68
|
-
| `config.npm.package_file`
|
69
|
-
| `config.npm.output_file`
|
70
|
-
| `config.npm.browserify_options`
|
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
|
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
|
|
data/lib/npm/rails.rb
CHANGED
data/lib/npm/rails/package.rb
CHANGED
@@ -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
|
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)
|
data/lib/npm/rails/railtie.rb
CHANGED
@@ -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.
|
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
|
data/lib/npm/rails/version.rb
CHANGED
data/lib/tasks/npm.rake
CHANGED
@@ -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 =
|
17
|
-
|
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 #{
|
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
|
-
|
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.
|
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-
|
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
|