-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
75 lines (66 loc) · 1.82 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
var gulp = require( "gulp" );
var header = require( "gulp-header" );
var beautify = require( "gulp-beautify" );
var hintNot = require( "gulp-hint-not" );
var uglify = require( "gulp-uglify" );
var rename = require( "gulp-rename" );
var plato = require( "gulp-plato" );
var gutil = require( "gulp-util" );
var pkg = require( "./package.json" );
var express = require( "express" );
var path = require( "path" );
var open = require( "open" );
var port = 3080;
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( "optimize", function() {
gulp.src( [ "./src/postal.react.js" ] )
.pipe( header( banner, {
pkg: pkg
} ) )
.pipe( hintNot() )
.pipe( beautify( {
indentSize: 4
} ) )
.pipe( gulp.dest( "./lib/" ) )
.pipe( gulp.dest( "./lib/" ) )
.pipe( uglify( {
compress: {
negate_iife: false
}
} ) )
.pipe( header( banner, {
pkg: pkg
} ) )
.pipe( rename( "postal.react.min.js" ) )
.pipe( gulp.dest( "./lib/" ) );
} );
gulp.task( "default", ["optimize"], function() { } );
gulp.task( "report", function() {
gulp.src( "./lib/postal.react.js" )
.pipe( plato( "report" ) );
} );
var createServers = 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", [ "optimize", "report" ], function() {
if ( !servers ) {
servers = createServers( port );
}
open( "http://localhost:" + port + "/index.html" );
} );