-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
130 lines (109 loc) · 3.23 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
(function() {
'use strict';
var gulp = require('gulp');
var browserify = require('browserify');
var jscs = require('gulp-jscs');
var jshint = require('gulp-jshint');
var source = require('vinyl-source-stream');
var streamify = require('gulp-streamify');
var svgSprite = require('gulp-svg-sprite');
var ts = require('gulp-typescript');
var uglify = require('gulp-uglify');
var paths = {
self: 'gulpfile.js',
src: {
js: {
root: 'client/js',
app: 'client/js/angular/app.js',
lib: 'client/js/lib/index.js'
},
svg: 'client/svg/*.svg',
ts: {
root: 'client/ts'
}
},
dest: 'assets/gen'
};
gulp.task('default', ['watch']);
gulp.task('watch', ['ts', 'js'], function() {
console.log('watching');
gulp.watch(paths.src.js.root + '/**/*.js', ['js']).on('change', function(event) {
console.log(event.path);
});
gulp.watch(paths.src.ts.root + '/**/*.ts', ['ts']).on('change', function(event) {
console.log(event.path);
});
});
gulp.task('test', ['js-lint']);
gulp.task('build', ['js', 'svg']);
gulp.task('js', ['js-lint', 'browserify-app']);
gulp.task('js-lint', ['jscs', 'jshint']);
gulp.task('jshint', function() {
return gulp.src([paths.self, paths.src.root + '/**/*.js'])
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'));
});
gulp.task('jscs', function() {
return gulp.src([paths.self, paths.src.js.root + '/**/*.js'])
.pipe(jscs())
.pipe(jscs.reporter('jscs-stylish'))
.pipe(jscs.reporter('fail'));
});
gulp.task('browserify', ['browserify-app', 'browserify-lib']);
gulp.task('browserify-app', function() {
return browserify([paths.src.js.app], {
debug: true
})
.bundle()
.pipe(source('app.min.js'))
.pipe(gulp.dest(paths.dest));
});
gulp.task('browserify-lib', function() {
return browserify([paths.src.js.lib])
.bundle()
.pipe(source('lib.min.js'))
.pipe(gulp.dest(paths.dest));
});
gulp.task('release', ['js-release', 'svg']);
gulp.task('js-release', ['ts', 'js-lint', 'browserify-release']);
gulp.task('browserify-release', [
'browserify-release-app',
'browserify-release-lib'
]);
gulp.task('browserify-release-app', function() {
return browserify([paths.src.js.app], {
debug: true
})
.bundle()
.pipe(source('app.min.js'))
.pipe(streamify(uglify()))
.pipe(gulp.dest(paths.dest));
});
gulp.task('browserify-release-lib', function() {
return browserify([paths.src.js.lib])
.bundle()
.pipe(source('lib.min.js'))
.pipe(streamify(uglify()))
.pipe(gulp.dest(paths.dest));
});
gulp.task('svg', function() {
return gulp.src(paths.src.svg)
.pipe(svgSprite({
mode: {
defs: {
dest: '',
sprite: 'sprite.defs.svg'
}
}
}))
.pipe(gulp.dest(paths.dest));
});
gulp.task('ts', function() {
var tsProject = ts.createProject(paths.src.ts.root + '/tsconfig.json', {
outDir: paths.src.js.root
});
var tsResult = tsProject.src().pipe(tsProject());
return tsResult.js.pipe(gulp.dest(paths.src.js.root));
});
})();