This repository was archived by the owner on Jan 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
91 lines (76 loc) · 2.3 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
var del = require("del");
var execSync = require("child_process").execSync;//Node.js
var gulp = require("gulp");
var path = require("path");//Node.js
var sass = require("gulp-sass");
var sequence = require("gulp-sequence");
var sourcemaps = require("gulp-sourcemaps");
var through = require("through2");
var ts = require("gulp-typescript");
tsProject = ts.createProject("tsconfig.json");
var tsAbsoluteOutDir = tsProject.options.outDir;
var srcFolderName = "src";
var allFolders = "**";
var buildTask = "build";
var cleanTask = "clean";
var rebuildTask = "rebuild";
var internalCopyTask = "_copy";
var internalSrcCopyTask = "_copySrcFiles";
var internalSassTask = "_sass";
var internalTsoaTask = "_tsoa";
var internalTypescriptTask = "_ts";
var srcFilesToCopy = [
path.join(srcFolderName, allFolders, "*.html")
];
gulp.task(buildTask, sequence(
internalTsoaTask,
[internalCopyTask, internalSassTask, internalTypescriptTask]
));
gulp.task(cleanTask, function() {
return del([tsAbsoluteOutDir]);
});
gulp.task(internalCopyTask, sequence(
[internalSrcCopyTask]
));
gulp.task(internalSrcCopyTask, function() {
var src$ = gulp.src(srcFilesToCopy)
.pipe(gulp.dest(tsAbsoluteOutDir))
;
return src$;
});
gulp.task(rebuildTask, sequence(
cleanTask,
buildTask
));
gulp.task(internalSassTask, function() {
var globs = path.join(srcFolderName, allFolders, "*.scss");
var src$ = gulp.src(globs)
.pipe(sass().on("error", sass.logError))
.pipe(gulp.dest(tsAbsoluteOutDir))
;
return src$;
});
gulp.task(internalTsoaTask, function() {
var globs = path.join(srcFolderName, allFolders, "tsoa.json");
var src$ = gulp.src(globs, {read: false})
.pipe(through.obj(function(file, enc, cb) { // see https://stackoverflow.com/questions/27923523/how-can-i-write-a-simple-gulp-pipe-function
var folderPath = path.dirname(file.path);
execSync("tsoa swagger", {cwd: folderPath});
execSync("tsoa routes", {cwd: folderPath});
cb(null, file);
}))
;
return src$;
});
gulp.task(internalTypescriptTask, function() {
var writeOptions = {
sourceRoot: "." // see https://github.com/Microsoft/vscode/issues/14988
};
var src$ = gulp.src(path.join(srcFolderName, allFolders, "*.ts"))
.pipe(sourcemaps.init())
.pipe(tsProject())
.pipe(sourcemaps.write(".", writeOptions))
.pipe(gulp.dest(tsAbsoluteOutDir))
;
return src$;
});