-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.babel.js
101 lines (86 loc) · 2.41 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
import {src, dest, series} from "gulp";
import insert from "gulp-insert";
import webpackStream from "webpack-stream";
import webpack from "webpack";
import babel from "gulp-babel";
import rename from "gulp-rename";
import uglify from "gulp-uglify";
import sourcemaps from "gulp-sourcemaps";
import del from "del";
import cleanCSS from "gulp-clean-css";
import header from "gulp-header";
import trim from "trim";
import filter from 'gulp-filter-each';
import fs from "fs";
import gulpTypescript from "gulp-typescript";
import typescript from "typescript";
const tsProject = gulpTypescript.createProject("tsconfig.json", {
declaration: true,
typescript: typescript
});
const exportFilter = "export {};";
const copyFiles = () =>
src(["README.md", "LICENSE", "package.json"])
.pipe(dest("dist"));
const copyDocs = () =>
src(["docs/**/*"])
.pipe(dest("dist/docs"));
const umd = () => {
const outputPath = "dist/umd";
const packageJson = JSON.parse(fs.readFileSync("./package.json"));
const headerTxt = fs.readFileSync("./copyright-header.txt");
return src("./src/ts/index.ts")
.pipe(webpackStream(require("./webpack.config.js"), webpack))
.pipe(header(headerTxt, {package: packageJson}))
.pipe(dest(outputPath));
};
const minifyUmd = () =>
src("dist/umd/codemirror-collab-ext.js")
.pipe(sourcemaps.init())
.pipe(uglify({
output: {
comments: "some"
}
}))
.pipe(rename({extname: ".min.js"}))
.pipe(sourcemaps.write("."))
.pipe(dest("dist/umd"));
const commonjs = () =>
src("src/ts/*.ts")
.pipe(babel())
.pipe(dest("dist/lib"));
const typings = () =>
src("src/ts/*.ts")
.pipe(tsProject())
.dts
.pipe(filter(content => trim(content) !== exportFilter))
.pipe(dest("dist/typings"));
const appendTypingsNamespace = () =>
src("dist/typings/index.d.ts", {base: './'})
.pipe(insert.append('\nexport as namespace CodeMirrorCollabExt;\n'))
.pipe(dest("./"));
const css = () =>
src("src/css/*.css")
.pipe(dest("dist/css"));
const minifyCss = () =>
src(`dist/css/codemirror-collab-ext.css`)
.pipe(sourcemaps.init())
.pipe(cleanCSS())
.pipe(rename({extname: ".min.css"}))
.pipe(sourcemaps.write("."))
.pipe(dest("dist/css"));
const clean = () => del(["dist"]);
const dist = series([
umd,
minifyUmd,
commonjs,
typings,
appendTypingsNamespace,
css,
minifyCss,
copyFiles,
copyDocs]);
export {
dist,
clean
}