|
1 |
| -const gulp = require( 'gulp' ); |
2 |
| -const $ = require( 'gulp-load-plugins' )(); |
3 |
| -const del = require( 'del' ); |
4 |
| -const browserSync = require( 'browser-sync' ); |
5 |
| -const named = require( 'vinyl-named' ); |
6 |
| -const webpack = require( 'webpack-stream' ); |
7 |
| -const qunit = require( 'node-qunit-phantomjs' ); |
8 |
| -const { data } = require( 'json-file' ).read( './package.json' ); |
| 1 | +/* eslint-disable function-paren-newline */ |
| 2 | +const gulp = require('gulp'); |
| 3 | +const $ = require('gulp-load-plugins')(); |
| 4 | +const del = require('del'); |
| 5 | +const browserSync = require('browser-sync'); |
| 6 | +const named = require('vinyl-named'); |
| 7 | +const webpack = require('webpack-stream'); |
| 8 | +const qunit = require('node-qunit-phantomjs'); |
| 9 | +const { data } = require('json-file').read('./package.json'); |
9 | 10 |
|
10 |
| -const webpackconfig = require( './webpack.config.js' ); |
| 11 | +const webpackconfig = require('./webpack.config'); |
11 | 12 |
|
12 | 13 | function getMainHeader() {
|
13 |
| - return `/*! |
| 14 | + return `/*! |
14 | 15 | * Name : Just Another Parallax [Jarallax]
|
15 |
| - * Version : ${ data.version } |
16 |
| - * Author : ${ data.author } |
17 |
| - * GitHub : ${ data.homepage } |
| 16 | + * Version : ${data.version} |
| 17 | + * Author : ${data.author} |
| 18 | + * GitHub : ${data.homepage} |
18 | 19 | */
|
19 | 20 | `;
|
20 | 21 | }
|
21 | 22 | function getVideoHeader() {
|
22 |
| - return `/*! |
| 23 | + return `/*! |
23 | 24 | * Name : Video Background Extension for Jarallax
|
24 | 25 | * Version : 1.0.1
|
25 |
| - * Author : ${ data.author } |
26 |
| - * GitHub : ${ data.homepage } |
| 26 | + * Author : ${data.author} |
| 27 | + * GitHub : ${data.homepage} |
27 | 28 | */
|
28 | 29 | `;
|
29 | 30 | }
|
30 | 31 | function getElementHeader() {
|
31 |
| - return `/*! |
| 32 | + return `/*! |
32 | 33 | * Name : DEPRECATED Elements Extension for Jarallax. Use laxxx instead https://github.com/alexfoxy/laxxx
|
33 | 34 | * Version : 1.0.0
|
34 |
| - * Author : ${ data.author } |
35 |
| - * GitHub : ${ data.homepage } |
| 35 | + * Author : ${data.author} |
| 36 | + * GitHub : ${data.homepage} |
36 | 37 | */
|
37 | 38 | `;
|
38 | 39 | }
|
39 | 40 |
|
40 | 41 | /**
|
41 | 42 | * Error Handler for gulp-plumber
|
42 | 43 | */
|
43 |
| -function errorHandler( err ) { |
44 |
| - // eslint-disable-next-line no-console |
45 |
| - console.error( err ); |
46 |
| - this.emit( 'end' ); |
| 44 | +function errorHandler(err) { |
| 45 | + // eslint-disable-next-line no-console |
| 46 | + console.error(err); |
| 47 | + this.emit('end'); |
47 | 48 | }
|
48 | 49 |
|
49 | 50 | /**
|
50 | 51 | * Clean Task
|
51 | 52 | */
|
52 |
| -gulp.task( 'clean', () => del( [ 'dist' ] ) ); |
| 53 | +gulp.task('clean', () => del(['dist'])); |
53 | 54 |
|
54 | 55 | /**
|
55 | 56 | * JS Task
|
56 | 57 | */
|
57 |
| -gulp.task( 'js', () => ( |
58 |
| - gulp.src( [ 'src/*.js', '!src/*.esm.js' ] ) |
59 |
| - .pipe( $.plumber( { errorHandler } ) ) |
60 |
| - .pipe( named() ) |
61 |
| - .pipe( webpack( { |
62 |
| - config: webpackconfig, |
63 |
| - } ) ) |
64 |
| - .pipe( $.if( ( file ) => file.path.match( /jarallax.js$/ ), $.header( getMainHeader() ) ) ) |
65 |
| - .pipe( $.if( ( file ) => file.path.match( /jarallax-video.js$/ ), $.header( getVideoHeader() ) ) ) |
66 |
| - .pipe( $.if( ( file ) => file.path.match( /jarallax-element.js$/ ), $.header( getElementHeader() ) ) ) |
67 |
| - .pipe( gulp.dest( 'dist' ) ) |
68 |
| - .pipe( $.rename( { suffix: '.min' } ) ) |
69 |
| - .pipe( $.uglify( { |
70 |
| - output: { |
71 |
| - comments: /^!/, |
72 |
| - }, |
73 |
| - } ) ) |
74 |
| - .pipe( $.sourcemaps.write( '.' ) ) |
75 |
| - .pipe( gulp.dest( 'dist' ) ) |
76 |
| - .pipe( browserSync.stream() ) |
77 |
| -) ); |
| 58 | +gulp.task('js', () => |
| 59 | + gulp |
| 60 | + .src(['src/*.js', '!src/*.esm.js']) |
| 61 | + .pipe($.plumber({ errorHandler })) |
| 62 | + .pipe(named()) |
| 63 | + .pipe( |
| 64 | + webpack({ |
| 65 | + config: webpackconfig, |
| 66 | + }) |
| 67 | + ) |
| 68 | + .pipe($.if((file) => file.path.match(/jarallax.js$/), $.header(getMainHeader()))) |
| 69 | + .pipe($.if((file) => file.path.match(/jarallax-video.js$/), $.header(getVideoHeader()))) |
| 70 | + .pipe($.if((file) => file.path.match(/jarallax-element.js$/), $.header(getElementHeader()))) |
| 71 | + .pipe(gulp.dest('dist')) |
| 72 | + .pipe($.rename({ suffix: '.min' })) |
| 73 | + .pipe( |
| 74 | + $.uglify({ |
| 75 | + output: { |
| 76 | + comments: /^!/, |
| 77 | + }, |
| 78 | + }) |
| 79 | + ) |
| 80 | + .pipe($.sourcemaps.write('.')) |
| 81 | + .pipe(gulp.dest('dist')) |
| 82 | + .pipe(browserSync.stream()) |
| 83 | +); |
78 | 84 |
|
79 | 85 | /**
|
80 | 86 | * CSS Task
|
81 | 87 | */
|
82 |
| -gulp.task( 'css', () => ( |
83 |
| - gulp.src( 'src/*.css' ) |
84 |
| - .pipe( gulp.dest( 'dist' ) ) |
85 |
| - .pipe( browserSync.stream() ) |
86 |
| -) ); |
87 |
| - |
| 88 | +gulp.task('css', () => gulp.src('src/*.css').pipe(gulp.dest('dist')).pipe(browserSync.stream())); |
88 | 89 |
|
89 | 90 | /**
|
90 | 91 | * BrowserSync Task
|
91 | 92 | */
|
92 |
| -gulp.task( 'browser_sync', ( cb ) => { |
93 |
| - browserSync.init( { |
94 |
| - server: { |
95 |
| - baseDir: [ 'demo', './' ], |
96 |
| - }, |
97 |
| - } ); |
| 93 | +gulp.task('browser_sync', (cb) => { |
| 94 | + browserSync.init({ |
| 95 | + server: { |
| 96 | + baseDir: ['demo', './'], |
| 97 | + }, |
| 98 | + }); |
98 | 99 |
|
99 |
| - cb(); |
100 |
| -} ); |
| 100 | + cb(); |
| 101 | +}); |
101 | 102 |
|
102 | 103 | /**
|
103 | 104 | * Build (default) Task
|
104 | 105 | */
|
105 |
| -gulp.task( 'build', gulp.series( 'clean', [ 'js', 'css' ] ) ); |
| 106 | +gulp.task('build', gulp.series('clean', ['js', 'css'])); |
106 | 107 |
|
107 | 108 | /**
|
108 | 109 | * Watch Task
|
109 | 110 | */
|
110 |
| -gulp.task( 'dev', gulp.series( 'build', 'browser_sync', () => { |
111 |
| - gulp.watch( 'src/*.js', gulp.series( 'js' ) ); |
112 |
| - gulp.watch( 'src/*.css', gulp.series( 'css' ) ); |
113 |
| -} ) ); |
| 111 | +gulp.task( |
| 112 | + 'dev', |
| 113 | + gulp.series('build', 'browser_sync', () => { |
| 114 | + gulp.watch('src/*.js', gulp.series('js')); |
| 115 | + gulp.watch('src/*.css', gulp.series('css')); |
| 116 | + }) |
| 117 | +); |
114 | 118 |
|
115 |
| -gulp.task( 'default', gulp.series( 'build' ) ); |
| 119 | +gulp.task('default', gulp.series('build')); |
116 | 120 |
|
117 | 121 | /**
|
118 | 122 | * Test Task
|
119 | 123 | */
|
120 |
| -gulp.task( 'test', gulp.series( 'build', () => { |
121 |
| - qunit( './tests/index.html', { |
122 |
| - page: { |
123 |
| - viewportSize: { width: 1280, height: 800 }, |
124 |
| - }, |
125 |
| - 'phantomjs-options': [ '--local-to-remote-url-access=true' ], |
126 |
| - // verbose: true, |
127 |
| - timeout: 15, |
128 |
| - } ); |
129 |
| -} ) ); |
| 124 | +gulp.task( |
| 125 | + 'test', |
| 126 | + gulp.series('build', () => { |
| 127 | + qunit('./tests/index.html', { |
| 128 | + page: { |
| 129 | + viewportSize: { width: 1280, height: 800 }, |
| 130 | + }, |
| 131 | + 'phantomjs-options': ['--local-to-remote-url-access=true'], |
| 132 | + // verbose: true, |
| 133 | + timeout: 15, |
| 134 | + }); |
| 135 | + }) |
| 136 | +); |
0 commit comments