npm-pipeline-rails 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 46d50e558878bb7067e545c5e6d23b8bab48c620
4
+ data.tar.gz: d4af91051596cb74e6125ea7c88b770d5ee9555f
5
+ SHA512:
6
+ metadata.gz: 7ab31053f7879fc3575446561e3b6aaa2170bc807fea510bea2dcf13c8a8bb196047df4dcc2261d0a8ea21e42a70867126e6fe56182f4f022785abbce1560d82
7
+ data.tar.gz: 9e8f5151e74246cbca3cb474f91ed359c54af627ed59e41492ecaf21acb9868cddfbabd463ff48c08ee0ddabc741b60be4be302b8c89ce553b6e42c95e653439
@@ -0,0 +1 @@
1
+ /Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
@@ -0,0 +1,6 @@
1
+ ## [v1.0.0]
2
+ > Mar 22, 2016
3
+
4
+ - Initial release.
5
+
6
+ [v1.0.0]: https://github.com/rstacruz/npm-pipeline-rails/tree/v1.0.0
@@ -0,0 +1,87 @@
1
+ # npm-pipeline-rails
2
+
3
+ > Use npm as part of your Rails asset pipeline
4
+
5
+ npm-pipeline-rails allows you to use any toolchain to bulid your asset files. This allows you to:
6
+
7
+ - Use [webpack][] with Rails
8
+ - Use [brunch][] with Rails ([instructions](docs/brunch.md))
9
+ - Use [browserify][] with Rails
10
+ - Use any other asset tool with Rails
11
+
12
+ [webpack]: https://webpack.github.io/
13
+ [brunch]: http://brunch.io/
14
+ [browserify]: http://browserify.org/
15
+
16
+ > ![](docs/screenshots/full.png)
17
+
18
+ ## Usage
19
+
20
+ Add to your `Gemfile`.
21
+
22
+ ```rb
23
+ gem 'npm-pipeline-rails'
24
+ ```
25
+
26
+ You may do a manual setup:
27
+
28
+ * Create a `package.json` with `start` and `build` commands.
29
+ * Add compiled assets to `.gitignore`.
30
+
31
+ Or an automated setup:
32
+
33
+ * Run `./bin/rails generate npm_pipeline:brunch` to add a sample integration with [Brunch]. ([info](docs/brunch.md))
34
+
35
+ ## Configuration
36
+
37
+ npm-pipeline-rails provides these configuration options:
38
+
39
+ ```rb
40
+ # These are defaults; in most cases, you don't need to configure anything.
41
+
42
+ Rails.application.configure do
43
+ # Command to install dependencies
44
+ config.npm.install = ['npm install']
45
+
46
+ # Command to build production
47
+ config.npm.build = ['npm run build']
48
+
49
+ # Command to start a file watcher
50
+ config.npm.watch = ['npm run start']
51
+
52
+ # The commands are arrays; you may add more commands as needed:
53
+ config.npm.watch = [
54
+ 'npm run webpack:start',
55
+ 'npm run brunch:start'
56
+ ]
57
+ end
58
+ ```
59
+
60
+ ## How it works
61
+
62
+ 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
+
64
+ #### In development
65
+
66
+ 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.
67
+
68
+ #### In production
69
+
70
+ When running `rake assets:precompile`, it will first run the `install` command then the `build` command.
71
+
72
+ ## Integration examples
73
+
74
+ * [Brunch](docs/brunch.md)
75
+ * more to come soon
76
+
77
+ ## Thanks
78
+
79
+ **npm-pipeline-rails** © 2016+, Rico Sta. Cruz. Released under the [MIT] License.<br>
80
+ Authored and maintained by Rico Sta. Cruz with help from contributors ([list][contributors]).
81
+
82
+ > [ricostacruz.com](http://ricostacruz.com) &nbsp;&middot;&nbsp;
83
+ > GitHub [@rstacruz](https://github.com/rstacruz) &nbsp;&middot;&nbsp;
84
+ > Twitter [@rstacruz](https://twitter.com/rstacruz)
85
+
86
+ [MIT]: http://mit-license.org/
87
+ [contributors]: http://github.com/rstacruz/npm-pipeline-rails/contributors
@@ -0,0 +1,91 @@
1
+ # Brunch example
2
+
3
+ Run `./bin/rails generate npm_pipeline:brunch`.
4
+
5
+ ## Manual setup
6
+
7
+ If you don't want to use the generator, here's what it does.
8
+
9
+ ### `brunch-config.js`
10
+
11
+ Set it up to watch source files in `app/brunch`, then put built files into `vendor/assets`.
12
+
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
+ ```
27
+
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
+ ```
49
+
50
+ ### `.gitignore`
51
+
52
+ Set it up to ignore Brunch's built files.
53
+
54
+ ```
55
+ /vendor/assets/stylesheets/brunch/
56
+ /vendor/assets/javascripts/brunch/
57
+ ```
58
+
59
+ ### `app/assets/stylesheets/application.css`
60
+
61
+ Set it up to include Brunch's built files. This will load from `vendor/assets/stylesheets`, as built by Brunch.
62
+
63
+ ```css
64
+ /*
65
+ *= require brunch/app
66
+ */
67
+ ```
68
+
69
+ ### `app/assets/javascripts/application.js`
70
+
71
+ Set it up to include Brunch's built files. This will load from `vendor/assets/javascripts`, as built by Brunch.
72
+
73
+ ```css
74
+ //= require brunch/app
75
+ ```
76
+
77
+ ### `app/brunch`
78
+
79
+ Put your source files into `app/brunch`. For instance:
80
+
81
+ * `app/brunch/example.css`
82
+
83
+ ```css
84
+ * { color: blue }
85
+ ```
86
+
87
+ * `app/brunch/example.js`
88
+
89
+ ```js
90
+ alert('it works!')
91
+ ```
Binary file
@@ -0,0 +1,16 @@
1
+ // See http://brunch.io for documentation.
2
+ module.exports = {
3
+ paths: {
4
+ watched: ['app/brunch'],
5
+ public: 'vendor/assets'
6
+ },
7
+
8
+ modules: {
9
+ wrapper: false
10
+ },
11
+
12
+ files: {
13
+ javascripts: {joinTo: 'javascripts/brunch/app.js'},
14
+ stylesheets: {joinTo: 'stylesheets/brunch/app.css'}
15
+ }
16
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "brunch-app",
3
+ "description": "Description",
4
+ "author": "Your Name",
5
+ "version": "0.1.0",
6
+ "scripts": {
7
+ "start": "brunch watch",
8
+ "build": "brunch build --production"
9
+ },
10
+ "dependencies": {},
11
+ "devDependencies": {
12
+ "brunch": "^2.5.1",
13
+ "javascript-brunch": "^2.0.0",
14
+ "css-brunch": "^2.0.0",
15
+ "auto-reload-brunch": "^2.0.0"
16
+ }
17
+ }
@@ -0,0 +1,41 @@
1
+ require 'rails/generators/base'
2
+
3
+ module NpmPipeline
4
+ module Generators
5
+ class BrunchGenerator < Rails::Generators::Base
6
+ desc 'Creates'
7
+ source_root File.expand_path('../brunch', __FILE__)
8
+
9
+ def create_package_json
10
+ template 'package.json', 'package.json'
11
+ end
12
+
13
+ def create_brunch_config
14
+ template 'brunch-config.js', 'brunch-config.js'
15
+ end
16
+
17
+ def update_assets
18
+ append_to_file 'app/assets/stylesheets/application.css',
19
+ "/*\n *= require brunch/app\n */\n"
20
+ append_to_file 'app/assets/javascripts/application.js',
21
+ "//= require brunch/app\n"
22
+ end
23
+
24
+ def create_sample_brunch_css
25
+ create_file 'app/brunch/example.css',
26
+ %(html:before { content: 'Brunch assets added successfully! Edit app/brunch/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_brunch_js
30
+ create_file 'app/brunch/example.js',
31
+ "alert('Brunch works!')"
32
+ end
33
+
34
+ def update_gitignore
35
+ append_to_file '.gitignore',
36
+ "/vendor/assets/stylesheets/brunch\n" +
37
+ "/vendor/assets/javascripts/brunch\n"
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,5 @@
1
+ require_relative './npm-pipeline-rails/railtie'
2
+ require_relative './npm-pipeline-rails/version'
3
+
4
+ module NpmPipelineRails
5
+ end
@@ -0,0 +1,46 @@
1
+ require 'rails'
2
+ require 'rails/railtie'
3
+
4
+ module NpmPipelineRails
5
+ module Utils
6
+ def do_system(commands)
7
+ [*commands].each do |cmd|
8
+ system cmd
9
+ exit $? unless $? == 0
10
+
11
+ end
12
+ end
13
+ end
14
+
15
+ class Railtie < ::Rails::Railtie
16
+ include ::NpmPipelineRails::Utils
17
+
18
+ config.npm = ActiveSupport::OrderedOptions.new
19
+
20
+ config.npm.build = ['npm run build']
21
+ config.npm.watch = ['npm run start']
22
+ config.npm.install = ['npm install']
23
+
24
+ rake_tasks do |app|
25
+ namespace :assets do
26
+ desc 'Build assets prerequisites using npm'
27
+ task :npm_build do
28
+ do_system app.config.npm.install
29
+ do_system app.config.npm.build
30
+ end
31
+
32
+ task(:precompile).enhance ['npm_build']
33
+ end
34
+ end
35
+
36
+ initializer 'npm_pipeline.watch' do |app|
37
+ if ::Rails.env.development? && ::Rails.const_defined?(:Server)
38
+ do_system app.config.npm.install
39
+ exit $? unless $? == 0
40
+ [*app.config.npm.watch].each do |cmd|
41
+ fork { do_system [cmd] }
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module NpmPipelineRails
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'npm-pipeline-rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'npm-pipeline-rails'
8
+ spec.version = NpmPipelineRails::VERSION
9
+ spec.authors = ['Rico Sta. Cruz']
10
+ spec.email = ['rstacruz@users.noreply.github.com']
11
+
12
+ spec.summary = 'Build your Rails assets with npm'
13
+ spec.description = '...'
14
+ spec.homepage = 'https://github.com/rstacruz/npm-pipeline-rails'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(example|test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_runtime_dependency 'railties', '~> 4.0'
23
+ spec.add_runtime_dependency 'sprockets', '~> 3.5'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.11'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'minitest', '~> 5.0'
28
+ spec.add_development_dependency 'rails', '~> 4.2'
29
+ end
metadata ADDED
@@ -0,0 +1,143 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: npm-pipeline-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Rico Sta. Cruz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sprockets
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '4.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '4.2'
97
+ description: "..."
98
+ email:
99
+ - rstacruz@users.noreply.github.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - HISTORY.md
107
+ - README.md
108
+ - docs/brunch.md
109
+ - docs/screenshots/build.png
110
+ - docs/screenshots/full.png
111
+ - docs/screenshots/server.png
112
+ - lib/generators/npm_pipeline/brunch/brunch-config.js
113
+ - lib/generators/npm_pipeline/brunch/package.json
114
+ - lib/generators/npm_pipeline/brunch_generator.rb
115
+ - lib/npm-pipeline-rails.rb
116
+ - lib/npm-pipeline-rails/railtie.rb
117
+ - lib/npm-pipeline-rails/version.rb
118
+ - npm-pipeline-rails.gemspec
119
+ homepage: https://github.com/rstacruz/npm-pipeline-rails
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.5.1
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Build your Rails assets with npm
143
+ test_files: []