forked from pyrsmk/qwest
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
97 lines (72 loc) · 2.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
var fs = require('fs'),
gulp = require('gulp'),
size = require('gulp-sizereport'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
resolve = require('resolve'),
rename = require('gulp-rename'),
replace = require('gulp-replace'),
merge = require('merge2'),
shell = require('gulp-shell'),
derequire = require('gulp-derequire'),
browserify = require('browserify'),
resolve = require('resolve'),
through2 = require('through2'),
_ = require('lodash');
var name = 'qwest',
version = fs.readFileSync('./src/'+name+'.js', {encoding: 'utf8'}).match(/^\/\*\! [\w-]+ ([0-9.]+)/)[1];
// ======================================== gulp version
gulp.task('version', function() {
var streams = merge();
streams.add(
gulp.src( './package.json' )
.pipe( replace(/"version": "[0-9.]+",/, '"version": "'+version+'",') )
.pipe( gulp.dest('.') )
);
streams.add(
gulp.src( './README.md' )
.pipe( replace(/^(\w+) [0-9.]+/, '$1 '+version) )
.pipe( gulp.dest('.') )
);
return streams;
});
// ======================================== gulp lint
gulp.task('lint', function() {
return gulp.src( './src/'+name+'.js' )
.pipe( jshint() )
.pipe( jshint.reporter('jshint-stylish') );
});
// ======================================== gulp build
gulp.task('build', ['version', 'lint'], function() {
return gulp.src( './src/'+name+'.js' )
.pipe( size() )
.pipe( through2.obj(function(file, enc, next) {
var b = browserify(null, {
standalone: name,
insertGlobalVars: {process: false}
});
(_.keys(require('./package.json').dependencies) || []).forEach(function(name) {
b.add(resolve.sync(name, {moduleDirectory: './node_modules/'}));
});
b.require('./src/'+name+'.js', {expose: name});
b.bundle(function(err, res) {
file.contents = res;
next(null, file);
});
}) )
.pipe( derequire() )
.pipe( gulp.dest('.') )
.pipe( uglify() )
.pipe( rename(name+'.min.js') )
.pipe( gulp.dest('.') )
.pipe( size({gzip:true}) );
});
// ======================================== gulp publish
gulp.task('publish', shell.task([
"git tag -a "+version+" -m '"+version+"'",
'git push --tags',
'npm publish',
'jam publish'
]));
// ======================================== gulp
gulp.task('default', ['build']);