-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
116 lines (102 loc) · 3.54 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
var gulp = require( "gulp" ),
browserify = require( "gulp-browserify" ),
css = require( "gulp-minify-css" ),
concat = require( "gulp-concat" ),
jshint = require( "gulp-jshint" ),
jshintReporter = require( "jshint-stylish" ),
less = require( "gulp-less" ),
mochaPhantomJS = require( "gulp-mocha-phantomjs" ),
rename = require( "gulp-rename" ),
shell = require( "gulp-shell" ),
uglify = require( "gulp-uglify" );
var pkg = require( "./package.json" ),
livereloadServer,
moduleName = pkg.moduleName;
var livereload = function ( _file ) {
return function () {
if ( livereloadServer ) livereloadServer.changed( _file );
}
}
gulp.task( "concatScripts", function () {
return gulp.src( [ "./src/scripts/index.js", "./src/scripts/list.js" ] )
.pipe( concat( "src.js" ) )
.pipe( gulp.dest( "./.tmp/" ) );
} );
gulp.task( "jshint", function () {
return gulp.src( [ "./src/scripts/**/*.js", "test/**/*.js", "testClient/**/*.js" ] )
.pipe( jshint() )
.pipe( jshint.reporter( jshintReporter ) );
} );
gulp.task( "minifyScripts", [ "jshint", "scriptMain" ], function () {
gulp.src( [ "./dist/" + moduleName + ".js" ] )
.pipe( uglify() )
.pipe( rename( moduleName + ".min.js" ) )
.pipe( gulp.dest( "./dist/" ) )
.on( "end", livereload( ".js" ) );
} );
gulp.task( "minifyStyles", [ "stylesMain" ], function () {
gulp.src( [ "./dist/" + moduleName + ".css" ] )
.pipe( css() )
.pipe( rename( moduleName + ".min.css" ) )
.pipe( gulp.dest( "./dist/" ) )
.on( "end", livereload( ".js" ) );
} );
gulp.task( "readme", [ "concatScripts" ], function () {
gulp.src( "" )
.pipe( shell( [
"./node_modules/.bin/dox < ./.tmp/src.js -a > README.md"
] ) )
.on( "end", livereload( ".js" ) );
} );
gulp.task( "scriptMain", function () {
return gulp.src( [ "./src/scripts/index.js" ] )
.pipe( browserify( {
standalone: moduleName,
debug: true
} ) )
.pipe( rename( moduleName + ".js" ) )
.pipe( gulp.dest( "./dist/" ) )
.on( "end", livereload( ".js" ) );
} );
gulp.task( "stylesMain", function () {
return gulp.src( [ "./src/styles/index.less" ] )
.pipe( less() )
.pipe( rename( moduleName + ".css" ) )
.pipe( gulp.dest( "./dist/" ) )
.on( "end", livereload( ".css" ) );
} );
gulp.task( "test", function () {
return gulp.src( "" ).pipe( shell( [
"npm test"
] ) );
} );
gulp.task( "tests", [ "scriptMain", "stylesMain" ], function () {
[
"testClient/data.html",
"testClient/defaults.html",
"testClient/destroy.html",
"testClient/fuzzy-search.html",
"testClient/more-than-one.html",
"testClient/open-close.html",
"testClient/options-given-by-data-attrs.html",
"testClient/sort.html",
"testClient/templates.html"
].forEach( function ( _html ) {
gulp.src( _html ).pipe( mochaPhantomJS() );
} );
} );
gulp.task( "watch", function () {
livereloadServer = require( "gulp-livereload" )();
gulp.watch( [ "./src/scripts/**/*.js*" ], [ "scripts", "minifyScripts", "test", "docs" ] );
gulp.watch( [ "./src/styles/**/*.less" ], [ "styles" ] );
gulp.watch( [ "./demo/*" ], [ "default" ] );
gulp.watch( [ "./test/**/*", "./testClient/**/*" ], [ "test" ] );
gulp.watch( [ "*.js*" ], [ "default" ] );
} );
gulp.task( "default", [ "build", "test" ] );
gulp.task( "build", [ "scripts", "styles", "minify", "docs" ] );
gulp.task( "scripts", [ "scriptMain" ] );
gulp.task( "styles", [ "stylesMain" ] );
gulp.task( "minify", [ "minifyScripts", "minifyStyles" ] );
gulp.task( "docs", [ "readme" ] );
gulp.task( "run", [ "build", "test", "watch" ] );