-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.babel.js
137 lines (116 loc) · 3.34 KB
/
gulpfile.babel.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
import fs from 'fs';
import minimist from 'minimist';
import sequence from 'run-sequence';
import gulp from 'gulp';
import babel from 'gulp-babel';
import browserify from 'gulp-browserify';
import bump from 'gulp-bump';
import changelog from 'gulp-conventional-changelog';
import connect from 'gulp-connect';
import eslint from 'gulp-eslint';
import git from 'gulp-git';
import test from 'gulp-mocha';
import notify from 'gulp-notify';
import nsp from 'gulp-nsp';
import open from 'gulp-open';
import rename from 'gulp-rename';
import uglify from 'gulp-uglify';
import gutil from 'gulp-util';
const argv = minimist(process.argv.slice(2));
gulp.task('bump-version', () => {
let type;
if (argv.major) type = 'major';
else if (argv.minor) type = 'minor';
else type = 'patch';
return gulp.src(['./package.json'])
.pipe(bump({type}).on('error', gutil.log))
.pipe(gulp.dest('./'));
});
gulp.task('changelog', () =>
gulp.src('CHANGELOG.md', {buffer: false})
.pipe(changelog({
preset: 'angular' // Or to any other commit message convention you use.
}))
.pipe(gulp.dest('./'))
);
gulp.task('commit-changes', () =>
gulp.src('.')
.pipe(git.add())
.pipe(git.commit('[Prerelease] Bumped version number'))
);
gulp.task('create-new-tag', (cb) => {
var version = getPackageJsonVersion();
git.tag(`v${version}`, 'Created Tag for version: ' + version, (error) => {
if (error) return cb(error);
cb();
// git.push('origin', 'master', {args: '--tags'}, cb);
});
});
gulp.task('lint', () =>
gulp.src(['./index.js', './test/index.spec.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
);
gulp.task('test', () => {
if (argv['skip-tests']) return gutil.log('Tests skipped via --skip-tests argument');
return gulp.src('./test/*')
.pipe(test({reporter: 'spec'}));
});
gulp.task('security-checkup', (cb) => {
nsp({package: __dirname + '/package.json'}, cb);
});
gulp.task('full-checkup', [/*'lint', */'security-checkup', 'test']);
gulp.task('build', ['full-checkup'], () =>
gulp.src('index.js')
.pipe(rename('knockout-selectize.js'))
.pipe(babel())
.pipe(browserify({
insertGlobals: true
}))
.on('prebundle', (bundle) => {
bundle.external('knockout');
bundle.external('jquery');
bundle.external('selectize');
})
.pipe(gulp.dest('dist'))
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('dist'))
);
gulp.task('serve-demo', () => {
connect.server({
port: 8888,
root: '.'
});
gulp.src(__filename)
.pipe(open({
uri: 'http://localhost:8888/demo/'
}));
});
gulp.task('do-release', (done) =>
sequence(
'build',
'bump-version',
'changelog',
'commit-changes',
'create-new-tag',
(error) => {
if (error) gutil.log(error.message);
else gutil.log('RELEASE FINISHED SUCCESSFULLY');
done(error);
},
)
);
function getPackageJsonVersion() {
// We parse the json file instead of using require because require caches
// multiple calls so the version number won't be updated
return JSON.parse(fs.readFileSync('./package.json', 'utf8')).version;
}
function handleErrors(...args) {
notify.onError({
title: 'Compile Error',
message: '<%= error.message %>'
}).apply(this, args);
this.emit('end'); // Keep gulp from hanging on this task
}