|
2 | 2 |
|
3 | 3 | const gulp = require('gulp');
|
4 | 4 | const del = require('del');
|
5 |
| -const runSequence = require('run-sequence'); |
6 | 5 | const browserSync = require('browser-sync');
|
7 |
| -const gulpLoadPlugins = require('gulp-load-plugins'); |
8 | 6 | const lazypipe = require('lazypipe');
|
| 7 | +const eslint = require('gulp-eslint'); |
| 8 | +const uglify = require('gulp-uglify'); |
| 9 | +const rename = require('gulp-rename'); |
| 10 | +const header = require('gulp-header'); |
| 11 | +const babel = require('gulp-babel'); |
9 | 12 |
|
10 |
| -const $ = gulpLoadPlugins(); |
11 |
| -const reload = browserSync.reload; |
12 | 13 | const pkg = require('./package.json');
|
13 |
| -const today = $.util.date('dd-mm-yyyy HH:MM'); |
14 | 14 |
|
15 |
| -const browserSyncConfigs = { |
16 |
| - notify: false, |
17 |
| - // Disable open automatically when Browsersync starts. |
18 |
| - open: false, |
19 |
| - server: ['./'], |
20 |
| - port: 3000 |
21 |
| -}; |
| 15 | +const [todayDateISO, todayTimeISO] = new Date().toISOString().split('T'); |
| 16 | +const [todayYear, todayMonth, todayDay] = todayDateISO.split('-'); |
| 17 | +const [todayHour, todayMinute] = todayTimeISO.split(':'); |
| 18 | +const today = `${todayDay}-${todayMonth}-${todayYear} ${todayHour}:${todayMinute}`; |
22 | 19 |
|
23 | 20 | const banner = [
|
24 | 21 | '/*!',
|
25 | 22 | ' * MoveTo - ' + pkg.description,
|
26 | 23 | ' * Version ' + pkg.version + ' (' + today + ')',
|
27 | 24 | ' * Licensed under ' + pkg.license,
|
28 |
| - ' * Copyright ' + $.util.date('yyyy') + ' ' + pkg.author, |
| 25 | + ' * Copyright ' + todayYear + ' ' + pkg.author, |
29 | 26 | ' */\n\n'
|
30 | 27 | ].join('\n');
|
31 | 28 |
|
32 |
| - |
33 |
| -gulp.task('scripts:lint', (cb) => { |
| 29 | +function jsLint() { |
34 | 30 | return gulp.src('src/**/*.js')
|
35 |
| - .pipe($.eslint()) |
36 |
| - .pipe($.eslint.format()) |
37 |
| - .pipe(browserSync.active ? $.util.noop() : $.eslint.failOnError()); |
38 |
| -}); |
| 31 | + .pipe(eslint()) |
| 32 | + .pipe(eslint.format()) |
| 33 | + .pipe(browserSync.active ? () => undefined : eslint.failOnError()); |
| 34 | +} |
39 | 35 |
|
40 |
| -gulp.task('scripts', ['scripts:lint'], () => { |
| 36 | +function jsMain(cb) { |
41 | 37 | const scriptsMinChannel = lazypipe()
|
42 |
| - .pipe($.uglify) |
43 |
| - .pipe($.rename, {suffix: '.min'}) |
44 |
| - .pipe($.header, banner) |
| 38 | + .pipe(uglify) |
| 39 | + .pipe(rename, {suffix: '.min'}) |
| 40 | + .pipe(header, banner) |
45 | 41 | .pipe(gulp.dest, 'dist/');
|
46 | 42 |
|
47 | 43 | return gulp.src('src/**/*.js')
|
48 |
| - .pipe($.babel({presets: ['@babel/preset-env']})) |
49 |
| - .pipe($.header(banner)) |
| 44 | + .pipe(babel({ presets: ['@babel/preset-env'] })) |
| 45 | + .pipe(header(banner)) |
50 | 46 | .pipe(gulp.dest('dist'))
|
51 |
| - .pipe(scriptsMinChannel()); |
52 |
| -}); |
| 47 | + .pipe(scriptsMinChannel()) |
| 48 | + .on('end', cb); |
| 49 | +} |
| 50 | + |
| 51 | +function reload(cb) { |
| 52 | + browserSync.reload(); |
| 53 | + cb(); |
| 54 | +} |
| 55 | + |
| 56 | +function serve() { |
| 57 | + browserSync.init({ |
| 58 | + ghostMode: false, |
| 59 | + notify: false, |
| 60 | + server: ['./'], |
| 61 | + port: 3000 |
| 62 | + }); |
| 63 | + |
| 64 | + gulp.watch('src/**/*.js', gulp.series('scripts', reload)); |
| 65 | +} |
| 66 | + |
| 67 | +gulp.task('scripts:lint', jsLint); |
| 68 | +gulp.task('scripts:main', jsMain); |
| 69 | +gulp.task('scripts', gulp.series('scripts:lint', 'scripts:main')); |
53 | 70 |
|
54 |
| -gulp.task('clean:dist', () => del(['dist/*'], {dot: true})); |
| 71 | +gulp.task('clean:dist', () => del(['dist/*'], { dot: true })); |
55 | 72 |
|
56 |
| -gulp.task('build', (cb) => |
57 |
| - runSequence( |
58 |
| - ['clean:dist'], |
59 |
| - ['scripts'], |
60 |
| - cb |
61 |
| - ) |
62 |
| -); |
| 73 | +gulp.task('build', gulp.series('clean:dist', 'scripts')); |
63 | 74 |
|
64 |
| -gulp.task('serve', () => { |
65 |
| - browserSync(browserSyncConfigs); |
66 |
| - gulp.watch(['src/**/*.js'], ['scripts', reload]); |
67 |
| -}); |
| 75 | +gulp.task('serve', serve); |
0 commit comments