-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
170 lines (152 loc) · 4.74 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
"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"),
exec = require("child_process").exec,
sass = require("sass"),
{inc} = require("semver"),
log = require("plugin-log"),
{obj} = require("through2"),
{pathToFileURL} = require('url'),
{existsSync} = require("fs")
;
const libName = "ngx-tour-wizard";
const rootFolder = join(__dirname);
const srcFolder = join(rootFolder, `projects/${libName}/src/lib`);
const distFolder = join(rootFolder, `dist/${libName}`);
const taskNames = {
autoexports: "autoexports",
copySassSources: "copySassSources",
ngBuild: "ngBuild",
mdsCopy: "mdsCopy",
pack: "pack",
postBuild: "postBuild",
doSass: "doSass"
};
const doBump = (type) => {
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 = 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(gulp.dest(p));
}));
};
gulp.task("bump:patch", () => {
return doBump("patch");
});
gulp.task("bump:minor", () => {
return doBump("minor");
});
gulp.task("bump:major", () => {
return doBump("major");
});
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, 4));
log(
"Increased", log.colors.cyan(prevBuild),
"to", log.colors.magenta(pkgData.build)
);
cb(null, file);
}))
.pipe(gulp.dest(__dirname))
});
gulp.task(taskNames.doSass, (cb) => {
logStart(taskNames.doSass);
// SASS BUILD SCSS SOURCES
gulp.src([
join(srcFolder, "scss/tour-wizard.scss"),
])
.pipe(obj((file, enc, cb) => {
const compiled = sass.compile(join(srcFolder, "scss/tour-wizard.scss"), {
importers: [
{
findFileUrl(url) {
const useMatch = join(__dirname, "node_modules", url, "_index.scss");
const isMatch = existsSync(useMatch);
if (isMatch) {
return pathToFileURL(useMatch);
}
return null;
}
}
]
});
file.contents = Buffer.from(compiled.css);
log(log.colors.magenta("SASS"), log.colors.cyan("compiled"));
cb(null, file);
}))
.pipe(gulp.dest(join(distFolder, "css")))
.on("end", () => {
logEnd(taskNames.doSass);
cb();
});
});
gulp.task(taskNames.copySassSources, (cb) => {
// COPY SCSS SOURCES
return gulp.src([
join(srcFolder, "scss/*.scss"),
])
.pipe(gulp.dest(join(distFolder, "scss")))
.on("end", () => {
logEnd(taskNames.copySassSources);
cb();
});
})
gulp.task(taskNames.mdsCopy, (cb) => {
logStart(taskNames.mdsCopy);
return gulp.src([
join(rootFolder, "changelog.md"),
join(rootFolder, "README.md")
])
.pipe(gulp.dest(distFolder))
.on("end", () => {
logEnd(taskNames.mdsCopy);
cb();
});
});
gulp.task(taskNames.autoexports, () => {
// Require only if necessary, because this module can't be instaled in CI ;)
const generator = require("@tonysamperi/ts-autoexports");
return Promise.all(["components", "directives", "models", "services", "shared"].map((p) => {
return generator.autoExports(join(srcFolder, p), {
lineFeed: "\r\n",
fileName: "public.ts",
quotemark: "double"
});
}));
});
// PACK
gulp.task(taskNames.pack, (cb) => {
logStart(taskNames.pack);
exec(`npm pack ./dist/${libName}`, (err, stdout, stderr) => {
console.log(stdout);
console.log(stderr);
logEnd(taskNames.pack);
cb(err);
});
});
//MAIN
gulp.task(taskNames.postBuild, gulp.series(taskNames.doSass, taskNames.copySassSources, taskNames.mdsCopy, (cb, err) => {
logEnd(taskNames.postBuild);
cb(err);
}));