This repository has been archived by the owner on Jan 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.js
114 lines (96 loc) · 3.58 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
(function (require) {
'use strict';
var gulp = require('gulp'),
minify = require('gulp-uglify'),
cleanCss = require('gulp-clean-css'),
jshint = require('gulp-jshint'),
concat = require('gulp-concat'),
notify = require('gulp-notify'),
sourceMaps = require('gulp-sourcemaps'),
config = require('./gulpConfig.json'),
ejs = require('gulp-ejs'),
ext_replace = require('gulp-ext-replace'),
dir = require('node-dir'),
hashFiles = require('hash-files'),
templateCache = require('gulp-angular-templatecache'),
minifiedFile = 'app.min.js',
concatConfig = {newLine: '\n;'},
minifiedCss = 'app.min.css';
function compileJs(cfg) {
return gulp.src(cfg.src.js)
.pipe(jshint())
.pipe(jshint.reporter('fail'))
.on('error', notify.onError("JSHint Error: <%= error.message %>"))
.pipe(sourceMaps.init())
.pipe(minify())
.on('error', notify.onError("Error: <%= error.message %>"))
.pipe(concat(minifiedFile), concatConfig)
.pipe(sourceMaps.write())
.pipe(gulp.dest(cfg.folder))
.on('finish', function() { console.log("Safe to refresh"); });
}
function compileCss(cfg) {
return gulp.src(cfg.src.css)
.pipe(concat(minifiedCss))
.pipe(cleanCss())
.pipe(gulp.dest(cfg.folder));
}
function compileEjs(cfg) {
var hashes = {};
var appInsightsInstrumentationKey = 'c9bdc879-9b86-4632-b37b-e37879cbc985';
dir.files(cfg.folder, function(err, files) {
if (err) throw err;
files.forEach(function(file) {
hashes[file] = hashFiles.sync({ files: file }).slice(0, 7);
var newfile = file.replace("\\","/");
hashes[newfile] = hashes[file]
console.log("original");
console.log(hashes[file]);
console.log(file);
console.log("new");
console.log(hashes[newfile]);
});
});
return gulp.src(cfg.src.ejs)
.pipe(ejs({
hashes,
appInsightsInstrumentationKey
}))
.pipe(ext_replace('.html'))
.pipe(gulp.dest('./'))
}
function compileTemplateCache(cfg) {
return gulp.src(cfg.src.templateCache)
.pipe(templateCache('templateCache.js', {
module: 'templateCache',
moduleSystem: 'IIFE',
root: 'js/',
standalone: true
}))
.pipe(gulp.dest(cfg.folder));
}
gulp.task('js', function () {
compileJs(config.dev);
});
gulp.task('css', function () {
compileCss(config.dev);
});
gulp.task('ejs', function () {
compileEjs(config.dev);
});
gulp.task('templateCache', function () {
compileTemplateCache(config.dev);
});
gulp.task('watch', function() {
var cfg = config.dev;
function callback(event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
}
gulp.watch(cfg.src['js'], ['js']).on('change', callback);
gulp.watch(cfg.src['css'], ['css']).on('change', callback);
gulp.watch(cfg.src['templateCache'], ['templateCache']).on('change', callback);
gulp.watch(cfg.src['ejs'].concat([cfg.folder + '*']), ['ejs']).on('change', callback);
});
gulp.task('default', ['js', 'css', 'templateCache', 'ejs'], function () {
});
})(require);