-
Notifications
You must be signed in to change notification settings - Fork 6
/
Jakefile.js
195 lines (176 loc) · 6.03 KB
/
Jakefile.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
const exec = require("child_process").exec;
const fs = require("fs");
const {parseMD2} = require("./MDParser");
const {readdir} = require("fs").promises;
const ENV_PATH = "./.env";
const ENV_BUILD_YEAR_ROW = `BUILD_YEAR=${new Date().getFullYear()}`;
const ENV_BUILD_YEAR_REGEX = /^BUILD_YEAR=.*$/m;
var parseMD = require("./MDParser").parseMD;
var ParseDirectory = require("./jakeFunctions").ParseDirectory;
var GenerateProjectsFile = require("./jakeFunctions").generateProjectsFile;
var generateAchievementsFile = require("./jakeFunctions").generateAchievementsFile;
var minifyPath = require("./jakeFunctions").minifyPath;
desc("Build Landing Front for production");
task("default", [
"generate projects file",
"parse achievements.md", "parse staff.md", "parse equipment.md", "createEnv",
"buildFrontProd",
"minify build"
// "create service-worker",
], function () {
});
desc("Generate projects file");
task("generate projects file", GenerateProjectsFile);
desc("Creating achievements.json file from /info/achievements.md");
task("parse achievements.md", generateAchievementsFile);
/**
* equipment
*/
desc("Creating equipment.json file from /info/equipment.md");
task("parse equipment.md", function () {
return new Promise((resolve, reject) => {
let data = fs.readFileSync("./data/equipment/equipment.md", "utf-8");
let list = parseMD(data);
let result = [];
let buff = [];
for (let i of list) {
buff.push(i);
if (buff.length === 8) {
result.push(buff);
buff = [];
}
}
result.push(buff);
buff = [];
let file = "-\n\tconst equipmentData = " + JSON.stringify(result);
fs.writeFileSync("./src/js/data/equipment.pug", file, "utf-8");
resolve();
});
});
/**
* ------------------------
*/
/**
* STAFF.MD
*/
desc("Creating staff.json file from /info/staff.md");
task("parse staff.md", function () {
return new Promise((resolve, reject) => {
let data = fs.readFileSync("./data/staff/staff.md", "utf-8");
let list = parseMD(data);
let file = "-\n\tconst staffData = " + JSON.stringify(list);
fs.writeFileSync("./src/js/data/staff.pug", file, "utf-8");
resolve();
});
});
/**
* ------------------------
*/
/**
* service-worker
*/
desc("Create new service-worker.js file from serviceWorkerSample.js with new cache version and new caching links");
task("create service-worker", function () {
return new Promise((resolve, reject) => {
let list = [];
ParseDirectory(() => {
list.splice(list.indexOf("/service-worker.js"), 1);
list.splice(list.indexOf("/robots.txt"), 1);
list.splice(list.indexOf("/index.html"), 1);
list.push("/");
let data = fs.readFileSync("./info/serviceWorkerSample.js", "utf-8");
let dataSample = data;
let version = data.matchAll(/(var CACHE_NAME = )\'v(\d*)\';/gm);
let versionParse = version.next().value;
let newVersion = versionParse[0].replace("v" + versionParse[2].toString(), "v" + (Number(versionParse[2]) + 1).toString());
data = data
.replace("// THIS MESSAGE FOR PARSER #urls", JSON.stringify(list)
.replace(/(\[|\])/gm, "")
.replaceAll(",", ",\n\t\t\t\t\t\t\t"))
.replace(versionParse[0], newVersion);
fs.writeFileSync("./build/service-worker.js", data, "utf-8");
fs.writeFileSync("./info/serviceWorkerSample.js", dataSample.replace(versionParse[0], newVersion), "utf-8");
resolve();
}, list, "build");
});
});
/**
* --------------------------
*/
/**
* .env file
*/
desc("Create .env file with year of build");
task("createEnv", function () {
return new Promise((resolve) => {
try {
let data;
if (fs.existsSync(ENV_PATH)) {
data = fs.readFileSync(ENV_PATH, "utf8");
data = data
.replace(/\r/g, "")
.split("\n")
.filter((val) => !val.match(ENV_BUILD_YEAR_REGEX))
.join("\n");
data = `${ENV_BUILD_YEAR_ROW}\n${data}`;
} else {
data = ENV_BUILD_YEAR_ROW;
}
fs.writeFileSync(ENV_PATH, data);
} catch (error) {
console.error(error);
}
resolve(true);
});
});
/**
* ------------------------
*/
desc("Build Landing Front prod");
task("buildFrontProd", function () {
return new Promise((resolve, reject) => {
const rimraf = require("rimraf");
rimraf.sync("./build");
try {
fs.mkdirSync("./build")
}catch (e){}
try {
fs.mkdirSync("./build/dist")
}catch (e){}
fs.copyFileSync("./src/js/swiper/swiper-bundle.min.js","./build/dist/swiper-bundle.min.js")
fs.copyFileSync("./src/js/parallax/parallax.min.js","./build/dist/parallax.min.js")
fs.copyFileSync("./src/js/markdown-it/markdown-it.js","./build/dist/markdown-it.js")
let command = "parcel build ./src/index.pug --out-dir build --public-url ./ --no-minify --no-cache " + "&& parcel build ./src/projects/*.pug --out-dir build/projects --public-url ./ --no-minify --no-cache " + "&& parcel build ./src/achievements/*.pug --out-dir build/achievements --public-url ./ --no-minify --no-cache "
+ "&& cp -a ./src/images ./build/images "
+ "&& node ./postbuild.js && node ./postbuild.js projects && node ./postbuild.js achievements"
+ "&& cp -a ./robots.txt ./build/"
+ "&& exit 0";
if (process.platform === "win32") command =
"parcel build ./src/index.pug --out-dir build --public-url ./ --no-minify --no-cache "
+ "&& parcel build ./src/projects/*.pug --out-dir build/projects --public-url ./ --no-minify --no-cache "
+ "&& parcel build ./src/achievements/*.pug --out-dir build/achievements --public-url ./ --no-minify --no-cache "
+ "&& mkdir .\\build\\images "
+ "&& xcopy /E .\\src\\images .\\build\\images\\ "
+ "&& node .\\postbuild.js && node .\\postbuild.js projects && node .\\postbuild.js achievements"
+ "&& xcopy .\\robots.txt .\\build\\"
+ "&& exit 0";
exec(command, (err, stdout, stderr) => {
if (err) {
console.error(stderr);
reject(stderr);
// return;
}
fs.copyFileSync("./src/images/favicon.ico","./build/favicon.ico")
resolve(true);
});
});
});
task("minify build",function(){
return new Promise(async (_) => {
await minifyPath('./build/achievements')
await minifyPath('./build/projects')
await minifyPath('./build/dist')
await minifyPath('./build/')
_()
})
})