-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
89 lines (74 loc) · 2.25 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
var gulp = require('gulp'),
uglify = require('gulp-uglify'),
rimraf = require('gulp-rimraf'),
rename = require('gulp-rename'),
gutil = require('gulp-util'),
tap = require('gulp-tap'),
buffer = require('gulp-buffer'),
sourcemaps = require('gulp-sourcemaps'),
browserify = require('browserify'),
reactify = require('reactify'),
mochify = require('mochify'),
mocha = require('gulp-mocha'),
SRC = './lib/SmartString.js',
TEST_SRC = './test/SmartString.test.js',
DEST = 'dist',
SRC_COMPILED = 'SmartString.js',
MIN_FILE = 'SmartString.min.js'
gulp.task('browserify', function () {
return gulp.src(SRC, { read: false }) // no need of reading file because browserify does.
// transform file objects using gulp-tap plugin
.pipe(tap(function (file) {
gutil.log('bundling ' + file.path)
// replace file contents with browserify's bundle stream
file.contents = browserify(file.path, { debug: true }).bundle()
}))
// transform streaming contents into buffer contents (because gulp-sourcemaps does not support streaming contents)
.pipe(buffer())
// load and init sourcemaps
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglify())
// write sourcemaps
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('dist'))
})
/*
// gulp-browserify is deprecated
gulp.task('browserify', function() {
return gulp.src(SRC)
.pipe(browserify({
detectGlobals: true,
standalone: 'S'
}))
.pipe(gulp.dest(DEST))
})
*/
gulp.task('test', function () {
return gulp.src(TEST_SRC, { read: false })
.pipe(mocha({ reporter: 'spec', growl: 1 }))
})
gulp.task('clean', function () {
return gulp.src(DEST)
.pipe(rimraf())
})
gulp.task('build', ['test', 'clean', 'browserify'], function () {
gulp.src(DEST + '/' + SRC_COMPILED)
.pipe(uglify())
.pipe(rename(MIN_FILE))
.pipe(gulp.dest(DEST))
})
gulp.task('browserTest', function (done) {
return mochify({ wd: true })
.on('error', function (err) {
if (err) done(err)
else done()
})
.bundle()
})
// snippet
gulp.task('log', function() {
// content
console.log('just a placeholder');
});
// The default task (called when you run `gulp` from cli)
gulp.task('default', ['clean', 'build'])