-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
154 lines (137 loc) · 4.56 KB
/
gulpfile.js
File metadata and controls
154 lines (137 loc) · 4.56 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Improt Modules
var gulp = require('gulp');
var del = require('del');
var url = require('url');
var fs = require('fs');
var watch = require('gulp-watch');
var sequence = require('gulp-sequence');
var webserver = require('gulp-webserver');
var typescript = require('gulp-typescript');
var tscConfig = require('./tsconfig.json');
// Define Paths
var path = {
libjs: [
{ dist: 'lib/@angular', src: 'node_modules/@angular/**' },
{ dist: 'lib/angular2-in-memory-web-api', src: 'node_modules/angular2-in-memory-web-api/**' },
{ dist: 'lib/rxjs', src: 'node_modules/rxjs/**' },
{ dist: 'lib', src: 'node_modules/core-js/client/shim.min.js' },
{ dist: 'lib', src: 'node_modules/core-js/client/shim.min.js.map' },
{ dist: 'lib', src: 'node_modules/zone.js/dist/zone.js' },
{ dist: 'lib', src: 'node_modules/reflect-metadata/Reflect.js' },
{ dist: 'lib', src: 'node_modules/reflect-metadata/Reflect.js.map' },
{ dist: 'lib', src: 'node_modules/systemjs/dist/system.src.js' },
// { dist: 'lib', src: 'node_modules/firebase/firebase.js' },
// { dist: 'lib', src: 'node_modules/bootstrap/dist/js/bootstrap.js' },
{ dist: './', src: 'src/systemjs.config.js' }
],
// libcss: [
// 'node_modules/bootstrap/dist/css/bootstrap.css',
// 'node_modules/bootstrap/dist/css/bootstrap.css.map'
// ],
// libfonts: [
// 'node_modules/bootstrap/fonts/**/*'
// ],
index: 'src/index.html',
style: 'src/styles.css',
html: 'src/App/components/**/*.html',
css: 'src/App/components/**/*.css',
ts: 'src/**/*.ts',
dist: 'build',
distapp: 'build/',
distlib: 'build/lib',
distfonts: 'build/fonts'
};
// Clean the Contents of the Distribution Directory
gulp.task('clean', function () {
return del(path.dist);
});
// Copy Index
gulp.task('copy:index', function () {
return gulp.src(path.index)
.pipe(gulp.dest(path.dist));
});
// Copy Style/CSS
gulp.task('copy:style', function () {
return gulp.src(path.style)
.pipe(gulp.dest(path.dist));
});
// Copy Html
gulp.task('copy:html', function () {
return gulp.src(path.html)
.pipe(gulp.dest(path.distapp));
});
// Copy Css
gulp.task('copy:css', function () {
return gulp.src(path.css)
.pipe(gulp.dest(path.distapp));
});
// copy Libs
gulp.task('copy:libjs', function () {
path.libjs.forEach(function (val, indx) {
gulp.src(val.src)
.pipe(gulp.dest(path.dist + '/' + val.dist));
});
});
gulp.task('copy:libcss', function () {
return gulp.src(path.libcss)
.pipe(gulp.dest(path.distlib));
});
// copy Fonts
gulp.task('copy:fonts', function () {
return gulp.src(path.libfonts)
.pipe(gulp.dest(path.distfonts));
});
// TypeScript Transpile
gulp.task('transpile', function () {
return gulp
.src(path.ts)
.pipe(typescript(tscConfig.compilerOptions))
.pipe(gulp.dest(path.distapp));
});
// Build Project
gulp.task('build', sequence('clean', 'copy:index', 'copy:html', 'copy:style', 'copy:css', 'copy:libjs', 'transpile'));
// Default Task
gulp.task('default', sequence('build', ['serve', 'watch']));
// Serve Task
gulp.task('serve', function () {
gulp.src('build')
.pipe(webserver({
livereload: true,
open: true,
directoryListing: {
enable: true,
path: '/index.html'
},
middleware: function (req, res, next) {
var fileName = url.parse(req.url);
fileName = fileName.href.split(fileName.search).join("");
var fileExists = fs.existsSync("./build/" + fileName);
if (!fileExists) {
req.url = "/index.html";
}
return next();
}
}));
});
// Watch Task
gulp.task('watch', ['watchts', 'watchcss', 'watchhtml', 'watchindex']);
// Watch TypeScript (in linux for watch) echo fs.inotify.max_user_watches=582222 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
gulp.task('watchts', function () {
gulp.watch(path.ts, ['transpile'])
// return watch(path.ts).pipe(typescript(tscConfig.compilerOptions)).pipe(gulp.dest(path.distapp));
});
// Watch Index
gulp.task('watchindex', function () {
return watch(path.index)
.pipe(gulp.dest(path.dist));
});
// Watch Html
gulp.task('watchhtml', function () {
return watch(path.html)
.pipe(gulp.dest(path.distapp));
});
// Watch CSS
gulp.task('watchcss', function () {
return watch(path.css)
.pipe(gulp.dest(path.distapp));
});