-
Notifications
You must be signed in to change notification settings - Fork 193
/
gulpfile.js
162 lines (146 loc) · 4.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
var gulp = require( "gulp" );
var fileImports = require( "gulp-imports" );
var header = require( "gulp-header" );
var uglify = require( "gulp-uglify" );
var rename = require( "gulp-rename" );
var plato = require( "gulp-plato" );
var gutil = require( "gulp-util" );
var express = require( "express" );
var path = require( "path" );
var pkg = require( "./package.json" );
var open = require( "open" ); //jshint ignore:line
var port = 3080;
var jshint = require( "gulp-jshint" );
var jscs = require( "gulp-jscs" );
var gulpChanged = require( "gulp-changed" );
var replace = require( "gulp-replace" );
var replaceTargets = [
"([\\/][\\*][\\s]*jshint\\s.+[\\*\\/])",
"([\\/][\\*][\\s]*global\\s.+[\\*\\/])",
"([\\/][\\*][\\s]*jscs:\\s.+[\\*\\/])",
"([\\/][\\*][\\s]*istanbul\\s.+[\\*\\/])",
"(\\/\\/[\\s]*jshint.*)",
"(\\/\\/[\\s]*jscs:.*)",
"(\\/\\/[\\s]*istanbul.*)"
];
var banner = [ "/**",
" * <%= pkg.name %> - <%= pkg.description %>",
" * Author: <%= pkg.author %>",
" * Version: v<%= pkg.version %>",
" * Url: <%= pkg.homepage %>",
" * License(s): <% pkg.licenses.forEach(function( license, idx ){ %><%= license.type %><% if(idx !== pkg.licenses.length-1) { %>, <% } %><% }); %>",
" */",
""
].join( "\n" );
gulp.task( "combine", [ "combine.postal", "combine.postal-lodash" ] );
gulp.task( "combine.postal", [ "format-src" ], function() {
return gulp.src( [ "./src/postal.js" ] )
.pipe( header( banner, {
pkg: pkg
} ) )
.pipe( fileImports() )
.pipe( replace( new RegExp( replaceTargets.join( "|" ),"gi" ), "" ) )
.pipe( gulp.dest( "./lib/" ) )
.pipe( uglify( {
compress: {
negate_iife: false //jshint ignore:line
}
} ) )
.pipe( header( banner, {
pkg: pkg
} ) )
.pipe( rename( "postal.min.js" ) )
.pipe( gulp.dest( "./lib/" ) );
} );
gulp.task( "combine.postal-lodash", [ "format-src" ], function() {
return gulp.src( [ "./src/postal.lodash.js" ] )
.pipe( header( banner, {
pkg: pkg
} ) )
.pipe( fileImports() )
.pipe( replace( new RegExp( replaceTargets.join( "|" ),"gi" ), "" ) )
.pipe( gulp.dest( "./lib/" ) )
.pipe( uglify( {
compress: {
negate_iife: false //jshint ignore:line
}
} ) )
.pipe( header( banner, {
pkg: pkg
} ) )
.pipe( rename( "postal.lodash.min.js" ) )
.pipe( gulp.dest( "./lib/" ) );
} );
gulp.task( "default", [ "format-lib" ] );
var mocha = require( "gulp-spawn-mocha" );
gulp.task( "mocha", function() {
return gulp.src( [ "spec/**/*.spec.js" ], { read: false } )
.pipe( mocha( {
require: [ "spec/helpers/node-setup.js" ],
reporter: "spec",
colors: true,
inlineDiffs: true,
debug: false
} ) )
.on( "error", console.warn.bind( console ) );
} );
gulp.task( "mocha-lodash", function() {
return gulp.src( [ "spec/**/*.spec.js" ], { read: false } )
.pipe( mocha( {
require: [ "spec/helpers/node-lodash-build-setup.js" ],
reporter: "spec",
colors: true,
inlineDiffs: true,
debug: false
} ) )
.on( "error", console.warn.bind( console ) );
} );
gulp.task( "report", function() {
return gulp.src( "./lib/postal.js" )
.pipe( plato( "report" ) );
} );
var createServer = function( port ) {
var p = path.resolve( "./" );
var app = express();
app.use( express.static( p ) );
app.listen( port, function() {
gutil.log( "Listening on", port );
} );
return {
app: app
};
};
var servers;
gulp.task( "server", [ "combine" ], function() {
if ( !servers ) {
servers = createServer( port );
}
open( "http://localhost:" + port + "/index.html" );
} );
gulp.task( "watch", [ "default", "mocha" ], function() {
gulp.watch( "src/**/*", [ "default" ] );
gulp.watch( "{lib,spec}/**/*", [ "mocha" ] );
} );
gulp.task( "jshint", function() {
return gulp.src( [ "src/**/*.js", "spec/**/*.js" ] )
.pipe( jshint() )
.pipe( jshint.reporter( "jshint-stylish" ) )
.pipe( jshint.reporter( "fail" ) );
} );
gulp.task( "format-lib", [ "combine" ], function() {
return gulp.src( [ "./lib/postal.js", "./lib/postal.lodash.js" ] )
.pipe( jscs( {
configPath: ".jscsrc",
fix: true
} ) )
.pipe( gulp.dest( "./lib" ) );
} );
gulp.task( "format-src", [ "jshint" ], function() {
return gulp.src( [ "./src/**/*.js", "!node_modules/**" ] )
.pipe( jscs( {
configPath: ".jscsrc",
fix: true
} ) )
.pipe( gulpChanged( "./src", { hasChanged: gulpChanged.compareSha1Digest } ) )
.pipe( gulp.dest( "./src" ) );
} );