-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGulpfile.ts
101 lines (90 loc) · 3.73 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
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
import rootGulp = require("gulp");
import helper = require("gulp-help");
import ws = require("webpack-stream");
import webpack = require("webpack");
import mocha = require("gulp-mocha");
import gulpts = require("gulp-typescript");
import typedoc = require("gulp-typedoc");
import mergeStreams = require("merge2");
import child_process = require("child_process");
import path = require("path");
const gulp = helper(rootGulp);
// add node_modules to path so we don't need global modules, prefer the modules by adding them first
const nodeModulesPathPrefix = path.resolve("./node_modules/.bin/") + path.delimiter;
if (process.env.path !== undefined) {
process.env.path = nodeModulesPathPrefix + process.env.path;
} else if (process.env.PATH !== undefined) {
process.env.PATH = nodeModulesPathPrefix + process.env.PATH;
}
gulp.task("typedoc", "Generate documentation from code comments", function() {
return gulp
.src(["src/**/*.ts", "!src/test/**/*.ts", "!src/node_modules/**"])
.pipe(typedoc({
...require("./src/tsconfig.json").compilerOptions,
lib: ["lib.es6.d.ts"], // typedoc does something funky with this, so we need to give it a slightly different value
out: "docs/",
name: "Glacier",
mode: "modules",
disableOutputCheck: true
}))
;
});
gulp.task("lint", "Runs tslint over the typescript within the project", (done) => {
const proc = child_process.spawn("tslint", [
"--config", "tslint.json",
"--exclude", "src/node_modules",
"Gulpfile.ts",
"src/*.ts",
"src/test/*.ts",
"src/model/*.ts",
"src/reducers/*.ts",
"src/exporters/*.ts",
"src/adapters/*.ts",
"src/actions/*.ts"
], {shell: true, stdio: "inherit"});
proc.on("close", (code: number) => {
if (code !== 0) return done!(code);
done!();
});
});
function createBuildStream(release?: boolean) {
const ignore = new webpack.IgnorePlugin(/(^fs$|cptable|jszip|xlsx|xls|^es6-promise$|^net$|^tls$|^forever-agent$|^tough-cookie$|cpexcel|^path$|^react-native)/);
return gulp.src("src/index.ts")
.pipe(ws({
output: {
filename: release ? "glacier.min.js" : "glacier.js",
},
resolve: {
// Add `.ts` and `.tsx` as a resolvable extension.
extensions: ["", ".webpack.js", ".web.js", ".ts", ".tsx", ".js"]
},
module: {
loaders: [
{ test: /\.json$/, loader: "json-loader" },
// all files with a `.ts` or `.tsx` extension will be handled by `ts-loader`
{ test: /\.tsx?$/, loader: "ts-loader", exclude: /node_modules/ }
]
},
plugins: release ? [new webpack.optimize.UglifyJsPlugin(), ignore] : [ignore]
}))
.pipe(gulp.dest(release ? "dist/" : "dist/local/"));
}
gulp.task("build", "Compiles all typescript code and bundles it into a single file in the dist folder", [], () => {
return createBuildStream();
});
gulp.task("build-release", "Does a 'build' with minification enabled", [], () => {
const project = gulpts.createProject("./src/tsconfig.json", {typescript: require("typescript")});
const streams = project.src()
.pipe(project(gulpts.reporter.fullReporter(true)));
return mergeStreams(
streams.js.pipe(gulp.dest("./dist")),
streams.dts.pipe(gulp.dest("./dist")),
/*createBuildStream(/*release/true)*/
);
});
gulp.task("test", "Executes the test suite", ["lint", "build"], () => {
return gulp.src("src/test/**/*.ts", {read: false})
.pipe(mocha({reporter: "spec", timeout: 5000}));
});
gulp.task("release", "Runs tests and builds a release", ["test", "build-release"]);
gulp.task("default", ["test"]);