-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
112 lines (95 loc) · 2.42 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
'use strict';
var gulp = require('gulp');
var es = require('event-stream');
var concat = require('gulp-concat');
var babel = require('gulp-babel');
var less = require('gulp-less');
var order = require('gulp-order');
var header = require('gulp-header');
var wrap = require('gulp-wrap');
var watch = require('gulp-watch');
var connect = require('gulp-connect');
var openBrowser = require('gulp-open');
var karma = require('gulp-karma');
var pkg = require('./package.json');
var banner = [
'<!--',
'<%= pkg.name %> - <%= pkg.description %>',
'@version v<%= pkg.version %>',
'@link <%= pkg.homepage %>',
'@license <%= pkg.license %>',
'-->',
''
].join('\n');
function scripts() {
return gulp.src('src/js/main.js')
.pipe(babel())
.on('error', log)
.pipe(wrap('(function(){\n<%= contents %>\n}).call(this);'))
.pipe(wrap('<script>\n<%= contents %>\n</script>'))
.pipe(connect.reload());
}
function styles() {
return gulp.src('src/less/**/*.less')
.pipe(less())
.on('error', log)
.pipe(wrap('<style>\n<%= contents %>\n</style>'))
.pipe(connect.reload());
}
function html() {
return gulp.src('src/template/index.html')
.pipe(connect.reload());
}
gulp.task('build', function () {
return es.merge([
html(),
styles(),
scripts()
])
.pipe(order(['template.html', 'styles.css', 'scripts.js']))
.pipe(concat('index.html'))
.pipe(header(banner, {pkg: pkg}))
.pipe(gulp.dest('dist'));
});
gulp.task('copy', function(){
return gulp.src('./node_modules/forms-js/dist/forms-js.js')
.pipe(gulp.dest('dist'));
});
gulp.task('watch', function() {
return watch('{src,demo}/**/*.{js,less,html}', function(){
gulp.start('build');
});
});
gulp.task('connect', function() {
return connect.server({
port: 8123,
root: '.',
livereload: true
});
});
gulp.task('open', function () {
gulp.src('./demo/index.html')
.pipe(openBrowser('', {
url: 'http://localhost:8123/demo'
}));
})
gulp.task('test', function() {
return gulp.src([])
.pipe(karma({
configFile: 'karma.conf.js',
action: 'run'
}))
.on('error', log);
});
gulp.task('test:watch', function() {
return gulp.src([])
.pipe(karma({
configFile: 'karma.conf.js',
action: 'watch'
}));
});
function log(error) {
console.error(error.toString && error.toString());
}
gulp.task('default', ['build', 'copy']);
gulp.task('serve', ['default', 'watch', 'connect', 'open'])