This repository has been archived by the owner on Apr 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
gulpfile.js
136 lines (110 loc) · 3.53 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
var gulp = require('gulp'),
del = require('del'),
merge = require('merge-stream'),
tsc = require('gulp-typescript'),
tsProject = tsc.createProject('tsconfig.json'),
SystemBuilder = require('systemjs-builder'),
jsMinify = require('gulp-uglify'),
mocha = require('gulp-mocha'),
concat = require('gulp-concat'),
imagemin = require('gulp-imagemin'),
scssLint = require('gulp-scss-lint'),
sass = require('gulp-sass'),
cssPrefixer = require('gulp-autoprefixer'),
cssMinify = require('gulp-cssnano');
gulp.task('clean', () => {
return del('dist');
});
gulp.task('shims', () => {
return gulp.src([
'node_modules/core-js/client/shim.js',
'node_modules/zone.js/dist/zone.js',
'node_modules/reflect-metadata/Reflect.js'
])
.pipe(concat('shims.js'))
.pipe(gulp.dest('dist/js/'));
});
gulp.task('system-build', [ 'tsc' ], () => {
var builder = new SystemBuilder();
return builder.loadConfig('system.config.js')
.then(() => builder.buildStatic('app', 'dist/js/bundle.js', {
production: false,
rollup: false
}))
.then(() => del('build'));
});
gulp.task('tsc', () => {
del('build');
return gulp.src('src/app/**/*.ts')
.pipe(tsProject())
.pipe(gulp.dest('build/'));
});
gulp.task('html', () => {
return gulp.src('src/**/**.html')
.pipe(gulp.dest('dist/'));
});
gulp.task('images', () => {
return gulp.src('src/images/**/*.*')
.pipe(imagemin())
.pipe(gulp.dest('dist/images/'));
});
gulp.task('scss-lint', function() {
return gulp.src('src/scss/**/*.scss')
.pipe(scssLint({ config: 'lint.yml' }));
});
gulp.task('scss', () => {
return gulp.src('src/scss/main.scss')
.pipe(sass({
precision: 10,
includePaths: 'node_modules/node-normalize-scss'
}))
.pipe(concat('styles.css'))
.pipe(cssPrefixer())
.pipe(gulp.dest('dist/css/'));
});
gulp.task('test-run', [ 'tsc' ], () => {
return gulp.src('test/**/*.spec.js')
.pipe(mocha());
});
gulp.task('test', [ 'test-run' ], () => {
return del('build');
});
gulp.task('minify', () => {
var js = gulp.src('dist/js/bundle.js')
.pipe(jsMinify())
.pipe(gulp.dest('dist/js/'));
var css = gulp.src('dist/css/styles.css')
.pipe(cssMinify())
.pipe(gulp.dest('dist/css/'));
return merge(js, css);
});
gulp.task('watch', () => {
var watchTs = gulp.watch('src/app/**/**.ts', [ 'system-build' ]),
watchScss = gulp.watch('src/scss/**/*.scss', [ 'scss-lint', 'scss' ]),
watchHtml = gulp.watch('src/**/*.html', [ 'html' ]),
watchImages = gulp.watch('src/images/**/*.*', [ 'images' ]),
onChanged = function(event) {
console.log('File ' + event.path + ' was ' + event.type + '. Running tasks...');
};
watchTs.on('change', onChanged);
watchScss.on('change', onChanged);
watchHtml.on('change', onChanged);
watchImages.on('change', onChanged);
});
gulp.task('watchtests', () => {
var watchTs = gulp.watch('src/app/**/**.ts', [ 'test-run' ]),
watchTests = gulp.watch('test/**/*.spec.js', [ 'test-run' ]),
onChanged = function(event) {
console.log('File ' + event.path + ' was ' + event.type + '. Running tasks...');
};
watchTs.on('change', onChanged);
watchTests.on('change', onChanged);
});
gulp.task('default', [
'shims',
'system-build',
'html',
'images',
'scss-lint',
'scss'
]);