-
Notifications
You must be signed in to change notification settings - Fork 27
/
gulpfile.js
168 lines (150 loc) · 5.6 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
163
164
165
166
167
168
/*!
* gulp
* $ npm install gulp-less gulp-autoprefixer gulp-minify-css gulp-jshint gulp-concat gulp-uglify gulp-notify gulp-rename gulp-livereload gulp-cache del --save-dev
*/
/*
* Copyright 2015 Open mHealth
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
//Load Karma
var KarmaServer = require( 'karma' ).Server;
// Load plugins
var gulp = require( 'gulp' ),
less = require( 'gulp-less' ),
autoprefixer = require( 'gulp-autoprefixer' ),
minifycss = require( 'gulp-minify-css' ),
jshint = require( 'gulp-jshint' ),
uglify = require( 'gulp-uglify' ),
rename = require( 'gulp-rename' ),
concat = require( 'gulp-concat' ),
notify = require( 'gulp-notify' ),
cache = require( 'gulp-cache' ),
connect = require( 'gulp-connect' ),
jsdoc = require( 'gulp-jsdoc3' ),
// livereload = require('gulp-livereload'),
del = require( 'del' );
// Styles
gulp.task( 'generate-concatenated-styles', function () {
return gulp.src( [ 'src/*.less', '!src/styles-common.less' ] )
.pipe( concat( 'omh-web-visualizations-all.css' ) )
.pipe( less() )
.pipe( autoprefixer( 'last 2 version' ) )
.pipe( gulp.dest( 'dist' ) )
.pipe( rename( { suffix: '.min' } ) )
.pipe( minifycss() )
.pipe( gulp.dest( 'dist' ) )
.pipe( notify( { message: 'Concatenated styles task complete' } ) );
} );
gulp.task( 'generate-component-styles', function () {
return gulp.src( [ 'src/*.less', '!src/styles-common.less' ] )
.pipe( less() )
.pipe( autoprefixer( 'last 2 version' ) )
.pipe( rename( { prefix: 'omh-web-visualizations-' } ) )
.pipe( gulp.dest( 'dist/components' ) )
.pipe( rename( { suffix: '.min' } ) )
.pipe( minifycss() )
.pipe( gulp.dest( 'dist/components' ) )
.pipe( notify( { message: 'Component styles task complete' } ) );
} );
// Scripts
gulp.task( 'generate-concatenated-script', function () {
return gulp.src( 'src/*.js' )
.pipe( jshint( '.jshintrc' ) )
.pipe( jshint.reporter( 'default' ) )
.pipe( concat( 'omh-web-visualizations-all.js' ) )
.pipe( gulp.dest( 'dist' ) )
.pipe( rename( { suffix: '.min' } ) )
.pipe( uglify() )
.pipe( gulp.dest( 'dist' ) )
.pipe( notify( { message: 'Scripts concat task complete' } ) );
} );
gulp.task( 'generate-documentation', function () {
return gulp.src( [ 'README.md', 'src/*.js' ], { read: false } )
.pipe( jsdoc( {
"tags": {
"allowUnknownTags": true
},
"source": {
"excludePattern": "(^|\\/|\\\\)_"
},
"opts": {
"destination": "./docs/jsdoc"
},
"plugins": [
"plugins/markdown"
],
"templates": {
"cleverLinks": false,
"monospaceLinks": false,
"default": {
"outputSourceFiles": true
},
"path": "ink-docstrap",
"theme": "lumen",
"navType": "vertical",
"linenums": true,
"dateFormat": "MMMM Do YYYY, h:mm:ss a"
}
}
) );
} );
gulp.task( 'generate-component-scripts', function () {
return gulp.src( 'src/*.js' )
.pipe( jshint( '.jshintrc' ) )
.pipe( jshint.reporter( 'default' ) )
.pipe( rename( { prefix: 'omh-web-visualizations-' } ) )
.pipe( gulp.dest( 'dist/components' ) )
.pipe( rename( { suffix: '.min' } ) )
.pipe( uglify() )
.pipe( gulp.dest( 'dist/components' ) )
.pipe( notify( { message: 'Scripts copy task complete' } ) );
} );
// Run test once and exit
gulp.task( 'test-scripts', function ( done ) {
new KarmaServer( {
configFile: __dirname + '/karma.conf.js',
singleRun: true,
autoWatch: false
}, function () {
done();
} ).start();
} );
// Watch for file changes and re-run tests on each change
gulp.task( 'tdd', function ( done ) {
new KarmaServer( {
configFile: __dirname + '/karma.conf.js'
}, done ).start();
} );
// Clean
gulp.task( 'clean', function ( cb ) {
del( [ 'dist' ], cb );
} );
// Default task
gulp.task( 'default', [ 'clean' ], function () {
gulp.start( [ 'generate-component-styles', 'generate-concatenated-styles' ], [ 'generate-component-scripts', 'generate-concatenated-script', 'generate-documentation' ] );
} );
// Watch
gulp.task( 'watch', function () {
// Watch .scss files
gulp.watch( 'src/*.less', [ 'generate-component-styles', 'generate-concatenated-styles' ] );
// Watch .js files
gulp.watch( [ 'src/*.js', 'test/*.js' ], [ 'test-scripts', 'generate-component-scripts', 'generate-concatenated-script', 'generate-documentation' ] );
// Create LiveReload server
// livereload.listen();
// Watch any files in dist/, reload on change
gulp.watch( [ 'dist/**' ] ).on( 'change', connect.reload );
connect.server( {
livereload: true
} );
} );