-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
gulpfile.ts
139 lines (117 loc) · 3.3 KB
/
gulpfile.ts
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
require("dotenv").config();
import { Product, RubricQuestion, Contributor } from "./src/parsing/types";
import {
loadRubric,
loadProducts,
loadContributors,
} from "./src/parsing/index";
import {
hbsFactory,
getProductPageBuildTasks,
getDirectoryPagesTasks,
getExtensionAPI,
} from "./src/build/utils";
const gulp = require("gulp");
const postcss = require("gulp-postcss");
const rename = require("gulp-rename");
const del = require("del");
const fs = require("fs");
const rubric: RubricQuestion[] = loadRubric();
const contributors: Contributor[] = loadContributors();
const products: Product[] = loadProducts(rubric, contributors);
gulp.task("clean", () => {
return del("./dist/**/*");
});
gulp.task("build api", async () => {
const apiVersion = "v2";
if (!fs.existsSync(`./dist/api/${apiVersion}/products`)) {
fs.mkdirSync(`./dist/api/${apiVersion}/products`, { recursive: true });
}
const resolvedDates = await Promise.all(
products.map((product) => product.lastUpdated)
);
const resolvedProducts = products.map((product, i) => {
return {
...product,
lastUpdated: resolvedDates[i],
};
});
resolvedProducts.forEach((product) => {
fs.writeFileSync(
`./dist/api/${apiVersion}/products/${product.slug}.json`,
JSON.stringify(product)
);
});
const api = getExtensionAPI(resolvedProducts);
return gulp
.src(["./src/templates/pages/api/**/*.json"])
.pipe(hbsFactory({ rubric, contributors, resolvedProducts, api }))
.pipe(gulp.dest("./dist/api/"));
});
gulp.task("build general pages", () => {
return gulp
.src(["./src/templates/pages/**/*.hbs", "./src/templates/pages/*.hbs"], {
ignore: [
"./src/templates/pages/product.hbs",
"./src/templates/pages/directory.hbs",
],
})
.pipe(rename({ extname: ".html" }))
.pipe(hbsFactory({ rubric, contributors, products }))
.pipe(gulp.dest("./dist/"));
});
gulp.task(
"build pages",
gulp.parallel(
...getProductPageBuildTasks(products),
...getDirectoryPagesTasks(products),
"build general pages",
"build api"
)
);
gulp.task("collect dependencies", () => {
return gulp
.src(["./node_modules/lunr/lunr.min.js"])
.pipe(gulp.dest("./dist/static/deps/"));
});
gulp.task("collect static", () => {
return gulp
.src([
"./src/static/**/*",
"./node_modules/@fortawesome/fontawesome-free/**/*.{woff2,woff}",
"!./src/static/**/*.{css,scss}",
])
.pipe(gulp.dest("./dist/static/"));
});
gulp.task("collect root favicon", () => {
return gulp.src(["./src/static/img/*.ico"]).pipe(gulp.dest("./dist/"));
});
gulp.task("collect product icons", () => {
return gulp.src(["./icons/**/*"]).pipe(gulp.dest("./dist/static/icons/"));
});
gulp.task("build css", () => {
return gulp
.src(["./src/static/css/base.scss"])
.pipe(postcss())
.pipe(rename({ extname: ".css" }))
.pipe(gulp.dest("./dist/static/css/"));
});
gulp.task(
"default",
gulp.series([
"clean",
"build pages",
"collect dependencies",
"collect static",
"collect product icons",
"collect root favicon",
"build css",
])
);
if (process.env.NODE_ENV === "debug") {
gulp.watch(
["./src/templates/**/*"],
gulp.series("build pages", "collect static")
);
gulp.watch(["./src/**/*.{css,scss}", "build css"]);
}