diff --git a/.gitignore b/.gitignore index 273fdeae4..523dc5f20 100644 --- a/.gitignore +++ b/.gitignore @@ -9,4 +9,4 @@ appdates.csv _config.yml tests/Layout/bin/tmp.* tests/Layout/testresult.bmp -apps.json +apps.local.json \ No newline at end of file diff --git a/bin/update_local_apps_json.js b/bin/update_local_apps_json.js new file mode 100755 index 000000000..3ba54f289 --- /dev/null +++ b/bin/update_local_apps_json.js @@ -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 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}`); \ No newline at end of file diff --git a/core b/core index 5023ee122..3093d78a5 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 5023ee1228030130ba9f026d5dbe920f7527ee7d +Subproject commit 3093d78a5d752cbf03ea8f9a1a7c0b50b9c8123b diff --git a/loader.js b/loader.js index 0355ea89c..d8ba26269 100644 --- a/loader.js +++ b/loader.js @@ -5,6 +5,11 @@ if (window.location.host=="banglejs.com") { document.title += " [Development]"; document.getElementById("apploaderlinks").innerHTML = 'This is the development Bangle.js App Loader - you can also try the Official Version 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 Official Version here.'; } else { document.title += " [Unofficial]"; document.getElementById("apploaderlinks").innerHTML = diff --git a/package.json b/package.json index b796044c9..aa1b0b88a 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,17 @@ "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", + "local": "npm-watch & npx http-server -a localhost -c-1", "start": "npx http-server -c-1" }, + "watch": { + "update-local-apps": "apps/*/metadata.json" + }, "dependencies": { "acorn": "^7.2.0" + }, + "devDpendencies": { + "npm-watch": "^0.11.0" } }