-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
101 lines (92 loc) · 4.31 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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) {
try {
const servapp = JSON.parse(fs.readFileSync(`./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://lilkidsuave.github.io/asteroidsinthecosmos/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://lilkidsuave.github.io/asteroidsinthecosmos/servapps/${file}/artefacts/${artefact}`);
}
}
//Cosmos Format
const primaryIconSource = `https://lilkidsuave.github.io/asteroidsinthecosmos/servapps/${file}/icon.png`;
if (fs.existsSync(`./servapps/${file}/icon.png`)) {
servapp.icon = primaryIconSource;
}
//TinyActive Format
let alternativeIconSource = null;
const alternativeIconPath = `https://lilkidsuave.github.io/asteroidsinthecosmos/servapps/${file}/logo`;
if (fs.existsSync(`./servapps/${file}/logo`)) {
const pngFiles = fs.readdirSync(`./servapps/${file}/logo`);
if (pngFiles.length > 0) {
alternativeIconSource = `${alternativeIconPath}/${pngFiles[0]}`;
}
servapp.icon = alternativeIconSource;
}
//RunTipi Format
const ThirdIconSource = `https://lilkidsuave.github.io/asteroidsinthecosmos/servapps/${file}/metadata/logo.jpg`;
if (fs.existsSync(`./servapps/${file}/metadata/logo.jpg`)) {
servapp.icon = ThirdIconSource;
}
//Asteroid Format
const FourthIconSource = `https://lilkidsuave.github.io/asteroidsinthecosmos/servapps/${file}/logo.jpg`;
if (fs.existsSync(`./servapps/${file}/logo.jpg`)) {
servapp.icon = FourthIconSource;
}
//Common Format,used by most
const primaryComposeSource = `https://lilkidsuave.github.io/asteroidsinthecosmos/servapps/${file}/docker-compose.yml`;
if (fs.existsSync(`./servapps/${file}/docker-compose.yml`)) {
servapp.compose = primaryComposeSource;
}
//Cosmos Legacy Format
const alternativeComposeSource = `https://lilkidsuave.github.io/asteroidsinthecosmos/servapps/${file}/cosmos-compose.json`;
if (fs.existsSync(`./servapps/${file}/cosmos-compose.json`)) {
servapp.compose = alternativeComposeSource;
}
servappsJSON.push(servapp)
} catch (error) {
if (error.message.includes('is not defined')) {
console.error(`Error loading description.json for ${file}: Skipping`);
continue;
} else {
console.error(`Unknown Error`, error.message);
continue;
}
}
}
// 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://lilkidsuave.github.io/asteroidsinthecosmos', 'http://localhost:3000')
}
for (const artefact in servapp.artefacts) {
servapp.artefacts[artefact] = servapp.artefacts[artefact].replace('https://lilkidsuave.github.io/asteroidsinthecosmos', 'http://localhost:3000')
}
}
fs.writeFileSync('./servapps_test.json', JSON.stringify(apps, null, 2))