railspack 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +16 -7
- data/lib/railspack/cli.rb +47 -1
- data/lib/railspack/templates/babelrc.js +1 -1
- data/lib/railspack/templates/index.js +6 -4
- data/lib/railspack/templates/{package.json → package.json.erb} +6 -8
- data/lib/railspack/templates/webpack.js +2 -4
- data/lib/railspack/version.rb +1 -1
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f7a3251194a5d83fe9264cba0e6eaea153920e7
|
4
|
+
data.tar.gz: ef9878cccb304fe06c3f79382f1d72658e58edad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3991414754154b63b61f10a320eb1c63898e32a785eec40e25319d0be912a19c137783d92ffe177b8e758f64ddcdd05f4f1dc0ac6fce579303ecc70982417e8
|
7
|
+
data.tar.gz: ccd1fd44d31c9ca6dc05a07894e66782ea662c2e1fb37f07ceafad581bce7fe805e7aafe242f37f5e6c785115c8403f10058393825768c926734e326937c5b2b
|
data/README.md
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
# Railspack
|
2
2
|
|
3
|
-
|
3
|
+
A CLI tool that assists in getting [Webpack](https://webpack.github.io/) setup
|
4
|
+
in your [Rails](http://rubyonrails.org/) application.
|
5
|
+
|
6
|
+
## Prerequisites
|
7
|
+
|
8
|
+
Make sure that you have `node` installed
|
9
|
+
|
10
|
+
The gem will install just fine without node, but you won't be able to
|
11
|
+
install any of dependencies listed in your new `package.json` file without
|
12
|
+
`node` and `npm`
|
4
13
|
|
5
14
|
## Installation
|
6
15
|
|
@@ -15,16 +24,16 @@ $ gem install railspack
|
|
15
24
|
1. Go to the root directory of your Rails project.
|
16
25
|
2. Run `railspack generate`
|
17
26
|
|
18
|
-
|
27
|
+
Make sure that you run `npm install` after running the `railspack generate`
|
28
|
+
command. This will install all the dependencies defined in the `package.json`
|
29
|
+
file.
|
19
30
|
|
20
|
-
|
21
|
-
|
22
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
31
|
+
Take a look at the [Generated Files Guide](docs/generated_files) page to see
|
32
|
+
a full description of all the files that are generated.
|
23
33
|
|
24
34
|
## Contributing
|
25
35
|
|
26
|
-
|
27
|
-
|
36
|
+
Please check out the [Contributing Guide](docs/contributing)
|
28
37
|
|
29
38
|
## License
|
30
39
|
|
data/lib/railspack/cli.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'thor'
|
2
|
+
require 'erubis'
|
3
|
+
require 'pathname'
|
2
4
|
|
3
5
|
module Railspack
|
4
6
|
class CLI < Thor
|
@@ -10,12 +12,56 @@ module Railspack
|
|
10
12
|
|
11
13
|
desc "generate", "Generate all webpack files"
|
12
14
|
def generate
|
15
|
+
if !npm_available?
|
16
|
+
puts "NPM not installed"
|
17
|
+
return
|
18
|
+
end
|
19
|
+
|
20
|
+
build_package_json
|
13
21
|
copy_file("index.js", "frontend/index.js")
|
14
22
|
copy_file("registerComponent.js", "frontend/registerComponent.js")
|
15
23
|
copy_file("react_helper.rb", "app/helpers/react_helper.rb")
|
16
|
-
copy_file("package.json", "package.json")
|
17
24
|
copy_file("babelrc.js", ".babelrc")
|
18
25
|
copy_file("webpack.js", "webpack.config.babel.js")
|
26
|
+
|
27
|
+
puts "Running `npm install`"
|
28
|
+
exec("npm install")
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def npm_available?
|
34
|
+
output = `which npm`
|
35
|
+
!output.include? "not found"
|
36
|
+
end
|
37
|
+
|
38
|
+
def get_git_username
|
39
|
+
username = `git config user.name`.strip
|
40
|
+
end
|
41
|
+
|
42
|
+
def get_project_name
|
43
|
+
directory_path = Pathname.new(FileUtils.pwd)
|
44
|
+
directory_path.basename
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_template_from_file(template_name)
|
48
|
+
template_path = File.join(File.dirname(__FILE__), 'templates', template_name)
|
49
|
+
file = File.open(template_path, "rb")
|
50
|
+
contents = file.read
|
51
|
+
end
|
52
|
+
|
53
|
+
def render_template(template_name, locals)
|
54
|
+
contents = get_template_from_file(template_name)
|
55
|
+
Erubis::Eruby.new(contents).result(locals)
|
56
|
+
end
|
57
|
+
|
58
|
+
def build_package_json
|
59
|
+
project_name = get_project_name
|
60
|
+
author_name = get_git_username
|
61
|
+
|
62
|
+
locals = { application_name: project_name, author_name: author_name }
|
63
|
+
contents = render_template('package.json.erb', locals)
|
64
|
+
create_file('package.json', contents)
|
19
65
|
end
|
20
66
|
end
|
21
67
|
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
import React from 'react'
|
2
2
|
import ReactDOM from 'react-dom'
|
3
3
|
|
4
|
-
import { registerComponent } from '
|
4
|
+
import { registerComponent } from 'registerComponent'
|
5
5
|
|
6
6
|
// Register any components that you want to call in your Rails views
|
7
7
|
// using the react_component view_helper
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
|
9
|
+
const domReadyEvent = (typeof TurboLinks !== 'undefined') ? 'turbolinks:load' : 'DOMContentLoaded'
|
10
|
+
document.addEventListener(domReadyEvent, () => {
|
11
|
+
// registerComponent(OhHai, 'oh-hai'));
|
12
|
+
}
|
@@ -1,28 +1,26 @@
|
|
1
1
|
{
|
2
|
-
"name": "
|
2
|
+
"name": "<%= application_name %>",
|
3
3
|
"version": "1.0.0",
|
4
|
-
"description": "
|
4
|
+
"description": "<%= application_name %>",
|
5
5
|
"main": "index.js",
|
6
|
-
"author": "
|
6
|
+
"author": "<%= author_name %>",
|
7
|
+
|
7
8
|
"scripts": {
|
8
9
|
"start-dev": "webpack -wc --config webpack.config.babel.js",
|
9
10
|
"postinstall": "webpack --config webpack.config.babel.js"
|
10
11
|
},
|
12
|
+
|
11
13
|
"dependencies": {
|
12
14
|
"babel-core": "latest",
|
13
15
|
"babel-loader": "latest",
|
14
16
|
"babel-preset-es2015": "latest",
|
15
17
|
"babel-preset-react": "latest",
|
16
18
|
"babel-preset-stage-0": "latest",
|
17
|
-
"classnames": "latest",
|
18
|
-
"lodash": "latest",
|
19
|
-
"moment": "latest",
|
20
19
|
"react": "latest",
|
21
|
-
"react-addons-css-transition-group": "latest",
|
22
20
|
"react-dom": "latest",
|
23
|
-
"react-input-slider": "latest",
|
24
21
|
"webpack": "latest"
|
25
22
|
},
|
23
|
+
|
26
24
|
"devDependencies": {
|
27
25
|
"webpack-dev-server": "latest"
|
28
26
|
}
|
@@ -2,14 +2,12 @@ import path from 'path'
|
|
2
2
|
import webpack from 'webpack'
|
3
3
|
|
4
4
|
module.exports = {
|
5
|
-
context: __dirname,
|
6
|
-
|
7
5
|
entry: {
|
8
|
-
app: path.join(__dirname, '
|
6
|
+
app: path.join(__dirname, 'frontend', 'index.js')
|
9
7
|
},
|
10
8
|
|
11
9
|
output: {
|
12
|
-
path: path.join(__dirname, 'assets', 'javascripts'),
|
10
|
+
path: path.join(__dirname, 'app', 'assets', 'javascripts'),
|
13
11
|
filename: 'frontend.js'
|
14
12
|
},
|
15
13
|
|
data/lib/railspack/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: railspack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jdmorlan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: erubis
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,7 +95,7 @@ files:
|
|
81
95
|
- lib/railspack/cli.rb
|
82
96
|
- lib/railspack/templates/babelrc.js
|
83
97
|
- lib/railspack/templates/index.js
|
84
|
-
- lib/railspack/templates/package.json
|
98
|
+
- lib/railspack/templates/package.json.erb
|
85
99
|
- lib/railspack/templates/react_helper.rb
|
86
100
|
- lib/railspack/templates/registerComponent.js
|
87
101
|
- lib/railspack/templates/webpack.js
|