forked from jakezatecky/react-checkbox-tree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
124 lines (108 loc) · 3.92 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
const gulp = require('gulp');
const eslint = require('gulp-eslint');
const mocha = require('gulp-mocha');
const header = require('gulp-header');
const webpack = require('webpack');
const webpackStream = require('webpack-stream');
const scsslint = require('gulp-scss-lint');
const sass = require('gulp-sass');
const less = require('gulp-less');
const minify = require('gulp-clean-css');
const run = require('gulp-run');
const autoprefixer = require('gulp-autoprefixer');
const browserSync = require('browser-sync').create();
const pkg = require('./package.json');
const webpackConfig = require('./webpack.config');
const testWebpackConfig = require('./webpack.test.config');
const banner = '/*! <%= pkg.name %> - v<%= pkg.version %> | <%= new Date().getFullYear() %> */\n';
gulp.task('test-script-format', () => (
gulp.src([
'./examples/src/**/*.js',
'./src/**/*.js',
'./test/**/*.js',
'./*.js',
])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError())
));
gulp.task('test-mocha', ['test-script-format'], () => (
gulp.src(['./test/**/*.js'])
.pipe(mocha({
require: [
'@babel/register',
'./test/setup.js',
],
}))
));
gulp.task('test', ['test-script-format', 'test-mocha']);
gulp.task('build-script', ['test'], () => (
gulp.src(['./src/index.js'])
.pipe(webpackStream(webpackConfig('node'), webpack))
.pipe(header(banner, { pkg }))
.pipe(gulp.dest('./lib/'))
));
gulp.task('build-script-web', ['build-script'], () => (
gulp.src(['./src/index.js'])
.pipe(webpackStream(webpackConfig('web'), webpack))
.pipe(header(banner, { pkg }))
.pipe(gulp.dest('./lib/'))
));
gulp.task('build-style', () => (
gulp.src('./src/scss/**/*.scss')
.pipe(scsslint())
.pipe(scsslint.failReporter())
.pipe(sass({
outputStyle: 'expanded',
}).on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
}))
.pipe(gulp.dest('./lib'))
.pipe(minify())
.pipe(gulp.dest('./.css-compare/scss'))
));
gulp.task('build-style-less', () => (
gulp.src('./src/less/**/*.less')
.pipe(less())
.pipe(autoprefixer({
browsers: ['last 2 versions'],
}))
.pipe(minify())
.pipe(gulp.dest('./.css-compare/less'))
));
gulp.task('compare-css-output', ['build-style', 'build-style-less'], () => (
run('cmp .css-compare/less/react-checkbox-tree.css .css-compare/scss/react-checkbox-tree.css').exec()
));
gulp.task('build', ['build-script-web', 'compare-css-output']);
gulp.task('build-examples-style', () => (
gulp.src('./examples/src/scss/**/*.scss')
.pipe(scsslint())
.pipe(scsslint.failReporter())
.pipe(sass({
outputStyle: 'expanded',
}).on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
}))
.pipe(gulp.dest('./examples/dist'))
.pipe(browserSync.stream())
));
gulp.task('build-examples-script', () => (
gulp.src(['./examples/src/index.js'])
.pipe(webpackStream(testWebpackConfig, webpack))
.pipe(gulp.dest('./examples/dist/'))
.pipe(browserSync.stream())
));
gulp.task('build-examples-html', () => (
gulp.src('./examples/src/index.html')
.pipe(gulp.dest('./examples/dist/'))
.pipe(browserSync.stream())
));
gulp.task('examples', ['build-examples-style', 'build-examples-script', 'build-examples-html'], () => {
browserSync.init({ server: './examples/dist' });
gulp.watch(['./src/js/**/*.js', './examples/src/**/*.js'], ['build-examples-script']);
gulp.watch(['./src/scss/**/*.scss', './examples/src/**/*.scss'], ['build-examples-style']);
gulp.watch(['./examples/src/**/*.html'], ['build-examples-html']).on('change', browserSync.reload);
});
gulp.task('default', ['build']);