1
0
Fork 0

oops - fix sanity check

master
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 = [
'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`);

View File

@ -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("<COMMS> reset: got "+JSON.stringify(result));
if (result===null) return reject("Connection failed");
@ -148,7 +148,7 @@ const Comms = {
console.log("<COMMS> 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("<COMMS> 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 */);
});
},

View File

@ -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();
});