forked from citizenos/citizenos-fe-old
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
181 lines (170 loc) · 6.16 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
'use strict';
var gulp = require('gulp'),
sass = require('gulp-sass'),
path = require('path'),
concat = require('gulp-concat'),
cleanCSS = require('gulp-clean-css'),
sourcemaps = require('gulp-sourcemaps'),
plumber = require('gulp-plumber'),
jshint = require('gulp-jshint'),
stylish = require('jshint-stylish'),
uglify = require('gulp-uglify'),
watch = require('gulp-watch'),
batch = require('gulp-batch'),
runSequence = require('run-sequence').use(gulp),
cachebust = require('gulp-cache-bust'),
fs = require('fs'),
templateCache = require('gulp-angular-templatecache');
var pkg = JSON.parse(fs.readFileSync('package.json'));
gulp.task('templatecache', function () {
return gulp.src('public/views/**/*.html')
.pipe(templateCache({
module: 'citizenos',
root: '/views/',
templateHeader: '/** AUTOGENERATED BY GULP templatecache TASK **/ \n\nangular\n .module(\'<%= module %>\'<%= standalone %>)\n .run([\'$log\', \'$http\', \'$templateCache\', function ($log, $http, $templateCache) {\n var templates = [\n',
templateBody: ' \'<%= url %>\',',
templateFooter: '\n'
+ ' ];\n var i = 0;\n'
+ ' if (templates.length) {\n'
+ ' downloadToCache();\n'
+ ' }\n'
+ ' function downloadToCache() {\n'
+ ' var template = templates[i];\n'
+ ' $http\n'
+ ' .get(template, {\n'
+ ' ignoreLoadingBar: true\n'
+ ' })\n'
+ ' .then(\n'
+ ' function (response) {\n'
+ ' $templateCache.put(response.config.url, response.data);\n'
+ ' if (++i < templates.length) {\n'
+ ' downloadToCache();\n'
+ ' }\n'
+ ' },\n'
+ ' function (err) {\n'
+ ' $log.error(\'error\', err);\n'
+ ' if (++i < templates.length) {\n'
+ ' downloadToCache();\n'
+ ' }\n'
+ ' }\n'
+ ' );\n'
+ ' }\n'
+ ' }]);',
standalone: false
}))
.pipe(concat('template-cache.js'))
.pipe(gulp.dest('public/js/libs'));
});
gulp.task('default', function () {
return runSequence(
'uglify',
'sass',
'sass_etherpad',
'sass_widgets',
'cachebreaker',
'watch'
);
});
gulp.task('jshint', function () {
return gulp.src([
'public/js/**/*.js',
'!public/js/libs/**/*.js',
'!public/js/*.bundle.js'
])
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
gulp.task('uglify', function () {
return gulp.src([
'public/js/libs/OneDrive.js',
'public/js/libs/moment-with-locales.js',
'public/js/libs/hwcrypto-legacy.js',
'public/js/libs/hwcrypto.js',
'public/js/libs/angular.js',
'public/js/libs/angular-touch.js',
'public/js/libs/angular-resource.js',
'public/js/libs/angular-route.js',
'public/js/libs/angular-translate.js',
'public/js/libs/raven.js',
'public/js/libs/angular-raven.js',
'public/js/libs/**/*.js',
'!public/js/libs/template-cache.js',
'public/js/app.js',
'public/js/factories/**/*.js',
'public/js/services/**/*.js',
'public/js/filters/**/*.js',
'public/js/directives/**/*.js',
'public/js/controllers/**/*.js'
])
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(plumber())
.pipe(uglify({
mangle: false,
compress: false,
beautify: true
}))
.pipe(concat(pkg.name + '.bundle.js'))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('public/js/'));
});
gulp.task('cachebreaker', function () {
return gulp.src('public/index.html')
.pipe(cachebust({
type: 'MD5',
showLog: true
}))
.pipe(gulp.dest('public/'));
});
gulp.task('watch', function () {
gulp.watch(['public/js/**/*.js', '!public/js/*.bundle.js', '!public/js/widgets.arguments.js'], function () {
return runSequence(
'uglify',
'cachebreaker'
);
});
gulp.watch('public/styles/**/*.scss', function () {
return runSequence(
'sass',
'sass_etherpad',
'sass_widgets',
'cachebreaker'
);
});
gulp.watch('public/views/**/*.html', function () {
return runSequence(
'templatecache'
);
});
});
/**
* TODO: Would be 1 SASS task if followed the best practice - http://thesassway.com/beginner/how-to-structure-a-sass-project
* BUT, if we try to follow it with current code, SASS goes berserk and generates 31 mb CSS or hangs. Needs some investigation.
*/
gulp.task('sass', function () {
gulp.src(['public/styles/*.scss'])
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(cleanCSS())
.pipe(concat(pkg.name + '.bundle.css'))
.pipe(sourcemaps.write('maps'))
.pipe(gulp.dest('public/styles/'))
});
gulp.task('sass_etherpad', function () {
gulp.src(['public/styles/etherpad/etherpad.scss'])
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(cleanCSS())
.pipe(sourcemaps.write('maps'))
.pipe(gulp.dest('public/styles/'))
});
gulp.task('sass_widgets', function () {
gulp.src(['public/styles/widgets/widgets.scss'])
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(cleanCSS())
.pipe(sourcemaps.write('maps'))
.pipe(gulp.dest('public/styles/'))
});