-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
125 lines (109 loc) · 3.17 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
'use strict';
var gulp = require('gulp');
var add = require('gulp-add');
var del = require('del');
var browserSync = require('browser-sync').create();
var reload = browserSync.reload;
var ghPages = require('gulp-gh-pages');
var bower = require('gulp-bower');
var fs = require('fs');
var vinylPaths = require('vinyl-paths');
var execSync = require('child_process').execSync;
var merge = require('merge-stream');
var copy = require('gulp-copy');
var bump = require('gulp-bump');
var tagVersion = require('gulp-tag-version');
var git = require('gulp-git');
var filter = require('gulp-filter');
var portfinder = require('portfinder');
function getPackage() {
return JSON.parse(fs.readFileSync('bower.json', 'utf8'));
}
function getBowerConfig() {
if (fs.existsSync('.bowerrc')) {
return JSON.parse(fs.readFileSync('.bowerrc', 'utf8'));
}
return {dir: 'bower_components'};
}
function gitFiles() {
return execSync('git ls-files').toString().split('\n');
}
var bowerDir = getBowerConfig().dir;
gulp.task('clean', function() {
return gulp.src([bowerDir, '.publish', '.tmp'])
.pipe(vinylPaths(del));
});
gulp.task('bower', function() {
return bower(bowerDir);
});
gulp.task('bower:reload', ['bower'], reload);
var redirect = function(from, to) {
return function(req, res, next) {
if (from === req.url) {
res.writeHead(301, {
'Location': to,
'Cache-Control': 'cache-control: private, max-age=0, no-cache'
});
res.end();
}
next();
};
};
function _bump(type) {
return gulp.src(['bower.json', 'package.json'])
.pipe(bump({type: type}))
.pipe(gulp.dest('./'))
.pipe(git.commit('version bump'))
.pipe(filter('package.json'))
.pipe(tagVersion({prefix: ''}));
}
gulp.task('release', _bump.bind(null, 'patch'));
gulp.task('release:minor', _bump.bind(null, 'minor'));
gulp.task('release:major', _bump.bind(null, 'major'));
// Watch Files For Changes & Reload
gulp.task('serve', ['bower'], function () {
var pkgRoot = '/' + getPackage().name;
var opts = {
notify: false,
snippetOptions: {
rule: {
match: /<\/body>/i,
fn: function(snippet, match) {
return snippet + match;
}
}
},
server: {
baseDir: bowerDir,
middleware: [redirect('/', pkgRoot + '/demo')],
routes: {}
}
};
opts.server.routes[pkgRoot] = '.';
portfinder.basePort = 3000;
portfinder.getPort(function (err, port) {
opts.port = port;
console.log('using port: ' + port);
browserSync.init(opts);
});
gulp.watch(['**/*.html']).on('change', reload);
gulp.watch(['**/*.css']).on('change', reload);
//gulp.watch(['bower.json']).on('change', 'bower:reload');
});
gulp.task('gh-pages', function() {
var pkgName = getPackage().name;
return merge(
gulp.src(gitFiles())
.pipe(copy('.tmp/' + pkgName)),
bower('.tmp')
.pipe(add(
'index.html',
'<meta http-equiv="refresh" content="0;' + pkgName + '/">'
))
).pipe(ghPages()).on('end', function() {
del(['.tmp', '.publish']);
});
});
// Load tasks for web-component-tester
// Adds tasks for `gulp test:local` and `gulp test:remote`
require('web-component-tester').gulp.init(gulp);