-
Notifications
You must be signed in to change notification settings - Fork 13
/
gulpfile.babel.js
179 lines (155 loc) · 4.92 KB
/
gulpfile.babel.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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
* Copyright (c) 2019 - Convergence Labs, Inc.
*
* This file is part of the Convergence JavaScript Client, which is released
* under the terms of the GNU Lesser General Public License version 3
* (LGPLv3), which is a refinement of the GNU Lesser General Public License
* version 3 (GPLv3). A copy of the both the GPLv3 and the LGPLv3 should have
* been provided along with this file, typically located in the "COPYING" and
* "COPYING.LESSER" files (respectively), which are part of this source code
* package. Alternatively, see <https://www.gnu.org/licenses/gpl-3.0.html> and
* <https://www.gnu.org/licenses/lgpl-3.0.html> for the full text of the GPLv3
* and LGPLv3 licenses, if they were not provided.
*/
import {series, src, dest} from "gulp";
import bump from "gulp-bump";
import fs from "fs-extra";
import rename from "gulp-rename";
import replace from "gulp-replace";
import ts from "gulp-typescript";
import tsLint from "gulp-tslint";
import mocha from "gulp-mocha";
import sourceMaps from "gulp-sourcemaps";
import uglify from 'gulp-uglify-es';
import typescript from "typescript";
import header from 'gulp-header';
import shell from "gulp-shell";
import filter from 'gulp-filter-each';
import trim from "trim";
import insert from "gulp-insert";
import merge from "merge2";
import webpack from "webpack-stream";
const distDir = "./dist";
function minify() {
return src([`${distDir}/*.js`, `!${distDir}/*.min.js`])
.pipe(sourceMaps.init())
.pipe(uglify({
output: {
comments: "some"
},
mangle: {
properties: {
regex: /^_/
}
}
}))
.pipe(rename({
suffix: ".min"
}))
.pipe(sourceMaps.write("."))
.pipe(dest(distDir));
}
function readAndParse(path) {
return JSON.parse(fs.readFileSync(path));
}
const lint = () =>
src(["src/**/*.ts"])
.pipe(tsLint({formatter: "prose"}))
.pipe(tsLint.report());
const copyNpmJs = () => src(["./npmjs/**/*", "./COPYING", "./COPYING.LESSER"]).pipe(dest(distDir));
const bumpPackageVersion = () => {
const packageJson = readAndParse("./package.json");
const version = packageJson.version.endsWith("SNAPSHOT") ?
packageJson.version + "." + new Date().getTime() :
packageJson.version;
return src(`${distDir}/package.json`)
.pipe(bump({version }))
.pipe(dest(distDir));
};
const docsClean = (cb) => {
fs.removeSync(`${distDir}/docs`);
cb();
};
const docsBuild = shell.task(['typedoc --options typedoc.js src/main']);
const docsMarkup = () => {
const packageJson = readAndParse(`${distDir}/package.json`);
return src([`${distDir}/docs/**/*.html`])
.pipe(replace('$PROJECT_VERSION', `${packageJson.version}`))
.pipe(dest(`${distDir}/docs`));
};
const docs = series(docsClean, docsBuild, docsMarkup);
const webpackBundle = () => {
return merge(
src('src/main/index.ts')
.pipe(webpack(require('./webpack/webpack.amd.config')))
.pipe(dest(distDir)),
src('src/main/index.ts')
.pipe(webpack(require('./webpack/webpack.global.config')))
.pipe(dest(distDir))
)
};
const rollupBundle = shell.task(['rollup -c']);
const injectVersion = () => {
const packageJson = readAndParse(`${distDir}/package.json`);
return src([`${distDir}/**/*.js`])
.pipe(replace('CONVERGENCE_CLIENT_VERSION', "" + packageJson.version))
.pipe(dest(distDir));
};
const compile = series(rollupBundle, webpackBundle, injectVersion);
const tsDeclarations = () => {
const exportFilter = "export {};";
const tsProject = ts.createProject("tsconfig.json", {
declaration: true,
typescript: typescript
});
return src(["src/main/**/*.ts", "!src/main/model/rt/richtext/**/*"])
.pipe(tsProject())
.dts
.pipe(filter(content => trim(content) !== exportFilter))
.pipe(dest(`${distDir}/typings`));
};
const declarationsNamedExport = () =>
src(`${distDir}/typings/index.d.ts`)
.pipe(insert.append("\nexport as namespace Convergence;"))
.pipe(dest(`${distDir}/typings`));
const typings = series(tsDeclarations, declarationsNamedExport);
const applyHeader = () => {
const headerTxt = fs.readFileSync("./copyright-header.txt");
const packageJson = readAndParse(`${distDir}/package.json`);
return src([`${distDir}/*.js`])
.pipe(header(headerTxt, {package: packageJson}))
.pipe(dest(`${distDir}`));
};
const test = () => {
// Required because ts-node doesn't deal with ES6 module imports:
// https://github.com/TypeStrong/ts-node/issues/617
// process.env.TS_NODE_COMPILER_OPTIONS='{ \"module\": \"commonjs\" }';
return src("src/test*/**/*Spec.ts")
.pipe(mocha({
reporter: "progress",
require: ['ts-node/register']
}));
};
const clean = (cb) => {
[distDir, "coverage", ".nyc_output"].forEach(file => fs.removeSync(file));
cb();
};
const dist = series(
copyNpmJs,
bumpPackageVersion,
typings,
compile,
applyHeader,
minify,
docs
);
export {
typings,
webpackBundle,
compile,
test,
lint,
clean,
dist,
docs,
};