-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
117 lines (103 loc) · 3.04 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
111
112
113
114
115
116
117
const fs = require('fs')
const gulp = require('gulp')
const glob = require('glob')
const rename = require('gulp-rename')
const sourcemaps = require('gulp-sourcemaps')
const clean = require('gulp-clean')
const header = require('gulp-header')
const ts = require('gulp-typescript')
const rollup = require('gulp-rollup')
const includePaths = require('rollup-plugin-includepaths')
const uglify = require('gulp-uglify')
gulp.task('clean', () =>
gulp.src(['build', 'packages/*/dist'])
.pipe(clean())
)
const tsResult =
gulp.src(['assets/env.d.ts', 'packages/*/src/**/*.ts'])
.pipe(sourcemaps.init())
.pipe(ts(ts.createProject('tsconfig.json', {
typescript: require('typescript'),
noEmit: false,
})))
gulp.task('typings', () =>
tsResult.dts
.pipe(rename(maybeRenameSourcePath))
.pipe(gulp.dest('build/typings'))
)
gulp.task('es6', () =>
tsResult.js
.pipe(sourcemaps.write())
.pipe(rename(maybeRenameSourcePath))
.pipe(gulp.dest('build/es6'))
)
gulp.task('es3', ['es6'], () =>
gulp.src('build/es6/**/*.js')
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(ts({
allowJs: true,
target: 'es3',
module: 'commonjs',
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest('build/es3'))
)
const headerTemplate =
`/*!
* Vulture v<%= version %>
* (c) 2016 Caleb Meredith
* Released under the MIT License.
*/
`
gulp.task('dist', ['es6'], () =>
gulp.src(['assets/entries/*.js', 'build/es6/**/*.js'])
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(rollup({
entry: glob.sync('assets/entries/*.js'),
format: 'iife',
moduleName: 'Vulture',
plugins: [
includePaths({ paths: ['build/es6'] }),
],
}))
.pipe(ts({
allowJs: true,
target: 'es3',
}))
.pipe(header(headerTemplate, {
version: JSON.parse(fs.readFileSync('lerna.json', 'utf8')).version,
}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('build/dist'))
)
gulp.task('dist-min', ['dist'], () =>
gulp.src('build/dist/+([^.]).js')
.pipe(sourcemaps.init())
.pipe(uglify({ preserveComments: 'license' }))
.pipe(sourcemaps.write('.'))
.pipe(rename(addMinToPath))
.pipe(gulp.dest('build/dist'))
)
gulp.task('bundle', ['typings', 'es6', 'es3'], () =>
gulp.src('build/{typings,es6,es3}/*/**/*.*')
.pipe(rename(moveToPackage))
.pipe(gulp.dest('packages'))
)
gulp.task('default', ['typings', 'es6', 'es3', 'dist', 'dist-min'])
function maybeRenameSourcePath (path) {
const sourcePathRe = /(vulture[^/]*)\/src(.*)$/
if (sourcePathRe.test(path.dirname)) {
const [, package, dirname] = sourcePathRe.exec(path.dirname)
path.dirname = `${package}${dirname}`
}
}
function addMinToPath (path) {
const jsPathRe = /^(.*?)(\.js)?$/
const [, basename, extension] = jsPathRe.exec(path.basename)
path.basename = `${basename}.min${extension || ''}`
}
function moveToPackage (path) {
const dirnameRe = /^([^/]+)\/([^/]+)(\/.+)?$/
const [, artifact, package, rest] = dirnameRe.exec(path.dirname)
path.dirname = `${package}/dist/${artifact}/${rest || ''}`
}