Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
deviceId = undefined;
onOff = false;
break;
case 'all':
deviceId = undefined;
break;
}
if (deviceId) {
return cloudLib.signalDevice(deviceId, onOff)
.then(() => {
log.success(`${deviceId} is ${onOff ? 'shouting rainbows' : 'back to normal'}`);
});
}
return pipeline([
() => {
if (deviceId) {
return [deviceId];
}
return cloudLib.listDevices().then(devices => {
return _.chain(devices).filter('connected').map('id').value();
});
},
(deviceIds) => {
return when.settle(deviceIds.map(id => {
return cloudLib.signalDevice(id, onOff).catch(err => {
const errors = err && err.body && err.body.errors;
return when.reject(errors || err);
});
}));
addLibraryToProject(library) {
return pipeline([
() => this.site.addedLibrary(library.name, library.version),
() => this.projectProperties.addDependency(library.name, library.version)
]);
}
compileCode(opts) {
const downloadPath = path.resolve(opts.saveTo || `${opts.deviceType}_firmware_${Date.now()}.bin`);
return pipeline([
() => {
return whenNode.lift(fs.stat)(downloadPath).then(() => {
log.silly(`Deleting ${downloadPath} before download`);
return whenNode.lift(fs.unlink)(downloadPath);
}, () => {});
},
() => {
return ui.spin(cloudLib.compileCode(opts), 'Compiling');
},
(resp) => {
return ui.spin(cloudLib.downloadFirmwareBinary(resp.binary_id, downloadPath), `Downloading to ${downloadPath}`)
.then(() => {
log.success(`Downloaded to ${downloadPath}`);
log.info(resp.sizeInfo);
});
}
processLibrary(repo, libname, state, site, libdir) {
return resultError(pipeline([
() => repo.getLibraryLayout(libname),
(layout) => {
if (layout === 2) {
return false;
} else {
return repo.setLibraryLayout(libname, 2)
.then(() => {
if (site.isAdaptersRequired()) {
return buildAdapters(libdir, libname);
}
})
.then(() => true);
}
}
]));
}
run(state, site) {
this.site = site;
this.projectProperties = new ProjectProperties(this.site.projectDir());
const lib = site.libraryIdent();
if (lib.version === undefined) {
lib.version = 'latest';
}
return pipeline([
() => this.ensureProjectExists(),
() => this.loadProject(),
() => this.fetchLibrary(lib.name, lib.version),
(library) => this.addLibraryToProject(library),
() => this.saveProject()
]);
}
addLibraryToProject(library) {
return pipeline([
() => this.site.addedLibrary(library.name, library.version),
() => this.projectProperties.addDependency(library.name, library.version)
]);
}
listDevices(opts) {
return pipeline([
() => {
return ui.spin(cloudLib.listDevicesWithFunctionsAndVariables(opts.filter), 'Retrieving device functions and variables...');
},
(devices) => {
if (devices.length === 0) {
return log.info('No devices claimed to your account');
}
ui.render('deviceList', devices, { platformsById });
}
]).catch(UnauthorizedError, () => {
log.error('Not logged in');
});
},
processLibrary(repo, libname, state, site) {
return resultError(pipeline([
() => repo.getLibraryLayout(libname),
(layout) => {
if (layout === 2) {
return false;
} else {
return repo.setLibraryLayout(libname, 2)
.then(() => true);
}
}
]));
}
}
run(site, { name, version = 'latest' } = {}) {
this.site = site;
this.projectProperties = new ProjectProperties(this.site.projectDir());
return pipeline([
() => this.ensureProjectExists(),
() => this.loadProject(),
() => this.fetchLibrary(name, version),
(library) => this.addLibraryToProject(library),
() => this.saveProject()
]);
}