-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.mjs
More file actions
30 lines (21 loc) · 1.01 KB
/
start.mjs
File metadata and controls
30 lines (21 loc) · 1.01 KB
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
import { createHash } from "node:crypto";
import fs from "node:fs/promises";
import simpleGit from "simple-git";
const packages = await fs.readdir("./packages");
const hashes = [];
for (let index = 0; index < packages.length; index++) {
const val = packages[index];
const jsonModule = await fs.readFile("./packages/"+val+"/module/module.json");
const module = JSON.parse(jsonModule);
const zipFile = await fs.readFile(`./${val}.tar.gz`);
const hash = createHash('sha256').update(zipFile, 'binary').digest('hex');
const git = simpleGit("./packages/"+val+"/module/");
module.tags = (await git.tags()).all;
module.latestCommit = (await git.log()).latest.hash;
module.allCommitHashes = (await git.log()).all.map((v) => (v.hash));
module.hash = hash;
module.size = zipFile.byteLength;
hashes.push(hash);
await fs.writeFile(`./packages/${val}/manifest.json`, JSON.stringify(module, null, 4), "utf8");
console.log(`Hashed ${val} module: ${hash} , size: ${module.size}`);
}