From 456d2c729390cea44ce5e5d7df8847db96e23195 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Fri, 7 Jul 2023 14:31:30 +0100 Subject: [PATCH] misc tweaks to built-in tools --- bin/language_scan.js | 17 +++++++++++++++++ bin/lib/apploader.js | 40 ++++++++++++++++++++++++++-------------- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/bin/language_scan.js b/bin/language_scan.js index 99d91b5191..77c91f1529 100755 --- a/bin/language_scan.js +++ b/bin/language_scan.js @@ -3,6 +3,23 @@ outputs a list of strings that have been found. See https://github.com/espruino/BangleApps/issues/1311 + +Needs old 'translate': + +npm install translate@1.4.1 + +For actual translation you need to sign up for a free Deepl API at https://www.deepl.com/ + +``` +# show status +bin/language_scan.js -r + +# add missing keys for all languages (in english) +bin/language_scan.js -r + +# for translation +bin/language_scan.js --deepl YOUR_API_KEY --turl https://api-free.deepl.com + */ var childProcess = require('child_process'); diff --git a/bin/lib/apploader.js b/bin/lib/apploader.js index c1aaa5389c..737a2d9046 100644 --- a/bin/lib/apploader.js +++ b/bin/lib/apploader.js @@ -30,20 +30,32 @@ exports.init = function(options) { DEVICEID = options.DEVICEID; device.id = options.DEVICEID; } - // Load app metadata - var dirs = require("fs").readdirSync(APPSDIR, {withFileTypes: true}); - dirs.forEach(dir => { - var appsFile; - if (dir.name.startsWith("_example") || !dir.isDirectory()) - return; - try { - appsFile = require("fs").readFileSync(APPSDIR+dir.name+"/metadata.json").toString(); - } catch (e) { - ERROR(dir.name+"/metadata.json does not exist"); - return; - } - apps.push(JSON.parse(appsFile)); - }); + // Try loading from apps.json + apps.length=0; + try { + var appsStr = require("fs").readFileSync(BASE_DIR+"/apps.json"); + var appList = JSON.parse(appsStr); + appList.forEach(a => apps.push(a)); + } catch (e) { + console.log("Couldn't load apps.json", e.toString()); + } + // Load app metadata from each app + if (!apps.length) { + console.log("Loading apps/.../metadata.json"); + var dirs = require("fs").readdirSync(APPSDIR, {withFileTypes: true}); + dirs.forEach(dir => { + var appsFile; + if (dir.name.startsWith("_example") || !dir.isDirectory()) + return; + try { + appsFile = require("fs").readFileSync(APPSDIR+dir.name+"/metadata.json").toString(); + } catch (e) { + console.error(dir.name+"/metadata.json does not exist"); + return; + } + apps.push(JSON.parse(appsFile)); + }); + } }; exports.AppInfo = AppInfo;