This repository has been archived by the owner on Nov 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
76 lines (65 loc) · 2.44 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
'use strict';
const gulp = require('gulp'),
source = require('vinyl-source-stream'),
rename = require('gulp-rename'),
browserify = require('browserify'),
glob = require('glob'),
es = require('event-stream'),
del = require('del'),
wrapper = require('gulp-wrapper'),
bufferify = require('vinyl-buffer'),
bump = require('gulp-bump'),
babelify = require('babelify');
const distFolder = './dist';
const sourceFiles = './src/lendy/**/*.js';
const header = file => {
const fileName = file.path.replace(__dirname, '').replace('/src/lendy/', '').replace('.js', '');
const pkg = require('./package.json');
return [
'// ==UserScript==',
`// @name ${pkg.name} => ${fileName}`,
`// @version ${pkg.version}`,
`// @timestamp ${new Date().toISOString()}`,
`// @author ${pkg.author}`,
`// @match https://lendy.co.uk/${fileName}`,
'// @homepageURL https://github.com/bbonanno/saving-stream-enhancer',
`// @downloadURL https://raw.githubusercontent.com/bbonanno/saving-stream-enhancer/master/dist/lendy/${fileName}.user.js`,
'// @require http://code.jquery.com/jquery-latest.min.js',
'// @require https://raw.githubusercontent.com/christianbach/tablesorter/master/jquery.tablesorter.min.js',
'// ==/UserScript==',
'\n'
].join('\n');
};
gulp.task('clean', function (cb) {
return del([distFolder], cb);
});
gulp.task('dist', ['clean', 'bump'], function (done) {
glob(sourceFiles, function (err, files) {
if (err) done(err);
const tasks = files.map(function (entry) {
return browserify({entries: [entry]})
.transform('babelify', {presets: ['es2015']})
.bundle()
.pipe(source(entry))
.pipe(bufferify())
.pipe(wrapper({
header: header
}))
.pipe(rename(file => {
file.dirname = file.dirname.replace('src/', '');
file.extname = '.user.js';
}))
.pipe(gulp.dest(distFolder));
});
es.merge(tasks).on('end', done);
})
});
gulp.task('default', ['dist']);
gulp.task('watch', function () {
gulp.watch(sourceFiles, ['dist']);
});
gulp.task('bump', function () {
gulp.src('./package.json')
.pipe(bump())
.pipe(gulp.dest('./'));
});