-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
74 lines (61 loc) · 2.42 KB
/
index.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
const fs = require("fs");
const { config } = require("process");
const configFile = require("./config.json");
// list all directories in the directory servapps and compile them in servapps.json
const servapps = fs
.readdirSync("./servapps")
.filter((file) => fs.lstatSync(`./servapps/${file}`).isDirectory());
let servappsJSON = [];
for (const file of servapps) {
const servapp = require(`./servapps/${file}/description.json`);
servapp.id = file;
servapp.screenshots = [];
servapp.artefacts = {};
// list all screenshots in the directory servapps/${file}/screenshots
if (fs.existsSync(`./servapps/${file}/screenshots`)) {
const screenshots = fs.readdirSync(`./servapps/${file}/screenshots`);
for (const screenshot of screenshots) {
servapp.screenshots.push(
`https://cosmos.bigbeartechworld.com/servapps/${file}/screenshots/${screenshot}`
);
}
}
if (fs.existsSync(`./servapps/${file}/artefacts`)) {
const artefacts = fs.readdirSync(`./servapps/${file}/artefacts`);
for (const artefact of artefacts) {
servapp.artefacts[
artefact
] = `https://cosmos.bigbeartechworld.com/servapps/${file}/artefacts/${artefact}`;
}
}
servapp.icon = `https://cosmos.bigbeartechworld.com/servapps/${file}/icon.png`;
servapp.compose = `https://cosmos.bigbeartechworld.com/servapps/${file}/docker-compose.yml`;
servappsJSON.push(servapp);
}
// add showcase
const _sc = ["Jellyfin", "Home Assistant", "Nextcloud"];
const showcases = servappsJSON.filter((app) => _sc.includes(app.name));
let apps = {
source: configFile.url,
showcase: showcases,
all: servappsJSON,
};
fs.writeFileSync("./servapps.json", JSON.stringify(servappsJSON, null, 2));
fs.writeFileSync("./index.json", JSON.stringify(apps, null, 2));
for (const servapp of servappsJSON) {
servapp.compose = `http://localhost:3000/servapps/${servapp.id}/docker-compose.yml`;
servapp.icon = `http://localhost:3000/servapps/${servapp.id}/icon.png`;
for (let i = 0; i < servapp.screenshots.length; i++) {
servapp.screenshots[i] = servapp.screenshots[i].replace(
"https://cosmos.bigbeartechworld.com",
"http://localhost:3000"
);
}
for (const artefact in servapp.artefacts) {
servapp.artefacts[artefact] = servapp.artefacts[artefact].replace(
"https://cosmos.bigbeartechworld.com",
"http://localhost:3000"
);
}
}
fs.writeFileSync("./servapps_test.json", JSON.stringify(apps, null, 2));