|
1 |
| -'use strict'; |
2 |
| - |
3 |
| -var gulp = require('gulp'); |
4 |
| -var eslint = require('gulp-eslint'); |
5 |
| - |
6 |
| -var paths = gulp.paths; |
7 |
| - |
8 |
| -var $ = require('gulp-load-plugins')({ |
9 |
| - pattern: ['gulp-*', 'uglify-save-license', 'del'] |
10 |
| -}); |
11 |
| - |
12 |
| -gulp.task('partials', function () { |
13 |
| - return gulp.src([ |
14 |
| - paths.src + '/{app,components}/**/*.html', |
15 |
| - paths.tmp + '/{app,components}/**/*.html' |
16 |
| - ]) |
17 |
| - .pipe($.minifyHtml({ |
18 |
| - empty: true, |
19 |
| - spare: true, |
20 |
| - quotes: true |
21 |
| - })) |
22 |
| - .pipe($.angularTemplatecache('templateCacheHtml.js', { |
23 |
| - module: 'topcoderX' |
24 |
| - })) |
25 |
| - .pipe(gulp.dest(paths.tmp + '/partials/')); |
26 |
| -}); |
27 |
| - |
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 |
| - }; |
35 |
| - |
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(/\.?\.?\/node_modules\/\w+-?\/?\w+\/fonts\/?/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 |
| -}); |
66 |
| - |
67 |
| -gulp.task('images', function () { |
68 |
| - return gulp.src(paths.src + '/assets/images/**/*') |
69 |
| - .pipe(gulp.dest(paths.dist + '/assets/images/')); |
70 |
| -}); |
71 |
| - |
72 |
| -gulp.task('fonts', function () { |
73 |
| - return gulp.src([ |
74 |
| - "node_modules/bootstrap/dist/fonts/*.{eot,svg,ttf,woff,woff2}", |
75 |
| - "node_modules/footable/css/fonts/*.{eot,svg,ttf,woff,woff2}" |
76 |
| - ]) |
77 |
| - .pipe($.filter('**/*.{eot,svg,ttf,woff,woff2}')) |
78 |
| - .pipe($.flatten()) |
79 |
| - .pipe(gulp.dest(paths.dist + '/fonts/')) |
80 |
| - .pipe(gulp.dest(paths.dist + '/styles/fonts/')); |
81 |
| -}); |
82 |
| - |
83 |
| -gulp.task('fontawesome', function () { |
84 |
| - return gulp.src('node_modules/font-awesome/fonts/*.{eot,svg,ttf,woff,woff2}') |
85 |
| - .pipe(gulp.dest(paths.dist + '/fonts/')); |
86 |
| -}); |
87 |
| - |
88 |
| -gulp.task('misc', function () { |
89 |
| - return gulp.src(paths.src + '/**/*.ico') |
90 |
| - .pipe(gulp.dest(paths.dist + '/')); |
91 |
| -}); |
92 |
| - |
93 |
| -gulp.task('clean', function (done) { |
94 |
| - $.del([paths.dist + '/', paths.tmp + '/', paths.src + '/app/config.js'], done); |
95 |
| -}); |
96 |
| - |
97 |
| -gulp.task('lint', () => { |
98 |
| - // ESLint ignores files with "node_modules" paths. |
99 |
| - // So, it's best to have gulp ignore the directory as well. |
100 |
| - // Also, Be sure to return the stream from the task; |
101 |
| - // 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 |
| - // eslint() attaches the lint output to the "eslint" property |
104 |
| - // of the file object so it can be used by other modules. |
105 |
| - .pipe(eslint({ |
106 |
| - fix: true |
107 |
| - })) |
108 |
| - // eslint.format() outputs the lint results to the console. |
109 |
| - // Alternatively use eslint.formatEach() (see Docs). |
110 |
| - .pipe(eslint.format()) |
111 |
| - // To have the process exit with an error code (1) on |
112 |
| - // lint error, return the stream and pipe to failAfterError last. |
113 |
| - .pipe(eslint.failAfterError()); |
114 |
| -}); |
115 |
| - |
116 |
| -gulp.task('build', ['lint', 'html', 'images', 'fonts', 'fontawesome', 'misc']); |
117 |
| -gulp.task('build:watch', ['watch:build']); |
| 1 | +'use strict'; |
| 2 | + |
| 3 | +var gulp = require('gulp'); |
| 4 | +var eslint = require('gulp-eslint'); |
| 5 | + |
| 6 | +var paths = gulp.paths; |
| 7 | + |
| 8 | +var $ = require('gulp-load-plugins')({ |
| 9 | + pattern: ['gulp-*', 'uglify-save-license', 'del'] |
| 10 | +}); |
| 11 | + |
| 12 | +gulp.task('partials', function () { |
| 13 | + return gulp.src([ |
| 14 | + paths.src + '/{app,components}/**/*.html', |
| 15 | + paths.tmp + '/{app,components}/**/*.html' |
| 16 | + ]) |
| 17 | + .pipe($.minifyHtml({ |
| 18 | + empty: true, |
| 19 | + spare: true, |
| 20 | + quotes: true |
| 21 | + })) |
| 22 | + .pipe($.angularTemplatecache('templateCacheHtml.js', { |
| 23 | + module: 'topcoderX' |
| 24 | + })) |
| 25 | + .pipe(gulp.dest(paths.tmp + '/partials/')); |
| 26 | +}); |
| 27 | + |
| 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 | + }; |
| 35 | + |
| 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(/\.?\.?\/node_modules\/\w+-?\/?\w+\/fonts\/?/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 | +}); |
| 66 | + |
| 67 | +gulp.task('images', function () { |
| 68 | + return gulp.src(paths.src + '/assets/images/**/*') |
| 69 | + .pipe(gulp.dest(paths.dist + '/assets/images/')); |
| 70 | +}); |
| 71 | + |
| 72 | +gulp.task('fonts', function () { |
| 73 | + return gulp.src([ |
| 74 | + "node_modules/bootstrap/dist/fonts/*.{eot,svg,ttf,woff,woff2}", |
| 75 | + "node_modules/footable/css/fonts/*.{eot,svg,ttf,woff,woff2}" |
| 76 | + ]) |
| 77 | + .pipe($.filter('**/*.{eot,svg,ttf,woff,woff2}')) |
| 78 | + .pipe($.flatten()) |
| 79 | + .pipe(gulp.dest(paths.dist + '/fonts/')) |
| 80 | + .pipe(gulp.dest(paths.dist + '/styles/fonts/')); |
| 81 | +}); |
| 82 | + |
| 83 | +gulp.task('fontawesome', function () { |
| 84 | + return gulp.src('node_modules/font-awesome/fonts/*.{eot,svg,ttf,woff,woff2}') |
| 85 | + .pipe(gulp.dest(paths.dist + '/fonts/')); |
| 86 | +}); |
| 87 | + |
| 88 | +gulp.task('misc', function () { |
| 89 | + return gulp.src(paths.src + '/**/*.ico') |
| 90 | + .pipe(gulp.dest(paths.dist + '/')); |
| 91 | +}); |
| 92 | + |
| 93 | +gulp.task('clean', function (done) { |
| 94 | + $.del([paths.dist + '/', paths.tmp + '/', paths.src + '/app/config.js'], done); |
| 95 | +}); |
| 96 | + |
| 97 | +gulp.task('lint', () => { |
| 98 | + // ESLint ignores files with "node_modules" paths. |
| 99 | + // So, it's best to have gulp ignore the directory as well. |
| 100 | + // Also, Be sure to return the stream from the task; |
| 101 | + // 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 | + // eslint() attaches the lint output to the "eslint" property |
| 104 | + // of the file object so it can be used by other modules. |
| 105 | + .pipe(eslint({ |
| 106 | + fix: true |
| 107 | + })) |
| 108 | + // eslint.format() outputs the lint results to the console. |
| 109 | + // Alternatively use eslint.formatEach() (see Docs). |
| 110 | + .pipe(eslint.format()) |
| 111 | + // To have the process exit with an error code (1) on |
| 112 | + // lint error, return the stream and pipe to failAfterError last. |
| 113 | + .pipe(eslint.failAfterError()); |
| 114 | +}); |
| 115 | + |
| 116 | +gulp.task('build', ['ng-config', 'lint', 'html', 'images', 'fonts', 'fontawesome', 'misc']); |
| 117 | +gulp.task('build:watch', ['watch:build']); |
0 commit comments