forked from ninjasort/react-star-rating
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
102 lines (93 loc) · 2.45 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
'use strict';
var gulp = require('gulp');
var source = require('vinyl-source-stream');
var browserify = require('browserify');
var babelify = require('babelify');
var babel = require('gulp-babel');
var server = require('gulp-webserver');
var sass = require('gulp-sass');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var eslint = require('gulp-eslint');
var replace = require('gulp-replace');
var minifyCSS = require('gulp-minify-css');
var karma = require('gulp-karma');
var config = {
componentFileName: 'react-star-rating',
componentSrc: './src/StarRating.jsx',
componentStylesDir: './src/sass',
stylesDest: './dist/css'
};
/**
* Lint
*/
gulp.task('lint', function () {
return gulp.src('./src/**/*.{jsx, js}')
.pipe(eslint({
useEslintrc: true
}))
.pipe(eslint.format())
.pipe(eslint.failOnError());
});
/**
* Styles
*/
gulp.task('styles', ['demo-styles'], function () {
return gulp.src(config.componentStylesDir + '/' + config.componentFileName + '.scss')
.pipe(sass({
includePaths: require('node-bourbon').includePaths
}))
.pipe(gulp.dest(config.stylesDest))
.pipe(minifyCSS())
.pipe(rename(config.componentFileName + '.min.css'))
.pipe(gulp.dest(config.stylesDest));
});
/**
* Build
*/
gulp.task('build', ['lint'], function () {
return gulp.src(config.componentSrc)
.pipe(babel())
.pipe(rename(config.componentFileName + '.js'))
.pipe(gulp.dest('dist'))
.pipe(rename(config.componentFileName + '.min.js'))
.pipe(uglify())
.pipe(gulp.dest('dist'));
});
/**
* Demo Styles
*/
gulp.task('demo-styles', function () {
return gulp.src(config.componentStylesDir + '/demo.scss')
.pipe(sass({
includePaths: require('node-bourbon').includePaths
}))
.pipe(gulp.dest(config.stylesDest));
});
/**
* Demo Bundle
*/
gulp.task('default', ['lint', 'styles'], function () {
return browserify('./src/docs.jsx', {extensions: '.jsx'})
.transform(babelify)
.bundle()
.on('error', function (err) {
console.log(err);
})
.pipe(source('docs.js'))
.pipe(gulp.dest('dist'));
});
/**
* Watch
*/
gulp.task('watch', ['default'], function () {
gulp.watch(['./src/*.js', './src/**/*.jsx', './src/sass/{*/,}*.scss'], ['dist']);
return gulp.src('.').pipe(server({
port: 3000
}));
});
/**
* Dist
*/
gulp.task('dist', ['default', 'styles', 'build']);