|
2 | 2 | /*jshint esversion: 6 */ |
3 | 3 |
|
4 | 4 | // include plug-ins |
5 | | -const { src, dest, series, parallel, watch } = require('gulp'); |
6 | | -const del = require('del'); |
7 | | -const sourcemaps = require('gulp-sourcemaps'); |
8 | | -const rename = require('gulp-rename'); |
9 | | -const concat = require('gulp-concat'); |
10 | | -const less = require('gulp-less'); |
11 | | -const autoprefixer = require('gulp-autoprefixer'); |
12 | | -const cleanCss = require('gulp-clean-css'); |
13 | | -const uglify = require('gulp-uglify'); |
14 | | - |
15 | | -const webRootPath = "wwwroot"; |
16 | | -const bowerDirPath = webRootPath + "/lib"; |
17 | | -const styleDirPath = webRootPath + '/styles'; |
18 | | -const scriptDirPath = webRootPath + '/scripts'; |
| 5 | +let { src, dest, series, parallel, watch } = require('gulp'); |
| 6 | +let del = require('del'); |
| 7 | +let sourcemaps = require('gulp-sourcemaps'); |
| 8 | +let rename = require('gulp-rename'); |
| 9 | +let concat = require('gulp-concat'); |
| 10 | +let less = require('gulp-less'); |
| 11 | +let autoprefixer = require('gulp-autoprefixer'); |
| 12 | +let cleanCss = require('gulp-clean-css'); |
| 13 | +let uglify = require('gulp-uglify'); |
| 14 | + |
| 15 | +const WEB_ROOT_PATH = "wwwroot"; |
| 16 | +const BOWER_DIR_PATH = WEB_ROOT_PATH + "/lib"; |
| 17 | +const STYLE_DIR_PATH = WEB_ROOT_PATH + '/styles'; |
| 18 | +const SCRIPT_DIR_PATH = WEB_ROOT_PATH + '/scripts'; |
19 | 19 |
|
20 | 20 | //#region Clean |
21 | 21 | //#region Clean builded assets |
22 | 22 | function cleanBuildedStyles() { |
23 | | - return del([styleDirPath + '/build/*']); |
| 23 | + return del([STYLE_DIR_PATH + '/build/*']); |
24 | 24 | } |
25 | 25 |
|
26 | 26 | function cleanBuildedScripts() { |
27 | | - return del([scriptDirPath + '/build/*']); |
| 27 | + return del([SCRIPT_DIR_PATH + '/build/*']); |
28 | 28 | } |
29 | 29 |
|
30 | | -const cleanBuildedAssets = parallel(cleanBuildedStyles, cleanBuildedScripts); |
| 30 | +let cleanBuildedAssets = parallel(cleanBuildedStyles, cleanBuildedScripts); |
31 | 31 | //#endregion |
32 | 32 | //#endregion |
33 | 33 |
|
34 | 34 | //#region Build assets |
35 | 35 | //#region Build styles |
36 | | -const autoprefixerOptions = { |
| 36 | +let autoprefixerOptions = { |
37 | 37 | overrideBrowserslist: ['> 1%', 'last 3 versions', 'Firefox ESR', 'Opera 12.1'], |
38 | 38 | cascade: true |
39 | 39 | }; |
40 | | -const cssCleanOptions = { specialComments: '*' }; |
41 | | -const cssRenameOptions = { extname: '.min.css' }; |
| 40 | +let cssCleanOptions = { specialComments: '*' }; |
| 41 | +let cssRenameOptions = { extname: '.min.css' }; |
42 | 42 |
|
43 | 43 | function buildCommonStyles() { |
44 | | - return src([styleDirPath + '/app.less']) |
| 44 | + return src([STYLE_DIR_PATH + '/app.less']) |
45 | 45 | .pipe(sourcemaps.init()) |
46 | 46 | .pipe(less({ |
47 | 47 | relativeUrls: true, |
48 | 48 | rootpath: '/styles/' |
49 | 49 | })) |
50 | 50 | .pipe(autoprefixer(autoprefixerOptions)) |
51 | 51 | .pipe(sourcemaps.write('./')) |
52 | | - .pipe(dest(styleDirPath + '/build')) |
| 52 | + .pipe(dest(STYLE_DIR_PATH + '/build')) |
53 | 53 | .pipe(sourcemaps.init({ loadMaps: true })) |
54 | 54 | .pipe(concat('common-styles.css')) |
55 | 55 | .pipe(cleanCss(cssCleanOptions)) |
56 | 56 | .pipe(rename(cssRenameOptions)) |
57 | 57 | .pipe(sourcemaps.write('./')) |
58 | | - .pipe(dest(styleDirPath + '/build')) |
| 58 | + .pipe(dest(STYLE_DIR_PATH + '/build')) |
59 | 59 | ; |
60 | 60 | } |
61 | 61 |
|
62 | | -const buildStyles = buildCommonStyles; |
| 62 | +let buildStyles = buildCommonStyles; |
63 | 63 | //#endregion |
64 | 64 |
|
65 | 65 | //#region Build scripts |
66 | | -const jsConcatOptions = { newLine: ';' }; |
67 | | -const jsUglifyOptions = { |
| 66 | +let jsConcatOptions = { newLine: ';' }; |
| 67 | +let jsUglifyOptions = { |
68 | 68 | output: { comments: /^!/ } |
69 | 69 | }; |
70 | | -const jsRenameOptions = { extname: '.min.js' }; |
| 70 | +let jsRenameOptions = { extname: '.min.js' }; |
71 | 71 |
|
72 | 72 | function buildModernizrScripts() { |
73 | | - return src([bowerDirPath + '/modernizr/modernizr.js']) |
| 73 | + return src([BOWER_DIR_PATH + '/modernizr/modernizr.js']) |
74 | 74 | .pipe(sourcemaps.init()) |
75 | 75 | .pipe(uglify(jsUglifyOptions)) |
76 | 76 | .pipe(rename(jsRenameOptions)) |
77 | 77 | .pipe(sourcemaps.write('./')) |
78 | | - .pipe(dest(scriptDirPath + '/build')) |
| 78 | + .pipe(dest(SCRIPT_DIR_PATH + '/build')) |
79 | 79 | ; |
80 | 80 | } |
81 | 81 |
|
82 | 82 | function buildCommonScripts() { |
83 | | - return src([scriptDirPath + '/common.js']) |
| 83 | + return src([SCRIPT_DIR_PATH + '/common.js']) |
84 | 84 | .pipe(sourcemaps.init({ loadMaps: true })) |
85 | 85 | .pipe(rename({ basename: 'common-scripts' })) |
86 | 86 | .pipe(uglify(jsUglifyOptions)) |
87 | 87 | .pipe(rename(jsRenameOptions)) |
88 | 88 | .pipe(sourcemaps.write('./')) |
89 | | - .pipe(dest(scriptDirPath + '/build')) |
| 89 | + .pipe(dest(SCRIPT_DIR_PATH + '/build')) |
90 | 90 | ; |
91 | 91 | } |
92 | 92 |
|
93 | 93 | function buildEvaluationFormScripts() { |
94 | | - return src([bowerDirPath + '/jquery-validation/dist/jquery.validate.js', |
95 | | - bowerDirPath + '/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js', |
96 | | - bowerDirPath + '/bootstrap/js/button.js', |
97 | | - scriptDirPath + '/evaluation-form.js']) |
| 94 | + return src([BOWER_DIR_PATH + '/jquery-validation/dist/jquery.validate.js', |
| 95 | + BOWER_DIR_PATH + '/jquery-validation-unobtrusive/jquery.validate.unobtrusive.js', |
| 96 | + BOWER_DIR_PATH + '/bootstrap/js/button.js', |
| 97 | + SCRIPT_DIR_PATH + '/evaluation-form.js']) |
98 | 98 | .pipe(sourcemaps.init({ loadMaps: true })) |
99 | 99 | .pipe(concat('evaluation-form-scripts.js', jsConcatOptions)) |
100 | 100 | .pipe(uglify(jsUglifyOptions)) |
101 | 101 | .pipe(rename(jsRenameOptions)) |
102 | 102 | .pipe(sourcemaps.write('./')) |
103 | | - .pipe(dest(scriptDirPath + '/build')) |
| 103 | + .pipe(dest(SCRIPT_DIR_PATH + '/build')) |
104 | 104 | ; |
105 | 105 | } |
106 | 106 |
|
107 | | -const buildScripts = parallel(buildModernizrScripts, buildCommonScripts, buildEvaluationFormScripts); |
| 107 | +let buildScripts = parallel(buildModernizrScripts, buildCommonScripts, buildEvaluationFormScripts); |
108 | 108 | //#endregion |
109 | 109 |
|
110 | | -const buildAssets = parallel(buildStyles, buildScripts); |
| 110 | +let buildAssets = parallel(buildStyles, buildScripts); |
111 | 111 | //#endregion |
112 | 112 |
|
113 | 113 | //#region Watch assets |
114 | 114 | function watchStyles() { |
115 | | - return watch([styleDirPath + '/**/*.{less,css}', '!' + styleDirPath + '/build/**/*.*'], |
| 115 | + return watch([STYLE_DIR_PATH + '/**/*.{less,css}', '!' + STYLE_DIR_PATH + '/build/**/*.*'], |
116 | 116 | buildStyles); |
117 | 117 | } |
118 | 118 |
|
119 | 119 | function watchScripts() { |
120 | | - return watch([scriptDirPath + '/**/*.js', '!' + scriptDirPath + '/build/**/*.*'], |
| 120 | + return watch([SCRIPT_DIR_PATH + '/**/*.js', '!' + SCRIPT_DIR_PATH + '/build/**/*.*'], |
121 | 121 | buildScripts); |
122 | 122 | } |
123 | 123 |
|
124 | | -const watchAssets = parallel(watchStyles, watchScripts); |
| 124 | +let watchAssets = parallel(watchStyles, watchScripts); |
125 | 125 | //#endregion |
126 | 126 |
|
127 | 127 | // Export tasks |
|
0 commit comments