-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.js
42 lines (32 loc) · 1.25 KB
/
build.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
// Copyright (C) 2024 Katsute <https://github.com/Katsute>
const fs = require("fs");
const path = require("path");
const AdmZip = require("adm-zip");
const src = path.join(__dirname, "src");
const dist = path.join(__dirname, "dist");
const ext = path.join(__dirname, "extension.zip");
/* clear dist */ {
if(fs.existsSync(dist))
fs.rmSync(dist, {recursive: true});
fs.mkdirSync(dist);
!fs.existsSync(ext) || fs.rmSync(ext, {recursive: true});
}
/* copy src to zip */ {
fs.copyFileSync("LICENSE", path.join(dist, "LICENSE.txt"));
for(const file of fs.readdirSync(src))
fs.copyFileSync(path.join(src, file), path.join(dist, file));
}
/* minify */ {
for(const file of ["style.css"])
fs.writeFileSync(path.join(dist, file), fs.readFileSync(path.join(dist, file), "utf-8")
.replace(/(?<!^)\/\*.*\*\//g, '') // /* comments (except first copyright)
.replace(/ \/\/.*$/gm,'') // // comments
.replace(/ +/gm, ' ') // extra spaces
.replace(/^ +/gm, '') // leading space
.replace(/\r?\n/gm, '') // new line
.trim());
}
const zip = new AdmZip();
zip.addLocalFolderPromise(dist)
.then(() => zip.writeZip(ext))
.then(() => fs.rmSync(dist, {recursive: true}));