-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
144 lines (121 loc) · 4.36 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
136
137
138
139
140
141
142
143
144
const gulp = require('gulp'),
changed = require('gulp-changed'),
del = require('del'),
path = require('path'),
ts = require('gulp-typescript'),
sourcemaps = require('gulp-sourcemaps'),
using = require('gulp-using'),
typescript = require('typescript'),
sequence = require('run-sequence'),
merge = require('merge-stream'),
rsync = require('gulp-rsync');
const tsProject = ts.createProject("tsconfig.json");
let hasError = false;
let finalMessage = '';
const sep = '----------------------------------------------------------------------------';
gulp.task('default', [ 'run' ]);
gulp.task('run', [ 'build' ]);
gulp.task('cleanAndBuild', function (done) {
sequence('clean', 'build', done);
});
gulp.task('build', function (done) {
console.log("Task build gestartet");
sequence('transpile', 'copyFiles', 'rsyncFiles', () => {
console.log(finalMessage);
});
});
gulp.task('clean', function (done) {
console.log("Task clean gestartet");
const toDelete = [ 'dist/*' ];
for (let s of toDelete) {
console.log(' --> deleting ' + s);
}
return del(toDelete);
});
gulp.task('transpile', function (done) {
const tsResult = gulp.src('src/**/*.ts', { follow: true, followSymlinks: true })
.pipe(changed('dist', { extension: '.js'}))
.pipe(using( { prefix:' --> Transpiling file', path:'cwd', color:'green', filesize:false } ))
.pipe(sourcemaps.init())
.pipe(tsProject( { error: myReporter, finish: myFinishHandler } ))
.js.pipe(sourcemaps.mapSources(
function(sourcePath, file) {
return sourcePath.substr(0);
}))
.pipe(sourcemaps.write('./', { sourceRoot: __dirname } ))
.pipe(gulp.dest('dist'));
return tsResult;
});
gulp.task('copyFiles', function (done) {
const copyPugViews =
gulp.src('src/views/**/*.pug')
.pipe(changed('dist/views', { extension: '.pug' }))
.pipe(using({prefix:' --> Copying file', path:'cwd', color:'blue', filesize:false}))
.pipe(gulp.dest('dist/views/'));
const copyPublic =
gulp.src('src/public/**/*')
.pipe(changed('dist/public', { }))
.pipe(using({prefix:' --> Copying file', path:'cwd', color:'blue', filesize:false}))
.pipe(gulp.dest('dist/public/'));
return merge(copyPugViews, copyPublic);
});
gulp.task('rsyncFiles', function (done) {
const rsyncSrc =
gulp.src('src/**')
.pipe(rsync({
root: 'src/',
hostname: 'rpi',
destination: '/home/pi/prj/src/'
}));
const rsyncDist =
gulp.src('dist/**')
.pipe(rsync({
root: 'dist/',
hostname: 'rpi',
destination: '/home/pi/prj/dist/'
}));
const rsyncOthers =
gulp.src(['package.json', 'README.md'])
.pipe(rsync({
root: '',
hostname: 'rpi',
destination: '/home/pi/prj/'
}));
return merge(rsyncSrc, rsyncDist, rsyncOthers);
});
const cache = {};
function myReporter (error) {
if (cache[error.message]) {
return;
}
cache[error.message] = true;
console.log(error.message);
}
function myFinishHandler (results) {
let msg = sep;
const showErrorCount = (count, errorTyp) => {
if (count === 0) {
return;
}
hasError = true;
msg += '\nTypescript: ' + count.toString() + ' ' + errorTyp + ' errors.';
}
showErrorCount(results.transpileErrors, '');
showErrorCount(results.optionsErrors, 'options');
showErrorCount(results.syntaxErrors, 'syntax');
showErrorCount(results.globalErrors, 'global');
showErrorCount(results.semanticErrors, 'semantic');
showErrorCount(results.declarationErrors, 'declaration');
showErrorCount(results.emitErrors, 'emit');
if (hasError) {
msg += '\n' + sep;
}
if (results.emitSkipped) {
msg += '\nTypeScript: emit failed';
} else if (hasError) {
msg += '\nTypeScript: emit succeeded (with errors)';
} else {
msg += '\nTypeScript: emit succeeded (no errors)';
}
finalMessage = msg;
}