-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgulpfile.js
107 lines (94 loc) · 3.08 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
'use strict';
const gulp = require('gulp');
const mocha = require('gulp-mocha');
const eslint = require('gulp-eslint');
const webpack = require('webpack-stream');
const tagVersion = require('gulp-tag-version');
const bump = require('gulp-bump');
const git = require('gulp-git');
const conventionalChangelog = require('gulp-conventional-changelog');
const conventionalRecommendedBump = np(require('conventional-recommended-bump'));
const gulpIgnore = require('gulp-ignore');
const readPkg = require('read-pkg');
const injectVersion = require('gulp-inject-version');
const toc = require('gulp-doctoc');
const webpackConfig = require('./webpack.config.js');
const addSrc = require('gulp-add-src');
const concat = require('gulp-concat');
gulp.task('default', ['test', 'lint'], () => runWebpackBuild());
gulp.task('lint', () =>
gulp.src('./lib/**/*.js')
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError())
);
gulp.task('test', () =>
gulp.src('test/test-*.js', { read: false })
.pipe(mocha())
);
gulp.task('buildReleaseVersionScript', ['bumpVersion'], () => runWebpackBuild());
gulp.task('release', ['changelog', 'doctoc', 'buildReleaseVersionScript'], (done) => {
// Get all the files to bump version in
gulp.src(['./package.json', './CHANGELOG.md', './README.md'])
.pipe(git.commit('chore(release): bump package version and update changelog [ci skip]', { emitData: true }))
.pipe(gulpIgnore.exclude(/CHANGELOG.md|README.md/))
// **tag it in the repository**
.pipe(tagVersion({ prefix: '' }))
.on('end', done);
return undefined;
});
gulp.task('doctoc', () =>
gulp.src('README.md')
.pipe(toc({ depth: 2 }))
.pipe(gulp.dest('./'))
);
gulp.task('changelog', ['bumpVersion'], () =>
gulp.src('./CHANGELOG.md', { buffer: false })
.pipe(conventionalChangelog({ preset: 'angular' }, { currentTag: readPkg.sync().version }))
.pipe(gulp.dest('./'))
);
gulp.task('bumpVersion', (done) => {
conventionalRecommendedBump({ preset: 'angular' })
.then(result =>
gulp.src('./package.json')
.pipe(bump({ type: result.releaseType }))
.pipe(gulp.dest('./'))
.on('end', done)
);
return undefined;
});
function runWebpackBuild() {
return gulp.src('./lib/entry-point.js')
.pipe(webpack(webpackConfig))
.pipe(injectVersion({
replace: /%%GULP_INJECT_VERSION%%/g,
}))
.pipe(addSrc('./data/5eSRDData.js'))
.pipe(concat('./5eShapedCompanion.js'))
.pipe(gulp.dest('./'));
}
function np(method) {
return function promiseWrapper() {
const self = this;
const args = Array.prototype.slice.call(arguments);
return new Promise((resolve, reject) => {
args.push((err, data) => {
if (err !== null) {
return reject(err);
}
return resolve(data);
});
return method.apply(self, args);
});
};
}
function sp(method) {
return function promiseWrapper() {
const self = this;
const args = Array.prototype.slice(arguments);
return new Promise((resolve) => {
args.push(data => resolve(data));
return method.apply(self, args);
});
};
}