-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
110 lines (101 loc) · 3.29 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
const rollup = require('rollup');
const resolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
const uglify = require('rollup-plugin-uglify-es');
const babel = require('rollup-plugin-babel');
const replace = require('rollup-plugin-replace');
const sourcemaps = require('rollup-plugin-sourcemaps');
const builtin = require('rollup-plugin-node-builtins');
const pkg = require('./package.json');
const gulp = require('gulp');
const mocha = require('gulp-mocha');
const clear = require('clear');
const vinylPaths = require('vinyl-paths');
const del = require('del');
var child_exec = require('child_process').exec;
const srcPaths = ['./src/**/*.js']
gulp.task('build-umd', () => {
return rollup.rollup({
input: 'src/main.js',
external: ['events', 'process', 'axios'],
plugins: [
builtin(),
sourcemaps(),
resolve({
browser: true,
preferBuiltins: true
}),
commonjs(),
babel({
exclude: 'node_modules/**' // only transpile our source code
}),
replace({
ENV: JSON.stringify(process.env.NODE_ENV || 'development'),
}),
(process.env.NODE_ENV === 'production' && uglify())
]
}).then(bundle => {
return bundle.write({
name: 'js-data-frappe',
file: pkg.browser,
format: 'umd',
sourcemap: true
});
});
});
gulp.task('build-cjs-es', () => {
return rollup.rollup({
input: 'src/main.js',
external: ['events', 'process', 'axios'],
plugins: [
sourcemaps(),
resolve(),
replace({
ENV: JSON.stringify(process.env.NODE_ENV || 'development'),
}),
(process.env.NODE_ENV === 'production' && uglify())
]
}).then(bundle => {
return bundle.write({
name: 'js-data-frappe',
file: pkg.common,
format: 'cjs',
sourcemap: true
}).then(() => {
return bundle.write({
name: 'js-data-frappe',
file: pkg.module,
format: 'es',
sourcemap: true
});
});
})
});
gulp.task('test', ['build-umd', 'build-cjs-es'], () => {
return gulp.src('./test/**/*.test.js', { read: false })
.pipe(mocha({
reporter: 'list',
bail: true
}))
});
gulp.task('docs', ['build'], function (done) {
let docPath = `./docs/${pkg.name}/${pkg.version}`;
function moveDocs() {
gulp.src(`${docPath}/**/*`, { base: docPath })
.pipe(gulp.dest('./docs')).on('end', () => { cleanDocs(done) });
}
function cleanDocs(done) {
gulp.src(`./docs/${pkg.name}`, { base: './', read: false })
.pipe(vinylPaths(del)).on('finish', () => { done() });
}
child_exec('node ./node_modules/jsdoc/jsdoc.js -c ./jsdoc.json', undefined, moveDocs);
})
gulp.task('build', ['build-umd', 'build-cjs-es', 'test']);
gulp.task('watch', () => {
clear();
return gulp.watch(['src/**/*', 'test/**/*'], ['build']);
});
gulp.task('watch:docs', () => {
clear();
return gulp.watch(['src/**/*', 'test/**/*', 'README.md'], ['docs']);
});