-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathgulpfile.js
93 lines (80 loc) · 2.44 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
"use strict";
function logStart(msg) {
console.info("***** Task '" + msg + "' started *****");
}
function logEnd(msg) {
console.info("***** Task '" + msg + "' finished *****");
}
const gulp = require("gulp"),
{join} = require("path"),
semver = require("semver"),
log = require("plugin-log"),
{obj} = require("through2");
const libName = "ngx-mat-timepicker";
const rootFolder = join(__dirname);
const distFolder = join(rootFolder, `dist/${libName}`);
const doBump = (type, identifier) => {
return Promise.all(["./", join(rootFolder, "projects", libName)].map((p) => {
return gulp.src(join(p, "package.json"))
.pipe(obj((file, enc, cb) => {
const pkgData = JSON.parse(file.contents.toString());
const prevVersion = pkgData.version;
pkgData.version = semver.inc(prevVersion, type, identifier);
file.contents = Buffer.from(JSON.stringify(pkgData, null, 2));
log(
"Bumped", log.colors.cyan(prevVersion),
"to", log.colors.magenta(pkgData.version),
"with type:", log.colors.cyan(type)
);
cb(null, file);
}))
.pipe(gulp.dest(p));
}));
};
const taskNames = {
postBuild: "postBuild",
copyMDs: "copyMDs"
};
// TASKS
gulp.task("bump:patch", () => {
return doBump("patch");
});
gulp.task("bump:minor", () => {
return doBump("minor");
});
gulp.task("bump:major", () => {
return doBump("major");
});
gulp.task("bump:beta", () => {
return doBump("prerelease", "beta");
});
gulp.task("build++", () => {
return gulp.src(join(__dirname, "package.json"))
.pipe(obj((file, enc, cb) => {
const pkgData = JSON.parse(file.contents.toString());
const prevBuild = pkgData.build;
pkgData.build++;
file.contents = Buffer.from(JSON.stringify(pkgData, null, 2));
log(
"Increased", log.colors.cyan(prevBuild),
"to", log.colors.magenta(pkgData.build)
);
cb(null, file);
}))
.pipe(gulp.dest(__dirname))
})
gulp.task(taskNames.copyMDs, (cb) => {
logStart(taskNames.copyMDs);
gulp.src([
join(rootFolder, "changelog.md"),
join(rootFolder, "README.md")
])
.pipe(gulp.dest(distFolder));
logEnd(taskNames.copyMDs);
cb();
});
// MAIN
gulp.task(taskNames.postBuild, gulp.series(taskNames.copyMDs, function (cb, err) {
logEnd(taskNames.postBuild);
cb(err);
}));