1
- 'use strict' ;
1
+ const gulp = require ( 'gulp' ) ;
2
+ const eslint = require ( 'gulp-eslint' ) ;
3
+ const gulpIf = require ( 'gulp-if' ) ;
4
+ const { inject } = require ( './inject' )
2
5
3
- var gulp = require ( 'gulp' ) ;
4
- var eslint = require ( 'gulp-eslint' ) ;
6
+ const paths = gulp . paths ;
5
7
6
- var paths = gulp . paths ;
7
-
8
- var $ = require ( 'gulp-load-plugins' ) ( {
8
+ const $ = require ( 'gulp-load-plugins' ) ( {
9
9
pattern : [ 'gulp-*' , 'uglify-save-license' , 'del' ]
10
10
} ) ;
11
11
12
- gulp . task ( 'partials' , function ( ) {
12
+ const partialsFn = ( ) => {
13
13
return gulp . src ( [
14
14
paths . src + '/{app,components}/**/*.html' ,
15
15
paths . tmp + '/{app,components}/**/*.html'
@@ -23,53 +23,49 @@ gulp.task('partials', function () {
23
23
module : 'topcoderX'
24
24
} ) )
25
25
. pipe ( gulp . dest ( paths . tmp + '/partials/' ) ) ;
26
- } ) ;
26
+ }
27
+ gulp . task ( 'partials' , partialsFn ) ;
27
28
28
- gulp . task ( 'html' , [ 'inject' , 'partials' ] , function ( ) {
29
- var partialsInjectFile = gulp . src ( paths . tmp + '/partials/templateCacheHtml.js' , { read : false } ) ;
30
- var partialsInjectOptions = {
31
- starttag : '<!-- inject:partials -->' ,
32
- ignorePath : paths . tmp + '/partials' ,
33
- addRootSlash : false
34
- } ;
29
+ const html = ( ) => {
30
+ return new Promise ( async ( resolve , reject ) => {
31
+ const partialsInjectFile = gulp . src ( paths . tmp + '/partials/templateCacheHtml.js' , { read : false } ) ;
32
+ const partialsInjectOptions = {
33
+ starttag : '<!-- inject:partials -->' ,
34
+ ignorePath : paths . tmp + '/partials' ,
35
+ addRootSlash : false
36
+ } ;
37
+ const rev = ( await import ( 'gulp-rev' ) ) . default ;
35
38
36
- var htmlFilter = $ . filter ( '*.html' ) ;
37
- var jsFilter = $ . filter ( '**/*.js' ) ;
38
- var cssFilter = $ . filter ( '**/*.css' ) ;
39
- var assets ;
40
-
41
- return gulp . src ( paths . tmp + '/serve/*.html' )
42
- . pipe ( $ . inject ( partialsInjectFile , partialsInjectOptions ) )
43
- . pipe ( assets = $ . useref . assets ( ) )
44
- . pipe ( $ . rev ( ) )
45
- . pipe ( jsFilter )
46
- . pipe ( $ . ngAnnotate ( ) )
47
- . pipe ( $ . uglify ( { preserveComments : $ . uglifySaveLicense } ) )
48
- . pipe ( jsFilter . restore ( ) )
49
- . pipe ( cssFilter )
50
- . pipe ( $ . replace ( / \. ? \. ? \/ n o d e _ m o d u l e s \/ \w + - ? \/ ? \w + \/ f o n t s \/ ? / g, '../fonts/' ) )
51
- . pipe ( $ . csso ( ) )
52
- . pipe ( cssFilter . restore ( ) )
53
- . pipe ( assets . restore ( ) )
54
- . pipe ( $ . useref ( ) )
55
- . pipe ( $ . revReplace ( ) )
56
- . pipe ( htmlFilter )
57
- . pipe ( $ . minifyHtml ( {
58
- empty : true ,
59
- spare : true ,
60
- quotes : true
61
- } ) )
62
- . pipe ( htmlFilter . restore ( ) )
63
- . pipe ( gulp . dest ( paths . dist + '/' ) )
64
- . pipe ( $ . size ( { title : paths . dist + '/' , showFiles : true } ) ) ;
65
- } ) ;
39
+ return gulp . src ( paths . tmp + '/serve/*.html' )
40
+ . pipe ( $ . inject ( partialsInjectFile , partialsInjectOptions ) )
41
+ . pipe ( $ . useref ( ) )
42
+ . pipe ( rev ( ) )
43
+ . pipe ( gulpIf ( '**/*.js' , $ . ngAnnotate ( ) ) )
44
+ . pipe ( gulpIf ( '**/*.js' , $ . uglify ( ) ) )
45
+ . pipe ( gulpIf ( '**/*.css' , $ . replace ( / \. ? \. ? \/ n o d e _ m o d u l e s \/ \w + - ? \/ ? \w + \/ f o n t s \/ ? / g, '../fonts/' ) ) )
46
+ . pipe ( gulpIf ( '**/*.css' , $ . csso ( ) ) )
47
+ . pipe ( $ . revReplace ( ) )
48
+ . pipe ( gulpIf ( '**/*.html' , $ . minifyHtml ( {
49
+ empty : true ,
50
+ spare : true ,
51
+ quotes : true ,
52
+ conditionals : true
53
+ } ) ) )
54
+ . pipe ( gulp . dest ( paths . dist + '/' ) )
55
+ . pipe ( $ . size ( { title : paths . dist + '/' , showFiles : true } ) )
56
+ . on ( 'finish' , resolve )
57
+ . on ( 'error' , reject ) ;
58
+ } ) ;
59
+ }
60
+ gulp . task ( 'html' , gulp . series ( inject , partialsFn , html ) ) ;
66
61
67
- gulp . task ( ' images' , function ( ) {
62
+ const images = ( ) => {
68
63
return gulp . src ( paths . src + '/assets/images/**/*' )
69
64
. pipe ( gulp . dest ( paths . dist + '/assets/images/' ) ) ;
70
- } ) ;
65
+ }
66
+ gulp . task ( 'images' , images ) ;
71
67
72
- gulp . task ( ' fonts' , function ( ) {
68
+ const fonts = ( ) => {
73
69
return gulp . src ( [
74
70
"node_modules/bootstrap/dist/fonts/*.{eot,svg,ttf,woff,woff2}" ,
75
71
"node_modules/footable/css/fonts/*.{eot,svg,ttf,woff,woff2}"
@@ -78,28 +74,34 @@ gulp.task('fonts', function () {
78
74
. pipe ( $ . flatten ( ) )
79
75
. pipe ( gulp . dest ( paths . dist + '/fonts/' ) )
80
76
. pipe ( gulp . dest ( paths . dist + '/styles/fonts/' ) ) ;
81
- } ) ;
77
+ }
78
+ gulp . task ( 'fonts' , fonts ) ;
82
79
83
- gulp . task ( 'fontawesome' , function ( ) {
80
+ const fontAwesome = ( ) => {
84
81
return gulp . src ( 'node_modules/font-awesome/fonts/*.{eot,svg,ttf,woff,woff2}' )
85
82
. pipe ( gulp . dest ( paths . dist + '/fonts/' ) ) ;
86
- } ) ;
83
+ }
84
+ gulp . task ( 'fontawesome' , fontAwesome ) ;
87
85
88
- gulp . task ( ' misc' , function ( ) {
86
+ const misc = ( ) => {
89
87
return gulp . src ( paths . src + '/**/*.ico' )
90
88
. pipe ( gulp . dest ( paths . dist + '/' ) ) ;
91
- } ) ;
89
+ }
90
+ gulp . task ( 'misc' , misc ) ;
92
91
93
- gulp . task ( 'clean' , function ( done ) {
92
+ const cleanFn = ( done ) => {
94
93
$ . del ( [ paths . dist + '/' , paths . tmp + '/' , paths . src + '/app/config.js' ] , done ) ;
95
- } ) ;
94
+ }
95
+ const clean = gulp . series ( cleanFn ) ;
96
+ gulp . task ( 'clean' , cleanFn ) ;
96
97
97
- gulp . task ( ' lint' , ( ) => {
98
+ const lint = ( ) => {
98
99
// ESLint ignores files with "node_modules" paths.
99
100
// So, it's best to have gulp ignore the directory as well.
100
101
// Also, Be sure to return the stream from the task;
101
102
// Otherwise, the task may end before the stream has finished.
102
- return gulp . src ( [ 'src/**/*.js' , '!src/front/e2e/**/*.js' , '!src/public/**' , '!gulp/**' , '!node_modules/**' ] )
103
+ return gulp
104
+ . src ( [ 'src/**/*.js' , '!src/front/e2e/**/*.js' , '!src/public/**' , '!gulp/**' , '!node_modules/**' ] )
103
105
// eslint() attaches the lint output to the "eslint" property
104
106
// of the file object so it can be used by other modules.
105
107
. pipe ( eslint ( {
@@ -111,7 +113,10 @@ gulp.task('lint', () => {
111
113
// To have the process exit with an error code (1) on
112
114
// lint error, return the stream and pipe to failAfterError last.
113
115
. pipe ( eslint . failAfterError ( ) ) ;
114
- } ) ;
116
+ }
117
+ gulp . task ( 'lint' , lint ) ;
118
+
119
+ const build = gulp . series ( lint , html , images , fonts , fontAwesome , misc ) ;
120
+ gulp . task ( 'build' , build ) ;
115
121
116
- gulp . task ( 'build' , [ 'lint' , 'html' , 'images' , 'fonts' , 'fontawesome' , 'misc' ] ) ;
117
- gulp . task ( 'build:watch' , [ 'watch:build' ] ) ;
122
+ module . exports = { clean, build } ;
0 commit comments