-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
328 lines (261 loc) · 6.44 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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
'use strict';
const gulp = require('gulp');
const sequence = require('run-sequence');
let pkg = require('./package.json');
let banner = '/**\n * Copyright (c) ${new Date().getFullYear()} ${pkg.author}\n * All rights reserved.\n */\n';
let date = new Date().getTime();
gulp.task('default', function(done) {
sequence('devel', 'watch', done);
});
gulp.task('build', function(done) {
sequence('lint', 'clean', ['copy:assets', 'copy:templates', 'nunjucks', 'less', 'uglify'], 'snapshot', done);
});
gulp.task('bundle:frontend', function() {
const path = require('path');
const zip = require('gulp-zip');
const rename = require('gulp-rename');
let basename = path.basename(process.cwd());
let renameExpression = new RegExp('^' + basename);
return gulp.src([
'src/**'
], {
base: 'src',
nodir: true
})
.pipe(rename(function(path) {
path.dirname = path.dirname.replace(renameExpression, pkg.name);
return path;
}))
.pipe(zip(pkg.name + '-frontend-' + pkg.version + '.zip'))
.pipe(gulp.dest('dist'));
});
gulp.task('bundle:backend', function() {
const path = require('path');
const zip = require('gulp-zip');
const rename = require('gulp-rename');
let basename = path.basename(process.cwd());
let renameExpression = new RegExp('^' + basename);
return gulp.src([
'lib/**'
], {
base: 'lib',
nodir: true
})
.pipe(rename(function(path) {
path.dirname = path.dirname.replace(renameExpression, pkg.name);
return path;
}))
.pipe(zip(pkg.name + '-backend-' + pkg.version + '.zip'))
.pipe(gulp.dest('dist'));
});
gulp.task('clean', function() {
const clean = require('gulp-clean');
return gulp.src([
'artifacts/',
'dist/',
'dump/'
], {
read: false
})
.pipe(clean({
force: true
}));
});
gulp.task('copy:assets', function() {
return gulp.src([
'static/**/*',
'!static/**/*.js',
'!static/**/*.less'
], {
nodir: true
})
.pipe(gulp.dest('artifacts/'));
});
gulp.task('copy:templates', function() {
return gulp.src([
'templates/**'
])
.pipe(gulp.dest('dist/static/' + date))
});
gulp.task('devel', function(done) {
sequence('clean', ['copy:assets', 'copy:templates', 'less', 'uglify:devel'], done);
});
gulp.task('less', function() {
const LessAutoPrefix = require('less-plugin-autoprefix');
const cleanCSS = require('gulp-clean-css');
const header = require('gulp-header');
const less = require('gulp-less');
const rename = require('gulp-rename');
return gulp.src([
'static/less/site.less'
])
.pipe(less({
plugins: [
new LessAutoPrefix({
browsers: ['last 3 versions', 'ie 11', 'ie 10']
})
]
}))
.pipe(cleanCSS())
.pipe(rename({
extname: '.min.css'
}))
.pipe(header(banner, {
pkg: pkg
}))
.pipe(gulp.dest('artifacts/css'));
});
gulp.task('lint', ['lint:js', 'lint:json']);
gulp.task('lint:js', function() {
const eslint = require('gulp-eslint');
return gulp.src([
'*.js',
'static/**/*.js',
'src/**/*.js',
'test/**/*.js',
'!node_modules/**/*.js',
'!src/node_modules/**/*.js',
'!static/lib/**/*.js'
])
.pipe(eslint({
configFile: 'eslint.json'
}))
.pipe(eslint.formatEach());
});
gulp.task('lint:json', function() {
const jsonlint = require('gulp-jsonlint');
return gulp.src([
'*.json',
'src/**/*.json',
'fixtures/**/*.json'
])
.pipe(jsonlint())
.pipe(jsonlint.failOnError())
.pipe(jsonlint.reporter());
});
gulp.task('lint:less', function() {
const lesshint = require('gulp-lesshint');
return gulp.src([
'static/**/*.less'
])
.pipe(lesshint())
.pipe(lesshint.failOnError())
.pipe(lesshint.reporter());
});
gulp.task('nunjucks', function() {
const path = require('path');
const concat = require('gulp-concat');
const gutil = require('gulp-util');
const header = require('gulp-header');
const nunjucks = require('gulp-nunjucks');
const rename = require('gulp-rename');
const uglify = require('gulp-uglify');
return gulp.src([
'nunjucks/**/*.html'
])
.pipe(nunjucks.precompile({
env: (function(nunjucks) {
var environment;
environment = new nunjucks.Environment();
environment.addFilter('get', function() {});
environment.addFilter('date', function() {});
environment.addFilter('fileSize', function() {});
return environment;
})(require('nunjucks')),
name: (function() {
let delimiter, names;
delimiter = 'nunjucks' + path.sep;
names = {};
return function(file) {
let filename = file.path;
let i = filename.indexOf(delimiter);
let template = ~i ? filename.slice(i + delimiter.length) : template.replace(new RegExp(path.sep, 'g'), '/');
if (names.hasOwnProperty(template)) {
gutil.log('Name collison on nunjucks template "' + template + '":\n\tOld: ' + names[template] + '\n\tNew: ' + filename);
}
names[template] = filename;
return template;
};
})()
}))
.pipe(concat('templates.js'))
.pipe(uglify())
.pipe(header(banner, {
pkg: pkg
}))
.pipe(rename({
extname: '.min.js'
}))
.pipe(gulp.dest('artifacts/js'));
});
gulp.task('snapshot', function() {
return gulp.src([
'artifacts/**'
])
.pipe(gulp.dest('dist/static/' + date));
});
gulp.task('uglify', function() {
const addsrc = require('gulp-add-src');
const babel = require('gulp-babel');
const header = require('gulp-header');
const rename = require('gulp-rename');
const uglify = require('gulp-uglify');
return gulp.src([
'static/**/*.js',
'!static/js/site2.js',
'!static/lib/requirejs/**/*.js'
])
.pipe(babel({
presets: ['es2015'],
plugins: ['transform-es2015-modules-amd']
}))
.pipe(addsrc([
'static/lib/requirejs/**/*.js'
], {
base: 'static'
}))
.pipe(uglify())
.pipe(header(banner, {
pkg: pkg
}))
.pipe(rename({
extname: '.min.js'
}))
.pipe(gulp.dest('artifacts'));
});
gulp.task('uglify:devel', function() {
const addsrc = require('gulp-add-src');
const babel = require('gulp-babel');
const rename = require('gulp-rename');
return gulp.src([
'static/**/*.js',
'!static/lib/requirejs/**/*.js'
])
.pipe(babel({
presets: ['es2015'],
plugins: ['transform-es2015-modules-amd']
}))
.pipe(addsrc([
'static/lib/requirejs/**/*.js'
], {
base: 'static'
}))
.pipe(rename({
extname: '.min.js'
}))
.pipe(gulp.dest('artifacts'));
});
gulp.task('watch', function() {
gulp.watch([
'static/**/*.js'
], ['uglify:devel'])
.on('error', function() {
this.emit('end');
});
gulp.watch([
'static/**/*.less'
], ['less'])
.on('error', function() {
this.emit('end');
});
});