This repository has been archived by the owner on May 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.ts
84 lines (70 loc) · 2.21 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
/*!
* @author electricessence / https://github.com/electricessence/
* Licensing: MIT
*/
import {src, dest, parallel, series, task} from "gulp";
import * as clean from "gulp-clean";
import * as ts from "gulp-typescript";
import * as sourcemaps from "gulp-sourcemaps";
import * as uglify from "gulp-uglify";
import * as merge from "merge2";
import {readdirSync, existsSync} from "fs";
const PACKAGES = "./packages/";
const RENDER_PACKAGES = "Render Packages";
const REMOVE_SOURCE_JAVASCRIPT = "Remove Source JavaScript";
function setupDist(dist:string)
{
const localPackage = PACKAGES + dist + "/";
const distFolder = localPackage + "dist";
console.log(distFolder);
const
cleanTask = distFolder + " [ Clean ]",
tsTask = localPackage + " [ TS Compile ]",
copyDefTask = distFolder + " [ Copy Definitions ]",
packageFiles = distFolder + " [ Copy Package Files ]";
const tsProject = ts.createProject(localPackage + 'tsconfig.json');
// First things first... Avoid artifacts.
task(cleanTask,
() => src(distFolder, {allowEmpty: true})
.pipe(clean()));
// Compile the project.
task(tsTask,
() => {
// This is quite the pain. When using gulp, you have to split up the streams and reintegrate.
const tsResult = tsProject.src()
.pipe(sourcemaps.init())
.pipe(tsProject());
return merge(
tsResult.dts, // Doesn't need sourcemaps nor minification.
tsResult.js
.pipe(uglify({output: {comments: /^\/*!/}})) // uglify but keep special comments.
.pipe(sourcemaps.write('.')))
.pipe(dest(distFolder));
});
// Copy *.d.ts files since the TS Compiler won't do it for us.
task(copyDefTask,
() => src(localPackage + "source/**/*.d.ts")
.pipe(dest(distFolder)));
task(packageFiles,
() => src([
localPackage + "package.json",
localPackage + "README*",
"LICENSE*"
])
.pipe(dest(distFolder)));
return series(cleanTask,
parallel(
tsTask,
copyDefTask,
packageFiles));
}
const packages = readdirSync(PACKAGES);
task(RENDER_PACKAGES,
parallel(packages
.filter(d => existsSync(PACKAGES + d + "/package.json"))
.map(setupDist)));
task(REMOVE_SOURCE_JAVASCRIPT,
() => src(PACKAGES + "*/source/**/*.js").pipe(clean()));
export default parallel(
RENDER_PACKAGES
);