hauler 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/.babelrc +1 -0
- data/.eslintrc +5 -1
- data/.gitignore +1 -0
- data/.nvmrc +1 -0
- data/Makefile +6 -1
- data/bin/dev-server.js +6 -4
- data/bin/read-config.js +15 -0
- data/bin/update-scripts.js +1 -1
- data/lib/generators/hauler/install_generator.rb +5 -1
- data/lib/generators/hauler/install_npm_generator.rb +1 -0
- data/lib/generators/hauler/templates/config/hauler.js +9 -5
- data/lib/generators/hauler/templates/config/initializers/hauler.rb +1 -0
- data/lib/generators/hauler/templates/eslintrc.json +1 -3
- data/lib/generators/hauler/templates/webpack.config.js +4 -3
- data/lib/hauler/helpers/hauler_helper.rb +76 -0
- data/lib/hauler/railtie.rb +11 -18
- data/lib/hauler/version.rb +6 -1
- data/lib/hauler.rb +3 -0
- data/make-package.js +11 -1
- data/package.json +24 -9
- data/src/decls/hauler.js +7 -0
- data/src/decls/webpack.js +16 -11
- data/src/defaults/compiler_config_factory.js +5 -96
- data/src/defaults/dev_server_config_factory.js +3 -4
- data/src/defaults/project_config_factory.js +109 -0
- data/src/index.js +25 -104
- data/src/utils/__tests__/extract_config-test.js +132 -0
- data/src/utils/__tests__/merge_config-test.js +75 -0
- data/src/utils/__tests__/path-test.js +26 -0
- data/src/utils/extract_config.js +103 -0
- data/src/utils/index.js +6 -0
- data/src/utils/merge_config.js +34 -0
- data/src/utils/misc.js +61 -0
- data/src/utils/path.js +73 -0
- data/wallaby.js +20 -0
- metadata +16 -4
- data/lib/hauler/asset_tag_helper.rb +0 -27
- data/src/utils.js +0 -103
data/src/utils/misc.js
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
// @flow
|
2
|
+
|
3
|
+
export function getEnvName(): string {
|
4
|
+
return String(process.env.RAILS_ENV || process.env.NODE_ENV || 'development');
|
5
|
+
}
|
6
|
+
|
7
|
+
export function compact<A>(list: Array<?A>): Array<A> {
|
8
|
+
const output = [];
|
9
|
+
list.forEach(item => {
|
10
|
+
if (item != null) {
|
11
|
+
output.push(item);
|
12
|
+
}
|
13
|
+
});
|
14
|
+
|
15
|
+
return output;
|
16
|
+
}
|
17
|
+
|
18
|
+
export function merge<A: Hash, B: Hash>(a?: A, b?: B): A & B {
|
19
|
+
return Object.assign({}, a, b);
|
20
|
+
}
|
21
|
+
|
22
|
+
export function deepMerge<A: Hash, B: Hash>(a?: A, b?: B): A & B {
|
23
|
+
const output = Object.assign({}, a, b);
|
24
|
+
if (a == null || b == null) {
|
25
|
+
return output;
|
26
|
+
}
|
27
|
+
|
28
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
29
|
+
return b;
|
30
|
+
}
|
31
|
+
|
32
|
+
const validB = b;
|
33
|
+
const keysB = Object.keys(validB);
|
34
|
+
keysB.forEach(keyB => {
|
35
|
+
const valueA = output[keyB];
|
36
|
+
const valueB = validB[keyB];
|
37
|
+
if (valueB === undefined) {
|
38
|
+
return;
|
39
|
+
}
|
40
|
+
|
41
|
+
// TODO: valueB null should overwrite valueA
|
42
|
+
if (valueA instanceof Object && valueB instanceof Object) {
|
43
|
+
Object.assign(output, { [keyB]: deepMerge(valueA, valueB) });
|
44
|
+
return;
|
45
|
+
}
|
46
|
+
|
47
|
+
Object.assign(output, { [keyB]: valueB });
|
48
|
+
});
|
49
|
+
|
50
|
+
return output;
|
51
|
+
}
|
52
|
+
|
53
|
+
export function omit(keys: Array<string>, hash: Hash) {
|
54
|
+
const output = {};
|
55
|
+
Object.keys(hash).forEach((key) => {
|
56
|
+
if (keys.indexOf(key) === -1) {
|
57
|
+
output[key] = hash[key];
|
58
|
+
}
|
59
|
+
});
|
60
|
+
return output;
|
61
|
+
}
|
data/src/utils/path.js
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
// @flow
|
2
|
+
|
3
|
+
let railsRoot = process.cwd();
|
4
|
+
|
5
|
+
export function setRailsRoot(newRailsRoot: string) {
|
6
|
+
railsRoot = newRailsRoot;
|
7
|
+
}
|
8
|
+
|
9
|
+
export function pathJoin(...pieces: Array<?string>): string {
|
10
|
+
const output = [];
|
11
|
+
if (pieces[0]) {
|
12
|
+
const firstPiece = pieces[0].replace(/\s+|[\s\/]+$/g, '');
|
13
|
+
output.push(firstPiece);
|
14
|
+
}
|
15
|
+
|
16
|
+
pieces.slice(1).forEach(piece => {
|
17
|
+
if (piece == null) {
|
18
|
+
return;
|
19
|
+
}
|
20
|
+
|
21
|
+
const cleanPiece = piece.replace(/^[\s\/]+|[\/\s]+$/g, '');
|
22
|
+
output.push(cleanPiece);
|
23
|
+
});
|
24
|
+
|
25
|
+
return output.join('/');
|
26
|
+
}
|
27
|
+
|
28
|
+
export function preparePublicPath(publicPath: ?string): string {
|
29
|
+
if (publicPath == null) {
|
30
|
+
return '';
|
31
|
+
}
|
32
|
+
|
33
|
+
return publicPath.replace(/^\/|\/$/g, '');
|
34
|
+
}
|
35
|
+
|
36
|
+
export function getHostname(hostInfo: HostInfo): string {
|
37
|
+
if ([80, 443].indexOf(hostInfo.port) === -1) {
|
38
|
+
return `${hostInfo.host}:${hostInfo.port}`;
|
39
|
+
}
|
40
|
+
|
41
|
+
return hostInfo.host;
|
42
|
+
}
|
43
|
+
|
44
|
+
export function formatPublicPath(publicPath: ?string, hostInfo: HostInfo): string {
|
45
|
+
if (publicPath && publicPath.indexOf('//') !== -1) {
|
46
|
+
return publicPath;
|
47
|
+
}
|
48
|
+
|
49
|
+
const protocol = hostInfo.port === 443 ? 'https' : 'http';
|
50
|
+
const host = getHostname(hostInfo);
|
51
|
+
const pathname = preparePublicPath(publicPath);
|
52
|
+
return `${protocol}://${host}/${pathname}/`;
|
53
|
+
}
|
54
|
+
|
55
|
+
export function railsPath(value: any): any {
|
56
|
+
if (Array.isArray(value)) {
|
57
|
+
return value.map(item => railsPath(item));
|
58
|
+
}
|
59
|
+
|
60
|
+
if (value instanceof Object) {
|
61
|
+
const output = {};
|
62
|
+
Object.keys(value).forEach((key) => {
|
63
|
+
output[key] = railsPath(value[key]);
|
64
|
+
});
|
65
|
+
return output;
|
66
|
+
}
|
67
|
+
|
68
|
+
if (!/^~/.test(value)) {
|
69
|
+
return value;
|
70
|
+
}
|
71
|
+
|
72
|
+
return pathJoin(railsRoot, value.replace(/^~/, ''));
|
73
|
+
}
|
data/wallaby.js
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module.exports = function (wallaby) {
|
2
|
+
return {
|
3
|
+
files: ['src/**/*.js', '!src/**/*-test.js'],
|
4
|
+
|
5
|
+
tests: ['src/**/*-test.js'],
|
6
|
+
|
7
|
+
compilers: {
|
8
|
+
'src/**/*.js': wallaby.compilers.babel()
|
9
|
+
},
|
10
|
+
|
11
|
+
env: {
|
12
|
+
type: 'node',
|
13
|
+
runner: 'node'
|
14
|
+
},
|
15
|
+
|
16
|
+
testFramework: 'jest',
|
17
|
+
|
18
|
+
debug: true,
|
19
|
+
};
|
20
|
+
};
|
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.2.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-07
|
11
|
+
date: 2016-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- ".eslintrc"
|
67
67
|
- ".flowconfig"
|
68
68
|
- ".gitignore"
|
69
|
+
- ".nvmrc"
|
69
70
|
- ".rubocop.yml"
|
70
71
|
- ".travis.yml"
|
71
72
|
- Gemfile
|
@@ -75,18 +76,20 @@ files:
|
|
75
76
|
- Rakefile
|
76
77
|
- bin/console
|
77
78
|
- bin/dev-server.js
|
79
|
+
- bin/read-config.js
|
78
80
|
- bin/setup
|
79
81
|
- bin/update-scripts.js
|
80
82
|
- hauler.gemspec
|
81
83
|
- lib/generators/hauler/install_generator.rb
|
82
84
|
- lib/generators/hauler/install_npm_generator.rb
|
83
85
|
- lib/generators/hauler/templates/config/hauler.js
|
86
|
+
- lib/generators/hauler/templates/config/initializers/hauler.rb
|
84
87
|
- lib/generators/hauler/templates/eslintrc.json
|
85
88
|
- lib/generators/hauler/templates/package.json
|
86
89
|
- lib/generators/hauler/templates/sass-lint.yml
|
87
90
|
- lib/generators/hauler/templates/webpack.config.js
|
88
91
|
- lib/hauler.rb
|
89
|
-
- lib/hauler/
|
92
|
+
- lib/hauler/helpers/hauler_helper.rb
|
90
93
|
- lib/hauler/railtie.rb
|
91
94
|
- lib/hauler/version.rb
|
92
95
|
- make-package.js
|
@@ -95,8 +98,17 @@ files:
|
|
95
98
|
- src/decls/webpack.js
|
96
99
|
- src/defaults/compiler_config_factory.js
|
97
100
|
- src/defaults/dev_server_config_factory.js
|
101
|
+
- src/defaults/project_config_factory.js
|
98
102
|
- src/index.js
|
99
|
-
- src/utils.js
|
103
|
+
- src/utils/__tests__/extract_config-test.js
|
104
|
+
- src/utils/__tests__/merge_config-test.js
|
105
|
+
- src/utils/__tests__/path-test.js
|
106
|
+
- src/utils/extract_config.js
|
107
|
+
- src/utils/index.js
|
108
|
+
- src/utils/merge_config.js
|
109
|
+
- src/utils/misc.js
|
110
|
+
- src/utils/path.js
|
111
|
+
- wallaby.js
|
100
112
|
homepage: https://github.com/guzart/hauler
|
101
113
|
licenses:
|
102
114
|
- MIT
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'active_support/concern'
|
2
|
-
require 'action_view/helpers'
|
3
|
-
|
4
|
-
module Hauler
|
5
|
-
#:nodoc:
|
6
|
-
module AssetTagHelper
|
7
|
-
extend ::ActiveSupport::Concern
|
8
|
-
|
9
|
-
include ::ActionView::Helpers
|
10
|
-
|
11
|
-
included do
|
12
|
-
def hauler_javascript_include_tag(*sources)
|
13
|
-
if Rails.application.config.hauler.dev_server
|
14
|
-
# TODO: Get this from the configuration
|
15
|
-
return javascript_include_tag('http://localhost:3001/assets/' + sources.first + '.js')
|
16
|
-
end
|
17
|
-
|
18
|
-
javascript_include_tag(*sources)
|
19
|
-
end
|
20
|
-
|
21
|
-
def hauler_stylesheet_link_tag(*sources)
|
22
|
-
return nil if Rails.application.config.hauler.dev_server
|
23
|
-
stylesheet_link_tag(*sources)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
data/src/utils.js
DELETED
@@ -1,103 +0,0 @@
|
|
1
|
-
// @flow
|
2
|
-
export type Hash = {[name: string]: any};
|
3
|
-
|
4
|
-
const railsRoot = process.cwd();
|
5
|
-
|
6
|
-
function pathJoin(...pieces: Array<?string>): string {
|
7
|
-
const firstPiece = (pieces[0] || '').replace(/\/$/, '');
|
8
|
-
const output = [firstPiece];
|
9
|
-
pieces.slice(1).forEach(piece => {
|
10
|
-
if (piece == null) {
|
11
|
-
return;
|
12
|
-
}
|
13
|
-
|
14
|
-
const cleanPiece = piece.replace(/^\/|\/$/g, '');
|
15
|
-
output.push(cleanPiece);
|
16
|
-
});
|
17
|
-
|
18
|
-
return output.join('/');
|
19
|
-
}
|
20
|
-
|
21
|
-
function railsPath(value: any): any {
|
22
|
-
if (Array.isArray(value)) {
|
23
|
-
return value.map(item => railsPath(item));
|
24
|
-
}
|
25
|
-
|
26
|
-
if (value instanceof Object) {
|
27
|
-
const output = {};
|
28
|
-
Object.keys(value).forEach((key) => {
|
29
|
-
output[key] = railsPath(value[key]);
|
30
|
-
});
|
31
|
-
return output;
|
32
|
-
}
|
33
|
-
|
34
|
-
if (!/^~/.test(value)) {
|
35
|
-
return value;
|
36
|
-
}
|
37
|
-
|
38
|
-
return pathJoin(railsRoot, value.replace(/^~/, ''));
|
39
|
-
}
|
40
|
-
|
41
|
-
function compact<A>(list: Array<?A>): Array<A> {
|
42
|
-
const output = [];
|
43
|
-
list.forEach(item => {
|
44
|
-
if (item != null) {
|
45
|
-
output.push(item);
|
46
|
-
}
|
47
|
-
});
|
48
|
-
|
49
|
-
return output;
|
50
|
-
}
|
51
|
-
|
52
|
-
function merge<A: Hash, B: Hash>(a?: A, b?: B): A & B {
|
53
|
-
return Object.assign({}, a, b);
|
54
|
-
}
|
55
|
-
|
56
|
-
function deepMerge<A: Hash, B: Hash>(a?: A, b?: B): A & B {
|
57
|
-
const output = Object.assign({}, a, b);
|
58
|
-
if (a == null || b == null) {
|
59
|
-
return output;
|
60
|
-
}
|
61
|
-
|
62
|
-
if (Array.isArray(a) && Array.isArray(b)) {
|
63
|
-
return b;
|
64
|
-
}
|
65
|
-
|
66
|
-
const validB = b;
|
67
|
-
const keysB = Object.keys(validB);
|
68
|
-
keysB.forEach(keyB => {
|
69
|
-
const valueA = output[keyB];
|
70
|
-
const valueB = validB[keyB];
|
71
|
-
if (valueB === undefined) {
|
72
|
-
return;
|
73
|
-
}
|
74
|
-
|
75
|
-
if (valueA instanceof Object && valueB instanceof Object) {
|
76
|
-
Object.assign(output, { [keyB]: deepMerge(valueA, valueB) });
|
77
|
-
return;
|
78
|
-
}
|
79
|
-
|
80
|
-
Object.assign(output, { [keyB]: valueB });
|
81
|
-
});
|
82
|
-
|
83
|
-
return output;
|
84
|
-
}
|
85
|
-
|
86
|
-
function omit(keys: Array<string>, hash: Hash) {
|
87
|
-
const output = {};
|
88
|
-
Object.keys(hash).forEach((key) => {
|
89
|
-
if (keys.indexOf(key) === -1) {
|
90
|
-
output[key] = hash[key];
|
91
|
-
}
|
92
|
-
});
|
93
|
-
return output;
|
94
|
-
}
|
95
|
-
|
96
|
-
module.exports = {
|
97
|
-
pathJoin,
|
98
|
-
railsPath,
|
99
|
-
compact,
|
100
|
-
merge,
|
101
|
-
deepMerge,
|
102
|
-
omit,
|
103
|
-
};
|