-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpFile.js
194 lines (178 loc) · 10.5 KB
/
gulpFile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/*==============================================================================================================================
| Author Ignia, LLC
| Client GoldSim
| Project Website
\=============================================================================================================================*/
/*==============================================================================================================================
| DEPENDENCIES
\-----------------------------------------------------------------------------------------------------------------------------*/
const {src, dest, parallel} = require('gulp');
const gulpif = require('gulp-if'),
concat = require('gulp-concat'),
merge = require('merge2');
const sass = require('gulp-sass')(require('node-sass')),
postCss = require("gulp-postcss"),
autoPrefixer = require("autoprefixer"),
cssNano = require("cssnano"),
sourceMaps = require("gulp-sourcemaps"),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify');
/*==============================================================================================================================
| VARIABLES
\-----------------------------------------------------------------------------------------------------------------------------*/
var environment = 'development',
outputDir = 'wwwroot',
isProduction = false;
/*==============================================================================================================================
| SOURCE FILE PATHS
>-------------------------------------------------------------------------------------------------------------------------------
| Paths to files referenced in the build process. Path names may use any "magic" glob characters, as documented at
| https://github.com/isaacs/node-glob.
>-------------------------------------------------------------------------------------------------------------------------------
| ### NOTE: JJC021715: These paths are only intended for source files. Destination files will not use glob "magic", and will
| be conditional based on the outputDir. As a result, they will likely be hardcoded into each task's dest() method.
\-----------------------------------------------------------------------------------------------------------------------------*/
const files = {
scss : [ 'Shared/Styles/**/*.scss',
'Shared/Styles/**/!*.scss'
],
js : 'Shared/Scripts/*.js',
jsViews : 'Shared/Scripts/Views/**/*.js'
}
/*==============================================================================================================================
| DEPENDENCIES
>-------------------------------------------------------------------------------------------------------------------------------
| Paths to third-party dependencies that need to by copies into the project. This is exclusively for pre-compiled client-side
| files, such as JavaScript (excluding TypeScript), CSS (excluding SCSS), images, and the occasional font.
\-----------------------------------------------------------------------------------------------------------------------------*/
const dependencies = {
'Scripts': {
'ApplicationInsights' : 'node_modules/@microsoft/applicationinsights-web/dist/*.min.*',
'DashJS' : 'node_modules/dashjs/dist/dash.mediaplayer.*',
'GreenSock' : [ 'node_modules/gsap/src/minified/**',
'node_modules/gsap/src/uncompressed/**'
],
'Headroom' : 'node_modules/headroom.js/dist/**',
'jQuery' : 'node_modules/jquery/dist/*.*',
'OwlCarousel' : 'node_modules/owl.carousel/dist/*.js',
'ScrollMagic' : [ 'node_modules/scrollmagic/scrollmagic/minified/**',
'scrollmagic/scrollmagic/uncompressed/**'
],
'ZURB' : 'node_modules/foundation-sites/dist/js/**/*.min.*',
},
'Styles': {
'OwlCarousel' : 'node_modules/owl.carousel/dist/assets/*.*'
},
'Fonts': {
'FontAwesome' : 'node_modules/@fortawesome/fontawesome-free/webfonts/*'
}
}
/*==============================================================================================================================
| SET ENVIRONMENT
>-------------------------------------------------------------------------------------------------------------------------------
| Looks for an environment variable and conditionally set local context accordingly.
\-----------------------------------------------------------------------------------------------------------------------------*/
environment = process.env.BUILD_ENVIRONMENT || environment;
// Environment: Development
if (environment === 'development') {
isProduction = false;
}
// Environment: Production
else {
isProduction = true;
}
/*==============================================================================================================================
| TASK: SCSS
>-------------------------------------------------------------------------------------------------------------------------------
| Compiles the SCSS files, including views, and moves them to the build directory.
\-----------------------------------------------------------------------------------------------------------------------------*/
function scssTask() {
return src(files.scss, { base: 'Shared/Styles' })
//.pipe(autoPrefixer({ browsers: ['last 2 versions', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'] }))
//.pipe(sassUnicode())
.pipe(sourceMaps.init())
.pipe(sass({
includePaths: [
'./Shared/Styles',
'./node_modules',
'./node_modules/foundation-sites/scss',
'./node_modules/@fortawesome'
]
}))
.on("error", sass.logError)
.pipe(postCss([
autoPrefixer(),
cssNano()
]))
.pipe(sourceMaps.write('.'))
.pipe(dest(outputDir + '/Shared/Styles/'));
}
/*==============================================================================================================================
| TASK: JAVASCRIPT FILES
>-------------------------------------------------------------------------------------------------------------------------------
| Minimizes JavaScript files as part of production process.
\-----------------------------------------------------------------------------------------------------------------------------*/
function jsTask() {
return src(files.js, { base: 'Shared/Scripts' })
//.pipe(jshint('.jshintrc'))
.pipe(sourceMaps.init())
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(concat('Scripts.js'))
.pipe(uglify())
.pipe(sourceMaps.write('.'))
.pipe(dest(outputDir + '/Shared/Scripts/'));
}
/*==============================================================================================================================
| TASK: JAVASCRIPT VIEWS
>-------------------------------------------------------------------------------------------------------------------------------
| Minimizes JavaScript files associated with views as part of production process.
\-----------------------------------------------------------------------------------------------------------------------------*/
function jsViewsTask() {
return src(files.jsViews)
.pipe(sourceMaps.init())
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(uglify())
.pipe(sourceMaps.write('.'))
.pipe(dest(outputDir + '/Shared/Scripts/Views/'));
}
/*==============================================================================================================================
| TASK: DEPENDENCIES
>-------------------------------------------------------------------------------------------------------------------------------
| Copies static dependencies from their source folders and into their appropriate build folders.
\-----------------------------------------------------------------------------------------------------------------------------*/
function dependenciesTask() {
console.log("Beginning dependencies task");
var streams = [];
for (var contentType in dependencies) {
for (var dependency in dependencies[contentType]) {
streams.push(
src(dependencies[contentType][dependency])
.pipe(dest(outputDir.concat('/Shared/', contentType, '/Vendor/', dependency)))
);
}
}
return merge(streams);
}
/*==============================================================================================================================
| EXPORT TASKS
>-------------------------------------------------------------------------------------------------------------------------------
| Exports the above defined tasks for use by gulp.
\-----------------------------------------------------------------------------------------------------------------------------*/
exports.scss = scssTask;
exports.dependencies = dependenciesTask;
exports.js = parallel(jsTask, jsViewsTask);
/*==============================================================================================================================
| TASK: BUILD
>-------------------------------------------------------------------------------------------------------------------------------
| Composite task that will call all build-related tasks.
\-----------------------------------------------------------------------------------------------------------------------------*/
exports.build = parallel(scssTask, dependenciesTask, jsTask, jsViewsTask);
/*==============================================================================================================================
| TASK: DEFAULT
>-------------------------------------------------------------------------------------------------------------------------------
| The default task when Gulp runs, assuming no task is specified. Assuming the environment variable isn't explicitly defined
| otherwise, will run on development-oriented tasks.
\-----------------------------------------------------------------------------------------------------------------------------*/
exports.default = parallel(scssTask, dependenciesTask, jsTask, jsViewsTask);