-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
107 lines (97 loc) · 2.68 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
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
const fs = require("fs");
const { series, src, dest } = require("gulp");
const replace = require("gulp-replace");
const del = require("del");
const rev = require("gulp-rev");
const oss = require("gulp-aliyun-oss");
const postcss = require("gulp-postcss");
const postcssPresetEnv = require("postcss-preset-env");
const terser = require("gulp-terser");
const cssnano = require("cssnano");
const ts = require("gulp-typescript");
const tsProject = ts.createProject("tsconfig.json");
const merge = require("merge2");
async function clean() {
await del("assets/**");
}
function copySvf() {
return src("./src/*.svg").pipe(dest("./assets"));
}
function uploadOss() {
var options = {
accessKeyId: process.env.ACCESSKEYID,
accessKeySecret: process.env.ACCESSKEYSECRET,
bucket: "duimags",
prefix: "cornerCss/",
ossOpt: {
headers: {
"Cache-Control": "no-cache",
},
},
};
return src("./assets/*").pipe(oss(options));
}
function buildCdnJs() {
const tsResult = src("./src/index.ts")
.pipe(replace(/export const/, "//@ts-ignore\nwindow."))
.pipe(tsProject());
return merge([
tsResult.dts.pipe(dest("./assets")),
tsResult.js.pipe(terser()).pipe(rev()).pipe(dest("./assets")),
]);
}
function buildReleaseJs() {
const tsResult = src("./src/index.ts").pipe(tsProject());
return merge([
tsResult.dts.pipe(dest("./assets")),
tsResult.js.pipe(terser()).pipe(dest("./assets")),
]);
}
function buildCdnCss() {
const plugins = [postcssPresetEnv(), cssnano()];
return src("./src/index.css")
.pipe(
replace(
/\.\/([a-z]*\.svg)/g,
"https://resource.sunbohao.com/cornerCss/$1"
)
)
.pipe(postcss(plugins))
.pipe(rev())
.pipe(dest("./assets"));
}
function buildReleaseCss() {
const plugins = [postcssPresetEnv(), cssnano()];
return src("./src/index.css").pipe(postcss(plugins)).pipe(dest("./assets"));
}
function changeReadmeCDNHash() {
const jsHash = fs
.readdirSync("./assets")
.find((item) => item.includes(".js"));
const cssHash = fs
.readdirSync("./assets")
.find((item) => item.includes(".css"));
return src("./README.md")
.pipe(
replace(
/https:\/\/resource\.sunbohao\.com\/cornerCss\/index-[a-z0-9]*.js/g,
`https://resource.sunbohao.com/cornerCss/${jsHash}`
)
)
.pipe(
replace(
/https:\/\/resource\.sunbohao\.com\/cornerCss\/index-[a-z0-9]*\.css/g,
`https://resource.sunbohao.com/cornerCss/${cssHash}`
)
)
.pipe(dest("./"));
}
exports.cdn = series(
clean,
buildCdnCss,
buildCdnJs,
copySvf,
uploadOss,
changeReadmeCDNHash
);
exports.release = series(clean, buildReleaseCss, buildReleaseJs, copySvf);