-
Notifications
You must be signed in to change notification settings - Fork 42
/
index.js
69 lines (56 loc) · 2.81 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
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
const screenshots = fs.readdirSync(`./servapps/${file}/screenshots`)
for (const screenshot of screenshots) {
servapp.screenshots.push(`https://azukaar.github.io/cosmos-servapps-official/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://azukaar.github.io/cosmos-servapps-official/servapps/${file}/artefacts/${artefact}`)
}
}
servapp.icon = `https://azukaar.github.io/cosmos-servapps-official/servapps/${file}/icon.png`
//Common Format,used by most
const YMLComposeSource = `https://azukaar.github.io/cosmos-servapps-official/servapps/${file}/docker-compose.yml`;
if(fs.existsSync(`./servapps/${file}/docker-compose.yml`)) {
servapp.compose = YMLComposeSource;
}
//Cosmos Legacy Format
const CosmosComposeSource = `https://azukaar.github.io/cosmos-servapps-official/servapps/${file}/cosmos-compose.json`;
if(fs.existsSync(`./servapps/${file}/cosmos-compose.json`)) {
servapp.compose = CosmosComposeSource;
}
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}/cosmos-compose.json`
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://azukaar.github.io/cosmos-servapps-official', 'http://localhost:3000')
}
for (const artefact in servapp.artefacts) {
servapp.artefacts[artefact] = servapp.artefacts[artefact].replace('https://azukaar.github.io/cosmos-servapps-official', 'http://localhost:3000')
}
}
fs.writeFileSync('./servapps_test.json', JSON.stringify(apps, null, 2))