-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
97 lines (77 loc) · 2.47 KB
/
gulpfile.js
File metadata and controls
97 lines (77 loc) · 2.47 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
var gulp = require("gulp");
var path = require("path")
var source = require("vinyl-source-stream");
var browserify = require("browserify");
var watchify = require("watchify");
var tsify = require("tsify");
var ts = require("gulp-typescript");
var sourcemaps = require("gulp-sourcemaps");
var notify = require("gulp-notify");
var gutil = require("gulp-util");
var merge = require("merge2");
var config = {
apps: [
{
dest: path.join(__dirname,"/js/bin/"),
path: path.join(__dirname,"/js/src/"),
main: "index.tsx",
result: "index.js",
browserify: true
}
]
};
var tasks = [];
function register(i,app) {
var id = app.id || "task-" + i;
if(app.browserify) {
tasks[tasks.length] = id;
gulp.task(id,function() {
// gutil.log("Running sub-task " + id);
var bundler = browserify({
cache: {},
packageCache: {},
basedir: app.path
}).add(path.join(app.path,"/" + app.main))
.plugin(tsify)
.on("time",function(time) {
// gutil.log("Finished rebuilding after " + time/1000 + " s")
});
function build(rebuild) {
var bundle = bundler.bundle();
return bundle
.pipe(source(app.result))
.pipe(gulp.dest(app.dest))
}
return build(false);
});
}
else {
tasks[tasks.length] = id;
var project = ts.createProject(path.join(app.base,"tsconfig.json"),{
declaration: true,
sourceMap: true
});
gulp.task(id,function() {
// gutil.log("Running sub-task " + id);
var tsResult = project.src().pipe(sourcemaps.init()).pipe(ts(project));
return merge([
tsResult.js.pipe(sourcemaps.write(path.relative(app.source,app.sourceMapLocation),{
sourceRoot: (filepath) => {
return path.relative(path.dirname(filepath.path),app.source)
}
})).pipe(gulp.dest(app.dest)),
tsResult.dts.pipe(gulp.dest(app.definesLocation))
]);
});
}
}
for(var i=0;i < config.apps.length;i++) {
register(i,config.apps[i]);
}
gulp.task("watch",tasks,function() {
gulp.watch([
"**/*.ts",
"**/*.tsx",
"!**/*.d.ts"
],tasks);
});