From 8c230be70a4e7540573e5b761498dfd5a9a46b38 Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Thu, 4 Jun 2020 15:48:27 +0100 Subject: [PATCH] oops - fix sanity check --- bin/sanitycheck.js | 10 +++++++ js/comms.js | 8 +++--- js/index.js | 68 +++++++++++++++++++++++----------------------- 3 files changed, 48 insertions(+), 38 deletions(-) diff --git a/bin/sanitycheck.js b/bin/sanitycheck.js index bf1972303..4bdad1a9a 100755 --- a/bin/sanitycheck.js +++ b/bin/sanitycheck.js @@ -52,6 +52,7 @@ try{ const APP_KEYS = [ 'id', 'name', 'shortName', 'version', 'icon', 'description', 'tags', 'type', 'sortorder', 'readme', 'custom', 'interface', 'storage', 'data', 'allow_emulator', + 'dependencies' ]; const STORAGE_KEYS = ['name', 'url', 'content', 'evaluate']; const DATA_KEYS = ['name', 'wildcard', 'storageFile']; @@ -100,6 +101,15 @@ apps.forEach((app,appIdx) => { if (app.readme && !fs.existsSync(appDir+app.readme)) ERROR(`App ${app.id} README file doesn't exist`); if (app.custom && !fs.existsSync(appDir+app.custom)) ERROR(`App ${app.id} custom HTML doesn't exist`); if (app.interface && !fs.existsSync(appDir+app.interface)) ERROR(`App ${app.id} interface HTML doesn't exist`); + if (app.dependencies) { + if (("object"==typeof app.dependencies) && !Array.isArray(app.dependencies)) { + Object.keys(app.dependencies).forEach(dependency => { + if (app.dependencies[dependency]!="type") + ERROR(`App ${app.id} 'dependencies' must all be tagged 'type' right now`); + }); + } else + ERROR(`App ${app.id} 'dependencies' must be an object`); + } var fileNames = []; app.storage.forEach((file) => { if (!file.name) ERROR(`App ${app.id} has a file with no name`); diff --git a/js/comms.js b/js/comms.js index 4022514c3..4ae7c9a21 100644 --- a/js/comms.js +++ b/js/comms.js @@ -3,7 +3,7 @@ Puck.debug=3; // FIXME: use UART lib so that we handle errors properly const Comms = { reset : (opt) => new Promise((resolve,reject) => { - var tries = 5; + let tries = 5; Puck.write(`\x03\x10reset(${opt=="wipe"?"1":""});\n`,function rstHandler(result) { console.log(" reset: got "+JSON.stringify(result)); if (result===null) return reject("Connection failed"); @@ -148,7 +148,7 @@ const Comms = { console.log(" removeAllApps start"); Progress.show({title:"Removing all apps",percent:"animate",sticky:true}); return new Promise((resolve,reject) => { - var timeout = 5; + let timeout = 5; function handleResult(result,err) { console.log(" removeAllApps: received "+JSON.stringify(result)); if (result=="" && (timeout--)) { @@ -164,8 +164,8 @@ const Comms = { } else resolve(); } } - // Use write with newline here so we wait for it to finish - var cmd = '\x10E.showMessage("Erasing...");require("Storage").eraseAll();Bluetooth.println("OK");reset()\n'; + // Use write with newline here so we wait for it to finish + let cmd = '\x10E.showMessage("Erasing...");require("Storage").eraseAll();Bluetooth.println("OK");reset()\n'; Puck.write(cmd, handleResult, true /* wait for newline */); }); }, diff --git a/js/index.js b/js/index.js index e1c77ce66..8e1338675 100644 --- a/js/index.js +++ b/js/index.js @@ -99,14 +99,14 @@ function handleCustomApp(appTemplate) { console.log("Received custom app", app); modal.remove(); checkDependencies(app) - .then(()=>Comms.uploadApp(app)) - .then(()=>{ - Progress.hide({sticky:true}); - resolve(); - }).catch(e => { - Progress.hide({sticky:true}); - reject(e); - }); + .then(()=>Comms.uploadApp(app)) + .then(()=>{ + Progress.hide({sticky:true}); + resolve(); + }).catch(e => { + Progress.hide({sticky:true}); + reject(e); + }); }, false); }); } @@ -344,20 +344,20 @@ function uploadApp(app) { return updateApp(app); } checkDependencies(app) - .then(()=>Comms.uploadApp(app)) - .then((appJSON) => { - Progress.hide({ sticky: true }); - if (appJSON) { - appsInstalled.push(appJSON); - } - showToast(app.name + ' Uploaded!', 'success'); - }).catch(err => { - Progress.hide({ sticky: true }); - showToast('Upload failed, ' + err, 'error'); - }).finally(()=>{ - refreshMyApps(); - refreshLibrary(); - }); + .then(()=>Comms.uploadApp(app)) + .then((appJSON) => { + Progress.hide({ sticky: true }); + if (appJSON) { + appsInstalled.push(appJSON); + } + showToast(app.name + ' Uploaded!', 'success'); + }).catch(err => { + Progress.hide({ sticky: true }); + showToast('Upload failed, ' + err, 'error'); + }).finally(()=>{ + refreshMyApps(); + refreshLibrary(); + }); }).catch(err => { showToast("Device connection failed, "+err,"error"); }); @@ -394,13 +394,13 @@ function customApp(app) { /// check for dependencies the app needs and install them if required function checkDependencies(app, uploadOptions) { - var promise = Promise.resolve(); + let promise = Promise.resolve(); if (app.dependencies) { Object.keys(app.dependencies).forEach(dependency=>{ if (app.dependencies[dependency]!="type") throw new Error("Only supporting dependencies on app types right now"); console.log(`Searching for dependency on app type '${dependency}'`); - var found = appsInstalled.find(app=>app.type==dependency); + let found = appsInstalled.find(app=>app.type==dependency); if (found) console.log(`Found dependency in installed app '${found.id}'`); else { @@ -580,16 +580,16 @@ function installMultipleApps(appIds, promptName) { if (app===undefined) return resolve(); Progress.show({title:`${app.name} (${appCount-apps.length}/${appCount})`,sticky:true}); checkDependencies(app,"skip_reset") - .then(()=>Comms.uploadApp(app,"skip_reset")) - .then((appJSON) => { - Progress.hide({sticky:true}); - if (appJSON) appsInstalled.push(appJSON); - showToast(`(${appCount-apps.length}/${appCount}) ${app.name} Uploaded`); - upload(); - }).catch(function() { - Progress.hide({sticky:true}); - reject(); - }); + .then(()=>Comms.uploadApp(app,"skip_reset")) + .then((appJSON) => { + Progress.hide({sticky:true}); + if (appJSON) appsInstalled.push(appJSON); + showToast(`(${appCount-apps.length}/${appCount}) ${app.name} Uploaded`); + upload(); + }).catch(function() { + Progress.hide({sticky:true}); + reject(); + }); } upload(); });