react_on_rails 2.0.0.beta.1 → 2.0.0.beta.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/.dockerignore +2 -0
- data/.eslintignore +7 -0
- data/.eslintrc +19 -0
- data/.gitignore +28 -0
- data/.jscsrc +27 -0
- data/.npmignore +20 -0
- data/.rspec +2 -0
- data/.rubocop.yml +70 -0
- data/.scss-lint.yml +205 -0
- data/.travis.yml +43 -0
- data/CHANGELOG.md +34 -0
- data/Dockerfile_tests +12 -0
- data/Gemfile +40 -0
- data/README.md +365 -0
- data/Rakefile +5 -0
- data/app/helpers/react_on_rails_helper.rb +215 -0
- data/docker-compose.yml +11 -0
- data/docs/LICENSE +21 -0
- data/docs/additional_reading/heroku_deployment.md +23 -0
- data/docs/additional_reading/manual_installation.md +118 -0
- data/docs/additional_reading/node_dependencies_and_npm.md +29 -0
- data/docs/additional_reading/optional_configuration.md +33 -0
- data/docs/additional_reading/react-and-redux.md +36 -0
- data/docs/additional_reading/react_router.md +45 -0
- data/docs/additional_reading/server_rendering_tips.md +11 -0
- data/docs/additional_reading/tips.md +10 -0
- data/docs/additional_reading/webpack.md +46 -0
- data/docs/code_of_conduct.md +13 -0
- data/docs/coding-style/linters.md +64 -0
- data/docs/coding-style/style.md +42 -0
- data/docs/contributing.md +157 -0
- data/docs/generator_testing.md +20 -0
- data/docs/releasing.md +29 -0
- data/lib/generators/USAGE +99 -0
- data/lib/generators/react_on_rails/base_generator.rb +191 -0
- data/lib/generators/react_on_rails/bootstrap_generator.rb +89 -0
- data/lib/generators/react_on_rails/dev_tests_generator.rb +39 -0
- data/lib/generators/react_on_rails/generator_helper.rb +50 -0
- data/lib/generators/react_on_rails/heroku_deployment_generator.rb +30 -0
- data/lib/generators/react_on_rails/install_generator.rb +99 -0
- data/lib/generators/react_on_rails/js_linters_generator.rb +19 -0
- data/lib/generators/react_on_rails/react_no_redux_generator.rb +40 -0
- data/lib/generators/react_on_rails/react_with_redux_generator.rb +51 -0
- data/lib/generators/react_on_rails/ruby_linters_generator.rb +33 -0
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev.tt +4 -0
- data/lib/generators/react_on_rails/templates/base/base/REACT_ON_RAILS.md +16 -0
- data/lib/generators/react_on_rails/templates/base/base/app/controllers/hello_world_controller.rb +5 -0
- data/lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt +4 -0
- data/lib/generators/react_on_rails/templates/base/base/client/.babelrc +3 -0
- data/lib/generators/react_on_rails/templates/base/base/client/REACT_ON_RAILS_CLIENT_README.md +3 -0
- data/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/startup/clientRegistration.jsx.tt +5 -0
- data/lib/generators/react_on_rails/templates/base/base/client/index.jade +15 -0
- data/lib/generators/react_on_rails/templates/base/base/client/package.json.tt +104 -0
- data/lib/generators/react_on_rails/templates/base/base/client/server.js +64 -0
- data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.base.config.js.tt +62 -0
- data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.hot.config.js.tt +69 -0
- data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.rails.config.js +42 -0
- data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +26 -0
- data/lib/generators/react_on_rails/templates/base/base/lib/tasks/assets.rake.tt +26 -0
- data/lib/generators/react_on_rails/templates/base/base/lib/tasks/linters.rake.tt +88 -0
- data/lib/generators/react_on_rails/templates/base/base/package.json +31 -0
- data/lib/generators/react_on_rails/templates/base/server_rendering/client/app/bundles/HelloWorld/startup/serverRegistration.jsx +4 -0
- data/lib/generators/react_on_rails/templates/base/server_rendering/client/webpack.server.rails.config.js +39 -0
- data/lib/generators/react_on_rails/templates/bootstrap/app/assets/stylesheets/_bootstrap-custom.scss +63 -0
- data/lib/generators/react_on_rails/templates/bootstrap/client/assets/stylesheets/_post-bootstrap.scss +10 -0
- data/lib/generators/react_on_rails/templates/bootstrap/client/assets/stylesheets/_pre-bootstrap.scss +8 -0
- data/lib/generators/react_on_rails/templates/bootstrap/client/assets/stylesheets/_react-on-rails-sass-helper.scss +19 -0
- data/lib/generators/react_on_rails/templates/bootstrap/client/bootstrap-sass.config.js +89 -0
- data/lib/generators/react_on_rails/templates/dev_tests/.rspec +2 -0
- data/lib/generators/react_on_rails/templates/dev_tests/spec/features/hello_world_spec.rb +25 -0
- data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +57 -0
- data/lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb +21 -0
- data/lib/generators/react_on_rails/templates/dev_tests/spec/spec_helper.rb +95 -0
- data/lib/generators/react_on_rails/templates/heroku_deployment/.buildpacks +2 -0
- data/lib/generators/react_on_rails/templates/heroku_deployment/Procfile +1 -0
- data/lib/generators/react_on_rails/templates/heroku_deployment/config/puma.rb +15 -0
- data/lib/generators/react_on_rails/templates/js_linters/client/.eslintignore +1 -0
- data/lib/generators/react_on_rails/templates/js_linters/client/.eslintrc +48 -0
- data/lib/generators/react_on_rails/templates/js_linters/client/.jscsrc +18 -0
- data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx +39 -0
- data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/containers/HelloWorld.jsx +33 -0
- data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx.tt +8 -0
- data/lib/generators/react_on_rails/templates/no_redux/server_rendering/client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx +8 -0
- data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/actions/helloWorldActionCreators.jsx +8 -0
- data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx +48 -0
- data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/constants/helloWorldConstants.jsx +8 -0
- data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/containers/HelloWorld.jsx +43 -0
- data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/reducers/helloWorldReducer.jsx +19 -0
- data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/reducers/index.jsx +14 -0
- data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx.tt +19 -0
- data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/store/helloWorldStore.jsx +35 -0
- data/lib/generators/react_on_rails/templates/redux/base/client/app/lib/middlewares/loggerMiddleware.js +20 -0
- data/lib/generators/react_on_rails/templates/redux/server_rendering/client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx +19 -0
- data/lib/generators/react_on_rails/templates/ruby_linters/.rubocop.yml +26 -0
- data/lib/generators/react_on_rails/templates/ruby_linters/.scss-lint.yml +205 -0
- data/lib/generators/react_on_rails/templates/ruby_linters/lib/tasks/brakeman.rake +17 -0
- data/lib/generators/react_on_rails/templates/ruby_linters/lib/tasks/ci.rake +33 -0
- data/lib/generators/react_on_rails/templates/ruby_linters/ruby-lint.yml +20 -0
- data/lib/react_on_rails.rb +6 -0
- data/lib/react_on_rails/configuration.rb +60 -0
- data/lib/react_on_rails/engine.rb +7 -0
- data/lib/react_on_rails/prerender_error.rb +31 -0
- data/lib/react_on_rails/server_rendering_pool.rb +110 -0
- data/lib/react_on_rails/version.rb +3 -0
- data/package.json +76 -0
- data/rakelib/docker.rake +33 -0
- data/rakelib/dummy_apps.rake +20 -0
- data/rakelib/example_type.rb +160 -0
- data/rakelib/examples.rake +103 -0
- data/rakelib/examples_config.yml +19 -0
- data/rakelib/lint.rake +37 -0
- data/rakelib/node_package.rake +11 -0
- data/rakelib/run_rspec.rake +65 -0
- data/rakelib/task_helpers.rb +44 -0
- data/react_on_rails.gemspec +31 -0
- data/ruby-lint.yml +24 -0
- metadata +119 -2
@@ -0,0 +1,64 @@
|
|
1
|
+
// This file is used by the webpack HMR dev server to load your component without using Rails
|
2
|
+
// It should simply match routes to basic HTML or jade files that render your component
|
3
|
+
/* eslint-disable no-console, func-names, no-var */
|
4
|
+
var webpack = require('webpack');
|
5
|
+
var WebpackDevServer = require('webpack-dev-server');
|
6
|
+
var jade = require('jade');
|
7
|
+
var config = require('./webpack.client.hot.config');
|
8
|
+
|
9
|
+
var server = new WebpackDevServer(webpack(config), {
|
10
|
+
publicPath: config.output.publicPath,
|
11
|
+
hot: true,
|
12
|
+
historyApiFallback: true,
|
13
|
+
stats: {
|
14
|
+
colors: true,
|
15
|
+
hash: false,
|
16
|
+
version: false,
|
17
|
+
chunks: false,
|
18
|
+
children: false,
|
19
|
+
},
|
20
|
+
});
|
21
|
+
|
22
|
+
// The following code is commented out because the HelloWorld example
|
23
|
+
// does not use any asynchronous functionality. It is meant to serve
|
24
|
+
// as an example of how one might implement an API in express for their
|
25
|
+
// webpack dev server
|
26
|
+
// Note, it would be necessary to run `npm i --save body-parser sleep` for
|
27
|
+
// the following to work:
|
28
|
+
// var bodyParser = require('body-parser');
|
29
|
+
// var sleep = require('sleep');
|
30
|
+
// See tutorial for example of using AJAX:
|
31
|
+
// https://github.com/shakacode/react-webpack-rails-tutorial
|
32
|
+
|
33
|
+
// server.app.use(bodyParser.json(null));
|
34
|
+
// server.app.use(bodyParser.urlencoded({extended: true}));
|
35
|
+
// server.app.get('/hello_world.json', function(req, res) {
|
36
|
+
// res.setHeader('Content-Type', 'application/json');
|
37
|
+
// res.send(JSON.stringify(name));
|
38
|
+
// });
|
39
|
+
|
40
|
+
// server.app.post('/hello_world.json', function(req, res) {
|
41
|
+
// console.log('Processing name: %j', req.body.name);
|
42
|
+
// console.log('(shhhh...napping 1 seconds)');
|
43
|
+
// sleep.sleep(1);
|
44
|
+
// console.log('Just got done with nap!');
|
45
|
+
// name = req.body.name;
|
46
|
+
// res.setHeader('Content-Type', 'application/json');
|
47
|
+
// res.send(JSON.stringify(req.body.name));
|
48
|
+
// });
|
49
|
+
|
50
|
+
var initialName = 'Stranger';
|
51
|
+
|
52
|
+
server.app.use('/', function(req, res) {
|
53
|
+
var locals = {
|
54
|
+
props: JSON.stringify(initialName),
|
55
|
+
};
|
56
|
+
var layout = process.cwd() + '/index.jade';
|
57
|
+
var html = jade.compileFile(layout, { pretty: true })(locals);
|
58
|
+
res.send(html);
|
59
|
+
});
|
60
|
+
|
61
|
+
server.listen(4000, 'localhost', function(err) {
|
62
|
+
if (err) console.log(err);
|
63
|
+
console.log('Listening at localhost:4000...');
|
64
|
+
});
|
data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.base.config.js.tt
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
// Common client-side webpack configuration used by webpack.hot.config and webpack.rails.config.
|
2
|
+
|
3
|
+
const webpack = require('webpack');
|
4
|
+
const path = require('path');
|
5
|
+
|
6
|
+
const devBuild = process.env.NODE_ENV !== 'production';
|
7
|
+
const nodeEnv = devBuild ? 'development' : 'production';
|
8
|
+
|
9
|
+
module.exports = {
|
10
|
+
|
11
|
+
// the project dir
|
12
|
+
context: __dirname,
|
13
|
+
entry: {
|
14
|
+
|
15
|
+
// See use of 'vendor' in the CommonsChunkPlugin inclusion below.
|
16
|
+
vendor: [
|
17
|
+
'babel-polyfill',
|
18
|
+
'jquery',
|
19
|
+
],
|
20
|
+
|
21
|
+
// This will contain the app entry points defined by webpack.hot.config and webpack.rails.config
|
22
|
+
app: [
|
23
|
+
'./app/bundles/HelloWorld/startup/clientRegistration',
|
24
|
+
],
|
25
|
+
},
|
26
|
+
resolve: {
|
27
|
+
extensions: ['', '.webpack.js', '.web.js', '.js', '.jsx', '.scss', '.css', 'config.js'],
|
28
|
+
alias: {
|
29
|
+
lib: path.join(process.cwd(), 'app', 'lib'),
|
30
|
+
},
|
31
|
+
},
|
32
|
+
plugins: [
|
33
|
+
|
34
|
+
new webpack.DefinePlugin({
|
35
|
+
'process.env': {
|
36
|
+
NODE_ENV: JSON.stringify(nodeEnv),
|
37
|
+
},
|
38
|
+
}),
|
39
|
+
|
40
|
+
// https://webpack.github.io/docs/list-of-plugins.html#2-explicit-vendor-chunk
|
41
|
+
new webpack.optimize.CommonsChunkPlugin({
|
42
|
+
|
43
|
+
// This name 'vendor' ties into the entry definition
|
44
|
+
name: 'vendor',
|
45
|
+
|
46
|
+
// We don't want the default vendor.js name
|
47
|
+
filename: 'vendor-bundle.js',
|
48
|
+
|
49
|
+
// Passing Infinity just creates the commons chunk, but moves no modules into it.
|
50
|
+
// In other words, we only put what's in the vendor entry definition in vendor-bundle.js
|
51
|
+
minChunks: Infinity,
|
52
|
+
}),
|
53
|
+
],
|
54
|
+
module: {
|
55
|
+
loaders: [
|
56
|
+
|
57
|
+
// Not all apps require jQuery. Many Rails apps do, such as those using TurboLinks or bootstrap js
|
58
|
+
{test: require.resolve('jquery'), loader: 'expose?jQuery'},
|
59
|
+
{test: require.resolve('jquery'), loader: 'expose?$'},
|
60
|
+
],
|
61
|
+
},
|
62
|
+
};
|
@@ -0,0 +1,69 @@
|
|
1
|
+
// This config file setups up the Webpack Dev Server: https://webpack.github.io/docs/webpack-dev-server.html
|
2
|
+
// Run like this:
|
3
|
+
// cd client && node server.js
|
4
|
+
|
5
|
+
const webpack = require('webpack');
|
6
|
+
const path = require('path');
|
7
|
+
const config = require('./webpack.client.base.config');
|
8
|
+
|
9
|
+
config.entry.app.push(
|
10
|
+
|
11
|
+
// Webpack dev server
|
12
|
+
'webpack-dev-server/client?http://localhost:4000',
|
13
|
+
'webpack/hot/dev-server'<%- unless options.skip_bootstrap? -%>,
|
14
|
+
|
15
|
+
// See: https://github.com/shakacode/bootstrap-sass-loader
|
16
|
+
// We're using the bootstrap-sass loader.
|
17
|
+
'bootstrap-sass!./bootstrap-sass.config.js'
|
18
|
+
<%- end -%>
|
19
|
+
|
20
|
+
);
|
21
|
+
|
22
|
+
config.output = {
|
23
|
+
|
24
|
+
// this file is served directly by webpack
|
25
|
+
filename: '[name]-bundle.js',
|
26
|
+
path: __dirname,
|
27
|
+
};
|
28
|
+
config.plugins.unshift(new webpack.HotModuleReplacementPlugin());
|
29
|
+
config.devtool = 'eval-source-map';
|
30
|
+
|
31
|
+
// All the styling loaders only apply to hot-reload, not rails
|
32
|
+
config.module.loaders.push(
|
33
|
+
{
|
34
|
+
test: /\.jsx?$/,
|
35
|
+
loader: 'babel',
|
36
|
+
exclude: /node_modules/,
|
37
|
+
query: {
|
38
|
+
plugins: [
|
39
|
+
[
|
40
|
+
'react-transform',
|
41
|
+
{
|
42
|
+
transforms: [
|
43
|
+
{
|
44
|
+
transform: 'react-transform-hmr',
|
45
|
+
imports: ['react'],
|
46
|
+
locals: ['module'],
|
47
|
+
},
|
48
|
+
],
|
49
|
+
},
|
50
|
+
],
|
51
|
+
],
|
52
|
+
},
|
53
|
+
},
|
54
|
+
{test: /\.css$/, loader: 'style-loader!css-loader'},
|
55
|
+
{
|
56
|
+
test: /\.scss$/,
|
57
|
+
loader: 'style!css!sass?outputStyle=expanded&imagePath=/assets/images&includePaths[]=' +
|
58
|
+
path.resolve(__dirname, './assets/stylesheets'),
|
59
|
+
},
|
60
|
+
|
61
|
+
// The url-loader uses DataUrls. The file-loader emits files.
|
62
|
+
{test: /\.woff$/, loader: 'url-loader?limit=10000&mimetype=application/font-woff'},
|
63
|
+
{test: /\.woff2$/, loader: 'url-loader?limit=10000&mimetype=application/font-woff'},
|
64
|
+
{test: /\.ttf$/, loader: 'file-loader'},
|
65
|
+
{test: /\.eot$/, loader: 'file-loader'},
|
66
|
+
{test: /\.svg$/, loader: 'file-loader'}
|
67
|
+
);
|
68
|
+
|
69
|
+
module.exports = config;
|
@@ -0,0 +1,42 @@
|
|
1
|
+
// Run like this:
|
2
|
+
// cd client && npm run build:dev
|
3
|
+
// Note that Foreman (Procfile.dev) has also been configured to take care of this.
|
4
|
+
|
5
|
+
// NOTE: All style sheets handled by the asset pipeline in rails
|
6
|
+
|
7
|
+
const webpack = require('webpack');
|
8
|
+
const config = require('./webpack.client.base.config');
|
9
|
+
const devBuild = process.env.NODE_ENV !== 'production';
|
10
|
+
|
11
|
+
config.output = {
|
12
|
+
filename: '[name]-bundle.js',
|
13
|
+
path: '../app/assets/javascripts/generated',
|
14
|
+
};
|
15
|
+
|
16
|
+
// You can add entry points specific to rails here
|
17
|
+
// The es5-shim/sham is for capybara testing
|
18
|
+
config.entry.vendor.unshift(
|
19
|
+
'es5-shim/es5-shim',
|
20
|
+
'es5-shim/es5-sham'
|
21
|
+
);
|
22
|
+
|
23
|
+
config.entry.vendor.push('jquery-ujs');
|
24
|
+
|
25
|
+
// See webpack.common.config for adding modules common to both the webpack dev server and rails
|
26
|
+
|
27
|
+
config.module.loaders.push(
|
28
|
+
{test: /\.jsx?$/, loader: 'babel-loader', exclude: /node_modules/},
|
29
|
+
{test: require.resolve('react'), loader: 'imports?shim=es5-shim/es5-shim&sham=es5-shim/es5-sham'}
|
30
|
+
);
|
31
|
+
|
32
|
+
module.exports = config;
|
33
|
+
|
34
|
+
if (devBuild) {
|
35
|
+
console.log('Webpack dev build for Rails'); // eslint-disable-line no-console
|
36
|
+
module.exports.devtool = 'eval-source-map';
|
37
|
+
} else {
|
38
|
+
config.plugins.push(
|
39
|
+
new webpack.optimize.DedupePlugin()
|
40
|
+
);
|
41
|
+
console.log('Webpack production build for Rails'); // eslint-disable-line no-console
|
42
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Shown below are the defaults for configuration
|
2
|
+
ReactOnRails.configure do |config|
|
3
|
+
# Client bundles are configured in application.js
|
4
|
+
|
5
|
+
# Server rendering:
|
6
|
+
# Server bundle is a single file for all server rendering of components.
|
7
|
+
config.server_bundle_js_file = "app/assets/javascripts/generated/server-bundle.js"
|
8
|
+
# increase if you're on JRuby
|
9
|
+
config.server_renderer_pool_size = 1
|
10
|
+
# seconds
|
11
|
+
config.server_renderer_timeout = 20
|
12
|
+
# If set to true, this forces Rails to reload the server bundle if it is modified
|
13
|
+
config.development_mode = Rails.env.development?
|
14
|
+
# For server rendering. This can be set to false so that server side messages are discarded.
|
15
|
+
# Default is true. Be cautious about turning this off.
|
16
|
+
config.replay_console = true
|
17
|
+
# Default is true. Logs server rendering messags to Rails.logger.info
|
18
|
+
config.logging_on_server = true
|
19
|
+
|
20
|
+
# The following options can be overriden by passing to the helper method:
|
21
|
+
|
22
|
+
# Default is false
|
23
|
+
config.prerender = false
|
24
|
+
# Default is true for development, off otherwise
|
25
|
+
config.trace = Rails.env.development?
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# lib/tasks/assets.rake
|
2
|
+
# The webpack task must run before assets:environment task.
|
3
|
+
# Otherwise Sprockets cannot find the files that webpack produces.
|
4
|
+
# This is the secret sauce for how a Heroku deployment knows to create the webpack generated JavaScript files.
|
5
|
+
Rake::Task["assets:precompile"]
|
6
|
+
.clear_prerequisites
|
7
|
+
.enhance(["assets:compile_environment"])
|
8
|
+
|
9
|
+
namespace :assets do
|
10
|
+
# In this task, set prerequisites for the assets:precompile task
|
11
|
+
task compile_environment: :webpack do
|
12
|
+
Rake::Task["assets:environment"].invoke
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Compile assets with webpack"
|
16
|
+
task :webpack do
|
17
|
+
sh "cd client && npm run build:client"
|
18
|
+
<%- if options[:server_rendering] -%>
|
19
|
+
sh "cd client && npm run build:server"
|
20
|
+
<%- end -%>
|
21
|
+
end
|
22
|
+
|
23
|
+
task :clobber do
|
24
|
+
rm_r Dir.glob(Rails.root.join("app/assets/javascripts/generated/*"))
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
if %w(development test).include? Rails.env
|
2
|
+
namespace :lint do
|
3
|
+
<%- if options.ruby_linters? -%>
|
4
|
+
# This fails: https://github.com/bbatsov/rubocop/issues/1840
|
5
|
+
# RuboCop::RakeTask.new
|
6
|
+
# require "rubocop/rake_task"
|
7
|
+
desc "Run Rubocop lint in shell. Specify option fix to auto-correct (and don't have uncommitted files!)."
|
8
|
+
task :rubocop, [:fix] => [] do |_t, args|
|
9
|
+
def to_bool(str)
|
10
|
+
return true if str =~ (/^(true|t|yes|y|1)$/i)
|
11
|
+
return false if str.blank? || str =~ (/^(false|f|no|n|0)$/i)
|
12
|
+
fail ArgumentError, "invalid value for Boolean: \"#{str}\""
|
13
|
+
end
|
14
|
+
|
15
|
+
fix = (args.fix == "fix") || to_bool(args.fix)
|
16
|
+
cmd = "rubocop -S -D#{fix ? ' -a' : ''} ."
|
17
|
+
puts "Running Rubocop Linters via `#{cmd}`#{fix ? ' auto-correct is turned on!' : ''}"
|
18
|
+
sh cmd
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Run ruby-lint as shell"
|
22
|
+
task :ruby do
|
23
|
+
cmd = "ruby-lint app config spec lib"
|
24
|
+
puts "Running ruby-lint Linters via `#{cmd}`"
|
25
|
+
sh cmd
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "See docs for task 'scss_lint'"
|
29
|
+
task :scss do
|
30
|
+
begin
|
31
|
+
require 'scss_lint/rake_task'
|
32
|
+
SCSSLint::RakeTask.new do |t|
|
33
|
+
t.files = ["app/assets/stylesheets/", "client/assets/stylesheets/"]
|
34
|
+
end
|
35
|
+
Rake::Task[:scss_lint].invoke
|
36
|
+
rescue LoadError
|
37
|
+
puts "** add gem 'scss_lint' to your Gemfile for scss linting."
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# desc "haml_lint"
|
42
|
+
# task :haml_lint do
|
43
|
+
# require 'haml_lint/rake_task'
|
44
|
+
|
45
|
+
# HamlLint::RakeTask.new do |t|
|
46
|
+
# t.files = ["app/views"]
|
47
|
+
# end
|
48
|
+
# end
|
49
|
+
|
50
|
+
# desc "See docs for task 'slim_lint'"
|
51
|
+
# task slim: :slim_lint
|
52
|
+
# SlimLint::RakeTask.new do |t|
|
53
|
+
# t.files = ["app/views"]
|
54
|
+
# end
|
55
|
+
|
56
|
+
<%- end -%>
|
57
|
+
<%- unless options.skip_js_linters? -%>
|
58
|
+
desc "eslint"
|
59
|
+
task :eslint do
|
60
|
+
cmd = "cd client && npm run eslint . -- --ext .jsx,.js"
|
61
|
+
puts "Running eslint via `#{cmd}`"
|
62
|
+
sh cmd
|
63
|
+
end
|
64
|
+
|
65
|
+
desc "jscs"
|
66
|
+
task :jscs do
|
67
|
+
cmd = "cd client && npm run jscs ."
|
68
|
+
puts "Running jscs via `#{cmd}`"
|
69
|
+
sh cmd
|
70
|
+
end
|
71
|
+
|
72
|
+
desc "JS Linting"
|
73
|
+
task js: [:eslint, :jscs] do
|
74
|
+
puts "Completed running all JavaScript Linters"
|
75
|
+
end
|
76
|
+
<%- end -%>
|
77
|
+
|
78
|
+
<%- enabled_linters = [] -%>
|
79
|
+
<%- enabled_linters << %i(rubocop ruby scss) if options.ruby_linters? -%>
|
80
|
+
<%- enabled_linters << %i(js) unless options.skip_js_linters? -%>
|
81
|
+
task lint: <%= enabled_linters.flatten %> do
|
82
|
+
puts "Completed all linting"
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
desc "Runs all linters. Run `rake -D lint` to see all available lint options"
|
87
|
+
task lint: ["lint:lint"]
|
88
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
{
|
2
|
+
"name": "react-webpack-rails-tutorial",
|
3
|
+
"version": "1.1.1",
|
4
|
+
"description": "Built using the react_on_rails generator. Allows you to run npm install from root.",
|
5
|
+
"main": "server.js",
|
6
|
+
"engines": {
|
7
|
+
"node": "4.2.0",
|
8
|
+
"npm": "3.3.6"
|
9
|
+
},
|
10
|
+
"scripts": {
|
11
|
+
"postinstall": "cd client && npm install",
|
12
|
+
"test": "rspec && (cd client && npm run lint)"
|
13
|
+
},
|
14
|
+
"repository": {
|
15
|
+
"type": "git",
|
16
|
+
"url": "https://github.com/shakacode/react-webpack-rails-tutorial.git"
|
17
|
+
},
|
18
|
+
"keywords": [
|
19
|
+
"react",
|
20
|
+
"tutorial",
|
21
|
+
"comment",
|
22
|
+
"example"
|
23
|
+
],
|
24
|
+
"author": "justin808",
|
25
|
+
"license": "MIT",
|
26
|
+
"bugs": {
|
27
|
+
"url": "https://github.com/shakacode/react-webpack-rails-tutorial/issues"
|
28
|
+
},
|
29
|
+
"homepage": "https://github.com/shakacode/react-webpack-rails-tutorial",
|
30
|
+
"dependencies": {}
|
31
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
// Webpack configuration for server bundle
|
2
|
+
|
3
|
+
const webpack = require('webpack');
|
4
|
+
const path = require('path');
|
5
|
+
|
6
|
+
const devBuild = process.env.NODE_ENV !== 'production';
|
7
|
+
const nodeEnv = devBuild ? 'development' : 'production';
|
8
|
+
|
9
|
+
module.exports = {
|
10
|
+
|
11
|
+
// the project dir
|
12
|
+
context: __dirname,
|
13
|
+
entry: [
|
14
|
+
'babel-polyfill',
|
15
|
+
'./app/bundles/HelloWorld/startup/serverRegistration'
|
16
|
+
],
|
17
|
+
output: {
|
18
|
+
filename: 'server-bundle.js',
|
19
|
+
path: '../app/assets/javascripts/generated',
|
20
|
+
},
|
21
|
+
resolve: {
|
22
|
+
extensions: ['', '.webpack.js', '.web.js', '.js', '.jsx', 'config.js'],
|
23
|
+
alias: {
|
24
|
+
lib: path.join(process.cwd(), 'app', 'lib'),
|
25
|
+
},
|
26
|
+
},
|
27
|
+
plugins: [
|
28
|
+
new webpack.DefinePlugin({
|
29
|
+
'process.env': {
|
30
|
+
NODE_ENV: JSON.stringify('production'),
|
31
|
+
},
|
32
|
+
}),
|
33
|
+
],
|
34
|
+
module: {
|
35
|
+
loaders: [
|
36
|
+
{test: /\.jsx?$/, loader: 'babel-loader', exclude: /node_modules/},
|
37
|
+
],
|
38
|
+
},
|
39
|
+
};
|