Initial commit

This commit is contained in:
Chris Hunt
2022-12-14 15:03:50 +00:00
parent 501fbdb0e1
commit 99a12e2194
29 changed files with 12835 additions and 0 deletions

1451
processing/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

19
processing/package.json Normal file
View File

@@ -0,0 +1,19 @@
{
"name": "Kasm-Apps",
"version": "1.0.0",
"description": "Generate json file",
"main": "processjson.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
},
"dependencies": {
"folder-hash": "^4.0.2",
"glob": "^7.1.6",
"ncu": "^0.2.1"
}
}

68
processing/processjson.js Normal file
View File

@@ -0,0 +1,68 @@
const fs = require("fs");
const glob = require("glob");
const { hashElement } = require("folder-hash");
const nextConfig = require("../site/next.config.js")
var dir = "./site/out";
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
if (!fs.existsSync(dir + "/icons")) {
fs.mkdirSync(dir + "/icons");
}
glob("**/app.json", async function (err, files) {
if (err) {
console.log(
"cannot read the folder, something goes wrong with glob",
err
);
}
let apptotal = files.length;
let apps = [];
let promises = [];
const options = {
algho: "sha1",
encoding: "hex",
};
for (const file of files) {
//files.forEach(async function(file) {
let folder = file.replace("/app.json", "");
let hash = await hashElement(folder, options);
let filedata = fs.readFileSync(file);
let parsed = JSON.parse(filedata);
parsed.sha = hash.hash;
console.log(parsed.name + ' added')
apps.push(parsed);
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',
appcount: apptotal,
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(),
apps: apps,
};
let data = JSON.stringify(json);
fs.writeFileSync(dir + "/list.json", data);
});