Skip to content

Commit

Permalink
Lint gulpfile and upgrade to babel
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanFoster committed Nov 3, 2015
1 parent 258efab commit 440f14e
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 97 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
example/build
dist
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ example/css/*.css
.DS_Store
*.sublime-*
dist/ui-coverage/
npm-debug.log
82 changes: 40 additions & 42 deletions gulpfile.js → gulpfile.babel.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,83 @@
"use strict";

Object.assign = require('object.assign');

var fs = require('fs');
var path = require('path');
var gulp = require('gulp');
import fs from 'fs';
import path from 'path';
import gulp from 'gulp';

var plugins = require('gulp-load-plugins')();
var React = require('react');
var webpack = require('webpack');
var KarmaServer = require('karma').Server;
var clean = require('del');
import gulpLoadPlugins from 'gulp-load-plugins';
import React from 'react';
import webpack from 'webpack';
import { Server as KarmaServer } from 'karma';
import clean from 'del';

var PRODUCTION = (process.env.NODE_ENV === 'production');
const plugins = gulpLoadPlugins();
const PRODUCTION = (process.env.NODE_ENV === 'production');

var paths = {
const paths = {
src: 'src/**/*.js?(x)',
example: 'example/**/*.js?(x)'
}
};

var gulpPlugins = [
let gulpPlugins = [
// Fix for moment including all locales
// Ref: http://stackoverflow.com/a/25426019
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
];

if (PRODUCTION) {
gulpPlugins.push(new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
}
NODE_ENV: JSON.stringify("production"),
},
}));
gulpPlugins.push(new webpack.optimize.DedupePlugin());
gulpPlugins.push(new webpack.optimize.UglifyJsPlugin({
compress: true,
mangle: true,
sourceMap: true
sourceMap: true,
}));
}

var webpackConfig = {
const webpackConfig = {
cache: true,
debug: !PRODUCTION,
devtool: PRODUCTION ? 'source-map' : 'eval-source-map',
context: __dirname,
output: {
path: path.resolve('./example/build/'),
filename: 'index.js'
filename: 'index.js',
},
module: {
loaders: [
{
test: /\.jsx|.js$/,
exclude: /node_modules\//,
loaders: [
'babel-loader?stage=1&plugins[]=object-assign'
]
'babel-loader?stage=1&plugins[]=object-assign',
],
},
],
postLoaders: [
{
loader: "transform/cacheable?brfs"
}
]
loader: "transform/cacheable?brfs",
},
],
},
resolve: {
extensions: ['', '.js', '.jsx']
extensions: ['', '.js', '.jsx'],
},
plugins: gulpPlugins
plugins: gulpPlugins,
};

gulp.task('lint', function() {
return gulp.src([paths.src, paths.example])
.pipe(plugins.eslint())
return gulp.src('**/*.js?(x)')
.pipe(plugins.eslint({ ignorePath: '.eslintignore' }))
.pipe(plugins.eslint.format())
.pipe(plugins.eslint.failOnError());
.pipe(plugins.eslint.failAfterError());
});

gulp.task('test-unit', ['lint'], function (done) {
new KarmaServer({
configFile: __dirname + '/karma.conf.js'
configFile: __dirname + '/karma.conf.js',
}, done).start();
});

Expand All @@ -94,20 +92,20 @@ gulp.task('test-coverage', ['lint'], function (done) {
test: /\.(js|jsx)$/,
include: path.resolve('src/'),
exclude: /tests/,
loader: 'isparta'
loader: 'isparta',
}, {
test: /\.spec.js$/,
include: path.resolve('src/'),
loader: 'babel'
loader: 'babel',
}],
loaders: [
{test: /\.(js|jsx)$/, exclude: /node_modules/, loader: require.resolve('babel-loader')}
]
{test: /\.(js|jsx)$/, exclude: /node_modules/, loader: require.resolve('babel-loader')},
],
},
resolve: {
extensions: ['', '.js', '.jsx']
}
}
extensions: ['', '.js', '.jsx'],
},
},
}, done).start();
});

Expand All @@ -120,7 +118,7 @@ gulp.task('build-dist-js', ['clean-dist-js'], function() {
return gulp.src(['src/**/*.{js,jsx}', '!src/**/tests/**', '!src/tests.webpack.js'])
.pipe(plugins.babel({
stage: 1,
plugins: ['object-assign']
plugins: ['object-assign'],
}))
.pipe(plugins.extReplace('.js'))
.pipe(gulp.dest('dist'));
Expand All @@ -145,7 +143,7 @@ gulp.task('build-example', function() {
// setup babel hook
require("babel/register")({
stage: 1,
plugins: ['object-assign']
plugins: ['object-assign'],
});

var Index = React.createFactory(require('./example/base.jsx'));
Expand All @@ -171,7 +169,7 @@ gulp.task('watch-example-scss', ['build-example-scss'], function() {
gulp.task('example-server', function() {
plugins.connect.server({
root: 'example',
port: '9989'
port: '9989',
});
});

Expand Down
113 changes: 58 additions & 55 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,60 @@
module.exports = function (config) {
config.set({

browsers: ['PhantomJS'],

frameworks: ['jasmine'],

files: ['node_modules/babel-core/browser-polyfill.js', {
pattern: './src/tests.webpack.js', watched: false
}],

preprocessors: {
'src/tests.webpack.js': ['webpack']
},

webpack: {
resolve: {
extensions: ['', '.js', '.jsx']
},
module: {
loaders: [
{test: /\.(js|jsx)$/, exclude: /node_modules/, loader: 'babel-loader'}
]
},
stats: {
colors: true
},
devtool: 'inline-source-map'
},

webpackMiddleware: {
noInfo: true
},

reporters: ['mocha'],

mochaReporter: {
output: 'full'
},

coverageReporter: {
reporters: [
{ type: 'html', dir: 'dist/ui-coverage', subdir: 'html' },
{ type: 'cobertura', dir: 'dist/ui-coverage', subdir: 'cobertura' },
{ type: 'text-summary' }
]
},

thresholdReporter: {
statements: 90,
branches: 85,
functions: 90,
lines: 90
}

});
config.set({

browsers: ['PhantomJS'],

frameworks: ['jasmine'],

files: [
'node_modules/babel-core/browser-polyfill.js',
{
pattern: './src/tests.webpack.js',
watched: false,
},
],

preprocessors: {
'src/tests.webpack.js': ['webpack'],
},

webpack: {
resolve: {
extensions: ['', '.js', '.jsx'],
},
module: {
loaders: [
{ test: /\.(js|jsx)$/, exclude: /node_modules/, loader: 'babel-loader' },
],
},
stats: {
colors: true,
},
devtool: 'inline-source-map',
},

webpackMiddleware: {
noInfo: true,
},

reporters: ['mocha'],

mochaReporter: {
output: 'full',
},

coverageReporter: {
reporters: [
{ type: 'html', dir: 'dist/ui-coverage', subdir: 'html' },
{ type: 'cobertura', dir: 'dist/ui-coverage', subdir: 'cobertura' },
{ type: 'text-summary' },
],
},

thresholdReporter: {
statements: 90,
branches: 85,
functions: 90,
lines: 90,
},
});
};

0 comments on commit 440f14e

Please sign in to comment.