-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
103 lines (91 loc) · 3.12 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
var gulp = require('gulp'),
sourcemaps = require('gulp-sourcemaps'),
tsc = require('gulp-typescript'),
tslint = require('gulp-tslint'),
tsProject = tsc.createProject('tsconfig.json'),
config = require('./gulp.config')(),
util = require('gulp-util'),
browserSync = require('browser-sync'),
superstatic = require('superstatic'),
stylus = require('gulp-stylus'),
nib = require('nib'),
jeet = require('jeet'),
rupture = require('rupture'),
prefixer = require('gulp-autoprefixer'),
imagemin = require('gulp-imagemin'),
del = require('del'),
reload = browserSync.reload;
function Gdelete(error, deletedFiles) {
if (error) error(error);
util.log(util.colors.yellow('Files deleted: ', deletedFiles.join(', ')));
}
function error(error) {
util.log(util.colors.red(error.toString()));
}
function change(event) {
util.log(util.colors.blue('File ' + event.path + ' was ' + event.type));
}
gulp.task('ts-lint', function() {
return gulp.src(config.allTs)
.pipe(tslint())
.pipe(tslint.report('prose', {
emitError: false
}));
});
gulp.task('compile-ts', function() {
var sourceTsFiles = [
config.allTs
];
var tsResult = gulp
.src(sourceTsFiles)
.pipe(sourcemaps.init())
.pipe(tsc(tsProject));
return tsResult.js
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(config.tsOutputPath));
});
browserSync({
port: 3000,
files: ['index.html', '**/*.js', 'app/static/styles/src/*.styl', 'app/components/**/*.html'],
injectChanges: true,
logFileChanges: true,
logLevel: 'silent',
notify: true,
reloadDelay: 0,
server: {
baseDir: ['./'],
middleware: superstatic({ debug: false })
}
});
gulp.task('watch', function() {
var styleWatcher = gulp.watch(['app/static/styles/src/*.styl'], ['style:dev']);
var jsWatcher = gulp.watch([config.allTs], ['ts-lint', 'compile-ts']);
var imgWatcher = gulp.watch(['app/static/images/src/*.*'], ['image']);
var spriteWatcher = gulp.watch(['src/img/sprite/*.png'], ['sprite']);
});
gulp.task('style:dev', ['css:del'], function() {
return gulp.src('app/static/styles/src/*.styl')
.pipe(sourcemaps.init())
.pipe(stylus({ use: [nib(), jeet(), rupture()], 'include css': true })).on('error', error)
.pipe(prefixer({ browsers: ['last 2 version'], cascade: false }))
.pipe(sourcemaps.write())
.pipe(gulp.dest('app/static/styles/dist/'))
.pipe(browserSync.reload({ stream: true }));
});
gulp.task('css:del', function() {
del('app/static/styles/dist/*.css', Gdelete);
});
gulp.task('image', ['img:del'], function() {
return gulp.src('app/static/images/src/*.*')
.pipe(imagemin({
progressive: true,
svgoPlugins: [{ removeViewBox: false }],
interlaced: true
})).on('error', error)
.pipe(gulp.dest('app/static/images/dist'))
.pipe(browserSync.reload({ stream: true }));
});
gulp.task('img:del', function() {
del('app/static/images/dist', Gdelete);
});
gulp.task('default', ['watch', 'style:dev', 'image']);