oops - fix sanity check

pull/486/head
Gordon Williams 2020-06-04 15:48:27 +01:00
parent 8ec7878ede
commit 8c230be70a
3 changed files with 48 additions and 38 deletions

View File

@ -52,6 +52,7 @@ try{
const APP_KEYS = [ const APP_KEYS = [
'id', 'name', 'shortName', 'version', 'icon', 'description', 'tags', 'type', 'id', 'name', 'shortName', 'version', 'icon', 'description', 'tags', 'type',
'sortorder', 'readme', 'custom', 'interface', 'storage', 'data', 'allow_emulator', 'sortorder', 'readme', 'custom', 'interface', 'storage', 'data', 'allow_emulator',
'dependencies'
]; ];
const STORAGE_KEYS = ['name', 'url', 'content', 'evaluate']; const STORAGE_KEYS = ['name', 'url', 'content', 'evaluate'];
const DATA_KEYS = ['name', 'wildcard', 'storageFile']; 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.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.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.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 = []; var fileNames = [];
app.storage.forEach((file) => { app.storage.forEach((file) => {
if (!file.name) ERROR(`App ${app.id} has a file with no name`); if (!file.name) ERROR(`App ${app.id} has a file with no name`);

View File

@ -3,7 +3,7 @@ Puck.debug=3;
// FIXME: use UART lib so that we handle errors properly // FIXME: use UART lib so that we handle errors properly
const Comms = { const Comms = {
reset : (opt) => new Promise((resolve,reject) => { reset : (opt) => new Promise((resolve,reject) => {
var tries = 5; let tries = 5;
Puck.write(`\x03\x10reset(${opt=="wipe"?"1":""});\n`,function rstHandler(result) { Puck.write(`\x03\x10reset(${opt=="wipe"?"1":""});\n`,function rstHandler(result) {
console.log("<COMMS> reset: got "+JSON.stringify(result)); console.log("<COMMS> reset: got "+JSON.stringify(result));
if (result===null) return reject("Connection failed"); if (result===null) return reject("Connection failed");
@ -148,7 +148,7 @@ const Comms = {
console.log("<COMMS> removeAllApps start"); console.log("<COMMS> removeAllApps start");
Progress.show({title:"Removing all apps",percent:"animate",sticky:true}); Progress.show({title:"Removing all apps",percent:"animate",sticky:true});
return new Promise((resolve,reject) => { return new Promise((resolve,reject) => {
var timeout = 5; let timeout = 5;
function handleResult(result,err) { function handleResult(result,err) {
console.log("<COMMS> removeAllApps: received "+JSON.stringify(result)); console.log("<COMMS> removeAllApps: received "+JSON.stringify(result));
if (result=="" && (timeout--)) { if (result=="" && (timeout--)) {
@ -164,8 +164,8 @@ const Comms = {
} else resolve(); } else resolve();
} }
} }
// Use write with newline here so we wait for it to finish // 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'; let cmd = '\x10E.showMessage("Erasing...");require("Storage").eraseAll();Bluetooth.println("OK");reset()\n';
Puck.write(cmd, handleResult, true /* wait for newline */); Puck.write(cmd, handleResult, true /* wait for newline */);
}); });
}, },

View File

@ -99,14 +99,14 @@ function handleCustomApp(appTemplate) {
console.log("Received custom app", app); console.log("Received custom app", app);
modal.remove(); modal.remove();
checkDependencies(app) checkDependencies(app)
.then(()=>Comms.uploadApp(app)) .then(()=>Comms.uploadApp(app))
.then(()=>{ .then(()=>{
Progress.hide({sticky:true}); Progress.hide({sticky:true});
resolve(); resolve();
}).catch(e => { }).catch(e => {
Progress.hide({sticky:true}); Progress.hide({sticky:true});
reject(e); reject(e);
}); });
}, false); }, false);
}); });
} }
@ -344,20 +344,20 @@ function uploadApp(app) {
return updateApp(app); return updateApp(app);
} }
checkDependencies(app) checkDependencies(app)
.then(()=>Comms.uploadApp(app)) .then(()=>Comms.uploadApp(app))
.then((appJSON) => { .then((appJSON) => {
Progress.hide({ sticky: true }); Progress.hide({ sticky: true });
if (appJSON) { if (appJSON) {
appsInstalled.push(appJSON); appsInstalled.push(appJSON);
} }
showToast(app.name + ' Uploaded!', 'success'); showToast(app.name + ' Uploaded!', 'success');
}).catch(err => { }).catch(err => {
Progress.hide({ sticky: true }); Progress.hide({ sticky: true });
showToast('Upload failed, ' + err, 'error'); showToast('Upload failed, ' + err, 'error');
}).finally(()=>{ }).finally(()=>{
refreshMyApps(); refreshMyApps();
refreshLibrary(); refreshLibrary();
}); });
}).catch(err => { }).catch(err => {
showToast("Device connection failed, "+err,"error"); showToast("Device connection failed, "+err,"error");
}); });
@ -394,13 +394,13 @@ function customApp(app) {
/// check for dependencies the app needs and install them if required /// check for dependencies the app needs and install them if required
function checkDependencies(app, uploadOptions) { function checkDependencies(app, uploadOptions) {
var promise = Promise.resolve(); let promise = Promise.resolve();
if (app.dependencies) { if (app.dependencies) {
Object.keys(app.dependencies).forEach(dependency=>{ Object.keys(app.dependencies).forEach(dependency=>{
if (app.dependencies[dependency]!="type") if (app.dependencies[dependency]!="type")
throw new Error("Only supporting dependencies on app types right now"); throw new Error("Only supporting dependencies on app types right now");
console.log(`Searching for dependency on app type '${dependency}'`); 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) if (found)
console.log(`Found dependency in installed app '${found.id}'`); console.log(`Found dependency in installed app '${found.id}'`);
else { else {
@ -580,16 +580,16 @@ function installMultipleApps(appIds, promptName) {
if (app===undefined) return resolve(); if (app===undefined) return resolve();
Progress.show({title:`${app.name} (${appCount-apps.length}/${appCount})`,sticky:true}); Progress.show({title:`${app.name} (${appCount-apps.length}/${appCount})`,sticky:true});
checkDependencies(app,"skip_reset") checkDependencies(app,"skip_reset")
.then(()=>Comms.uploadApp(app,"skip_reset")) .then(()=>Comms.uploadApp(app,"skip_reset"))
.then((appJSON) => { .then((appJSON) => {
Progress.hide({sticky:true}); Progress.hide({sticky:true});
if (appJSON) appsInstalled.push(appJSON); if (appJSON) appsInstalled.push(appJSON);
showToast(`(${appCount-apps.length}/${appCount}) ${app.name} Uploaded`); showToast(`(${appCount-apps.length}/${appCount}) ${app.name} Uploaded`);
upload(); upload();
}).catch(function() { }).catch(function() {
Progress.hide({sticky:true}); Progress.hide({sticky:true});
reject(); reject();
}); });
} }
upload(); upload();
}); });