This repository has been archived by the owner on Nov 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
gulpfile.js
90 lines (79 loc) · 2.19 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
"use strict";
// https://code.visualstudio.com/docs/languages/css
// https://gist.github.com/jeromecoupe/0b807b0c1050647eb340360902c3203a
// Load plugins
const del = require("del");
const gulp = require("gulp");
const rename = require("gulp-rename");
const sass = require("gulp-sass");
const replace = require("gulp-replace");
const merge = require("merge-stream");
const fs = require("fs");
// Clean assets
function clean() {
return del(["./app.wxss"]);
}
// CSS task
function css() {
var appScss = gulp
.src("./scss/**/*.scss")
.pipe(sass({ outputStyle: "expanded" }))
.pipe(rename("app.wxss"))
.pipe(gulp.dest("./"));
var componentsScss = gulp
.src("./components/**/*.scss", { base: "." })
.pipe(sass({ outputStyle: "expanded" }))
.pipe(
rename((path) => {
path.extname = ".wxss";
})
)
.pipe(gulp.dest("./"));
return merge(appScss, componentsScss);
}
// Third party js libraries
function jsLibs() {
const dayjsBasePath = "./node_modules/dayjs";
const dayjsSrcList = [
`${dayjsBasePath}/dayjs.min.js`,
`${dayjsBasePath}/plugin/customParseFormat.js`,
`${dayjsBasePath}/plugin/isBetween.js`,
`${dayjsBasePath}/plugin/isoWeek.js`,
`${dayjsBasePath}/plugin/duration.js`,
];
return gulp
.src(dayjsSrcList, { base: dayjsBasePath })
.pipe(gulp.dest("./libs/dayjs/"));
}
// Record commit id
function commitHash(done) {
try {
const rev = fs.readFileSync(".git/HEAD").toString();
const hash = fs
.readFileSync(`.git/${rev.substring(5)}`.replace(/^\s+|\s+$/g, ""))
.toString()
.substring(0, 7);
gulp
.src(["env.js"])
.pipe(replace(/commitHash = ".*?"/g, `commitHash = "${hash}"`))
.pipe(gulp.dest("./"));
} catch (err) {
console.log("Failed to stamp commitHash: " + err);
}
done();
}
// Watch files
function watch() {
gulp.watch("./scss/**/*", css);
gulp.watch("./components/**/*.scss", css);
}
// define complex tasks
const build = gulp.series(clean, gulp.parallel(css, jsLibs, commitHash));
// export tasks
exports.clean = clean;
exports.css = css;
exports.jsLibs = jsLibs;
exports.commitHash = commitHash;
exports.build = build;
exports.watch = watch;
exports.default = build;