Passed
Push — master ( ce59c2...794d88 )
by Amit
04:23
created

GULP.task(ꞌdefaultꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
'use strict';
2
3
const GULP = require( 'gulp' ),
4
    SASS = require( 'gulp-sass' ),
5
    AUTOPREFIXER = require( 'gulp-autoprefixer' ),
6
    NANO = require( 'gulp-cssnano' ),
7
    BABEL = require( 'gulp-babel' ),
8
    UGLIFY = require( 'gulp-uglify' ),
9
    IMAGEMIN = require( 'gulp-imagemin' ),
10
    RENAME = require( 'gulp-rename' ),
11
    CONCAT = require( 'gulp-concat' ),
12
    SOURCEMAPS = require( 'gulp-sourcemaps' ),
13
    DEL = require( 'del' ),
14
    ESLINT = require( 'gulp-eslint' ),
15
    BROWSERSYNC = require( 'browser-sync' ).create( );
16
17
GULP.task( 'styles', function ( ) {
18
19
    // List al your SASS files HERE
20
    const SCSS_FILES = [
21
        'assets/styles/main.scss'
22
    ];
23
24
    GULP.src( SCSS_FILES )
25
        .pipe( SOURCEMAPS.init( ) )
26
        .pipe( SASS( )
27
            .on( 'error', function ( err ) {
28
                console.error(
29
                    'Error found:\n\x07' + err.message
30
                );
31
            } )
32
        )
33
        .pipe( AUTOPREFIXER( ) )
34
        .pipe( SOURCEMAPS.write( ) )
35
        .pipe( GULP.dest( 'dist/styles' ) )
36
        .pipe( BROWSERSYNC.stream( ) )
37
} );
38
39
GULP.task( 'styles-min', function ( ) {
40
    const SCSS_FILES = [
41
        'assets/styles/main.scss'
42
    ];
43
44
    GULP.src( SCSS_FILES )
45
        .pipe( SASS( )
46
            .on( 'error', function ( err ) {
47
                console.error(
48
                    'Error found:\n\x07' + err.message
49
                );
50
            } )
51
        )
52
        .pipe( AUTOPREFIXER( ) )
53
        .pipe( RENAME( {
54
            suffix: '.min'
55
        } ) )
56
        .pipe( NANO( {
57
            discardComments: {
58
                removeAll: true
59
            }
60
        } ) )
61
        .pipe( GULP.dest( 'dist/styles' ) )
62
} );
63
64
const CUSTOMJS_FILES = [
65
    'assets/scripts/**/*.js'
66
];
67
68
GULP.task( 'custom-scripts', function ( ) {
69
70
    return GULP.src( CUSTOMJS_FILES )
71
        .pipe( ESLINT( {
72
            fix: true
73
        } ) )
74
        .pipe( ESLINT.format( ) )
75
} );
76
77
78
// List all your JS files HERE
79
const JS_FILES = [
80
    'node_modules/jquery/dist/jquery.js',
81
    'node_modules/foundation-sites/dist/js/foundation.js',
82
    'assets/scripts/**/*.js'
83
];
84
85
GULP.task( 'scripts', function ( ) {
86
87
    return GULP.src( JS_FILES )
88
89
        .pipe( SOURCEMAPS.init( ) )
90
        .pipe( CONCAT( 'main.js' ) )
91
        .pipe( SOURCEMAPS.write( ) )
92
        .pipe( GULP.dest( 'dist/scripts' ) )
93
        .pipe( BROWSERSYNC.stream( ) )
94
} );
95
96
GULP.task( 'scripts-min', function ( ) {
97
    return GULP.src( JS_FILES )
98
99
        .pipe( BABEL( ) )
100
        .pipe( CONCAT( 'main.min.js' ) )
101
        .pipe( UGLIFY( )
102
            .on( 'error', function ( err ) {
103
                console.error(
104
                    err.toString( )
105
                );
106
                this.emit( 'end' );
107
            } ) )
108
        .pipe( GULP.dest( 'dist/scripts' ) )
109
} );
110
111
const RESOURCES_FILES = [
112
    'assets/resources/**/*.js'
113
];
114
115
GULP.task( 'resources', function ( ) {
116
117
    return GULP.src( RESOURCES_FILES )
118
119
        .pipe( SOURCEMAPS.init( ) )
120
        .pipe( SOURCEMAPS.write( ) )
121
        .pipe( BABEL( ) )
122
        .pipe( ESLINT( {
123
            fix: true
124
        } ) )
125
        .pipe( ESLINT.format( ) )
126
        .pipe( UGLIFY( )
127
            .on( 'error', function ( err ) {
128
                console.error(
129
                    err.toString( )
130
                );
131
                this.emit( 'end' );
132
            } ) )
133
        .pipe( GULP.dest( 'dist/scripts' ) )
134
        .pipe( BROWSERSYNC.stream( ) )
135
} );
136
137
const PHP_FILES = [
0 ignored issues
show
Unused Code introduced by
The constant PHP_FILES seems to be never used. Consider removing it.
Loading history...
138
    '{inc,template-parts}/**/*.php',
139
    '*.php'
140
];
141
142
GULP.task( 'php', function ( ) {
143
    BROWSERSYNC.reload;
0 ignored issues
show
introduced by
The result of the property access to BROWSERSYNC.reload is not used.
Loading history...
144
    return;
0 ignored issues
show
Unused Code introduced by
This return has no effect and can be removed.
Loading history...
145
} );
146
147
const IMG_FILES = [
148
    'assets/images/**/*'
149
];
150
151
GULP.task( 'images', function ( ) {
152
    return GULP.src( IMG_FILES )
153
        .pipe( GULP.dest( 'dist/images' ) )
154
        .pipe( BROWSERSYNC.stream( ) );
155
} );
156
157
GULP.task( 'images-min', function ( ) {
158
159
    return GULP.src( IMG_FILES )
160
        .pipe( IMAGEMIN( {
161
            optimizationLevel: 3,
162
            progressive: true,
163
            INTERLACED: true,
164
            use: [ IMAGEMIN.gifsicle( ), IMAGEMIN.jpegtran( ), IMAGEMIN.optipng( ), IMAGEMIN.svgo( ) ]
165
        } ) )
166
        .pipe( GULP.dest( 'dist/images' ) );
167
} );
168
169
const FONT_FILES = [
170
    'node_modules/font-awesome/fonts/*',
171
    'assets/fonts/**/*'
172
];
173
174
GULP.task( 'fonts', function ( ) {
175
176
    return GULP.src( FONT_FILES )
177
        .pipe( GULP.dest( 'dist/fonts' ) )
178
        .pipe( BROWSERSYNC.stream( ) );
179
} );
180
181
GULP.task( 'fonts-min', function ( ) {
182
183
    return GULP.src( FONT_FILES )
184
        .pipe( GULP.dest( 'dist/fonts' ) );
185
} );
186
187
GULP.task( 'clean', function ( cb ) {
188
    return DEL( [ 'dist/styles', 'dist/scripts', 'dist/resources', 'dist/images', 'dist/fonts' ], cb )
189
} );
190
191
GULP.task( 'default', [ 'clean' ], function ( ) {
192
    GULP.start( 'styles', 'custom-scripts', 'scripts', 'resources', 'php', 'images', 'fonts' );
193
} );
194
195
GULP.task( 'production', [ 'clean' ], function ( ) {
196
    GULP.start( 'styles-min', 'scripts-min', 'resources', 'images-min', 'fonts-min' );
197
} );
198
199
GULP.task( 'watch', function ( ) {
200
201
    // Run the styles task first time gulp watch is run
202
    GULP.start( 'styles' );
203
204
    BROWSERSYNC.init( {
205
        files: [ '{inc,template-parts}/**/*.php', '*.php' ],
206
        proxy: 'http://localhost/podium/',
207
        snippetOptions: {
208
            whitelist: [ '/wp-admin/admin-ajax.php' ],
209
            blacklist: [ '/wp-admin/**' ]
210
        }
211
    } );
212
    GULP.watch( [ 'assets/styles/**/*' ], [ 'styles' ] );
213
    GULP.watch( [ 'assets/scripts/**/*' ], [ 'scripts', 'custom-scripts' ] );
214
    GULP.watch( [ 'assets/fonts/**/*' ], [ 'fonts' ] );
215
    GULP.watch( [ 'assets/images/**/*' ], [ 'images' ] );
216
    GULP.watch( [ 'assets/resources/**/*' ], [ 'resources' ] );
217
    GULP.watch( [ '{inc,template-parts}/**/*.php', '*.php' ], [ 'php' ] );
218
} );
219