forked from webcomponents/webcomponentsjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
142 lines (122 loc) · 3.69 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
/**
* @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
audit = require('gulp-audit'),
concat = require('gulp-concat'),
exec = require('child_process').exec,
fs = require('fs'),
gulp = require('gulp'),
header = require('gulp-header'),
path = require('path'),
runseq = require('run-sequence'),
uglify = require('gulp-uglify')
;
// init tests with gulp
require('web-component-tester').gulp.init(gulp);
var isRelease = process.env.RELEASE !== undefined;
var banner = fs.readFileSync('banner.txt', 'utf8');
var pkg;
function defineBuildTask(name, manifest) {
(function() {
manifest = manifest || './src/' + name + '/build.json';
var output = name;
var list = readManifest(manifest);
gulp.task(name + '-debug', ['version'], function() {
return gulp.src(list)
.pipe(concat(output + '.js'))
.pipe(uglify({
mangle: false,
compress: false,
output: {
beautify: true,
indent_level: 2
}
}))
.pipe(header(banner, {pkg: pkg}))
.pipe(gulp.dest('dist/'))
;
});
gulp.task(name, ['version', name + '-debug'], function() {
return gulp.src(list)
.pipe(concat(output + '.min.js'))
.pipe(uglify())
.pipe(header(banner, {pkg: pkg}))
.pipe(gulp.dest('dist/'))
;
});
})();
}
function readJSON(filename) {
var blob = fs.readFileSync(filename, 'utf8');
return JSON.parse(blob);
}
gulp.task('audit', function() {
return gulp.src('dist/*.js')
.pipe(audit('build.log', {repos:['.']}))
.pipe(gulp.dest('dist/'));
});
gulp.task('version', function(cb) {
pkg = require('./package.json');
var cmd = ['git', 'rev-parse', '--short', 'HEAD'].join(' ');
if (!isRelease) {
exec(cmd, function(err, stdout, stderr) {
if (err) {
return cb(err);
}
if (stdout) {
stdout = stdout.trim();
}
pkg.version = pkg.version + '-' + stdout;
cb();
});
} else {
cb();
}
});
function readManifest(filename, modules) {
modules = modules || [];
var lines = readJSON(filename);
var dir = path.dirname(filename);
lines.forEach(function(line) {
var fullpath = path.join(dir, line);
if (line.slice(-5) == '.json') {
// recurse
modules = modules.concat(readManifest(fullpath, modules));
} else {
modules.push(fullpath);
}
});
var tmp = Object.create(null);
for (var i = 0; i < modules.length; i++) {
tmp[modules[i]] = 1;
}
modules = Object.keys(tmp);
return modules;
}
gulp.task('copy-bower', function() {
return gulp.src(['bower.json', 'package.json', 'README.md']).pipe(gulp.dest('dist/'));
});
defineBuildTask('webcomponents', './src/WebComponents/build.json');
defineBuildTask('webcomponents-lite', './src/WebComponents/build-lite.json');
defineBuildTask('CustomElements');
defineBuildTask('HTMLImports');
defineBuildTask('ShadowDOM');
defineBuildTask('MutationObserver');
gulp.task('build', ['webcomponents', 'webcomponents-lite', 'CustomElements',
'HTMLImports', 'ShadowDOM', 'copy-bower', 'MutationObserver']);
gulp.task('release', function(cb) {
isRelease = true;
runseq('build', 'audit', cb);
});
gulp.task('default', function(cb) {
runseq('build', 'audit', cb);
});