1
0
Fork 0

always use shell script to generate apps.json, remove js version

Gets rid of duplicated functionality, but allows passing a filename
argument to write to a different file instead of `apps.json`.
master
Richard de Boer 2022-01-20 20:22:58 +01:00
parent a3b49a0d82
commit e75a828fce
No known key found for this signature in database
GPG Key ID: 8721727971871937
4 changed files with 18 additions and 68 deletions

View File

@ -7,7 +7,10 @@
# Otherwise nothing has changed. GitHub Pages will automatically
# create apps.json as your site is hosted, or if you're hosting
# yourself you can run bin/create_apps_json.sh
#
#
# If you serve the store from localhost for development/testing,
# the loader looks for apps.local.json instead, you can run
# `bin/create_apps_json.sh apps.local.json` to create that file.
# =================================================================
# Uncomment the following line if you only want explicitly listed

View File

@ -13,17 +13,26 @@
#
# If you do this, please do not attempt to commit your modified
# apps.json back into the main BangleApps repository!
#
# You can pass an optional filename to this script, and it will write
# to that instead, apps.local.json is used when opening the loader on localhost
outfile="${1:-apps.json}"
cd `dirname $0`/..
echo "[" > apps.json
echo "[" > "$outfile"
first=1
for app in apps/*/; do
echo "Processing $app...";
if [[ "$app" =~ ^apps/_example.* ]]; then
echo "Ignoring $app"
else
cat ${app}metadata.json >> apps.json
if [ $first -eq 1 ]; then
first=0;
else
echo "," >> "$outfile"
fi;
cat ${app}metadata.json >> "$outfile"
# echo ",\"$app\"," >> apps.json # DEBUG ONLY
echo "," >> apps.json
fi
done
echo "null]" >> apps.json
echo "]" >> "$outfile"

View File

@ -1,62 +0,0 @@
#!/usr/bin/nodejs
/* Merge all apps/metadata.json files into apps.local.json
*/
const fs = require("fs");
const BASEDIR = __dirname+"/../";
const APPSDIR = BASEDIR+"apps/";
const APPSFILE = "apps.local.json";
const APPSPATH = BASEDIR+ APPSFILE;
function ERROR(s) {
console.error("ERROR: "+s);
process.exit(1);
}
function INFO(s) {
console.info(s);
}
const apps = [];
const dirs = fs.readdirSync(APPSDIR, {withFileTypes: true});
dirs.forEach(dir => {
let appsFile;
if (dir.name.startsWith("_example")) {
return;
}
try {
appsFile = fs.readFileSync(APPSDIR+dir.name+"/metadata.json").toString();
} catch(e) {
return;
}
try {
apps.push(JSON.parse(appsFile));
} catch(e) {
console.log(e);
const m = e.toString().match(/in JSON at position (\d+)/);
if (m) {
const char = parseInt(m[1]);
console.log("===============================================");
console.log("LINE "+appsFile.substr(0, char).split("\n").length);
console.log("===============================================");
console.log(appsFile.substr(char-10, 20));
console.log("===============================================");
}
console.log(m);
ERROR(dir.name+"/metadata.json not valid JSON");
}
});
// order doesn't matter as the loader sorts apps, but sort by <sortorder,id> anyway
apps.sort((a, b) => ((0|a.sortorder)-(0|b.sortorder)) || a.id.localeCompare(b.id));
const json = JSON.stringify(apps, null, 2);
let update = false;
if (fs.existsSync(APPSPATH)) {
const old = fs.readFileSync(APPSPATH).toString();
if (old===json) {
INFO(`${APPSFILE} is already up-to-date`);
process.exit();
}
update = true;
}
fs.writeFileSync(APPSPATH, json);
INFO(`${update ? 'Updated' : 'Wrote'} ${APPSFILE}`);

View File

@ -9,7 +9,7 @@
"scripts": {
"lint-apps": "eslint ./apps --ext .js",
"test": "node bin/sanitycheck.js && eslint ./apps --ext .js",
"update-local-apps": "node bin/update_local_apps_json.js",
"update-local-apps": "./bin/create_apps_json.sh apps.local.json",
"local": "npm-watch & npx http-server -a localhost -c-1",
"start": "npx http-server -c-1"
},