Support for localhost appstore
- Adds a script to generate `apps.local.json` from all metadata - Makes the loader use `apps.local.json` when serving from localhost - Adds npm `local` script to watch for changed metadata, while serving from localhostmaster
parent
e997ad59ed
commit
a3b49a0d82
|
|
@ -9,4 +9,4 @@ appdates.csv
|
||||||
_config.yml
|
_config.yml
|
||||||
tests/Layout/bin/tmp.*
|
tests/Layout/bin/tmp.*
|
||||||
tests/Layout/testresult.bmp
|
tests/Layout/testresult.bmp
|
||||||
apps.json
|
apps.local.json
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
#!/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}`);
|
||||||
2
core
2
core
|
|
@ -1 +1 @@
|
||||||
Subproject commit 5023ee1228030130ba9f026d5dbe920f7527ee7d
|
Subproject commit 3093d78a5d752cbf03ea8f9a1a7c0b50b9c8123b
|
||||||
|
|
@ -5,6 +5,11 @@ if (window.location.host=="banglejs.com") {
|
||||||
document.title += " [Development]";
|
document.title += " [Development]";
|
||||||
document.getElementById("apploaderlinks").innerHTML =
|
document.getElementById("apploaderlinks").innerHTML =
|
||||||
'This is the development Bangle.js App Loader - you can also try the <a href="https://banglejs.com/apps/">Official Version</a> for stable apps.';
|
'This is the development Bangle.js App Loader - you can also try the <a href="https://banglejs.com/apps/">Official Version</a> for stable apps.';
|
||||||
|
} else if (window.location.hostname==='localhost') {
|
||||||
|
document.title += " [Local]";
|
||||||
|
Const.APPS_JSON_FILE = "apps.local.json";
|
||||||
|
document.getElementById("apploaderlinks").innerHTML =
|
||||||
|
'This is your local Bangle.js App Loader - you can try the <a href="https://banglejs.com/apps/">Official Version</a> here.';
|
||||||
} else {
|
} else {
|
||||||
document.title += " [Unofficial]";
|
document.title += " [Unofficial]";
|
||||||
document.getElementById("apploaderlinks").innerHTML =
|
document.getElementById("apploaderlinks").innerHTML =
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,17 @@
|
||||||
"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",
|
||||||
|
"local": "npm-watch & npx http-server -a localhost -c-1",
|
||||||
"start": "npx http-server -c-1"
|
"start": "npx http-server -c-1"
|
||||||
},
|
},
|
||||||
|
"watch": {
|
||||||
|
"update-local-apps": "apps/*/metadata.json"
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"acorn": "^7.2.0"
|
"acorn": "^7.2.0"
|
||||||
|
},
|
||||||
|
"devDpendencies": {
|
||||||
|
"npm-watch": "^0.11.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue