-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
131 lines (115 loc) · 3.28 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
/* eslint-env node */
'use strict';
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var fs = require('fs');
var path = require('path');
var Karma = require('karma').Server;
var bs = require('browser-sync').create();
var runSequence = require('run-sequence');
var minimist = require('minimist');
var del = require('del');
var opn = require('opn');
var getJson = function (filepath) {
return JSON.parse(fs.readFileSync(filepath, 'utf8'));
};
var knownOptions = {
string: 'bump',
default: {
bump: 'patch'
}
};
var options = minimist(process.argv.slice(2), knownOptions);
var banner = [
'/*!',
' * Dyframe',
' * @version <%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' * @author <%= pkg.author %>',
' * @license <%= pkg.license %>',
' */',
''].join('\n');
var scripts = [
'gulpfile.js',
'karma.conf.js',
'src/*.js',
'demo/*.js',
'test/spec/*.js'
];
gulp.task('clean', del.bind(null, ['coverage']));
gulp.task('eslint', function () {
return gulp.src(scripts)
.pipe($.eslint())
.pipe($.eslint.format())
.pipe($.eslint.failAfterError());
});
gulp.task('karma', ['clean'], function (callback) {
new Karma({
configFile: path.resolve('./karma.conf.js')
}, callback).start();
});
gulp.task('scripts', function () {
var pkg = getJson('package.json');
return gulp.src('src/*.js')
.pipe($.header(banner, {pkg: pkg}))
.pipe(gulp.dest('.'))
.pipe($.uglify({preserveComments: 'some'}))
.pipe($.rename({suffix: '.min'}))
.pipe(gulp.dest('.'));
});
gulp.task('serve', ['clean'], function (callback) {
bs.init({
server: {
baseDir: ['src', 'demo']
},
notify: false,
open: false
}, function () {
opn('http://localhost:3000/demo.html');
callback();
});
new Karma({
configFile: path.resolve('./karma.conf.js'),
singleRun: false
}).start();
gulp.watch([
'demo/*',
'src/*.js'
]).on('change', bs.reload);
gulp.watch(scripts, ['eslint']);
});
gulp.task('link', function () {
var downloadBase = 'https://github.com/htanjo/dyframe/raw/';
var pattern = new RegExp(downloadBase + '.*?[/]', 'g');
var version = getJson('package.json').version;
var downloadDir = downloadBase + 'v' + version + '/';
return gulp.src(['README.md', 'demo/index.html'], {base: '.'})
.pipe($.replace(pattern, downloadDir))
.pipe(gulp.dest('.'));
});
gulp.task('bump', function () {
return gulp.src(['package.json', 'bower.json'])
.pipe($.bump({type: options.bump}))
.pipe(gulp.dest('.'));
});
gulp.task('commit', ['build', 'link'], function () {
var version = getJson('package.json').version;
return gulp.src(['package.json', 'bower.json', '*.js', 'README.md', 'demo/index.html'])
.pipe($.git.commit('Release v' + version));
});
gulp.task('tag', function (callback) {
var version = getJson('package.json').version;
$.git.tag('v' + version, 'Release v' + version, callback);
});
gulp.task('deploy', ['test'], function () {
return gulp.src(['src/*.js', 'demo/**/*', '!demo/demo.html'])
.pipe($.ghPages());
});
gulp.task('test', ['eslint', 'karma']);
gulp.task('build', ['scripts']);
gulp.task('release', function (callback) {
runSequence('test', 'bump', 'commit', 'tag', callback);
});
gulp.task('default', function (callback) {
runSequence('test', 'build', callback);
});