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.js
54 lines (54 loc) · 2.45 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
"use strict";
/*!
* @author electricessence / https://github.com/electricessence/
* Licensing: MIT
*/
Object.defineProperty(exports, "__esModule", { value: true });
const gulp_1 = require("gulp");
const clean = require("gulp-clean");
const ts = require("gulp-typescript");
const sourcemaps = require("gulp-sourcemaps");
const uglify = require("gulp-uglify");
const merge = require("merge2");
const fs_1 = require("fs");
const PACKAGES = "./packages/";
const RENDER_PACKAGES = "Render Packages";
const REMOVE_SOURCE_JAVASCRIPT = "Remove Source JavaScript";
function setupDist(dist) {
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.
gulp_1.task(cleanTask, () => gulp_1.src(distFolder, { allowEmpty: true })
.pipe(clean()));
// Compile the project.
gulp_1.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(gulp_1.dest(distFolder));
});
// Copy *.d.ts files since the TS Compiler won't do it for us.
gulp_1.task(copyDefTask, () => gulp_1.src(localPackage + "source/**/*.d.ts")
.pipe(gulp_1.dest(distFolder)));
gulp_1.task(packageFiles, () => gulp_1.src([
localPackage + "package.json",
localPackage + "README*",
"LICENSE*"
])
.pipe(gulp_1.dest(distFolder)));
return gulp_1.series(cleanTask, gulp_1.parallel(tsTask, copyDefTask, packageFiles));
}
const packages = fs_1.readdirSync(PACKAGES);
gulp_1.task(RENDER_PACKAGES, gulp_1.parallel(packages
.filter(d => fs_1.existsSync(PACKAGES + d + "/package.json"))
.map(setupDist)));
gulp_1.task(REMOVE_SOURCE_JAVASCRIPT, () => gulp_1.src(PACKAGES + "*/source/**/*.js").pipe(clean()));
exports.default = gulp_1.parallel(RENDER_PACKAGES);