2022-12-14 15:03:50 +00:00
|
|
|
const fs = require("fs");
|
|
|
|
const glob = require("glob");
|
|
|
|
const { hashElement } = require("folder-hash");
|
|
|
|
const nextConfig = require("../site/next.config.js")
|
|
|
|
|
2023-01-10 13:40:27 +00:00
|
|
|
var dir = "./public";
|
2022-12-14 15:03:50 +00:00
|
|
|
|
|
|
|
if (!fs.existsSync(dir)) {
|
|
|
|
fs.mkdirSync(dir);
|
|
|
|
}
|
|
|
|
if (!fs.existsSync(dir + "/icons")) {
|
|
|
|
fs.mkdirSync(dir + "/icons");
|
|
|
|
}
|
|
|
|
|
2023-01-19 11:18:02 +00:00
|
|
|
glob("**/workspace.json", async function (err, files) {
|
2022-12-14 15:03:50 +00:00
|
|
|
if (err) {
|
|
|
|
console.log(
|
|
|
|
"cannot read the folder, something goes wrong with glob",
|
|
|
|
err
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-01-19 11:18:02 +00:00
|
|
|
let workspacetotal = files.length;
|
|
|
|
let workspaces = [];
|
2022-12-14 15:03:50 +00:00
|
|
|
let promises = [];
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
algho: "sha1",
|
|
|
|
encoding: "hex",
|
|
|
|
};
|
|
|
|
|
2024-08-13 10:25:38 +00:00
|
|
|
let channels = new Set()
|
2024-08-20 10:26:36 +00:00
|
|
|
let versions = new Set()
|
2024-08-13 10:25:38 +00:00
|
|
|
|
2022-12-14 15:03:50 +00:00
|
|
|
for (const file of files) {
|
|
|
|
//files.forEach(async function(file) {
|
|
|
|
|
2023-01-19 11:18:02 +00:00
|
|
|
let folder = file.replace("/workspace.json", "");
|
2022-12-14 15:03:50 +00:00
|
|
|
|
|
|
|
let hash = await hashElement(folder, options);
|
|
|
|
let filedata = fs.readFileSync(file);
|
|
|
|
|
|
|
|
let parsed = JSON.parse(filedata);
|
|
|
|
parsed.sha = hash.hash;
|
2024-08-13 16:37:46 +00:00
|
|
|
console.log(parsed.friendly_name + ' added')
|
2024-08-13 09:31:16 +00:00
|
|
|
parsed.compatibility.forEach((element, index) => {
|
|
|
|
if ('available_tags' in element) {
|
|
|
|
element.available_tags.forEach((el) => {
|
|
|
|
channels.add(el)
|
|
|
|
})
|
|
|
|
}
|
2024-08-20 10:26:36 +00:00
|
|
|
if ('version' in element) {
|
|
|
|
versions.add(element.version)
|
|
|
|
}
|
2024-08-13 09:31:16 +00:00
|
|
|
})
|
2023-01-19 11:18:02 +00:00
|
|
|
workspaces.push(parsed);
|
2022-12-14 15:03:50 +00:00
|
|
|
|
|
|
|
if (fs.existsSync(folder + "/" + parsed.image_src)) {
|
|
|
|
let imagedata = fs.readFileSync(folder + "/" + parsed.image_src);
|
|
|
|
fs.writeFileSync(dir + "/icons/" + parsed.image_src, imagedata);
|
|
|
|
} else {
|
|
|
|
console.error("missing file: ".folder + "/" + parsed.image_src);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
let json = {
|
|
|
|
name: nextConfig.env.name || 'Unknown store',
|
2023-01-19 11:18:02 +00:00
|
|
|
workspacecount: workspacetotal,
|
2022-12-14 15:03:50 +00:00
|
|
|
icon: nextConfig.env.icon || null,
|
|
|
|
description: nextConfig.env.description || null,
|
|
|
|
list_url: nextConfig.env.listUrl || null,
|
|
|
|
contact_url: nextConfig.env.contactUrl || null,
|
|
|
|
modified: Date.now(),
|
2023-01-19 11:18:02 +00:00
|
|
|
workspaces: workspaces,
|
2024-08-13 10:05:25 +00:00
|
|
|
channels: [...channels],
|
|
|
|
default_channel: 'develop'
|
2022-12-14 15:03:50 +00:00
|
|
|
};
|
|
|
|
|
2024-08-13 10:05:25 +00:00
|
|
|
if (channels.size === 0) {
|
|
|
|
json.default_channel = null
|
|
|
|
}
|
|
|
|
|
2022-12-14 15:03:50 +00:00
|
|
|
let data = JSON.stringify(json);
|
|
|
|
|
|
|
|
fs.writeFileSync(dir + "/list.json", data);
|
2024-08-20 10:26:36 +00:00
|
|
|
fs.writeFileSync(dir + "/versions.json", JSON.stringify({
|
|
|
|
versions: [...versions]
|
|
|
|
}));
|
|
|
|
|
2022-12-14 15:03:50 +00:00
|
|
|
});
|