forked from Polymer/polymer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
131 lines (109 loc) · 3.55 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
/**
* @license
* Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at http:polymer.github.io/LICENSE.txt
* The complete set of authors may be found at http:polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at http:polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at http:polymer.github.io/PATENTS.txt
*/
// jshint node: true
'use strict';
var gulp = require('gulp');
var audit = require('gulp-audit');
var replace = require('gulp-replace');
var rename = require('gulp-rename');
var vulcanize = require('gulp-vulcanize');
var runseq = require('run-sequence');
var lazypipe = require('lazypipe');
var polyclean = require('polyclean');
var del = require('del');
var eslint = require('gulp-eslint');
var path = require('path');
var minimalDocument = require('./util/minimalDocument');
var micro = "polymer-micro.html";
var mini = "polymer-mini.html";
var max = "polymer.html";
var workdir = 'dist';
var distMicro = path.join(workdir, micro);
var distMini = path.join(workdir, mini);
var distMax = path.join(workdir, max);
var pkg = require('./package.json');
var cleanupPipe = lazypipe()
// remove leading whitespace and comments
.pipe(polyclean.leftAlignJs)
// remove html wrapper
.pipe(minimalDocument)
// Add real version number
.pipe(replace, /(Polymer.version = )'master'/, '$1"' + pkg.version + '"')
;
function vulcanizeWithExcludes(target, excludes) {
if (excludes) {
excludes = excludes.map(function(ex) { return path.resolve(ex); });
}
return function() {
return gulp.src(target)
.pipe(vulcanize({
stripComments: true,
excludes: excludes
}))
.pipe(cleanupPipe())
.pipe(gulp.dest(workdir));
};
}
gulp.task('micro', vulcanizeWithExcludes(micro));
gulp.task('mini', vulcanizeWithExcludes(mini, [micro]));
gulp.task('max', vulcanizeWithExcludes(max, [mini, micro]));
gulp.task('clean', function() {
return del(workdir);
});
// copy bower.json into dist folder
gulp.task('copy-bower-json', function() {
return gulp.src('bower.json').pipe(gulp.dest(workdir));
});
// Default Task
gulp.task('default', function(cb) {
runseq('clean', ['micro', 'mini', 'max'], cb);
});
// switch src and build for testing
gulp.task('save-src', function() {
return gulp.src([mini, micro, max])
.pipe(rename(function(p) {
p.extname += '.bak';
}))
.pipe(gulp.dest('.'));
});
gulp.task('restore-src', function() {
return gulp.src([mini + '.bak', micro + '.bak', max + '.bak'])
.pipe(rename(function(p) {
p.extname = '';
}))
.pipe(gulp.dest('.'));
});
gulp.task('cleanup-switch', function() {
return del([mini + '.bak', micro + '.bak', max + '.bak']);
});
gulp.task('switch-build', function() {
return gulp.src([distMini, distMicro, distMax])
.pipe(gulp.dest('.'));
});
gulp.task('switch', function(cb) {
runseq('default', 'save-src', 'switch-build', cb);
});
gulp.task('restore', function(cb) {
runseq('restore-src', 'cleanup-switch', cb);
});
gulp.task('audit', function() {
return gulp.src([distMini, distMicro, distMax])
.pipe(audit('build.log', { repos: ['.'] }))
.pipe(gulp.dest(workdir));
});
gulp.task('release', function(cb) {
runseq('default', ['copy-bower-json', 'audit'], cb);
});
gulp.task('lint', function() {
return gulp.src(['src/**/*.html', 'test/unit/*.html', 'util/*.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});