-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
59 lines (52 loc) · 2.03 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
const del = require("del");
const gulp = require("gulp");
const path = require("path");
const sourcemaps = require("gulp-sourcemaps");
const tsc = require("gulp-typescript");
const ts = require("typescript");
const paths = {
lib: "lib",
test: "test"
};
function getMapSource(sourcePath) {
// Since source/map/target files are in same directory, just keep the file name so VSCode can find source file
const index = sourcePath.lastIndexOf("/");
return index < 0 ? sourcePath : sourcePath.substr(index + 1);
}
const tsProject = tsc.createProject("tsconfig.json");
gulp.task("tsc", () => {
const result = tsProject.src()
.pipe(sourcemaps.init())
.pipe(tsProject());
return result.js
.pipe(sourcemaps.write(".", { includeContent: false, mapSources: getMapSource }))
.pipe(gulp.dest("."));
});
function watchTypeScriptProject(configFileName) {
const reportDiagnostic = ts.createDiagnosticReporter(ts.sys);
const configParseResult = ts.parseConfigFileWithSystem(configFileName, {}, ts.sys, reportDiagnostic);
const watchCompilerHost = ts.createWatchCompilerHostOfConfigFile(
configParseResult.options.configFilePath,
{},
ts.sys,
undefined,
reportDiagnostic,
ts.createWatchStatusReporter(ts.sys, configParseResult.options));
watchCompilerHost.rootFiles = configParseResult.fileNames;
watchCompilerHost.options = configParseResult.options;
watchCompilerHost.configFileSpecs = configParseResult.configFileSpecs;
watchCompilerHost.configFileWildCardDirectories = configParseResult.wildcardDirectories;
ts.createWatchProgram(watchCompilerHost);
}
gulp.task("watch", () => {
watchTypeScriptProject("tsconfig.json");
});
gulp.task("clean", () => {
return del([
"index.{js,js.map,d.ts}",
`${paths.lib}/**/*.{js,map,d.ts}`,
`${paths.test}/**/*.{js,map,d.ts}`,
`!${paths.test}/webpack.config.js`,
`!${paths.test}/public/index.js`
]);
});