-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
122 lines (108 loc) · 3.5 KB
/
gulpfile.js
File metadata and controls
122 lines (108 loc) · 3.5 KB
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
var gulp = require('gulp'),
del = require('del'),
url = require("url"),
path = require("path"),
fs = require("fs"),
typescript = require('gulp-typescript'),
tslint = require('gulp-tslint'),
tscConfig = require('./tsconfig.json'),
tsconfigGlob = require('tsconfig-glob'),
sourcemaps = require('gulp-sourcemaps'),
gulpif = require('gulp-if'),
argv = require('yargs').argv,
concat = require('gulp-concat'),
ngAnnotate = require('gulp-ng-annotate'),
autoprefixer = require('gulp-autoprefixer'),
browserSync = require('browser-sync').create(),
sass = require('gulp-sass'),
csso = require('gulp-csso'),
uglify = require('gulp-uglify'),
plumber = require('gulp-plumber'),
changed = require('gulp-changed');
const DIST = 'public/dist';
const LIB = DIST +'/lib';
const APP = DIST +'/app';
// clean the contents of the distribution directory
gulp.task('clean:lib', function () {
return del(LIB);
});
// SASS compile
gulp.task('sass', function() {
return gulp.src('app/scss/main.scss')
.pipe(plumber())
.pipe(sass())
.pipe(autoprefixer())
.pipe(gulpif(argv.production, csso()))
.pipe(concat('main.css'))
.pipe(gulp.dest(DIST))
.pipe(browserSync.stream());
});
// Compresses the templates
gulp.task('templates', function() {
return gulp.src('app/**/*.html')
.pipe(uglify())
.pipe(gulp.dest(APP));
});
// TypeScript compile
gulp.task('compile', function () {
return gulp
.src('app/**/*.ts')
.pipe(changed(APP))
.pipe(sourcemaps.init())
.pipe(typescript(tscConfig.compilerOptions))
.pipe(ngAnnotate())
.pipe(gulpif(argv.production, uglify()))
.pipe(gulp.dest(APP));
});
//Copies all the app files to the public dist directory
gulp.task('copy:assets', ['clean:lib'], function() {
return gulp.src(['app/**/*', '!app/**/*.ts', '!app/**/*.scss'], { base : './' })
.pipe(gulp.dest(DIST))
});
// Copys the library folders to the public folder
gulp.task('copy:libs', ['clean:lib'], function() {
return gulp.src([
'node_modules/**/*'
])
.pipe(gulp.dest(LIB))
});
// Typescript linter
gulp.task('tslint', function() {
return gulp.src('app/**/*.ts')
.pipe(tslint({
formatter: 'verbose'
}))
.pipe(tslint.report());
});
// DefinitelyTyped
gulp.task('tsconfig-glob', function () {
return tsconfigGlob({
configPath: '.',
indent: 2
});
});
var defaultFile = "index.html"
var baseDir = "public";
gulp.task('watch', ['tsconfig-glob'], function() {
browserSync.init({
server: {
baseDir: "./" + baseDir,
middleware: function(req, res, next) {
var fileName = url.parse(req.url);
fileName = fileName.href.split(fileName.search).join("");
var fileExists = fs.existsSync(__dirname + "/" + baseDir + fileName);
if (!fileExists && fileName.indexOf("browser-sync-client") < 0) {
req.url = "/" + defaultFile;
}
return next();
}
}
});
gulp.watch('app/scss/**/*.scss', ['sass']);
gulp.watch('app/**/*.html', ['templates']).on('change', browserSync.reload);
gulp.watch('app/**/**/*.html', ['templates']).on('change', browserSync.reload);
gulp.watch(['public/systemjs.config.js', 'public/index.html']).on('change', browserSync.reload);
gulp.watch('app/**/*.ts', ['compile']).on('change', browserSync.reload);
});
gulp.task('build', ['compile', 'copy:libs', 'copy:assets', 'sass']);
gulp.task('default', ['build']);