-
Notifications
You must be signed in to change notification settings - Fork 9
/
gulpfile.mjs
74 lines (62 loc) · 1.74 KB
/
gulpfile.mjs
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
import gulp from "gulp";
import { rimraf as rm } from "rimraf";
import jeditor from "gulp-json-editor";
import { execaCommandSync } from "execa";
import ts from "gulp-typescript";
import merge from "gulp-merge-json";
import yaml from "gulp-yaml";
import concat from "gulp-concat";
import babel from "gulp-babel";
import uglify from "gulp-uglify";
const inputs = ["src/**/*.js"];
const outputs = "dist/";
const merge_options = {
fileName: "config_default.js",
exportModule: "module.exports",
jsonSpace: " ",
};
const { src, dest, series, parallel } = gulp;
const version = execaCommandSync("git describe --tags", {
shell: true,
all: true,
}).stdout;
//yaml转js
const configjs = () => {
return src("src/config/**/*.yml")
.pipe(yaml({ schema: "DEFAULT_SAFE_SCHEMA" }))
.pipe(src("src/config/**/*.json"))
.pipe(merge(merge_options))
.pipe(dest("src/config/"));
};
const tsc = () => {
const ts0 = src("src/lib/**/*.ts")
.pipe(ts.createProject("tsconfig.json")())
.js.pipe(concat("mmedia.js"))
.pipe(babel())
.pipe(uglify())
.pipe(dest(outputs + "lib"));
const ts1 = src("src/mmedia-loader.ts")
.pipe(ts.createProject({ target: "es5", module: "es2015" })())
.pipe(babel())
.pipe(uglify())
.pipe(dest(outputs));
return Promise.all([ts0, ts1]);
};
function js() {
return src(inputs).pipe(babel()).pipe(uglify()).pipe(dest(outputs));
}
// 清理输出目录
const clean = () => rm(outputs);
//拷贝其他文件
const cpPackageJson = () => {
return src("package.json")
.pipe(
jeditor({
version: version,
})
)
.pipe(src("README.md"))
.pipe(src("LICENSE"))
.pipe(dest(outputs));
};
export const build = series(clean, configjs, parallel(tsc, js), cpPackageJson);