hauler 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintrc +3 -3
- data/Makefile +3 -0
- data/hauler.gemspec +2 -0
- data/lib/generators/hauler/install_generator.rb +15 -0
- data/lib/generators/hauler/install_npm_generator.rb +43 -43
- data/lib/generators/hauler/templates/app/assets/index.js +2 -0
- data/lib/generators/hauler/templates/config/hauler.js +1 -1
- data/lib/generators/hauler/templates/eslintrc.json +3 -3
- data/lib/generators/hauler/templates/webpack.config.js +2 -1
- data/lib/hauler/helpers/hauler_helper.rb +1 -1
- data/lib/hauler/version.rb +1 -1
- data/lib/hauler.rb +2 -1
- data/make-package.js +14 -17
- data/package.json +12 -17
- data/{bin → src/bin}/dev-server.js +1 -1
- data/{bin → src/bin}/read-config.js +1 -1
- data/{bin → src/bin}/update-scripts.js +0 -0
- data/src/decls/hauler.js +2 -1
- data/src/decls/webpack.js +2 -1
- data/src/defaults/compiler_config_factory.js +2 -1
- data/src/defaults/dev_server_config_factory.js +1 -2
- data/src/defaults/project_config_factory.js +3 -2
- data/src/index.js +21 -11
- data/src/mount/index.js +110 -0
- data/src/provide/index.js +14 -0
- data/src/utils/extract_config.js +12 -2
- data/src/utils/index.js +1 -0
- data/src/utils/webpack.js +29 -0
- metadata +23 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95d2666219596dd577163e01feb6471168c7c798
|
4
|
+
data.tar.gz: 3ec18ffa805f662b66bac763b851082736060aa4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3ca47a8f7a010a4a217f8adffeb981010199d0ad6571bade84283591c36b5b1aea6ae354666af38ae3c172214a697042f14a880803a8678a126ef8e5663d299
|
7
|
+
data.tar.gz: 488afcfb9a812311313290ef974d7528f406ed6e5f82f4ed74086d39ba6041f0cce9dda279f3c9051da78361f536a603326b506e8b17b9d7aa953934ac43b37a
|
data/.eslintrc
CHANGED
data/Makefile
CHANGED
data/hauler.gemspec
CHANGED
@@ -13,6 +13,11 @@ module Hauler
|
|
13
13
|
template 'config/hauler.js'
|
14
14
|
end
|
15
15
|
|
16
|
+
def copy_example_assets
|
17
|
+
has_file = File.exist?(Rails.root.join('app', 'assets', 'index.js'))
|
18
|
+
template 'app/assets/index.js' if !has_file
|
19
|
+
end
|
20
|
+
|
16
21
|
def copy_eslintrc
|
17
22
|
template 'eslintrc.json', '.eslintrc.json'
|
18
23
|
end
|
@@ -26,6 +31,16 @@ module Hauler
|
|
26
31
|
template 'package.json' if !has_package_json
|
27
32
|
end
|
28
33
|
|
34
|
+
def add_node_modules_to_gitignore
|
35
|
+
has_gitignore = File.exist?(Rails.root.join('package.json'))
|
36
|
+
return if !has_gitignore
|
37
|
+
|
38
|
+
has_node_modules = IO.read('.gitignore').include? 'node_modules'
|
39
|
+
return if has_node_modules
|
40
|
+
|
41
|
+
inject_into_file '.gitignore', "/node_modules\n", before: /\Z/m
|
42
|
+
end
|
43
|
+
|
29
44
|
def copy_webpack_config
|
30
45
|
template 'webpack.config.js'
|
31
46
|
end
|
@@ -6,54 +6,39 @@ module Hauler
|
|
6
6
|
source_root File.expand_path('../templates', __FILE__)
|
7
7
|
|
8
8
|
NPM_DEV_DEPENDENCIES = <<-TXT.freeze
|
9
|
-
babel-core@6.
|
9
|
+
babel-core@6.13.2
|
10
10
|
babel-loader@6.2.4
|
11
11
|
babel-plugin-transform-class-properties@6.11.5
|
12
|
-
babel-preset-es2015@6.
|
13
|
-
babel-preset-
|
12
|
+
babel-preset-es2015@6.13.2
|
13
|
+
babel-preset-react-hmre
|
14
|
+
babel-preset-stage-2@6.13.0
|
14
15
|
css-loader@0.23.1
|
15
|
-
extract-text-webpack-plugin@
|
16
|
+
extract-text-webpack-plugin@2.0.0-beta.3
|
16
17
|
file-loader@0.9.0
|
17
|
-
hauler@0.
|
18
|
+
hauler@0.3.0
|
18
19
|
image-webpack-loader@2.0.0
|
19
20
|
immutable-devtools@0.0.7
|
20
21
|
style-loader@0.13.1
|
21
22
|
url-loader@0.5.7
|
22
|
-
webpack@1.
|
23
|
-
webpack-dev-server@1.
|
23
|
+
webpack@2.1.0-beta.20
|
24
|
+
webpack-dev-server@2.1.0-beta.0
|
24
25
|
TXT
|
25
26
|
|
26
|
-
|
27
|
-
babel-
|
28
|
-
|
29
|
-
eslint-config-airbnb@9.0.1
|
30
|
-
eslint-import-resolver-webpack@0.4.0
|
31
|
-
eslint-plugin-flow-vars@0.5.0
|
32
|
-
eslint-plugin-import@1.12.0
|
33
|
-
eslint-plugin-jsx-a11y@1.5.5
|
34
|
-
eslint-plugin-react@5.2.2
|
35
|
-
sass-lint@1.8.2
|
36
|
-
TXT
|
37
|
-
|
38
|
-
REACT_NPM_DEV_DEPENDENCIES = <<-TXT.freeze
|
39
|
-
babel-plugin-transform-react-constant-elements@6.9.1
|
40
|
-
babel-plugin-transform-react-inline-elements@6.8.0
|
41
|
-
babel-plugin-transform-react-remove-prop-types@0.2.8
|
42
|
-
babel-preset-react@6.11.1
|
43
|
-
react-hot-loader@2.0.0-alpha-4
|
44
|
-
redux-logger@2.6.1
|
27
|
+
NPM_DEPENDENCIES = <<-TXT.freeze
|
28
|
+
babel-polyfill@6.13.0
|
29
|
+
whatwg-fetch@1.0.0
|
45
30
|
TXT
|
46
31
|
|
47
32
|
REACT_NPM_DEPENDENCIES = <<-TXT.freeze
|
48
33
|
immutable@3.8.1
|
49
|
-
react@15.
|
50
|
-
react-dom@15.
|
34
|
+
react@15.3.0
|
35
|
+
react-dom@15.3.0
|
51
36
|
react-redux@4.4.5
|
52
37
|
react-router@2.6.1
|
53
38
|
react-router-redux@4.0.5
|
54
|
-
react-router-scroll@0.
|
39
|
+
react-router-scroll@0.3.1
|
55
40
|
redux@3.5.2
|
56
|
-
redux-immutable@3.0.
|
41
|
+
redux-immutable@3.0.7
|
57
42
|
redux-saga@0.11.0
|
58
43
|
reselect@2.5.3
|
59
44
|
TXT
|
@@ -63,23 +48,34 @@ module Hauler
|
|
63
48
|
sass-loader@4.0.0
|
64
49
|
TXT
|
65
50
|
|
66
|
-
|
67
|
-
babel-
|
68
|
-
|
51
|
+
LINTER_DEV_DEPENDENCES = <<-TXT.freeze
|
52
|
+
babel-eslint@6.1.2
|
53
|
+
eslint@3.3.1
|
54
|
+
eslint-config-airbnb@10.0.1
|
55
|
+
eslint-import-resolver-webpack@0.5.1
|
56
|
+
eslint-plugin-flowtype@2.7.1
|
57
|
+
eslint-plugin-import@1.13.0
|
58
|
+
eslint-plugin-jsx-a11y@2.1.0
|
59
|
+
eslint-plugin-react@6.1.1
|
60
|
+
sass-lint@1.8.2
|
69
61
|
TXT
|
70
62
|
|
71
|
-
|
72
|
-
|
73
|
-
|
63
|
+
REACT_NPM_DEV_DEPENDENCIES = <<-TXT.freeze
|
64
|
+
babel-plugin-transform-react-constant-elements@6.9.1
|
65
|
+
babel-plugin-transform-react-inline-elements@6.8.0
|
66
|
+
babel-plugin-transform-react-remove-prop-types@0.2.9
|
67
|
+
babel-preset-react@6.11.1
|
68
|
+
redux-logger@2.6.1
|
69
|
+
TXT
|
74
70
|
|
75
71
|
def install_dev_dependencies
|
76
72
|
puts 'Installing NPM dev dependencies...'
|
77
73
|
install_deps(NPM_DEV_DEPENDENCIES)
|
78
74
|
end
|
79
75
|
|
80
|
-
def
|
81
|
-
puts 'Installing
|
82
|
-
install_deps(
|
76
|
+
def install_dependencies
|
77
|
+
puts 'Installing NPM dependencies...'
|
78
|
+
install_deps(NPM_DEPENDENCIES, dev: false)
|
83
79
|
end
|
84
80
|
|
85
81
|
def install_react_dependencies
|
@@ -95,16 +91,20 @@ module Hauler
|
|
95
91
|
install_deps(SASS_NPM_DEV_DEPENDENCIES)
|
96
92
|
end
|
97
93
|
|
98
|
-
def
|
99
|
-
puts 'Installing NPM dependencies...'
|
100
|
-
install_deps(
|
94
|
+
def install_linter_dev_dependencies
|
95
|
+
puts 'Installing Linter NPM dev dependencies...'
|
96
|
+
install_deps(LINTER_DEV_DEPENDENCES)
|
97
|
+
end
|
98
|
+
|
99
|
+
def add_scripts_to_package
|
100
|
+
run('hauler-update-scripts')
|
101
101
|
end
|
102
102
|
|
103
103
|
private
|
104
104
|
|
105
105
|
def install_deps(list, dev: true)
|
106
106
|
flag = dev ? '--save-dev' : '--save'
|
107
|
-
|
107
|
+
run("npm install #{flag} #{list.gsub(/\s+/m, ' ')}")
|
108
108
|
end
|
109
109
|
end
|
110
110
|
end
|
@@ -4,11 +4,11 @@
|
|
4
4
|
],
|
5
5
|
"parser": "babel-eslint",
|
6
6
|
"plugins": [
|
7
|
-
"
|
7
|
+
"flowtype"
|
8
8
|
],
|
9
9
|
"rules": {
|
10
|
-
"
|
11
|
-
"
|
10
|
+
"flowtype/define-flow-type": 1,
|
11
|
+
"flowtype/use-flow-type": 1,
|
12
12
|
"max-len": [2, 140, 2]
|
13
13
|
},
|
14
14
|
"settings": {
|
@@ -1,6 +1,7 @@
|
|
1
1
|
|
2
|
+
const appName = '<%= Rails.application.class.parent_name.underscore %>';
|
2
3
|
const hauler = require('hauler');
|
3
4
|
const env = hauler.getEnvName();
|
4
5
|
|
5
|
-
const config = hauler.getCompilerConfig(env, __dirname);
|
6
|
+
const config = hauler.getCompilerConfig(env, __dirname, appName);
|
6
7
|
module.exports = config;
|
@@ -16,7 +16,7 @@ module Hauler
|
|
16
16
|
|
17
17
|
def hauler_webpack_config
|
18
18
|
return nil if !hauler_dev_server?
|
19
|
-
@hauler_webpack_config ||= JSON.parse(`hauler-read-config`)
|
19
|
+
@hauler_webpack_config ||= JSON.parse(`hauler-read-config #{Rails.root}`)
|
20
20
|
end
|
21
21
|
|
22
22
|
def hauler_entries_names
|
data/lib/hauler/version.rb
CHANGED
data/lib/hauler.rb
CHANGED
data/make-package.js
CHANGED
@@ -1,23 +1,20 @@
|
|
1
1
|
#!/usr/bin/env node --use_strict
|
2
2
|
|
3
3
|
const fs = require('fs');
|
4
|
-
const path = require('path');
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
5
|
+
fs.mkdir('dist', function () {
|
6
|
+
const pkg = Object.assign({}, require('./package.json'));
|
7
|
+
delete pkg.scripts;
|
8
|
+
Object.assign(pkg, {
|
9
|
+
main: 'index.js',
|
10
|
+
bin: {
|
11
|
+
'hauler-read-config': 'bin/read-config.js',
|
12
|
+
'hauler-server': 'bin/dev-server.js',
|
13
|
+
'hauler-update-scripts': 'bin/update-scripts.js'
|
14
|
+
}
|
15
|
+
});
|
15
16
|
|
16
|
-
fs.
|
17
|
-
|
18
|
-
|
19
|
-
fs.writeFileSync(
|
20
|
-
path.join('dist', binaryPath),
|
21
|
-
fs.readFileSync(binaryPath).toString()
|
22
|
-
);
|
17
|
+
fs.writeFileSync('dist/package.json', JSON.stringify(pkg, null, 2));
|
18
|
+
fs.writeFileSync('dist/LICENSE.txt', fs.readFileSync('./LICENSE.txt').toString());
|
19
|
+
fs.writeFileSync('dist/README.md', fs.readFileSync('./README.md').toString());
|
23
20
|
});
|
data/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "hauler",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.3.0",
|
4
4
|
"description": "NodeJS binary for the hauler gem",
|
5
5
|
"author": "Arturo Guzman @guzart",
|
6
6
|
"license": "MIT",
|
@@ -8,26 +8,26 @@
|
|
8
8
|
"type": "git",
|
9
9
|
"url": "https://github.com/guzart/hauler.git"
|
10
10
|
},
|
11
|
-
"main": "
|
11
|
+
"main": "src/index.js",
|
12
12
|
"bin": {
|
13
|
-
"hauler-read-config": "bin/read-config.js",
|
14
|
-
"hauler-server": "bin/dev-server.js",
|
15
|
-
"hauler-update-scripts": "bin/update-scripts.js"
|
13
|
+
"hauler-read-config": "src/bin/read-config.js",
|
14
|
+
"hauler-server": "src/bin/dev-server.js",
|
15
|
+
"hauler-update-scripts": "src/bin/update-scripts.js"
|
16
16
|
},
|
17
17
|
"scripts": {
|
18
|
-
"build": "npm-run-all clean compile
|
18
|
+
"build": "npm-run-all clean generate_package compile",
|
19
19
|
"clean": "rm -rf ./dist",
|
20
20
|
"compile": "./node_modules/babel-cli/bin/babel.js --out-dir=./dist --ignore=./decls,**/__tests__ ./src",
|
21
|
-
"dev": "npm-run-all
|
21
|
+
"dev": "npm-run-all generate_package watch",
|
22
22
|
"generate_package": "node make-package.js",
|
23
23
|
"test": "jest --verbose",
|
24
24
|
"watch": "./node_modules/babel-cli/bin/babel.js --watch=./src --ignore=./decls,**/__tests__ --out-dir=./dist"
|
25
25
|
},
|
26
26
|
"peerDependencies": {
|
27
|
-
"extract-text-webpack-plugin": "~
|
28
|
-
"webpack": "~
|
29
|
-
"webpack-dev-server": "~
|
30
|
-
"whatwg-fetch": "~
|
27
|
+
"extract-text-webpack-plugin": "~2.0",
|
28
|
+
"webpack": "~2.1",
|
29
|
+
"webpack-dev-server": "~2.1",
|
30
|
+
"whatwg-fetch": "~1.0"
|
31
31
|
},
|
32
32
|
"devDependencies": {
|
33
33
|
"babel-cli": "^6.11.4",
|
@@ -39,14 +39,9 @@
|
|
39
39
|
"babel-preset-es2015": "^6.9.0",
|
40
40
|
"babel-preset-stage-2": "^6.11.0",
|
41
41
|
"eslint": "^3.2.0",
|
42
|
-
"eslint-plugin-flow-vars": "^0.5.0",
|
43
42
|
"eslint-plugin-flowtype": "^2.4.0",
|
44
|
-
"extract-text-webpack-plugin": "^1.0.1",
|
45
43
|
"flow-bin": "^0.30.0",
|
46
44
|
"jest-cli": "^14.1.0",
|
47
|
-
"npm-run-all": "^2.3.0"
|
48
|
-
"webpack": "^1.13.1",
|
49
|
-
"webpack-dev-server": "^1.14.1",
|
50
|
-
"whatwg-fetch": "^1.0.0"
|
45
|
+
"npm-run-all": "^2.3.0"
|
51
46
|
}
|
52
47
|
}
|
File without changes
|
data/src/decls/hauler.js
CHANGED
@@ -6,7 +6,8 @@ export type HostInfo = {
|
|
6
6
|
};
|
7
7
|
|
8
8
|
export type ProjectConfig = {
|
9
|
-
|
9
|
+
appName?: string,
|
10
|
+
entries?: WebpackEntry,
|
10
11
|
javascriptLoader?: WebpackLoader,
|
11
12
|
sassLoader?: WebpackLoader,
|
12
13
|
fontLoader?: WebpackLoader,
|
data/src/decls/webpack.js
CHANGED
@@ -92,7 +92,8 @@ export type WebpackOutputConfig = {
|
|
92
92
|
crossOriginLoading?: false | 'anonymous' | 'use-credentials',
|
93
93
|
};
|
94
94
|
|
95
|
-
|
95
|
+
type SimpleWebpackEntry = string | Array<string>;
|
96
|
+
export type WebpackEntry = SimpleWebpackEntry | { [key: string]: SimpleWebpackEntry };
|
96
97
|
|
97
98
|
export type WebpackConfig = {
|
98
99
|
context?: string,
|
@@ -8,10 +8,11 @@ export default function defaultConfigFactory(env: string): WebpackConfig {
|
|
8
8
|
chunkFilename: '[name].[chunkhash].chunk.js',
|
9
9
|
},
|
10
10
|
resolve: {
|
11
|
-
|
11
|
+
modules: [
|
12
12
|
'~app/assets',
|
13
13
|
'~lib/assets',
|
14
14
|
],
|
15
|
+
extensions: ['.js', '.json', '.jsx']
|
15
16
|
},
|
16
17
|
devtool: '',
|
17
18
|
target: 'web',
|
@@ -7,12 +7,11 @@ export default function defaultConfigFactory() {
|
|
7
7
|
host: 'localhost',
|
8
8
|
port: 3001,
|
9
9
|
hot: true,
|
10
|
-
inline: true,
|
11
10
|
headers: { 'AccessControl-Allow-Origin': '*' },
|
12
11
|
stats: {
|
13
12
|
colors: true,
|
14
13
|
chunks: true,
|
15
|
-
chunkModules:
|
14
|
+
chunkModules: false,
|
16
15
|
timings: true,
|
17
16
|
},
|
18
17
|
};
|
@@ -11,15 +11,14 @@ function getPlugins(env: string) {
|
|
11
11
|
new webpack.ProvidePlugin({ fetch: 'exports?self.fetch!whatwg-fetch' }),
|
12
12
|
new webpack.DefinePlugin({ 'process.env': { NODE_ENV: JSON.stringify(env) } }),
|
13
13
|
new webpack.optimize.CommonsChunkPlugin({
|
14
|
-
name: 'vendor',
|
15
14
|
children: true,
|
16
15
|
minChunks: 2,
|
17
|
-
async: true,
|
18
16
|
}),
|
19
17
|
];
|
20
18
|
|
21
19
|
if (env === 'development') {
|
22
20
|
plugins = plugins.concat([
|
21
|
+
new webpack.HotModuleReplacementPlugin(),
|
23
22
|
new webpack.NoErrorsPlugin(),
|
24
23
|
]);
|
25
24
|
}
|
@@ -79,6 +78,8 @@ function configFactory(env: string) {
|
|
79
78
|
'style',
|
80
79
|
sassLoader.loader.replace('style!', '')
|
81
80
|
);
|
81
|
+
} else {
|
82
|
+
javascriptLoader.query.presets = javascriptLoader.query.presets.concat(['react-hmre']);
|
82
83
|
}
|
83
84
|
|
84
85
|
const appendPlugins = [];
|
data/src/index.js
CHANGED
@@ -21,23 +21,33 @@ function getConfigFactory(): ProjectConfigFactory {
|
|
21
21
|
};
|
22
22
|
}
|
23
23
|
|
24
|
-
export function getConfig(env: string, railsRoot
|
25
|
-
|
26
|
-
utils.setRailsRoot(railsRoot);
|
27
|
-
}
|
28
|
-
|
24
|
+
export function getConfig(env: string, railsRoot: string, appName: string) {
|
25
|
+
utils.setRailsRoot(railsRoot);
|
29
26
|
const configFactory = getConfigFactory();
|
30
|
-
|
27
|
+
const config = configFactory(env);
|
28
|
+
return Object.assign(config, { appName });
|
31
29
|
}
|
32
30
|
|
33
|
-
export function getDevServerConfig(
|
34
|
-
|
31
|
+
export function getDevServerConfig(
|
32
|
+
env: string, railsRoot: string, appName: string
|
33
|
+
): WebpackDevServerConfig {
|
34
|
+
const config = getConfig(env, railsRoot, appName);
|
35
35
|
return utils.extractDevServerConfig(config);
|
36
36
|
}
|
37
37
|
|
38
|
-
export function getCompilerConfig(
|
39
|
-
|
40
|
-
|
38
|
+
export function getCompilerConfig(
|
39
|
+
env: string, railsRoot: string, appName: string
|
40
|
+
): WebpackConfig {
|
41
|
+
const config = getConfig(env, railsRoot, appName);
|
42
|
+
const compilerConfig = utils.extractCompilerConfig(config);
|
43
|
+
if (env !== 'development') {
|
44
|
+
return compilerConfig;
|
45
|
+
}
|
46
|
+
|
47
|
+
const devServerConfig = utils.extractDevServerConfig(config);
|
48
|
+
return Object.assign(compilerConfig, {
|
49
|
+
entry: utils.makeHotReloadableEntries(compilerConfig.entry, devServerConfig.publicPath),
|
50
|
+
});
|
41
51
|
}
|
42
52
|
|
43
53
|
export { getEnvName } from './utils';
|
data/src/mount/index.js
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
// https://github.com/reactjs/react-rails/blob/v1.8.2/lib/assets/javascripts/react_ujs_mount.js
|
2
|
+
|
3
|
+
import React from 'react';
|
4
|
+
import ReactDOM from 'react-dom';
|
5
|
+
|
6
|
+
// jQuery is optional. Use it to support legacy browsers.
|
7
|
+
const $ = (typeof global.jQuery !== 'undefined') && global.jQuery;
|
8
|
+
const document = global.document;
|
9
|
+
|
10
|
+
// This attribute holds the name of component which should be mounted
|
11
|
+
// example: `data-react-class="MyApp.Items.EditForm"`
|
12
|
+
const CLASS_NAME_ATTR = 'data-react-class';
|
13
|
+
|
14
|
+
// This attribute holds JSON stringified props for initializing the component
|
15
|
+
// example: `data-react-props="{\"item\": { \"id\": 1, \"name\": \"My Item\"} }"`
|
16
|
+
const PROPS_ATTR = 'data-react-props';
|
17
|
+
|
18
|
+
// helper method for the mount and unmount methods to find the
|
19
|
+
// `data-react-class` DOM elements
|
20
|
+
function findDOMNodes(searchSelector) {
|
21
|
+
// we will use fully qualified paths as we do not bind the callbacks
|
22
|
+
var selector, parent;
|
23
|
+
|
24
|
+
switch (typeof searchSelector) {
|
25
|
+
case 'undefined':
|
26
|
+
selector = '[' + CLASS_NAME_ATTR + ']';
|
27
|
+
parent = document;
|
28
|
+
break;
|
29
|
+
case 'object':
|
30
|
+
selector = '[' + CLASS_NAME_ATTR + ']';
|
31
|
+
parent = searchSelector;
|
32
|
+
break;
|
33
|
+
case 'string':
|
34
|
+
selector = searchSelector + '[' + CLASS_NAME_ATTR + '], ' +
|
35
|
+
searchSelector + ' [' + CLASS_NAME_ATTR + ']';
|
36
|
+
parent = document;
|
37
|
+
break
|
38
|
+
default:
|
39
|
+
break;
|
40
|
+
}
|
41
|
+
|
42
|
+
if ($) {
|
43
|
+
return $(selector, parent);
|
44
|
+
} else {
|
45
|
+
return parent.querySelectorAll(selector);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
// Get the constructor for a className
|
50
|
+
function getConstructor(className) {
|
51
|
+
// Assume className is simple and can be found at top-level (window).
|
52
|
+
// Fallback to eval to handle cases like 'My.React.ComponentName'.
|
53
|
+
// Also, try to gracefully import Babel 6 style default exports
|
54
|
+
//
|
55
|
+
var constructor;
|
56
|
+
|
57
|
+
// Try to access the class globally first
|
58
|
+
constructor = global[className];
|
59
|
+
|
60
|
+
// If that didn't work, try eval
|
61
|
+
if (!constructor) {
|
62
|
+
constructor = eval.call(global, className);
|
63
|
+
}
|
64
|
+
|
65
|
+
// Lastly, if there is a default attribute try that
|
66
|
+
if (constructor && constructor.default) {
|
67
|
+
constructor = constructor.default;
|
68
|
+
}
|
69
|
+
|
70
|
+
return constructor;
|
71
|
+
}
|
72
|
+
|
73
|
+
// Within `searchSelector`, find nodes which should have React components
|
74
|
+
// inside them, and mount them with their props.
|
75
|
+
export function mountComponents(searchSelector) {
|
76
|
+
var nodes = findDOMNodes(searchSelector);
|
77
|
+
|
78
|
+
for (var i = 0; i < nodes.length; ++i) {
|
79
|
+
var node = nodes[i];
|
80
|
+
var className = node.getAttribute(CLASS_NAME_ATTR);
|
81
|
+
var constructor = getConstructor(className);
|
82
|
+
var propsJson = node.getAttribute(PROPS_ATTR);
|
83
|
+
var props = propsJson && JSON.parse(propsJson);
|
84
|
+
|
85
|
+
if (typeof(constructor) === "undefined") {
|
86
|
+
var message = "Cannot find component: '" + className + "'"
|
87
|
+
if (console && console.log) {
|
88
|
+
console.log("%c[react-rails] %c" + message + " for element", "font-weight: bold", "", node)
|
89
|
+
}
|
90
|
+
var error = new Error(message + ". Make sure your component is globally available to render.")
|
91
|
+
throw error
|
92
|
+
} else {
|
93
|
+
ReactDOM.render(React.createElement(constructor, props), node);
|
94
|
+
}
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
98
|
+
// Within `searchSelector`, find nodes which have React components
|
99
|
+
// inside them, and unmount those components.
|
100
|
+
export function unmountComponents(searchSelector) {
|
101
|
+
var nodes = findDOMNodes(searchSelector);
|
102
|
+
|
103
|
+
for (var i = 0; i < nodes.length; ++i) {
|
104
|
+
var node = nodes[i];
|
105
|
+
|
106
|
+
ReactDOM.unmountComponentAtNode(node);
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
export default mountComponents;
|
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
export default function provide(namespace: string, value: Object, target = global) {
|
3
|
+
const parts = namespace.split('.');
|
4
|
+
let cur = target;
|
5
|
+
for (let part; parts.length && (part = parts.shift());) {
|
6
|
+
if (!parts.length && value !== undefined) {
|
7
|
+
cur[part] = value;
|
8
|
+
} else if (cur[part]) {
|
9
|
+
cur = cur[part];
|
10
|
+
} else {
|
11
|
+
cur = cur[part] = {};
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
data/src/utils/extract_config.js
CHANGED
@@ -22,11 +22,21 @@ function extractLoaders(config: ProjectConfig): Array<WebpackLoader> {
|
|
22
22
|
return baseLoaders.concat(customLoaders);
|
23
23
|
}
|
24
24
|
|
25
|
+
function extractResolveAlias(config: ProjectConfig): Object {
|
26
|
+
const resolveConfig = config.compiler && config.compiler.resolve || {};
|
27
|
+
const alias = resolveValuesRailsPath(resolveConfig.alias);
|
28
|
+
if (config.appName != null) {
|
29
|
+
Object.assign(alias, { [config.appName]: railsPath('~app/assets/') });
|
30
|
+
}
|
31
|
+
|
32
|
+
return alias;
|
33
|
+
}
|
34
|
+
|
25
35
|
function extractResolve(config: ProjectConfig): WebpackResolveConfig {
|
26
36
|
const resolveConfig = config.compiler && config.compiler.resolve || {};
|
27
37
|
return Object.assign(resolveConfig, {
|
28
|
-
alias:
|
29
|
-
|
38
|
+
alias: extractResolveAlias(config),
|
39
|
+
modules: railsPath(resolveConfig.modules),
|
30
40
|
});
|
31
41
|
}
|
32
42
|
|
data/src/utils/index.js
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
import url from 'url';
|
2
|
+
|
3
|
+
function getHotEntryPoint(publicPath: string): string {
|
4
|
+
const uri = url.parse(publicPath);
|
5
|
+
uri.pathname = '';
|
6
|
+
return `webpack-dev-server/client?${uri.format()}`;
|
7
|
+
}
|
8
|
+
|
9
|
+
export function makeHotReloadableEntries(entries: WebpackEntry, publicPath: string): WebpackEntry {
|
10
|
+
if (typeof entries === 'string') {
|
11
|
+
return [getHotEntryPoint(publicPath), entries];
|
12
|
+
}
|
13
|
+
|
14
|
+
if (Array.isArray(entries)) {
|
15
|
+
return [getHotEntryPoint(publicPath)].concat(entries);
|
16
|
+
}
|
17
|
+
|
18
|
+
if (entries.constructor === Object) {
|
19
|
+
const output = {};
|
20
|
+
Object.keys(entries).forEach(key => {
|
21
|
+
let hotEntry = makeHotReloadableEntries(entries[key], publicPath);
|
22
|
+
output[key] = hotEntry;
|
23
|
+
});
|
24
|
+
|
25
|
+
return output;
|
26
|
+
}
|
27
|
+
|
28
|
+
return entries;
|
29
|
+
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hauler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arturo Guzman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: react-rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.8'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.8'
|
55
69
|
description: 'Railtie to generate the files needed to use webpack as a replacement
|
56
70
|
of sprockets
|
57
71
|
|
@@ -75,13 +89,11 @@ files:
|
|
75
89
|
- README.md
|
76
90
|
- Rakefile
|
77
91
|
- bin/console
|
78
|
-
- bin/dev-server.js
|
79
|
-
- bin/read-config.js
|
80
92
|
- bin/setup
|
81
|
-
- bin/update-scripts.js
|
82
93
|
- hauler.gemspec
|
83
94
|
- lib/generators/hauler/install_generator.rb
|
84
95
|
- lib/generators/hauler/install_npm_generator.rb
|
96
|
+
- lib/generators/hauler/templates/app/assets/index.js
|
85
97
|
- lib/generators/hauler/templates/config/hauler.js
|
86
98
|
- lib/generators/hauler/templates/config/initializers/hauler.rb
|
87
99
|
- lib/generators/hauler/templates/eslintrc.json
|
@@ -94,12 +106,17 @@ files:
|
|
94
106
|
- lib/hauler/version.rb
|
95
107
|
- make-package.js
|
96
108
|
- package.json
|
109
|
+
- src/bin/dev-server.js
|
110
|
+
- src/bin/read-config.js
|
111
|
+
- src/bin/update-scripts.js
|
97
112
|
- src/decls/hauler.js
|
98
113
|
- src/decls/webpack.js
|
99
114
|
- src/defaults/compiler_config_factory.js
|
100
115
|
- src/defaults/dev_server_config_factory.js
|
101
116
|
- src/defaults/project_config_factory.js
|
102
117
|
- src/index.js
|
118
|
+
- src/mount/index.js
|
119
|
+
- src/provide/index.js
|
103
120
|
- src/utils/__tests__/extract_config-test.js
|
104
121
|
- src/utils/__tests__/merge_config-test.js
|
105
122
|
- src/utils/__tests__/path-test.js
|
@@ -108,6 +125,7 @@ files:
|
|
108
125
|
- src/utils/merge_config.js
|
109
126
|
- src/utils/misc.js
|
110
127
|
- src/utils/path.js
|
128
|
+
- src/utils/webpack.js
|
111
129
|
- wallaby.js
|
112
130
|
homepage: https://github.com/guzart/hauler
|
113
131
|
licenses:
|