forked from CoderDojo/cp-zen-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
163 lines (148 loc) · 5.12 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
(function(){
"use strict";
var path = require('path'),
gulp = require('gulp'),
concat = require('gulp-concat'),
ngAnnotate = require('gulp-ng-annotate'),
uglify = require('gulp-uglify'),
jshint = require('gulp-jshint'),
semistandard = require('gulp-semistandard'),
KarmaServer = require('karma').Server,
dependencies = require('./web/public/dependencies.json'),
app = require('./web/public/app.json'),
cdfApp = require('./web/public/cdf-app.json'),
less = require('gulp-less'),
qdom = require('gulp-qdom'),
tap = require('gulp-tap'),
del = require('del');
var lessFiles = [ relativePath('./web/public/css/app.less'), relativePath('./web/public/js/directives/**/*.less')];
function relativePath(paths) {
var buildPath = function (depPath) {
var excluded = depPath[0] === '!';
if (excluded) depPath = depPath.substring(1);
depPath = path.join(__dirname, depPath);
return excluded ? '!' + depPath : depPath;
}
if (paths.constructor === [].constructor) {
for (var i = 0; i < paths.length; i++) {
paths[i] = buildPath(paths[i]);
}
return paths;
} else {
return buildPath(paths);
}
}
gulp.task('clean', function () {
return del(relativePath([
'./web/public/dist/**/*'
]));
});
gulp.task('jshint', function () {
return gulp.src(relativePath([
'./web/controllers/**/*.js',
'./lib/**/*.js',
'./web/models/!**!/!*.js',
'./web/public/js/**/*.js'
]))
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
});
gulp.task('semistandard', function () {
return gulp.src(relativePath([
'./lib/**/*.js'
]))
.pipe(semistandard())
.pipe(semistandard.reporter('default', {
breakOnError: true
}));
});
gulp.task('validateHTML', function () {
var currentFile = void 0;
var errors = {};
return gulp.src(relativePath(['./web/public/**/*.dust']))
.pipe(tap(function(file, t) {
currentFile = file.path;
}))
.pipe(qdom(function($){
var clickables = $("button, *[ng-click], *.btn");
for(var clickableIndex = 0; clickableIndex < clickables.length; clickableIndex ++) {
var clickable = $(clickables[clickableIndex]);
console.log(clickable);
if (!errors[currentFile]) errors[currentFile] = [];
if (clickable['aria-label'] !== ''){
errors[currentFile].push(clickable[0].name + ' ' + clickable.text() + ' should have an aria-label');
}
if (clickable['data-name'] !== ''){
errors[currentFile].push(clickable[0].name + ' ' + clickable.text() + ' should have an data-name for analytics');
}
}
}))
.on('end', function(){
for (var fileName in errors) {
console.warn('in '+ fileName);
for (var i = 0; i < errors[fileName].length; i++){
console.warn(errors[fileName][i]);
}
}
})
})
gulp.task('build-dependencies', ['clean'], function () {
return gulp.src(relativePath(dependencies))
.pipe(ngAnnotate())
.pipe(concat('dependencies.js'))
.pipe(uglify())
.pipe(gulp.dest(relativePath('./web/public/dist/')));
});
gulp.task('build-less', ['clean'], function () {
return gulp.src(lessFiles)
.pipe(concat('app.less'))
.pipe(less({
compress: true,
paths: relativePath('./web/public/css/')
}))
.pipe(gulp.dest(relativePath('./web/public/dist/css/')))
});
gulp.task('build-cdf', ['build'], function () {
var _app = Array.from(app);
//Remove original init-master
for (var appIndex in _app) {
if (_app[appIndex].indexOf('init-master') > -1) {
_app.splice(appIndex, 1);
}
}
//Append cdf sources
for (var index in cdfApp) {
_app.push(cdfApp[index]);
}
return gulp.src(relativePath(_app))
.pipe(ngAnnotate())
.pipe(concat('cdf-app.js'))
//.pipe(uglify()) // Commented out until we figure it out why it's breaking
.pipe(gulp.dest(relativePath('./web/public/dist/')));
});
gulp.task('build', ['clean', 'jshint', 'build-less', 'build-dependencies'], function () {
var _app = Array.from(app);
for (var index in cdfApp) {
_app.push('!' + cdfApp[index]);
}
return gulp.src(relativePath(_app))
.pipe(ngAnnotate())
.pipe(concat('app.js'))
// .pipe(uglify()) // Commented out until we figure it out why it's breaking
.pipe(gulp.dest(relativePath('./web/public/dist/')));
});
gulp.task('test', ['semistandard', 'build', 'build-cdf'], function (done) {
new KarmaServer({
configFile: __dirname + '/karma.conf.js',
singleRun: true
}, done).start();
gulp.on('stop', function () { process.exit(0); });
gulp.on('err', function () { process.exit(1); });
});
gulp.task('watch-less', ['build-less'], function(){
return gulp.watch([ relativePath('./web/public/css/**/*.less'), relativePath('./web/public/js/directives/**/*.less')], ['build-less']);
});
gulp.task('default', ['test']);
gulp.task('dev', ['watch-less']);
})();