-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
150 lines (132 loc) · 4.09 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
145
146
147
148
149
150
"use strict";
const gulp = require("gulp");
const sass = require("gulp-sass");
const server = require("gulp-server-livereload");
const watch = require("gulp-watch");
const browserify = require("gulp-browserify");
const glob = require("multi-glob").glob;
const path = require("path");
const commandLineArgs = require("command-line-args");
const gulpif = require("gulp-if");
const uglify = require("gulp-uglify");
const cssnano = require("gulp-cssnano");
const ts = require("gulp-typescript");
const merge = require("merge2");
const tslint = require("gulp-tslint");
const tsfmt = require("gulp-tsfmt");
const changedInPlace = require("gulp-changed-in-place");
const babel = require("gulp-babel");
const rename = require("gulp-rename");
const fs = require("fs");
const jasmine = require("gulp-jasmine");
const reporter = require("jasmine-spec-reporter");
const benchmark = require("gulp-benchmark");
const gutil = require("gulp-util");
const nodemon = require("gulp-nodemon");
let cli = commandLineArgs([
{name: "production", alias: "p", type: Boolean, defaultOption: false}
]);
let options = cli.parse();
if (options.production === true) {
process.env.NODE_ENV = "production";
gutil.log("running in production mode");
}
let sassGlob = "./sass/everything.scss";
let tsGlob = "./src/**/*.@(ts|tsx)";
let typingsGlob = "./typings/**/*.ts";
let sassOutputGlob = "./css/**/*.css";
let tsOutputGlob = "./dist/**/*.js";
let tsWatchedGlob = "./dist/bundle/bundle.js";
let htmlGlob = "./index.html";
const exitOnError = function (level, error) {
process.exit(1);
};
gulp.task("default", ["serve"]);
gulp.task("browserify", ["ts"], function () {
gulp.src(["./dist/App.js", "!./dist/tests/*"])
.pipe(browserify({
insertGlobals: false,
debug: true,
outfile: tsWatchedGlob
}))
.pipe(rename("bundle.js"))
.pipe(gulp.dest("dist/bundle"))
.pipe(uglify({}))
.pipe(rename("bundle.min.js"))
.pipe(gulp.dest("dist/bundle"));
});
gulp.task("ts-strict", function () {
return gulp.src([tsGlob, typingsGlob])
.pipe(ts({
declaration: false,
module: "commonjs",
target: "es6",
experimentalDecorators: true,
jsx: "react"
}))
.on("error", exitOnError)
.js
.pipe(babel({
presets: ["es2015"]
}))
.on("error", exitOnError)
.pipe(gulp.dest("dist"))
});
gulp.task("ts", function () {
return gulp.src([tsGlob, typingsGlob])
.pipe(ts({
declaration: false,
module: "commonjs",
target: "es6",
experimentalDecorators: true,
jsx: "react"
}))
.js
.pipe(babel({
presets: ["es2015"]
}))
.pipe(gulp.dest("dist"))
});
gulp.task("sass", function () {
gulp.src(sassGlob)
.pipe(sass().on("error", sass.logError))
.pipe(rename("bundle.css"))
.pipe(gulp.dest("./css"))
.pipe(cssnano())
.pipe(rename("bundle.min.css"))
.pipe(gulp.dest("./css"));
});
gulp.task("serve", ["watch"], function () {
nodemon({
script: "./dist/server/Server.js",
env: {"NODE_ENV": "development"}
});
});
gulp.task("lint", function () {
return gulp.src(["./src/**/*.ts", "./src/**/*.tsx"])
.pipe(tslint())
.pipe(tslint.report("verbose", {
emitError: false
}))
});
gulp.task("watch", ["sass", "browserify"], function () {
gulp.watch("./sass/**/*.scss", ["sass"]);
gulp.watch(tsGlob, ["browserify"]);
});
gulp.task("test", ["browserify"], function () {
gulp.src("")
.pipe(jasmine({
config: JSON.parse(fs.readFileSync("./spec/support/jasmine.json", "utf8")),
reporter: new reporter()
}));
});
gulp.task("bench", ["ts"], function () {
return gulp.src("./dist/benchmarks/**/*.js", {read: false})
.pipe(benchmark({
reporters: [
benchmark.reporters.etalon("RegExp#test"),
benchmark.reporters.json()
]
}))
.pipe(gulp.dest("."));
});