-
Notifications
You must be signed in to change notification settings - Fork 7
/
gulpfile.js
137 lines (118 loc) · 3.84 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
"use strict";
function logStart(msg) {
console.info("***** Task '" + msg + "' started *****");
}
function logEnd(msg) {
console.info("***** Task '" + msg + "' finished *****");
}
const {task, dest, src, series} = require("gulp"),
{join} = require("path"),
exec = require("child_process").exec,
sass = require("gulp-sass")(require("sass")),
{inc} = require("semver"),
log = require("plugin-log"),
{obj} = require("through2")
;const gulp = require("gulp");
const libName = "ngx-float-ui";
const rootFolder = join(__dirname);
const srcFolder = join(rootFolder, `projects/${libName}/src/lib`);
const distFolder = join(rootFolder, `dist/${libName}`);
const doBump = (type) => {
return Promise.all(["./", join(rootFolder, "projects", libName)].map((p) => {
return src(join(p, "package.json"))
.pipe(obj((file, enc, cb) => {
const pkgData = JSON.parse(file.contents.toString());
const prevVersion = pkgData.version;
pkgData.version = inc(prevVersion, type);
file.contents = Buffer.from(JSON.stringify(pkgData, null, 4));
log(
"Bumped", log.colors.cyan(prevVersion),
"to", log.colors.magenta(pkgData.version),
"with type:", log.colors.cyan(type)
);
cb(null, file);
}))
.pipe(dest(p));
}));
};
//
task("bump:patch", () => {
return doBump("patch");
});
task("bump:minor", () => {
return doBump("minor");
});
task("bump:major", () => {
return doBump("major");
});
gulp.task("bump:beta", () => {
return doBump("prerelease", "beta");
});
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, 4));
log(
"Increased", log.colors.cyan(prevBuild),
"to", log.colors.magenta(pkgData.build)
);
cb(null, file);
}))
.pipe(dest(__dirname));
});
task("handleStyles", () => {
logStart("handleStyles");
const buildScss = new Promise((resolve, reject) => {
// SASS BUILD SCSS SOURCES
gulp.src([join(srcFolder, "scss/theme-*.scss")])
.pipe(sass({
outputStyle: "expanded"
}))
.pipe(gulp.dest(join(distFolder, "css")))
.on("error", reject)
.on("end", resolve);
});
const copyScss = new Promise((resolve, reject) => {
src([join(srcFolder, "scss/*.scss")])
.pipe(dest(join(distFolder, "scss")))
.on("error", reject)
.on("end", resolve);
});
const copyScssIndex = new Promise((resolve, reject) => {
src([join(srcFolder, "_index.scss")])
.pipe(dest(distFolder))
.on("error", reject)
.on("end", resolve);
});
return Promise.all([buildScss, copyScss, copyScssIndex])
.then(() => logEnd("handleStyles"))
.catch(console.error);
});
task("copyFiles", (cb) => {
logStart("copyFiles");
src([join(rootFolder, "changelog.md"), join(rootFolder, "README.md"), join(rootFolder, "tsbl.js")])
.pipe(dest(distFolder))
.on("error", cb)
.on("end", () => {
logEnd("copyFiles");
cb();
});
});
// PACK
task("pack", (cb) => {
logStart("pack");
exec(`npm pack ./dist/${libName}`, (err, stdout, stderr) => {
console.log(stdout);
console.log(stderr);
logEnd("pack");
cb(err);
});
});
//MAIN
task("postBuild", series("handleStyles", "copyFiles", function (cb, err) {
logEnd("postBuild");
cb(err);
}));