-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
100 lines (89 loc) · 3.05 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
"use strict";
const _ = require('lodash');
const path = require('path');
const gulp = require('gulp');
const browserify = require('browserify');
const browserifyShim = require('browserify-shim');
const babelify = require('babelify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const rename = require('gulp-rename');
const replace = require('gulp-replace');
const uglifyjs = require('gulp-uglify-es').default;
const sourcemaps = require('gulp-sourcemaps');
const eslint = require("gulp-eslint");
const jasmine = require('gulp-jasmine');
const jsdoc2md = require("jsdoc-to-markdown");
const Promise = require("bluebird");
const fs = Promise.promisifyAll(require("fs"));
const pkg = require('./package.json');
const CONFIG = {
BABEL: {
presets: [
["@babel/preset-env", {
targets: {
browsers: "cover 99.5%, last 2 versions, not dead"
}
}]
]
},
BROWSERIFY: {
global: _.keys(pkg.browser)[0],
bundle: path.basename(_.values(pkg.browser)[0]),
dirname: path.dirname(_.values(pkg.browser)[0]),
sourceMap: "./",
shimConfig: { global: true }
},
PATHS: {
src: `${path.dirname(pkg.main)}/**/*.js`,
testsPath: "./test/*.spec.js",
examplesPaths: ["./examples/*-template.xsls", "./examples/*.json"],
docAPIPath: "./API.md"
},
NAMES: {
docAPITitle: "# xlsx-datafill API reference\n\r"
}
};
gulp.task("browserify", () =>
browserify({
entries: pkg.main,
debug: true,
standalone: CONFIG.BROWSERIFY.global
})
.transform(browserifyShim, CONFIG.BROWSERIFY.shimConfig)
.transform(babelify, CONFIG.BABEL)
.bundle()
.pipe(source(CONFIG.BROWSERIFY.bundle))
.pipe(replace('{{VERSION}}', pkg.version))
.pipe(buffer())
.pipe(gulp.dest(CONFIG.BROWSERIFY.dirname))
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglifyjs())
.pipe(rename({ extname: '.min.js' }))
.pipe(sourcemaps.write(CONFIG.BROWSERIFY.sourceMap))
.pipe(gulp.dest(CONFIG.BROWSERIFY.dirname))
);
gulp.task("lint", () => gulp
.src([CONFIG.PATHS.src])
.pipe(eslint())
.pipe(eslint.format())
);
gulp.task("unit", async () => gulp
.src(CONFIG.PATHS.testsPath)
.pipe(jasmine())
);
gulp.task("docs", () =>
jsdoc2md.render({ files: CONFIG.PATHS.src })
.then(output => {
return fs.writeFileAsync(CONFIG.PATHS.docAPIPath, CONFIG.NAMES.docAPITitle + output);
})
);
gulp.task("watch", () => {
// Only watch src, unit, and docs for changes. Everything else is too slow or noisy.
gulp.watch([CONFIG.PATHS.src], gulp.series(["test"]));
gulp.watch([CONFIG.PATHS.testsPath].concat(CONFIG.PATHS.examplesPaths), gulp.series(["unit"]));
});
gulp.task("build", gulp.parallel("docs", "browserify", "lint"));
gulp.task("test", gulp.series("build", "unit"));
// Watch just the quick stuff to aid development.
gulp.task("default", gulp.series("test", "watch"));