npm-pipeline-rails 1.0.0 → 1.1.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: 46d50e558878bb7067e545c5e6d23b8bab48c620
4
- data.tar.gz: d4af91051596cb74e6125ea7c88b770d5ee9555f
3
+ metadata.gz: cf569c96c85c02b65915d854b5ed6023012bc7aa
4
+ data.tar.gz: d0e38db04bb99ed44153f96d65740caddda891a2
5
5
  SHA512:
6
- metadata.gz: 7ab31053f7879fc3575446561e3b6aaa2170bc807fea510bea2dcf13c8a8bb196047df4dcc2261d0a8ea21e42a70867126e6fe56182f4f022785abbce1560d82
7
- data.tar.gz: 9e8f5151e74246cbca3cb474f91ed359c54af627ed59e41492ecaf21acb9868cddfbabd463ff48c08ee0ddabc741b60be4be302b8c89ce553b6e42c95e653439
6
+ metadata.gz: 1ef48bbe254b7960785f489b19401423419baa51776ebbe69837810c9bc78094fcd95107fc28376ca7a3b00f82a9b48b96d000c550fce141f5b57fa7ca5378ed
7
+ data.tar.gz: b8f655d71c5eab1cd5b1ecc7bd1fc8832a44e035fae1435b2e16fd9e7ee36d0315fcf2a1d2183f7ab7902ac239bab37809b348777a10b03946e423f7ce9bfbf6
data/HISTORY.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [v1.1.0]
2
+ > Mar 22, 2016
3
+
4
+ - Add Gulp generator (`rails g npm_pipeline:gulp`).
5
+
6
+ [v1.1.0]: https://github.com/rstacruz/npm-pipeline-rails/compare/v1.0.0...v1.1.0
7
+
1
8
  ## [v1.0.0]
2
9
  > Mar 22, 2016
3
10
 
data/README.md CHANGED
@@ -2,36 +2,49 @@
2
2
 
3
3
  > Use npm as part of your Rails asset pipeline
4
4
 
5
- npm-pipeline-rails allows you to use any toolchain to bulid your asset files. This allows you to:
5
+ npm-pipeline-rails allows you to use any toolchain to bulid your asset files in [Rails] 4.2+. This allows you to:
6
6
 
7
- - Use [webpack][] with Rails
8
- - Use [brunch][] with Rails ([instructions](docs/brunch.md))
9
- - Use [browserify][] with Rails
7
+ - Use [Brunch][] with Rails ([instructions](docs/brunch.md))
8
+ - Use [Gulp][] with Rails ([instructions](docs/gulp.md))
9
+ - Use [Grunt][] with Rails
10
+ - Use [Webpack][] with Rails
11
+ - Use [Browserify][] with Rails
10
12
  - Use any other asset tool with Rails
11
13
 
12
- [webpack]: https://webpack.github.io/
13
- [brunch]: http://brunch.io/
14
- [browserify]: http://browserify.org/
14
+ [Rails]: http://rubyonrails.org/
15
+ [Webpack]: https://webpack.github.io/
16
+ [Brunch]: http://brunch.io/
17
+ [Browserify]: http://browserify.org/
18
+ [Gulp]: http://gulpjs.com/
19
+ [Grunt]: http://gruntjs.com/
15
20
 
16
- > ![](docs/screenshots/full.png)
21
+ <br>
17
22
 
18
- ## Usage
23
+ ![](docs/screenshots/full.png)
24
+
25
+ > _See [§ How it Works](#how-it-works) for an explanation of the diagram above._
19
26
 
20
- Add to your `Gemfile`.
27
+ <br>
21
28
 
22
- ```rb
23
- gem 'npm-pipeline-rails'
24
- ```
29
+ ## Usage
25
30
 
26
- You may do a manual setup:
31
+ Add this line below to your `Gemfile`. After that, proceed with an automated or manual setup.
27
32
 
28
- * Create a `package.json` with `start` and `build` commands.
29
- * Add compiled assets to `.gitignore`.
33
+ ```rb
34
+ gem 'npm-pipeline-rails'
35
+ ```
30
36
 
31
- Or an automated setup:
37
+ #### Automated setup
32
38
 
33
39
  * Run `./bin/rails generate npm_pipeline:brunch` to add a sample integration with [Brunch]. ([info](docs/brunch.md))
34
40
 
41
+ #### Manual setup
42
+
43
+ * Create a `package.json` with `start` and `build` scripts. ([See example](lib/generators/npm_pipeline/brunch/package.json))
44
+ * Add your expected compiled assets to `.gitignore`.
45
+
46
+ <br>
47
+
35
48
  ## Configuration
36
49
 
37
50
  npm-pipeline-rails provides these configuration options:
@@ -43,7 +56,7 @@ Rails.application.configure do
43
56
  # Command to install dependencies
44
57
  config.npm.install = ['npm install']
45
58
 
46
- # Command to build production
59
+ # Command to build production assets
47
60
  config.npm.build = ['npm run build']
48
61
 
49
62
  # Command to start a file watcher
@@ -57,10 +70,14 @@ Rails.application.configure do
57
70
  end
58
71
  ```
59
72
 
73
+ <br>
74
+
60
75
  ## How it works
61
76
 
62
77
  npm-pipeline-rails allows you to hook certain commands, usually npm scripts, during the Rails app lifecycle. It assumes that your tool will build plain JS and CSS files into `vendor/assets`, allowing it to be picked up by Rails's asset pipeline.
63
78
 
79
+ It does __not__ replace the Rails asset pipeline, but rather it works with it. The files you build with your npm pipeline will be available as regular files in the Rails asset pipeline.
80
+
64
81
  #### In development
65
82
 
66
83
  When starting a Rails development server (`bundle exec rails s`), it runs the `install` command. After that, it starts a background process that runs your `watch` command.
@@ -69,10 +86,25 @@ When starting a Rails development server (`bundle exec rails s`), it runs the `i
69
86
 
70
87
  When running `rake assets:precompile`, it will first run the `install` command then the `build` command.
71
88
 
89
+ #### More info
90
+
91
+ Consult [railtie.rb](https://github.com/rstacruz/npm-pipeline-rails/blob/master/lib/npm-pipeline-rails/railtie.rb) for the actual code that makes all these happen.
92
+
93
+ <br>
94
+
72
95
  ## Integration examples
73
96
 
74
97
  * [Brunch](docs/brunch.md)
75
- * more to come soon
98
+
99
+ <br>
100
+
101
+ ## Motivation
102
+
103
+ Rails's asset pipeline was a great step forward for Rails 3. For today's requirements however, it doesn't always come with all the tools you need. npm-pipeline-rails lets you outsource asset building complexities to Node.js-based tools.
104
+
105
+ > __[Read more →](docs/motivation.md)__
106
+
107
+ <br>
76
108
 
77
109
  ## Thanks
78
110
 
data/docs/brunch.md CHANGED
@@ -1,4 +1,4 @@
1
- # Brunch example
1
+ # Brunch integration
2
2
 
3
3
  Run `./bin/rails generate npm_pipeline:brunch`.
4
4
 
@@ -6,57 +6,27 @@ Run `./bin/rails generate npm_pipeline:brunch`.
6
6
 
7
7
  If you don't want to use the generator, here's what it does.
8
8
 
9
- ### `brunch-config.js`
9
+ ### brunch-config.js
10
10
 
11
11
  Set it up to watch source files in `app/brunch`, then put built files into `vendor/assets`.
12
+ [See example.](../lib/generators/npm_pipeline/brunch/brunch-config.js)
12
13
 
13
- ```js
14
- // See http://brunch.io for documentation.
15
- module.exports = {
16
- paths: {
17
- watched: ['app/brunch'],
18
- public: 'vendor/assets'
19
- },
20
-
21
- files: {
22
- javascripts: {joinTo: 'javascripts/brunch/app.js'},
23
- stylesheets: {joinTo: 'stylesheets/brunch/app.css'}
24
- }
25
- }
26
- ```
14
+ ### package.json
27
15
 
28
- ### `package.json`
29
-
30
- ```js
31
- {
32
- "name": "brunch-app",
33
- "description": "Description",
34
- "author": "Your Name",
35
- "version": "0.1.0",
36
- "scripts": {
37
- "start": "brunch watch",
38
- "build": "brunch build --production"
39
- },
40
- "dependencies": {},
41
- "devDependencies": {
42
- "brunch": "^2.5.1",
43
- "javascript-brunch": "^2.0.0",
44
- "css-brunch": "^2.0.0",
45
- "auto-reload-brunch": "^2.0.0"
46
- }
47
- }
48
- ```
16
+ Set it up with `brunch` and some basic plugins.
17
+ [See example.](../lib/generators/npm_pipeline/brunch/package.json)
49
18
 
50
- ### `.gitignore`
19
+ ### .gitignore
51
20
 
52
21
  Set it up to ignore Brunch's built files.
53
22
 
54
23
  ```
55
- /vendor/assets/stylesheets/brunch/
56
- /vendor/assets/javascripts/brunch/
24
+ /node_modules
25
+ /vendor/assets/stylesheets/brunch
26
+ /vendor/assets/javascripts/brunch
57
27
  ```
58
28
 
59
- ### `app/assets/stylesheets/application.css`
29
+ ### app/assets/stylesheets/application.css
60
30
 
61
31
  Set it up to include Brunch's built files. This will load from `vendor/assets/stylesheets`, as built by Brunch.
62
32
 
@@ -66,7 +36,7 @@ Set it up to include Brunch's built files. This will load from `vendor/assets/st
66
36
  */
67
37
  ```
68
38
 
69
- ### `app/assets/javascripts/application.js`
39
+ ### app/assets/javascripts/application.js
70
40
 
71
41
  Set it up to include Brunch's built files. This will load from `vendor/assets/javascripts`, as built by Brunch.
72
42
 
@@ -74,7 +44,7 @@ Set it up to include Brunch's built files. This will load from `vendor/assets/ja
74
44
  //= require brunch/app
75
45
  ```
76
46
 
77
- ### `app/brunch`
47
+ ### app/brunch/
78
48
 
79
49
  Put your source files into `app/brunch`. For instance:
80
50
 
data/docs/gulp.md ADDED
@@ -0,0 +1,60 @@
1
+ # Gulp integration
2
+
3
+ Run `./bin/rails generate npm_pipeline:gulp`.
4
+
5
+ ## Manual setup
6
+
7
+ If you don't want to use the generator, here's what it does.
8
+
9
+ ### package.json
10
+
11
+ Set up `gulp`, `gulp-cli`, and some basic Gulp plugins.
12
+ [See example.](../lib/generators/npm_pipeline/gulp/package.json)
13
+
14
+ ### gulpfile.js
15
+
16
+ Set it up to watch source files in `app/gulp`, then put built files into `vendor/assets`. [See example.](../lib/generators/npm_pipeline/gulp/gulpfile.js)
17
+
18
+ ### .gitignore
19
+
20
+ Set it up to ignore Gulp's built files.
21
+
22
+ ```
23
+ /node_modules
24
+ /vendor/assets/stylesheets/gulp
25
+ /vendor/assets/javascripts/gulp
26
+ ```
27
+
28
+ ### app/assets/stylesheets/application.css
29
+
30
+ Set it up to include Gulp's built files. This will load from `vendor/assets/stylesheets/gulp/app.css`, as built by Gulp.
31
+
32
+ ```css
33
+ /*
34
+ *= require gulp/app
35
+ */
36
+ ```
37
+
38
+ ### app/assets/javascripts/application.js
39
+
40
+ Set it up to include Gulp's built files. This will load from `vendor/assets/javascripts/gulp/app.js`, as built by Gulp.
41
+
42
+ ```css
43
+ //= require gulp/app
44
+ ```
45
+
46
+ ### app/gulp/
47
+
48
+ Put your source files into `app/gulp`. For instance:
49
+
50
+ * `app/brunch/example.css`
51
+
52
+ ```css
53
+ * { color: blue }
54
+ ```
55
+
56
+ * `app/brunch/example.js`
57
+
58
+ ```js
59
+ alert('it works!')
60
+ ```
@@ -0,0 +1,35 @@
1
+ # Motivation
2
+
3
+ Rails's asset pipeline was a great step forward for Rails 3. For today's requirements however, it doesn't always come with all the tools you need. Here's a portrait of Rails's shortcomings with respect to CSS/JS development in 2016:
4
+
5
+ * __npm assets:__ Frontend packages are now usually hosted in [npm], but there's no easy solution to integrate npm with Rails. Putting files into `vendor/assets` should be a thing of the past.
6
+
7
+ * __Auto-reload:__ Automatic CSS reloading can be done with [guard-livereload], but is unwieldy at best. They require too much configuration and mental overhead to maintain.
8
+
9
+ * __Modern CSS tools:__ Integrating modern CSS tools like [libsass] and [postcss] can be done, but is hackish and slow. It has to invoke a separate Node.js process for each CSS file rather than keeping those tools running in the background. Some newer CSS pre/post processors like [Myth](http://www.myth.io/) don't have production-grade integrations with Rails.
10
+
11
+ * __Modern JS tools:__ Working with complex frontends typically need [Webpack] or [Browserify]. While integrations for these exist, they can be slow and unreliable.
12
+
13
+ ## Using Node.js
14
+
15
+ npm-pipeline-rails lets you outsource asset building complexities to Node.js-based tools, which is the gold stardard for asset tooling nowadays.
16
+
17
+ It doesn't lock you into one specific solution; you can use npm-pipeline-rails for any task manager. I recommend [Brunch] for its ease-of-use and familiarity with Rails's asset pipeline's features. [Gulp] and [Grunt] are also popular choices.
18
+
19
+ ## Brunch
20
+
21
+ You can use [Brunch] with Rails with ease using npm-pipeline-rails. With Brunch, you get [automatic code reloading][auto-reload-brunch], easier integration with [postcss][postcss-brunch], `require()` support, and more. You may even hook [Browserify][browserify-brunch] if you need it.
22
+
23
+ [guard-livereload]: http://rubygems.org/gems/guard-livereload
24
+ [npm]: http://npmjs.com/
25
+ [libsass]: http://sass-lang.com/libsass
26
+ [postcss]: https://github.com/postcss/postcss
27
+ [auto-reload-brunch]: https://www.npmjs.com/package/auto-reload-brunch
28
+ [postcss-brunch]: https://www.npmjs.com/package/postcss-brunch
29
+ [browserify-brunch]: https://www.npmjs.com/package/browserify-brunch
30
+ [Grunt]: http://gruntjs.com/
31
+ [Webpack]: https://webpack.github.io/
32
+ [Brunch]: http://brunch.io/
33
+ [Browserify]: http://browserify.org/
34
+ [Gulp]: http://gulpjs.com/
35
+ [Grunt]: http://gruntjs.com/
@@ -33,6 +33,7 @@ module NpmPipeline
33
33
 
34
34
  def update_gitignore
35
35
  append_to_file '.gitignore',
36
+ "/node_modules\n" +
36
37
  "/vendor/assets/stylesheets/brunch\n" +
37
38
  "/vendor/assets/javascripts/brunch\n"
38
39
  end
@@ -0,0 +1,24 @@
1
+ var gulp = require('gulp')
2
+ var concat = require('gulp-concat')
3
+
4
+ gulp.task('build:js', function () {
5
+ return gulp.src('app/gulp/js/**/*.js')
6
+ .pipe(concat('app.js'))
7
+ .pipe(gulp.dest('vendor/assets/javascripts/gulp/'))
8
+ })
9
+
10
+ gulp.task('build:css', function () {
11
+ return gulp.src('app/gulp/css/**/*.css')
12
+ .pipe(gulp.dest('vendor/assets/stylesheets/gulp/'))
13
+ })
14
+
15
+ gulp.task('watch:js', function () {
16
+ gulp.watch('app/gulp/js/**/*.js', ['build:js'])
17
+ })
18
+
19
+ gulp.task('watch:css', function () {
20
+ gulp.watch('app/gulp/css/**/*.css', ['build:css'])
21
+ })
22
+
23
+ gulp.task('watch', ['watch:js', 'watch:css'])
24
+ gulp.task('build', ['build:js', 'build:css'])
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "gulp-app",
3
+ "description": "Description",
4
+ "author": "Your Name",
5
+ "version": "0.1.0",
6
+ "scripts": {
7
+ "start": "gulp watch",
8
+ "build": "gulp build"
9
+ },
10
+ "dependencies": {},
11
+ "devDependencies": {
12
+ "gulp": "^3.9.1",
13
+ "gulp-cli": "^1.2.1",
14
+ "gulp-concat": "^2.6.0"
15
+ }
16
+ }
@@ -0,0 +1,42 @@
1
+ require 'rails/generators/base'
2
+
3
+ module NpmPipeline
4
+ module Generators
5
+ class GulpGenerator < Rails::Generators::Base
6
+ desc 'Creates'
7
+ source_root File.expand_path('../gulp', __FILE__)
8
+
9
+ def create_package_json
10
+ template 'package.json', 'package.json'
11
+ end
12
+
13
+ def create_gulpfile
14
+ template 'gulpfile.js', 'gulpfile.js'
15
+ end
16
+
17
+ def update_assets
18
+ append_to_file 'app/assets/stylesheets/application.css',
19
+ "/*\n *= require gulp/app\n */\n"
20
+ append_to_file 'app/assets/javascripts/application.js',
21
+ "//= require gulp/app\n"
22
+ end
23
+
24
+ def create_sample_css
25
+ create_file 'app/gulp/css/example.css',
26
+ %(html:before { content: 'Gulp assets added successfully! Edit app/gulp/example.css or remove it.'; display: block; padding: 20px; background: #ffc; color: #111; position: fixed; top: 16px; right: 16px; max-width: 600px; z-index: 10000; font-family: sans-serif; font-size: 14px; line-height: 1.6; }\n)
27
+ end
28
+
29
+ def create_sample_js
30
+ create_file 'app/gulp/js/example.js',
31
+ "alert('Gulp works!')"
32
+ end
33
+
34
+ def update_gitignore
35
+ append_to_file '.gitignore',
36
+ "/node_modules\n" +
37
+ "/vendor/assets/stylesheets/gulp\n" +
38
+ "/vendor/assets/javascripts/gulp\n"
39
+ end
40
+ end
41
+ end
42
+ end
@@ -7,7 +7,6 @@ module NpmPipelineRails
7
7
  [*commands].each do |cmd|
8
8
  system cmd
9
9
  exit $? unless $? == 0
10
-
11
10
  end
12
11
  end
13
12
  end
@@ -16,14 +15,13 @@ module NpmPipelineRails
16
15
  include ::NpmPipelineRails::Utils
17
16
 
18
17
  config.npm = ActiveSupport::OrderedOptions.new
19
-
20
18
  config.npm.build = ['npm run build']
21
19
  config.npm.watch = ['npm run start']
22
20
  config.npm.install = ['npm install']
23
21
 
24
22
  rake_tasks do |app|
25
23
  namespace :assets do
26
- desc 'Build assets prerequisites using npm'
24
+ desc 'Build asset prerequisites using npm'
27
25
  task :npm_build do
28
26
  do_system app.config.npm.install
29
27
  do_system app.config.npm.build
@@ -36,7 +34,6 @@ module NpmPipelineRails
36
34
  initializer 'npm_pipeline.watch' do |app|
37
35
  if ::Rails.env.development? && ::Rails.const_defined?(:Server)
38
36
  do_system app.config.npm.install
39
- exit $? unless $? == 0
40
37
  [*app.config.npm.watch].each do |cmd|
41
38
  fork { do_system [cmd] }
42
39
  end
@@ -1,3 +1,3 @@
1
1
  module NpmPipelineRails
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = 'https://github.com/rstacruz/npm-pipeline-rails'
15
15
  spec.license = 'MIT'
16
16
 
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(example|test|spec|features)/}) }
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(examples|test|spec|features)/}) }
18
18
  spec.bindir = 'exe'
19
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ['lib']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: npm-pipeline-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rico Sta. Cruz
@@ -106,12 +106,17 @@ files:
106
106
  - HISTORY.md
107
107
  - README.md
108
108
  - docs/brunch.md
109
+ - docs/gulp.md
110
+ - docs/motivation.md
109
111
  - docs/screenshots/build.png
110
112
  - docs/screenshots/full.png
111
113
  - docs/screenshots/server.png
112
114
  - lib/generators/npm_pipeline/brunch/brunch-config.js
113
115
  - lib/generators/npm_pipeline/brunch/package.json
114
116
  - lib/generators/npm_pipeline/brunch_generator.rb
117
+ - lib/generators/npm_pipeline/gulp/gulpfile.js
118
+ - lib/generators/npm_pipeline/gulp/package.json
119
+ - lib/generators/npm_pipeline/gulp_generator.rb
115
120
  - lib/npm-pipeline-rails.rb
116
121
  - lib/npm-pipeline-rails/railtie.rb
117
122
  - lib/npm-pipeline-rails/version.rb