hauler 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 517e3c307e0c965ff5d4d8db2ed055cb4e1c39a4
4
- data.tar.gz: 864053fb64d3c840c4eea0b276dab19282eed481
3
+ metadata.gz: 44c97c03d5cd92496e95c6114b6b41b87bbf4d2f
4
+ data.tar.gz: ec2bfd1a32429b15d41d61d971e9665cc3604834
5
5
  SHA512:
6
- metadata.gz: 7a3c900c022d9b185d912b9b69e087a2b81bd29352c36af60b6e94c3b9eb1a8fd8c69d05f214ca8d94421c6acd7221e9dada5f4b21b388d5837da9a53645d93a
7
- data.tar.gz: f75794386bfcc518f0323d74c513f9527ded971b2d409c71a464eabbc41cfc68cc51a4700f726b1a46491dfc3764b3a41600a1a7b182a8c8af8c1f3c6bdbe531
6
+ metadata.gz: 36aed3fdde813b4acc9f3d414f04ab227406eec3dc77de06555f80e982f6a3d67ba5ce4a7116b3372a53ede0c88c3b4da234622d84696cd5bca11bd6f566b716
7
+ data.tar.gz: 01e66bba70893eef6eae9d74c8611fce337670135e5bd6c7e1776533c509b3a983db4e35547d744681279d1bbdf73a50ad512b6f63c41948f34d51cc7eb21897
data/.babelrc CHANGED
@@ -1,3 +1,4 @@
1
1
  {
2
+ "presets": ["es2015", "stage-2"],
2
3
  "plugins": ["transform-flow-strip-types"]
3
4
  }
data/.eslintrc CHANGED
@@ -1,9 +1,13 @@
1
1
  ---
2
2
  extends:
3
- - airbnb
3
+ - eslint:recommended
4
4
 
5
5
  parser: babel-eslint
6
6
 
7
+ env:
8
+ node: true
9
+ jest: true
10
+
7
11
  plugins:
8
12
  - flow-vars
9
13
 
data/.gitignore CHANGED
@@ -10,4 +10,5 @@
10
10
  /tmp/
11
11
 
12
12
  /Gemfile.lock
13
+ /npm-debug.log
13
14
  /*.gem
data/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ 6.3.1
data/Makefile CHANGED
@@ -1,5 +1,10 @@
1
1
 
2
- build:
2
+ build_gem:
3
3
  gem build hauler.gemspec
4
4
 
5
+ publish_npm:
6
+ npm run build
7
+ cd dist/
8
+ npm publish
9
+
5
10
  .PHONY: all;
data/bin/dev-server.js CHANGED
@@ -1,12 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ const hauler = require('hauler');
3
4
  const webpack = require('webpack');
4
5
  const WebpackDevServer = require('webpack-dev-server');
5
6
 
6
- const env = String(process.env.RAILS_ENV || process.env.NODE_ENV);
7
- const Hauler = require('hauler');
8
- const devServerConfig = Hauler.getDevServerConfig(env);
9
- const compilerConfig = Hauler.getCompilerConfig(env);
7
+ const env = hauler.getEnvName();
8
+ const railsRoot = process.argv[2];
9
+
10
+ const devServerConfig = hauler.getDevServerConfig(env, railsRoot);
11
+ const compilerConfig = hauler.getCompilerConfig(env, railsRoot);
10
12
 
11
13
  // console.log(devServerConfig);
12
14
  // console.log(compilerConfig);
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env node
2
+ // @flow
3
+ 'use strict';
4
+
5
+ const railsRoot = process.argv[2];
6
+
7
+ const hauler = require('hauler');
8
+ const env = hauler.getEnvName();
9
+
10
+ const devServerConfig = hauler.getDevServerConfig(env, railsRoot);
11
+ const compilerConfig = hauler.getCompilerConfig(env, railsRoot);
12
+ const config = { devServerConfig, compilerConfig };
13
+ const output = JSON.stringify(config);
14
+
15
+ process.stdout.write(output);
@@ -10,7 +10,7 @@ if (!pkg.scripts) {
10
10
  }
11
11
 
12
12
  Object.assign(pkg.scripts, {
13
- start: './node_modules/hauler/bin/dev-server.js',
13
+ start: 'hauler-server $(pwd)',
14
14
  });
15
15
 
16
16
  const output = JSON.stringify(pkg, null, 2);
@@ -5,7 +5,11 @@ module Hauler
5
5
  desc 'Copy Hauler configuration files'
6
6
  source_root File.expand_path('../templates', __FILE__)
7
7
 
8
- def copy_config_hauler
8
+ def copy_hauler_initializer
9
+ template 'config/initializers/hauler.rb'
10
+ end
11
+
12
+ def copy_hauler_config
9
13
  template 'config/hauler.js'
10
14
  end
11
15
 
@@ -14,6 +14,7 @@ module Hauler
14
14
  css-loader@0.23.1
15
15
  extract-text-webpack-plugin@1.0.1
16
16
  file-loader@0.9.0
17
+ hauler@0.1.1
17
18
  image-webpack-loader@2.0.0
18
19
  immutable-devtools@0.0.7
19
20
  style-loader@0.13.1
@@ -1,6 +1,10 @@
1
1
 
2
- module.exports = {
3
- entries: [
4
- '~app/assets/my_app/index.js',
5
- ],
6
- };
2
+ function haulerConfigFactory(env) {
3
+ return {
4
+ entries: {
5
+ application: '~app/assets/my_app/index.js',
6
+ },
7
+ };
8
+ }
9
+
10
+ module.exports = haulerConfigFactory;
@@ -0,0 +1 @@
1
+ Rails.application.config.hauler.dev_server = Rails.env.development?
@@ -1,8 +1,6 @@
1
1
  {
2
2
  "extends": [
3
- "airbnb",
4
- "plugin:import/errors",
5
- "plugin:import/warnings"
3
+ "airbnb"
6
4
  ],
7
5
  "parser": "babel-eslint",
8
6
  "plugins": [
@@ -1,5 +1,6 @@
1
1
 
2
- const Hauler = require('hauler');
3
- const env = String(process.env.RAILS_ENV || process.env.NODE_ENV);
2
+ const hauler = require('hauler');
3
+ const env = hauler.getEnvName();
4
4
 
5
- module.exports = Hauler.getCompilerConfig(env);
5
+ const config = hauler.getCompilerConfig(env, __dirname);
6
+ module.exports = config;
@@ -0,0 +1,76 @@
1
+ require 'active_support/concern'
2
+ require 'action_view/helpers'
3
+
4
+ module Hauler
5
+ module Helpers
6
+ #:nodoc:
7
+ module HaulerHelper
8
+ extend ::ActiveSupport::Concern
9
+
10
+ include ::ActionView::Helpers
11
+
12
+ included do
13
+ def hauler_dev_server?
14
+ Rails.application.config.hauler.dev_server
15
+ end
16
+
17
+ def hauler_webpack_config
18
+ return nil if !hauler_dev_server?
19
+ @hauler_webpack_config ||= JSON.parse(`hauler-read-config`)
20
+ end
21
+
22
+ def hauler_entries_names
23
+ @hauler_entries_names ||= begin
24
+ entries = hauler_webpack_config.try(:[], 'compilerConfig').try(:[], 'entry')
25
+ entries.try(:keys) || []
26
+ end
27
+ end
28
+
29
+ def hauler_entry?(path)
30
+ entry = path.gsub(/\.(css|js)$/, '')
31
+ hauler_entries_names.include?(entry)
32
+ end
33
+
34
+ def hauler_public_path
35
+ @hauler_public_path ||= begin
36
+ public_path = hauler_webpack_config.try(:[], 'devServerConfig').try(:[], 'publicPath')
37
+ public_path.gsub(%r{/$}, '')
38
+ end
39
+ end
40
+
41
+ def hauler_format_entry_path(entry)
42
+ output = entry
43
+ output += '.js' unless entry.end_with?('.js')
44
+ output.gsub(%r{^/}, '')
45
+ end
46
+
47
+ alias_method :orig_asset_path, :asset_path
48
+
49
+ def hauler_asset_path(path, options = {})
50
+ return nil unless options[:type].to_s == 'javascript'
51
+ return nil unless hauler_dev_server? && hauler_entry?(path)
52
+ [hauler_public_path, hauler_format_entry_path(path)].join('/')
53
+ end
54
+
55
+ def asset_path(source, options = {})
56
+ hauler_asset_path(source, options) || orig_asset_path(source, options)
57
+ end
58
+
59
+ def path_to_asset(*args)
60
+ asset_path(*args)
61
+ end
62
+
63
+ alias_method :orig_stylesheet_link_tag, :stylesheet_link_tag
64
+
65
+ def stylesheet_link_tag(*sources)
66
+ return orig_stylesheet_link_tag(*sources) unless hauler_dev_server?
67
+ options = sources.extract_options!.stringify_keys
68
+ sources.map do |source|
69
+ next if hauler_entry?(source)
70
+ orig_stylesheet_link_tag(source, options)
71
+ end.compact.join("\n").html_safe
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
@@ -1,27 +1,20 @@
1
+ require 'hauler'
1
2
  require 'rails'
2
- require 'rails/railtie'
3
- require 'active_support/ordered_options'
4
- require 'hauler/asset_tag_helper'
5
- # require 'yaml'
6
- # require 'erb'
3
+ require 'hauler/helpers/hauler_helper'
4
+ require 'active_support/core_ext/hash/indifferent_access'
7
5
 
6
+ # :nodoc:
8
7
  module Hauler
9
- #:nodoc:
10
- class Railtie < ::Rails::Railtie
8
+ # :nodoc:
9
+ class Railtie < Rails::Railtie
11
10
  config.hauler = ActiveSupport::OrderedOptions.new
12
- config.hauler.dev_server = true
11
+ config.hauler.dev_server = false
13
12
 
14
- initializer 'hauler.configure_rails_initialization' do
15
- # yaml = Pathname.new(Rails.root.join('config', 'assets.yml'))
16
- # assets_config = YAML.load(ERB.new(yaml.read).result) || {}
17
- # assets_config = assets_config[Rails.env]
13
+ config.eager_load_namespaces << Hauler
18
14
 
19
- # if config.action_controller.asset_host.blank?
20
- # config.action_controller.asset_host = assets_config['asset_host']
21
- # end
22
-
23
- ::ActiveSupport.on_load :action_view do
24
- include ::Hauler::AssetTagHelper
15
+ initializer 'hauler.helpers' do
16
+ ::ActiveSupport.on_load(:action_view) do
17
+ include Hauler::Helpers::HaulerHelper
25
18
  end
26
19
  end
27
20
  end
@@ -1,3 +1,8 @@
1
+ # :nodoc:
1
2
  module Hauler
2
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.2.0'.freeze
4
+
5
+ def self.version
6
+ VERSION
7
+ end
3
8
  end
data/lib/hauler.rb CHANGED
@@ -1,2 +1,5 @@
1
+ require 'active_support'
2
+ require 'active_support/rails'
1
3
  require 'hauler/version'
4
+
2
5
  require 'hauler/railtie' if defined?(Rails)
data/make-package.js CHANGED
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env node --use_strict
2
2
 
3
3
  const fs = require('fs');
4
+ const path = require('path');
4
5
 
5
- const pkg = require('./package.json');
6
+ const pkg = Object.assign({}, require('./package.json'));
6
7
  delete pkg.scripts;
7
8
  Object.assign(pkg, {
8
9
  main: 'index.js',
@@ -11,3 +12,12 @@ Object.assign(pkg, {
11
12
  fs.writeFileSync('dist/package.json', JSON.stringify(pkg, null, 2));
12
13
  fs.writeFileSync('dist/LICENSE.txt', fs.readFileSync('./LICENSE.txt').toString());
13
14
  fs.writeFileSync('dist/README.md', fs.readFileSync('./README.md').toString());
15
+
16
+ fs.mkdirSync('dist/bin');
17
+ Object.keys(pkg.bin).forEach(key => {
18
+ const binaryPath = pkg.bin[key];
19
+ fs.writeFileSync(
20
+ path.join('dist', binaryPath),
21
+ fs.readFileSync(binaryPath).toString()
22
+ );
23
+ });
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hauler",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "NodeJS binary for the hauler gem",
5
5
  "author": "Arturo Guzman @guzart",
6
6
  "license": "MIT",
@@ -10,28 +10,43 @@
10
10
  },
11
11
  "main": "dist/index.js",
12
12
  "bin": {
13
+ "hauler-read-config": "bin/read-config.js",
13
14
  "hauler-server": "bin/dev-server.js",
14
- "hauler-update-scripts": "bin/update-scripts"
15
- },
16
- "directories": {
17
- "test": "test"
15
+ "hauler-update-scripts": "bin/update-scripts.js"
18
16
  },
19
17
  "scripts": {
20
18
  "build": "npm-run-all clean compile generate_package",
21
19
  "clean": "rm -rf ./dist",
22
- "compile": "./node_modules/babel-cli/bin/babel.js --out-dir=./dist --ignore=./decls ./src",
20
+ "compile": "./node_modules/babel-cli/bin/babel.js --out-dir=./dist --ignore=./decls,**/__tests__ ./src",
23
21
  "dev": "npm-run-all clean watch",
24
22
  "generate_package": "node make-package.js",
25
- "test": "echo \"Error: no test specified\" && exit 1",
26
- "watch": "./node_modules/babel-cli/bin/babel.js --watch=./src --ignore=./decls --out-dir=./dist"
23
+ "test": "jest --verbose",
24
+ "watch": "./node_modules/babel-cli/bin/babel.js --watch=./src --ignore=./decls,**/__tests__ --out-dir=./dist"
25
+ },
26
+ "peerDependencies": {
27
+ "extract-text-webpack-plugin": "~ 1.0",
28
+ "webpack": "~ 1.0",
29
+ "webpack-dev-server": "~ 1.0",
30
+ "whatwg-fetch": "~ 1.0"
27
31
  },
28
32
  "devDependencies": {
29
33
  "babel-cli": "^6.11.4",
34
+ "babel-core": "^6.11.4",
30
35
  "babel-eslint": "^6.1.2",
36
+ "babel-jest": "^14.1.0",
31
37
  "babel-plugin-transform-flow-strip-types": "^6.8.0",
38
+ "babel-polyfill": "^6.9.1",
39
+ "babel-preset-es2015": "^6.9.0",
40
+ "babel-preset-stage-2": "^6.11.0",
32
41
  "eslint": "^3.2.0",
33
42
  "eslint-plugin-flow-vars": "^0.5.0",
34
43
  "eslint-plugin-flowtype": "^2.4.0",
35
- "flow-bin": "^0.30.0"
44
+ "extract-text-webpack-plugin": "^1.0.1",
45
+ "flow-bin": "^0.30.0",
46
+ "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"
36
51
  }
37
52
  }
data/src/decls/hauler.js CHANGED
@@ -1,3 +1,9 @@
1
+ export type Hash = {[name: string]: any};
2
+
3
+ export type HostInfo = {
4
+ host: string,
5
+ port: number,
6
+ };
1
7
 
2
8
  export type ProjectConfig = {
3
9
  entries?: {[name: string]: string | Array<string>},
@@ -8,6 +14,7 @@ export type ProjectConfig = {
8
14
  prependPlugins?: Array<WebpackPlugin>,
9
15
  plugins?: Array<WebpackPlugin>,
10
16
  appendPlugins?: Array<WebpackPlugin>,
17
+ publicPath?: string,
11
18
  devServer?: WebpackDevServerConfig,
12
19
  compiler?: WebpackConfig,
13
20
  };
data/src/decls/webpack.js CHANGED
@@ -1,5 +1,7 @@
1
1
  // @flow
2
2
 
3
+ // DEV SERVER
4
+
3
5
  export type WebpackDevServerStatsConfig = {
4
6
  colors?: boolean,
5
7
  hash?: boolean,
@@ -29,7 +31,18 @@ export type WebpackDevServerConfig = {
29
31
  stats?: WebpackDevServerStatsConfig,
30
32
  };
31
33
 
32
- export type WebpackEntry = string | Array<string> | { [key: string]: WebpackEntry };
34
+ // COMPILER
35
+
36
+ export type WebpackPlugin = Object;
37
+
38
+ export type WebpackLoader = {
39
+ test?: Object,
40
+ exclude?: Object,
41
+ include?: Object,
42
+ loader?: string,
43
+ loaders?: Array<string>,
44
+ query?: Object,
45
+ };
33
46
 
34
47
  export type WebpackResolveConfig = {
35
48
  alias?: Object,
@@ -46,14 +59,6 @@ export type WebpackResolveLoaderConfig = WebpackResolveConfig & {
46
59
  moduleTemplates?: Array<string>,
47
60
  };
48
61
 
49
- export type WebpackLoader = {
50
- test?: Object,
51
- exclude?: Object,
52
- include?: Object,
53
- loader?: string,
54
- loaders?: Array<string>,
55
- query?: Object,
56
- };
57
62
 
58
63
  export type WebpackModuleConfig = {
59
64
  loaders?: Array<WebpackLoader>;
@@ -62,8 +67,6 @@ export type WebpackModuleConfig = {
62
67
  noParse?: Object | Array<Object>;
63
68
  }
64
69
 
65
- export type WebpackPlugin = Object;
66
-
67
70
  export type WebpackOutputConfig = {
68
71
  filename?: string,
69
72
  path?: string,
@@ -89,6 +92,8 @@ export type WebpackOutputConfig = {
89
92
  crossOriginLoading?: false | 'anonymous' | 'use-credentials',
90
93
  };
91
94
 
95
+ export type WebpackEntry = string | Array<string> | { [key: string]: WebpackEntry };
96
+
92
97
  export type WebpackConfig = {
93
98
  context?: string,
94
99
  entry?: WebpackEntry,
@@ -1,87 +1,7 @@
1
1
  // @flow
2
2
 
3
- const ExtractTextPlugin = require('extract-text-webpack-plugin');
4
- const webpack = require('webpack');
5
-
6
- function getPlugins(env: string) {
7
- let plugins = [
8
- new webpack.ProvidePlugin({ fetch: 'exports?self.fetch!whatwg-fetch' }),
9
- new webpack.DefinePlugin({ 'process.env': { NODE_ENV: JSON.stringify(env) } }),
10
- new webpack.optimize.CommonsChunkPlugin({
11
- name: 'vendor',
12
- children: true,
13
- minChunks: 2,
14
- async: true,
15
- }),
16
- ];
17
-
18
- if (env === 'development') {
19
- plugins = plugins.concat([
20
- new webpack.NoErrorsPlugin(),
21
- ]);
22
- }
23
-
24
- if (env === 'production') {
25
- plugins = plugins.concat([
26
- new webpack.optimize.OccurrenceOrderPlugin(true),
27
- new webpack.optimize.DedupePlugin(),
28
- new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }),
29
- new ExtractTextPlugin('[name].[contenthash].css'),
30
- ]);
31
- }
32
-
33
- return plugins;
34
- }
35
-
36
- function configFactory(env: string) {
37
- // individual loaders so that they can be replaced separately
38
- const javascriptLoader = {
39
- test: /\.jsx?$/,
40
- loader: 'babel',
41
- exclude: /node_modules/,
42
- query: {
43
- presets: ['es2015', 'react', 'stage-2'],
44
- plugins: ['transform-class-properties'],
45
- },
46
- };
47
-
48
- const sassLoader = {
49
- test: /\.scss$/,
50
- loader: 'style!css!sass',
51
- };
52
-
53
- const fontLoader = {
54
- test: /\.(eot|svg|ttf|woff|woff2)$/,
55
- loader: 'file',
56
- };
57
-
58
- const imageLoader = {
59
- test: /\.(jpg|png|gif)$/,
60
- loaders: [
61
- 'file',
62
- 'image-webpack?{progressive:true, optimizationLevel: 7, interlaced: false, pngquant:{quality: "65-90", speed: 4}}',
63
- ],
64
- };
65
-
66
- if (env === 'production') {
67
- javascriptLoader.query.plugins = javascriptLoader.query.plugins.concat([
68
- 'transform-react-remove-prop-types',
69
- 'transform-react-constant-elements',
70
- 'transform-react-inline-elements',
71
- ]);
72
-
73
- sassLoader.loader = ExtractTextPlugin.extract(
74
- 'style',
75
- sassLoader.loader.replace('style!', '')
76
- );
77
- }
78
-
79
- const appendPlugins = [];
80
- const plugins = getPlugins(env);
81
- const prependPlugins = [];
82
-
83
- // straight webpack configuration
84
- const compiler = {
3
+ export default function defaultConfigFactory(env: string): WebpackConfig {
4
+ const config = {
85
5
  output: {
86
6
  filename: '[name].[chunkhash].js',
87
7
  path: '~public/assets',
@@ -98,20 +18,9 @@ function configFactory(env: string) {
98
18
  };
99
19
 
100
20
  if (env === 'development') {
101
- compiler.output.filename = '[name].js';
102
- compiler.output.chunkFilename = '[name].chunk.js';
21
+ config.output.filename = '[name].js';
22
+ config.output.chunkFilename = '[name].chunk.js';
103
23
  }
104
24
 
105
- return {
106
- javascriptLoader,
107
- sassLoader,
108
- fontLoader,
109
- imageLoader,
110
- prependPlugins,
111
- plugins,
112
- appendPlugins,
113
- compiler,
114
- };
25
+ return config;
115
26
  }
116
-
117
- module.exports = configFactory;
@@ -1,4 +1,6 @@
1
- function defaultConfigFactory() {
1
+ // @flow
2
+
3
+ export default function defaultConfigFactory() {
2
4
  return {
3
5
  quiet: false,
4
6
  noInfo: false,
@@ -6,7 +8,6 @@ function defaultConfigFactory() {
6
8
  port: 3001,
7
9
  hot: true,
8
10
  inline: true,
9
- publicPath: '/assets/',
10
11
  headers: { 'AccessControl-Allow-Origin': '*' },
11
12
  stats: {
12
13
  colors: true,
@@ -16,5 +17,3 @@ function defaultConfigFactory() {
16
17
  },
17
18
  };
18
19
  }
19
-
20
- module.exports = defaultConfigFactory;