-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
69 lines (61 loc) · 1.71 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
/*jshint globalstrict: true*/
/*global require*/
'use strict'
const gulp = require('gulp')
const util = require('util')
const jdists = require('gulp-jdists')
const uglify = require('gulp-uglify')
const rename = require('gulp-rename')
const examplejs = require('gulp-examplejs')
const replace = require('gulp-replace')
const typescript = require('gulp-typescript')
const merge2 = require('merge2')
const pkg = require('./package')
gulp.task('build', function () {
var tsResult = gulp.src(`src/${pkg}.ts`)
.pipe(jdists())
.pipe(gulp.dest('lib'))
.pipe(typescript({
target: 'ES5',
declaration: true,
module: 'umd',
}))
return merge2([
tsResult.dts.pipe(gulp.dest('lib')),
tsResult.js
.pipe(replace(
/(\(function\s*\()(factory\)\s*\{)/, '$1root, $2\n /* istanbul ignore next */'
))
.pipe(replace(
/(define\(\["require",\s*"exports"\],\s*factory\);\s*\})/, '$1 else { factory(null, root["' + pkg.name + '"] = {}); }'
))
.pipe(replace(
/(\s*\}\s*\)\s*\()(function\s*\(require,\s*exports\)\s*\{)/, '$1this, $2'
))
.pipe(gulp.dest('lib'))
])
})
gulp.task('uglify', function () {
gulp.src(`lib/${pkg.name}.js`)
.pipe(uglify())
.pipe(rename(`${pkg.name}.min.js`))
.pipe(gulp.dest('lib'))
})
gulp.task('example', function() {
return gulp.src('src/**.js')
.pipe(jdists({
trigger: 'example'
}))
.pipe(examplejs({
header: `const ${pkg.name} = require('../')\n`
}))
.pipe(gulp.dest('test'))
})
gulp.task('cli', function () {
gulp.src(`src/cli.ts`)
.pipe(typescript({
target: 'es5',
}))
.pipe(gulp.dest('lib'))
})
gulp.task('dist', ['build', 'cli', 'example', 'uglify'])