-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-modpack.js
57 lines (48 loc) · 1.59 KB
/
update-modpack.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
const walk = require('walk')
const path = require('path')
const fs = require('fs')
const sha1File = require("sha1-file");
const { gzip, ungzip } = require('node-gzip');
const source = "online_modpack/overrides"
const sourcefile = "online_modpack/server-manifest.json"
const backupFolder = "pack_updater/manifest_backup"
manifestJson = JSON.parse(fs.readFileSync(sourcefile));
sourceJson = JSON.parse(fs.readFileSync(sourcefile));
//console.log(manifestJson);
manifestJson.files = [];
manifestJson.version = increaseVersion(manifestJson.version)
//console.log(manifestJson);
let walker = walk.walk(source);
function increaseVersion(version) {
version = version.split(".")
let major = parseInt(version[0])
let minor = parseInt(version[1])
return `${major}.${minor + 1}`;
}
walker.on('file', function (root, fileStats, next) {
let filePath = path.join(root, fileStats.name);
let configPath = path.join(path.relative(source, root), fileStats.name)
manifestJson.files.push(
{
path: configPath,
hash: sha1File.sync(filePath)
}
)
next();
}
);
walker.on("end", async function () {
try{
fs.unlinkSync(sourcefile);
fs.unlinkSync("online_modpack/server-manifest.json.gz");
}catch(e){
console.error(e);
}
let json = JSON.stringify(manifestJson, null, ' ');
let backupPath = path.join(backupFolder, `server-manifest-${sourceJson.version}.json`)
fs.writeFileSync(sourcefile, json);
fs.writeFileSync("online_modpack/server-manifest.json.gz", await gzip(json));
fs.writeFileSync(backupPath, JSON.stringify(sourceJson, null, ' '));
console.log("all done");
}
);