This repository has been archived by the owner on May 12, 2022. It is now read-only.
forked from Asmor/5e-monsters
-
Notifications
You must be signed in to change notification settings - Fork 7
/
gulpfile.js
175 lines (143 loc) · 4.85 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
"use strict";
var config = require('./gulp.config')();
var del = require('del');
var gulp = require('gulp');
var $ = require('gulp-load-plugins')({ lazy: true });
var argv = require('yargs').argv;
var replace = require('gulp-replace');
// var fs = require('fs');
var dev = argv.dev;
gulp.task('help', $.taskListing);
gulp.task('default', ['inject']);
gulp.task('copy-thirdparty', function() {
return gulp.src(config.root + '/thirdparty/**/*')
.pipe(gulp.dest(config.root + '/' + config.build + '/thirdparty'));
});
gulp.task('copy-json', function() {
return gulp.src(config.root + '/json/**/*')
.pipe(gulp.dest(config.root + '/' + config.build + '/json'));
});
gulp.task('copy-images', function() {
return gulp.src(config.root + '/images/**/*')
.pipe(gulp.dest(config.root + '/' + config.build + '/images'));
});
gulp.task('copy-manifest', function() {
return gulp.src(config.root + '/manifest.json')
.pipe(gulp.dest(config.root + '/' + config.build));
});
gulp.task('copy-cname', function() {
return gulp.src(config.root + '/CNAME')
.pipe(gulp.dest(config.root + '/' + config.build));
});
gulp.task('copy-resources', ['copy-thirdparty', 'copy-json', 'copy-images', 'copy-manifest']);
gulp.task('clean-styles', function (done) {
clean(config.cssFile, done);
});
gulp.task('clean-code', function (done) {
var files = [].concat(
config.temp + '**/*.js'
);
clean(files, done);
});
gulp.task('compile-sass', ['clean-styles'], function () {
log('Compiling SASS --> CSS');
return gulp
.src(config.sassDir)
.pipe($.sass())
.pipe(gulp.dest(config.cssDir));
});
gulp.task('sass-watcher', function () {
gulp.watch(config.sassWatchFiles, ['compile-sass']);
});
gulp.task('template-cache', ['clean-code'], function () {
log('Creating an AngularJS $templateCache');
return gulp
.src(config.htmltemplates)
.pipe($.minifyHtml({ empty: true }))
.pipe($.order(['*']))
.pipe($.angularTemplatecache(
config.templateCache.file,
config.templateCache.options
))
.pipe(gulp.dest(config.temp));
});
gulp.task('remove-template', function () {
log('Removing template');
return gulp.src(config.index)
.pipe(replace(
/(<!-- inject:templates:js -->)(?:[\S\s]*?)(<!-- endinject -->)/gmi,
'$1\r\n\t$2'
))
.pipe(gulp.dest(config.root));
});
// If we're in dev mode, the template.js file will be removed from index.html
var injectDependencies = ['compile-sass'];
if ( dev ) {
injectDependencies.push('remove-template');
} else {
injectDependencies.push('template-cache');
}
gulp.task('inject', injectDependencies, function () {
log('Wire up css and js into the html, after files are ready');
var result = gulp
.src(config.index)
.pipe(inject(config.cssFile))
.pipe(inject(config.js, '', config.jsOrder));
// Only put in the template cache if we're not in dev mode
if ( !dev ) {
var templateCache = config.temp + config.templateCache.file;
result = result.pipe(inject(templateCache, 'templates'));
}
result = result.pipe(gulp.dest(config.root));
return result;
});
gulp.task('clean-build', function(done) {
clean(config.buildFiles, done);
});
gulp.task('optimize', ['inject', 'clean-build', 'copy-resources'], function () {
// TODO: JS filter temporarily disabled until the dependency injection issue is resolved
var cssFilter = $.filter('./styles/*.css', {restore: true});
// var jsAppFilter = $.filter('**/' + config.optimized.app, {restore: true});
var indexHtmlFilter = $.filter(['**/*', '!**/index.html'], { restore: true });
return gulp
.src(config.index)
.pipe($.useref())
.pipe(cssFilter)
.pipe($.csso())
.pipe(cssFilter.restore)
// .pipe(jsAppFilter)
// .pipe($.uglify())
// .pipe(jsAppFilter.restore)
.pipe(indexHtmlFilter)
.pipe($.rev())
.pipe(indexHtmlFilter.restore)
.pipe($.revReplace())
.pipe(gulp.dest(config.build));
});
function clean(path, done) {
log('Cleaning: ' + $.util.colors.blue(path));
del(path, { force: true }).then(paths => done());
}
function log(msg) {
if (typeof (msg) === 'object') {
for (var item in msg) {
if (msg.hasOwnProperty(item)) {
$.util.log($.util.colors.blue(msg[item]));
}
}
} else {
$.util.log($.util.colors.blue(msg));
}
}
function inject(src, label, order) {
var options = { addRootSlash: false };
if (label) {
options.name = 'inject:' + label;
}
return $.inject(orderSrc(src, order), options).on('error', log);
}
function orderSrc(src, order) {
return gulp
.src(src)
.pipe($.if(order, $.order(order)));
}