-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
98 lines (79 loc) · 3.8 KB
/
gulpfile.js
File metadata and controls
98 lines (79 loc) · 3.8 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
// File Paths
var devOutputPathServer = "build";
var serverSrcFolderPath = "src";
var serverTypeScriptFiles = serverSrcFolderPath + "/**/*.ts";
var serverTypeScriptCompilerFiles = [serverTypeScriptFiles, 'typings_own/**/*.ts', 'typings/**/*.ts'];
// Gulp Tools
var gulp = require('gulp');
var server = require('gulp-develop-server');
var del = require('del');
var gulpTsc = require('gulp-typescript');
var typescript = require('typescript');
var sourcemaps = require('gulp-sourcemaps');
var serverTsProject = gulpTsc.createProject('tsconfig.json', {typescript: typescript});
var browserSync = require('browser-sync').create();
// is used in order to control if tasks should be run parallel or in sequenze
var gulpSequence = require('gulp-sequence');
// ////////////////////////////////////////////////
// Server TypeScript Files Tasks
// // /////////////////////////////////////////////
// the task compiles all the own TypeScript files of the project to JavaScript files
gulp.task('server-typescript-own-dev', function (cb) {
var tscResult = gulp.src(serverTypeScriptCompilerFiles) // instead of "serverTsProject.src()" because the other one slows down the transpile process
.pipe(sourcemaps.init()) // This means sourcemaps will be generated
.pipe(serverTsProject());
return tscResult.js
.pipe(sourcemaps.write()) // Now the sourcemaps are added to the .js file
.pipe(gulp.dest(devOutputPathServer, cb));
});
// ////////////////////////////////////////////////
// Web Development Tasks
// ////////////////////////////////////////////////
// starts the node.js server for development
gulp.task('start-dev-server', function () {
server.listen({path: devOutputPathServer + '/server.js'});
});
// this tasks starts a simple HTTP web server with browser sync functionality
// this means that when ever the content inside web browser changes, all browsers are getting refreshed automatically
gulp.task('serve-dev', ['start-dev-server'], function (cb) {
browserSync.init({
proxy: "localhost:3000", // local node app address
port: 5000, // use *different* port than above
notify: true,
// if true all sessions in different browsers and devices are getting synced = if you type in something in one window it will appear in every video
// this feature is good for testing multiple browsers at the same time
ghostMode: false
});
gulp.watch(serverTypeScriptFiles, ["browserSync-server-typescript-dev"], cb);
});
// the task reloads all browsers using browserSync after compiling all TypeScript server files to JavaScript files and copying the files to the server
// and finally also restarting the server
gulp.task('browserSync-server-typescript-dev', ["server-typescript-own-dev"], function (cb) {
// restart the server
server.restart(function () {
// reload all browser windows
browserSync.reload();
});
cb();
});
gulp.task('clear-console', function (cb) {
process.stdout.write("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
cb();
});
// the tasks compiles all the own typescript files automatically, when ever they change
gulp.task('dev-typescript', ['clear-web-dev'], function (cb) {
gulp.watch(serverTypeScriptFiles, ["clear-console", "server-typescript-own-dev"], cb);
});
// ////////////////////////////////////////////////
// Build Tasks
// // /////////////////////////////////////////////
// clean out all files and folders from build folder
gulp.task('clear-web-dev', function (cb) {
del([devOutputPathServer + '/**'], cb);
});
// build process for production
gulp.task('develop-web', gulpSequence('clear-web-dev', ['server-typescript-own-dev'], 'serve-dev'));
// ////////////////////////////////////////////////
// Default Tasks
// // /////////////////////////////////////////////
gulp.task('default', ['develop-web']);