-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
67 lines (61 loc) · 2.06 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
import gulp from 'gulp'
import merge from 'merge2'
import rename from 'gulp-rename'
import rimraf from 'rimraf'
import sourcemaps from 'gulp-sourcemaps'
import terser from 'gulp-terser'
import ts from 'gulp-typescript'
import typedoc from 'gulp-typedoc'
import fsa from 'fs/promises'
import rewriteImports from 'gulp-rewrite-imports'
import path from 'path'
/** @type {{version:string}} */
const pj = await fsa.readFile("package.json").then(jsonString => JSON.parse(jsonString));
const unpkgRoot = "https://unpkg.com/microdata-tooling@" + pj.version + "/dist/";
/** @type {{[k:string]: string}} */
const importMappings = {};
for (const srcFile of await fsa.readdir("src/")) {
const name = path.basename(srcFile, ".ts");
importMappings["./" + name + ".js"] = unpkgRoot + name + ".min.js";
}
gulp.task("docs", function () {
return gulp.src("src/index.ts").pipe(typedoc({
out: "docs",
excludeExternals: true,
excludePrivate: true,
excludeInternal: true,
entryPoints: ["src/index.ts"]
}));
});
gulp.task("ts-build", function () {
pj.version
const tsProject = ts.createProject("tsconfig.json");
const result = tsProject.src().
pipe(sourcemaps.init()).
pipe(tsProject());
return merge([
result.js.
pipe(sourcemaps.write(".", { includeContent: false, sourceRoot: "../src" })).
pipe(gulp.dest("dist")),
result.dts.
pipe(gulp.dest("dist"))
]);
});
gulp.task("minify", function () {
return gulp.src("dist/*.js").
pipe(sourcemaps.init()).
pipe(rewriteImports({
noRequire: true,
noImport: true,
experimentalEnableStreams: true,
mappings: importMappings
})).
pipe(terser()).
pipe(rename({ extname: ".min.js" })).
pipe(sourcemaps.write(".", { includeContent: false, sourceRoot: "." })).
pipe(gulp.dest("dist"));
});
gulp.task("clean", async function () {
rimraf("dist/*.*", function () {});
});
gulp.task("build", gulp.series(["clean", "ts-build", "minify"]));