-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
111 lines (89 loc) · 2.51 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
var gulp = require("gulp");
var tsc = require("gulp-typescript");
var sourcemaps = require("gulp-sourcemaps");
var concat = require("gulp-concat");
var ngAnnotate = require("gulp-ng-annotate");
var uglify = require("gulp-uglify");
var del = require("del");
var merge = require("merge2");
var args = require('yargs').argv;
var gulpif = require('gulp-if');
var rename = require('gulp-rename');
var runseq = require("run-sequence");
// example only
var browserSync = require("browser-sync");
var isRelease = args.rel || false;
console.log(">>>>> Is Release: " isRelease);
var tsProject = tsc.createProject('tsconfig.json', { sortOutput: true });
var paths = {
tscripts: {
src: ["tools/typings/tsd.d.ts", "src/command.module.ts", "src/**/*.ts"],
},
distFileName: "ng-command.js",
distTypeScriptDefName: "ng-command.d.ts",
dist: "./dist",
exampleRoot: "./example"
};
gulp.task("default", ["compile:typescript"], function () {
});
// ** Watching ** //
gulp.task("watch", [], function () {
gulp.watch(paths.tscripts.src, ["compile:typescript"]).on("change", reportChange);
});
// ** Compilation ** //
gulp.task("build:rel", ["clean"], function (cb) {
//runseq("compile:typescript", "minify", cb);
runseq("compile:typescript", "compile:typescript:rel", cb);
});
gulp.task("compile:typescript", function () {
var tsResult = gulp
.src(paths.tscripts.src)
.pipe(sourcemaps.init())
.pipe(tsc(tsProject));
return merge([
tsResult.js
.pipe(concat(paths.distFileName))
.pipe(ngAnnotate())
.pipe(sourcemaps.write("."))
.pipe(gulp.dest(paths.dist))
]);
});
gulp.task("compile:typescript:rel", function () {
var tsResult = gulp
.src(paths.tscripts.src)
.pipe(tsc(tsProject));
return merge([
tsResult.dts
.pipe(concat(paths.distTypeScriptDefName))
.pipe(gulp.dest(paths.dist)),
tsResult.js
.pipe(concat(paths.distFileName))
.pipe(ngAnnotate())
.pipe(uglify())
.pipe(rename({ extname: '.min.js' }))
.pipe(gulp.dest(paths.dist))
]);
});
// ** Clean ** //
gulp.task("clean", function (cb) {
del([paths.dist], cb);
});
function reportChange(event) {
console.log("File " event.path " was " event.type ", running tasks...");
}
// ** Example ** //
gulp.task("serve-example", ["build:rel"], function (done) {
browserSync({
open: true,
port: 9500,
server: {
baseDir: ["."],
index: "example/command-lab.html",
middleware: function (req, res, next) {
res.setHeader("Access-Control-Allow-Origin", "*");
next();
}
},
files: ["example/*.*", "dist/*.*"]
}, done);
});