This repository has been archived by the owner on Dec 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
/
gulpfile.js
193 lines (179 loc) · 5.07 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
const path = require('path');
const gulp = require('gulp');
const concat = require('gulp-concat');
const ngAnnotate = require('gulp-ng-annotate');
const uglify = require('gulp-uglify');
const jshint = require('gulp-jshint');
const eslint = require('gulp-eslint');
const dependencies = require('./web/public/dependencies.json');
const app = require('./web/public/app.json');
const cdfApp = require('./web/public/cdf-app.json');
const less = require('gulp-less');
const qdom = require('gulp-qdom');
const tap = require('gulp-tap');
const nodemon = require('gulp-nodemon');
const del = require('del');
const lessFiles = [
relativePath('./web/public/css/app.less'),
relativePath('./web/public/js/directives/**/*.less'),
];
function relativePath(paths) {
const buildPath = arg => {
let depPath = arg;
const excluded = depPath[0] === '!';
if (excluded) depPath = depPath.substring(1);
depPath = path.join(__dirname, depPath);
return excluded ? `!${depPath}` : depPath;
};
if (paths.constructor === [].constructor) {
for (let i = 0; i < paths.length; i += 1) {
paths[i] = buildPath(paths[i]);
}
return paths;
}
return buildPath(paths);
}
gulp.task('clean', () => del(relativePath(['./web/public/dist/**/*'])));
gulp.task('jshint', () =>
gulp
.src(
relativePath([
'./web/public/js/**/*.js',
'!./web/public/components/**',
'!./web/public/dist/**',
])
)
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'))
);
gulp.task('lint', () =>
gulp
.src(relativePath(['**/*.js', '!node_modules/**', '!web/public/**']))
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
);
gulp.task('validateHTML', () => {
let currentFile;
const errors = {};
return gulp
.src(relativePath(['./web/public/**/*.dust']))
.pipe(
tap(file => {
currentFile = file.path;
})
)
.pipe(
qdom($ => {
const clickables = $('button, *[ng-click], *.btn');
for (
let clickableIndex = 0;
clickableIndex < clickables.length;
clickableIndex += 1
) {
const clickable = $(clickables[clickableIndex]);
console.log(clickable); // eslint-disable-line no-console
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', () => {
errors.forEach(fileName => {
console.warn(`in ${fileName}`); // eslint-disable-line no-console
fileName.forEach(err => {
console.warn(err); // eslint-disable-line no-console
});
});
});
});
gulp.task('build-dependencies', ['clean'], () =>
gulp
.src(relativePath(dependencies))
.pipe(ngAnnotate())
.pipe(concat('dependencies.js'))
.pipe(uglify())
.pipe(gulp.dest(relativePath('./web/public/dist/')))
);
gulp.task('build-less', ['clean'], () =>
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'], () => {
const appArray = Array.from(app);
// Remove original init-master
appArray.forEach((appLocal, index) => {
if (appLocal.includes('init-master')) {
appArray.splice(index, 1);
}
});
// Append cdf sources
cdfApp.forEach(appLocal => {
appArray.push(appLocal);
});
return (
gulp
.src(relativePath(appArray))
.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', 'build-less', 'build-dependencies'], () => {
const appArray = Array.from(app);
cdfApp.forEach(appLocal => {
appArray.push(`!${appLocal}`);
});
return (
gulp
.src(relativePath(appArray))
.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('watch-less', ['build-cdf'], () =>
gulp.watch(
[
relativePath('./web/public/css/**/*.less'),
relativePath('./web/public/js/directives/**/*.less'),
],
['build-less']
)
);
gulp.task('dev', ['watch-less'], () => {
nodemon({
ignore: [
relativePath('./web/public/components/*'),
relativePath('./web/public/dist/*'),
],
script: 'index.js',
ext: 'js dust json',
tasks: ['build'],
});
});
gulp.task('default', ['lint', 'jshint', 'build-cdf']);