This repository has been archived by the owner on Apr 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
gulpfile.js
104 lines (100 loc) · 2.55 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
const gulp = require("gulp");
const through = require("through2");
const path = require("path");
const webpack = require("webpack-stream");
const fs = require("fs");
const webpackConfig = require("./webpack.config");
function cleanBuildDirectory(dir) {
let files = [];
try {
files = fs.readdirSync(path.resolve(dir));
} catch (error) {
return false;
}
for (let file of files)
try {
fs.unlinkSync(path.resolve(dir + "/" + file), () => {});
} catch (error) {
return false;
}
return true;
}
function createNewVersion(op) {
return through.obj(function(file, env, cb) {
if (file.isNull()) {
cb(null, file);
return;
}
try {
const contentString = file.contents.toString();
const contentObject = JSON.parse(contentString);
console.log("\n");
console.log("/**** Current Version", contentObject.version, "*****/");
contentObject.version = contentObject.version
.split(".")
.reduce((acc, curr, index, list) => {
let [main, min, patch] = list;
main = parseInt(main);
min = parseInt(min);
patch = parseInt(patch);
patch += 1;
if (patch >= 10) {
patch = 0;
min += 1;
}
if (min >= 10) {
min = 0;
main += 1;
}
return [main, min, patch].join(".");
});
console.log("/**** New Version", contentObject.version, "*****/");
console.log("\n");
file.contents = Buffer.from(JSON.stringify(contentObject, null, 2));
} catch (e) {
throw new Error(e);
}
cb(null, file);
});
}
const dest = dest => gulp.dest(dest ? dest : "./dist");
const src = "./index.ts";
exports.default = async next => {
try {
await cleanBuildDirectory("./dist");
await next();
await gulp
.src(path.resolve("./package.json"))
.pipe(createNewVersion())
.pipe(dest(process.cwd()));
await next();
await gulp
.src(src)
.pipe(
webpack(
webpackConfig(null, {
mode: "production",
filename: "typepicker.production.js",
type: "production"
})
)
)
.pipe(dest());
await next();
await gulp
.src(src)
.pipe(
webpack(
webpackConfig(null, {
mode: "production",
filename: "typepicker.development.js",
type: "development"
})
)
)
.pipe(dest());
await next();
} catch (error) {
console.error("Build Error:", error);
}
};