-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
132 lines (113 loc) · 4.11 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
"use strict";
//******************************************************************************
//* DEPENDENCIES
//******************************************************************************
var gulp = require("gulp"),
browserify = require("browserify"),
sass = require('gulp-sass'),
source = require("vinyl-source-stream"),
buffer = require("vinyl-buffer"),
tslint = require("gulp-tslint"),
tsc = require("gulp-typescript"),
sourcemaps = require("gulp-sourcemaps"),
uglify = require("gulp-uglify"),
runSequence = require("run-sequence"),
mocha = require("gulp-mocha"),
istanbul = require("gulp-istanbul"),
browserSync = require('browser-sync').create();
//******************************************************************************
//* LINT
//******************************************************************************
gulp.task("lint", function() {
return gulp.src([
"source/**/**.ts",
"test/**/**.test.ts"
])
.pipe(tslint({ }))
.pipe(tslint.report("verbose"));
});
//******************************************************************************
//* BUILD
//******************************************************************************
var tsProject = tsc.createProject("tsconfig.json");
gulp.task("build-app", function() {
return gulp.src([
"source/**/**.ts",
"typings/main.d.ts/",
"source/interfaces/interfaces.d.ts"
])
.pipe(tsc(tsProject))
.js.pipe(gulp.dest("source/"));
});
var tsTestProject = tsc.createProject("tsconfig.json");
gulp.task("build-test", function() {
return gulp.src([
"test/**/*.ts",
"typings/main.d.ts/",
"source/interfaces/interfaces.d.ts"
])
.pipe(tsc(tsTestProject))
.js.pipe(gulp.dest("test/"));
});
gulp.task('build-sass', function () {
return gulp.src([
"source/assets/sass/**/*.scss"
])
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('dist/assets/css'));
});
gulp.task("build", function(cb) {
runSequence(["build-app", "build-test", "build-sass"], cb);
});
//******************************************************************************
//* TEST
//******************************************************************************
gulp.task("istanbul:hook", function() {
return gulp.src(['source/**/*.js'])
// Covering files
.pipe(istanbul())
// Force `require` to return covered files
.pipe(istanbul.hookRequire());
});
gulp.task("test", ["istanbul:hook"], function() {
return gulp.src('test/**/*.test.js')
.pipe(mocha({ui: 'bdd'}))
.pipe(istanbul.writeReports());
});
//******************************************************************************
//* BUNDLE
//******************************************************************************
gulp.task("bundle", function() {
var libraryName = "app";
var mainTsFilePath = "source/app.js";
var outputFolder = "dist/";
var outputFileName = libraryName + ".min.js";
var bundler = browserify({
debug: true,
standalone : libraryName
});
return bundler.add(mainTsFilePath)
.bundle()
.pipe(source(outputFileName))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(outputFolder));
});
//******************************************************************************
//* DEV SERVER
//******************************************************************************
gulp.task("watch", ["default"], function () {
browserSync.init({
server: "./"
});
gulp.watch([ "source/**/**.ts", "test/**/*.ts"], ["default"]);
gulp.watch("dist/*.js").on('change', browserSync.reload);
});
//******************************************************************************
//* DEFAULT
//******************************************************************************
gulp.task("default", function (cb) {
runSequence("lint", "build", "test", "bundle", cb);
});