-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.ts
51 lines (40 loc) · 1.65 KB
/
gulpfile.ts
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
import { Gulpclass, Task, SequenceTask } from "gulpclass";
import * as path from "path";
import * as gulp from "gulp";
const concatFilenames = require("gulp-concat-filenames");
const folders = require("gulp-folders");
// Gulpclass example: https://github.com/molecuel/mlcl_core/blob/master/tasks/gulpclass.ts
@Gulpclass()
export class Gulpfile {
public sourceRoot: string = path.join(process.cwd(), "src");
public excludeFolders = ["config"];
private generateIndexFor(folder: string) {
// This will loop over all folders inside pathToFolder main, secondary
// Return stream so gulp-folders can concatenate all of them
// so you still can use safely use gulp multitasking
if (this.excludeFolders.indexOf(folder) > -1) return gulp.src("noop");
return gulp
.src([
path.join(folder, "**/*.ts"),
"!**/index.ts"
])
.pipe(concatFilenames("index.ts", { template: (file: string) => `export * from "./${path.basename(file, ".ts")}";` }))
.pipe(gulp.dest(folder));
}
@Task()
rootIndex() {
return this.generateIndexFor(this.sourceRoot);
}
@Task("indexes", ["rootIndex"])
indexes() {
return (folders(this.sourceRoot, (folder: string) => this.generateIndexFor(path.join(this.sourceRoot, folder) ) ))(()=>{});
}
@SequenceTask("watch") // this special annotation using "run-sequence" module to run returned tasks in sequence
watch(): any {
return gulp.watch([this.sourceRoot + "/**/*.ts"], ["indexes"]);
}
@SequenceTask("default")
default() { // because this task has "default" name it will be run as default gulp task
return ["indexes", "watch"];
}
}