mirror of https://github.com/espruino/BangleApps
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`.pull/1324/head
parent
a3b49a0d82
commit
e75a828fce
|
@ -7,7 +7,10 @@
|
||||||
# Otherwise nothing has changed. GitHub Pages will automatically
|
# Otherwise nothing has changed. GitHub Pages will automatically
|
||||||
# create apps.json as your site is hosted, or if you're hosting
|
# create apps.json as your site is hosted, or if you're hosting
|
||||||
# yourself you can run bin/create_apps_json.sh
|
# 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
|
# Uncomment the following line if you only want explicitly listed
|
||||||
|
|
|
@ -13,17 +13,26 @@
|
||||||
#
|
#
|
||||||
# If you do this, please do not attempt to commit your modified
|
# If you do this, please do not attempt to commit your modified
|
||||||
# apps.json back into the main BangleApps repository!
|
# 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`/..
|
cd `dirname $0`/..
|
||||||
echo "[" > apps.json
|
echo "[" > "$outfile"
|
||||||
|
first=1
|
||||||
for app in apps/*/; do
|
for app in apps/*/; do
|
||||||
echo "Processing $app...";
|
echo "Processing $app...";
|
||||||
if [[ "$app" =~ ^apps/_example.* ]]; then
|
if [[ "$app" =~ ^apps/_example.* ]]; then
|
||||||
echo "Ignoring $app"
|
echo "Ignoring $app"
|
||||||
else
|
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 ",\"$app\"," >> apps.json # DEBUG ONLY
|
||||||
echo "," >> apps.json
|
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
echo "null]" >> apps.json
|
echo "]" >> "$outfile"
|
||||||
|
|
|
@ -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}`);
|
|
|
@ -9,7 +9,7 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint-apps": "eslint ./apps --ext .js",
|
"lint-apps": "eslint ./apps --ext .js",
|
||||||
"test": "node bin/sanitycheck.js && 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",
|
"local": "npm-watch & npx http-server -a localhost -c-1",
|
||||||
"start": "npx http-server -c-1"
|
"start": "npx http-server -c-1"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue