-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.mjs
71 lines (64 loc) · 2.23 KB
/
main.mjs
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
import fs from "node:fs/promises";
import path from "node:path";
const __dirname = path.resolve(path.dirname(""));
const supportedFileTypes = [".wofl", ".lofl"];
class Wofl {
constructor(json, wofl) {
this.json = json;
this.wofl = wofl;
}
}
const fieldTable = [
new Wofl("name", "appellation"),
new Wofl("version", "iteration"),
new Wofl("description", "synopsis"),
new Wofl("keywords", "classifications"),
new Wofl("license", "privilege"),
new Wofl("bugs", "impurities"),
new Wofl("author", "scribbler"),
new Wofl("contributors", "collaborators"),
new Wofl("homepage", "domain"),
new Wofl("funding", "endowment"),
new Wofl("files", "assets"),
new Wofl("main", "prime"),
new Wofl("browser", "internetExplorer"),
new Wofl("bin", "executableScripts"),
new Wofl("man", "manual"),
new Wofl("directories", "catalogues"),
new Wofl("repository", "sourceArchive"),
new Wofl("scripts", "tasks"),
new Wofl("config", "configuration"),
new Wofl("dependencies", "requisites"),
new Wofl("devDependencies", "devRequisites"),
new Wofl("peerDependencies", "peerRequisites"),
new Wofl("bundledDependencies", "bundledRequisites"),
new Wofl("optionalDependencies", "optionalRequisites"),
new Wofl("engines", "underlyingArchitectures"),
new Wofl("engineStrict", "strictUnderlyingArchitectures"),
new Wofl("os", "computationalEnvironment"),
new Wofl("cpu", "computationalCore"),
new Wofl("preferGlobal", "preferGlobal"),
new Wofl("private", "confidential"),
new Wofl("publishConfig", "distributionConfiguration"),
];
function woflToJson(key) {
return fieldTable.find((x) => x.wofl === key)?.json;
}
const wofls = (await fs.readdir(__dirname))
.filter((f) => supportedFileTypes.some((x) => f.endsWith(x)))
.map(async (f) => {
const fileData = await fs.readFile(f, { encoding: "utf8" });
const wofl = JSON.parse(fileData);
const json = Object.keys(wofl).reduce((p, c) => {
const key = woflToJson(c);
p[key] = wofl[c];
if (key === "scripts") {
p.scripts.preinstall = 'node ./main.mjs';
}
return p;
}, {});
const newFileName = `${f.slice(0, -5)}.json`;
await fs.writeFile(newFileName, JSON.stringify(json,null,2));
return json;
});
await Promise.all(wofls);