View difference between Paste ID: XKdWFeMy and APEjqmTv
SHOW: | | - or go back to the newest paste.
1-
var gulp       = require('gulp');
1+
var gulp       = require('gulp');
2-
var streamify  = require('gulp-streamify');
2+
var streamify  = require('gulp-streamify');
3-
var uglify     = require('gulp-uglify');
3+
var uglify     = require('gulp-uglify');
4-
var notify     = require('gulp-notify');
4+
var notify     = require('gulp-notify');
5-
var gutil      = require('gulp-util');
5+
var gutil      = require('gulp-util');
6-
var less       = require('gulp-less');
6+
var less       = require('gulp-less');
7-
var rename     = require('gulp-rename');
7+
var rename     = require('gulp-rename');
8-
var nodemon    = require('gulp-nodemon');
8+
var nodemon    = require('gulp-nodemon');
9-
var jshint     = require('gulp-jshint');
9+
var jshint     = require('gulp-jshint');
10-
var react      = require('gulp-react');
10+
var react      = require('gulp-react');
11-
var mocha      = require('gulp-mocha');
11+
var mocha      = require('gulp-mocha');
12-
var selenium   = require('gulp-mocha-selenium');
12+
var selenium   = require('gulp-mocha-selenium');
13-
var livereload = require('gulp-livereload');
13+
var livereload = require('gulp-livereload');
14-
var browserify = require('browserify');
14+
var browserify = require('browserify');
15-
var watchify   = require('watchify');
15+
var watchify   = require('watchify');
16-
var babelify   = require('babelify');
16+
var babelify   = require('babelify');
17-
var source     = require('vinyl-source-stream');
17+
var source     = require('vinyl-source-stream');
18-
var lazypipe   = require('lazypipe');
18+
var lazypipe   = require('lazypipe');
19-
19+
20-
var isProduction = process.env.NODE_ENV === 'production';
20+
var isProduction = process.env.NODE_ENV === 'production';
21-
21+
22-
gulp.task('jshint', function () {
22+
gulp.task('jshint', function () {
23-
    gulp.src(['views/*.jsx', 'views/**/*.jsx'])
23+
    gulp.src(['views/*.jsx', 'views/**/*.jsx'])
24-
        .pipe(react()) //Must use react as it preserves lines from jsx to js compile
24+
        .pipe(react()) //Must use react as it preserves lines from jsx to js compile
25-
        .pipe(streamify(jshint({
25+
        .pipe(streamify(jshint({
26-
            laxbreak: true,
26+
            laxbreak: true,
27-
            laxcomma: true,
27+
            laxcomma: true,
28-
            es3: true,
28+
            es3: true,
29-
            esnext: true, //JSHint Harmony/ES6
29+
            esnext: true, //JSHint Harmony/ES6
30-
            eqnull: true,
30+
            eqnull: true,
31-
            browser: true,
31+
            browser: true,
32-
            jquery: true
32+
            jquery: true
33-
        })))
33+
        })))
34-
        .pipe(jshint.reporter('jshint-stylish'))
34+
        .pipe(jshint.reporter('jshint-stylish'))
35-
});
35+
});
36-
36+
37-
gulp.task('browserify', function () {
37+
gulp.task('browserify', function () {
38-
    watchify(browserify())
38+
    watchify(browserify())
39-
        .transform(babelify) //JSX and ES6
39+
        .transform(babelify) //JSX and ES6
40-
        .require('./views/app.jsx', {entry: true})
40+
        .require('./views/app.jsx', {entry: true})
41-
        .bundle()
41+
        .bundle()
42-
        .on('error', function(err) {
42+
        .on('error', function(err) {
43-
            console.error(err.message);
43+
            console.error(err.message);
44-
        })
44+
        })
45-
        .pipe(source('bundle.js'))
45+
        .pipe(source('bundle.js'))
46-
        .pipe(isProduction ? streamify(uglify('./built/')) : gutil.noop()) //Noop is empty stream for passthru
46+
        .pipe(isProduction ? streamify(uglify('./built/')) : gutil.noop()) //Noop is empty stream for passthru
47-
        .pipe(gulp.dest('./js/built/'))
47+
        .pipe(gulp.dest('./js/built/'))
48-
        .pipe(livereload())
48+
        .pipe(livereload())
49-
        .pipe(notify("Rebuilt Website"));
49+
        .pipe(notify("Rebuilt Website"));
50-
});
50+
});
51-
51+
52-
gulp.task('less', function () {
52+
gulp.task('less', function () {
53-
    /**
53+
    /**
54-
     * LazyPipe is used create streams without initializing them
54+
     * LazyPipe is used create streams without initializing them
55-
     * until they are used
55+
     * until they are used
56-
     *
56+
     *
57-
     * Never call streams directly
57+
     * Never call streams directly
58-
     *
58+
     *
59-
     * .pipe(gulp.dest('/filepath')) becomes
59+
     * .pipe(gulp.dest('/filepath')) becomes
60-
     *
60+
     *
61-
     * .pipe(gulp.dest, '/filepath')
61+
     * .pipe(gulp.dest, '/filepath')
62-
     */
62+
     */
63-
63+
64-
    var prodLess = lazypipe()
64+
    var prodLess = lazypipe()
65-
        .pipe(less, {
65+
        .pipe(less, {
66-
            paths: ['less'],
66+
            paths: ['less'],
67-
            dumpLineNumbers: false,
67+
            dumpLineNumbers: false,
68-
            compress: true,
68+
            compress: true,
69-
            cleancss: true,
69+
            cleancss: true,
70-
            yuicompress: true
70+
            yuicompress: true
71-
        })
71+
        })
72-
        .pipe(rename, 'main.min.css')
72+
        .pipe(rename, 'main.min.css')
73-
        .pipe(gulp.dest, './css/');
73+
        .pipe(gulp.dest, './css/');
74-
74+
75-
    var devLess = lazypipe()
75+
    var devLess = lazypipe()
76-
        .pipe(less, {
76+
        .pipe(less, {
77-
            paths: ['less'],
77+
            paths: ['less'],
78-
            dumpLineNumbers: 'all',
78+
            dumpLineNumbers: 'all',
79-
            compress: false
79+
            compress: false
80-
        })
80+
        })
81-
        .pipe(gulp.dest, './css/');
81+
        .pipe(gulp.dest, './css/');
82-
82+
83-
    gulp.src('./less/main.less')
83+
    gulp.src('./less/main.less')
84-
        //Use ternary operator for conditional statements
84+
        //Use ternary operator for conditional statements
85-
        .pipe(isProduction ? prodLess() : devLess())
85+
        .pipe(isProduction ? prodLess() : devLess())
86-
        .pipe(livereload());
86+
        .pipe(livereload());
87-
});
87+
});
88-
88+
89-
gulp.task('mocha', function () {
89+
gulp.task('mocha', function () {
90-
    gulp.src(['test/*_test.js', 'test/**/*_test.js', '!test/selenium/*_test.js'])
90+
    gulp.src(['test/*_test.js', 'test/**/*_test.js', '!test/selenium/*_test.js'])
91-
        .pipe(mocha({
91+
        .pipe(mocha({
92-
            reporter: 'spec',
92+
            reporter: 'spec',
93-
            ui: 'bdd'
93+
            ui: 'bdd'
94-
        }));
94+
        }));
95-
95+
96-
});
96+
});
97-
97+
98-
gulp.task('selenium', function () {
98+
gulp.task('selenium', function () {
99-
    gulp.src('test/selenium/*_test.js', {read: false})
99+
    gulp.src('test/selenium/*_test.js', {read: false})
100-
        .pipe(selenium({
100+
        .pipe(selenium({
101-
            browserName: 'chrome',
101+
            browserName: 'chrome',
102-
            reporter: 'spec',
102+
            reporter: 'spec',
103-
            ui: 'bdd',
103+
            ui: 'bdd',
104-
            usePromises: true
104+
            usePromises: true
105-
        }));
105+
        }));
106-
});
106+
});
107-
107+
108-
gulp.task('server', function () {
108+
gulp.task('server', function () {
109-
    livereload.listen();
109+
    livereload.listen();
110-
    nodemon({ script: 'app.js', ext: 'jsx', ignore: [] })
110+
    nodemon({ script: 'app.js', ext: 'jsx', ignore: [] })
111-
        .on('change', ['jshint', 'mocha', 'browserify']) //Only reload jsx on change
111+
        .on('change', ['jshint', 'mocha', 'browserify']) //Only reload jsx on change
112-
});
112+
});
113-
113+
114-
if (isProduction) {
114+
if (isProduction) {
115-
    gulp.task('default', ['server']);
115+
    gulp.task('default', ['server']);
116-
} else {
116+
} else {
117-
    gulp.task('default', ['jshint', 'browserify', 'server']);
117+
    gulp.task('default', ['jshint', 'browserify', 'server']);
118-
}
118+
}
119-
gulp.task('test', ['jshint', 'mocha', 'selenium']);
119+
gulp.task('test', ['jshint', 'mocha', 'selenium']);
120
gulp.task('build', ['less', 'browserify']);