2015-08-13 18:00:23 +00:00
|
|
|
(function() {
|
2015-08-27 14:01:33 +00:00
|
|
|
var Promise, _, form, resin, visuals;
|
|
|
|
|
|
|
|
_ = require('lodash');
|
2015-08-13 18:00:23 +00:00
|
|
|
|
|
|
|
Promise = require('bluebird');
|
|
|
|
|
|
|
|
form = require('resin-cli-form');
|
|
|
|
|
2015-08-27 14:01:33 +00:00
|
|
|
visuals = require('resin-cli-visuals');
|
|
|
|
|
|
|
|
resin = require('resin-sdk');
|
|
|
|
|
2015-08-13 18:00:23 +00:00
|
|
|
exports.selectDeviceType = function() {
|
|
|
|
return form.ask({
|
|
|
|
message: 'Device Type',
|
|
|
|
type: 'list',
|
|
|
|
choices: ['Raspberry Pi', 'Raspberry Pi 2', 'BeagleBone Black']
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.confirm = function(yesOption, message) {
|
|
|
|
return Promise["try"](function() {
|
|
|
|
if (yesOption) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return form.ask({
|
|
|
|
message: message,
|
|
|
|
type: 'confirm',
|
|
|
|
"default": false
|
|
|
|
});
|
2015-08-20 20:16:20 +00:00
|
|
|
}).then(function(confirmed) {
|
|
|
|
if (!confirmed) {
|
|
|
|
throw new Error('Aborted');
|
|
|
|
}
|
2015-08-13 18:00:23 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-08-27 14:01:33 +00:00
|
|
|
exports.selectApplication = function() {
|
|
|
|
return resin.models.application.hasAny().then(function(hasAnyApplications) {
|
|
|
|
if (!hasAnyApplications) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return resin.models.application.getAll().then(function(applications) {
|
|
|
|
applications = _.pluck(applications, 'app_name');
|
|
|
|
applications.unshift({
|
|
|
|
name: 'Create a new application',
|
|
|
|
value: null
|
|
|
|
});
|
|
|
|
return form.ask({
|
|
|
|
message: 'Select an application',
|
|
|
|
type: 'list',
|
|
|
|
choices: applications
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}).then(function(application) {
|
|
|
|
if (application != null) {
|
|
|
|
return application;
|
|
|
|
}
|
|
|
|
return form.ask({
|
|
|
|
message: 'Choose a Name for your new application',
|
|
|
|
type: 'input'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.selectProjectDirectory = function() {
|
|
|
|
return resin.settings.get('projectsDirectory').then(function(projectsDirectory) {
|
|
|
|
return form.ask({
|
|
|
|
message: 'Please choose a directory for your code',
|
|
|
|
type: 'input',
|
|
|
|
"default": projectsDirectory
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.awaitDevice = function(uuid) {
|
|
|
|
var poll, spinner;
|
|
|
|
spinner = new visuals.Spinner("Awaiting device: " + uuid);
|
|
|
|
poll = function() {
|
|
|
|
return resin.models.device.isOnline(uuid).then(function(isOnline) {
|
|
|
|
if (isOnline) {
|
|
|
|
spinner.stop();
|
|
|
|
console.info("Device became online: " + uuid);
|
|
|
|
} else {
|
|
|
|
spinner.start();
|
|
|
|
return Promise.delay(3000).then(poll);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
return resin.models.device.getName(uuid).then(function(deviceName) {
|
|
|
|
console.info("Waiting for " + deviceName + " to connect to resin...");
|
|
|
|
return poll()["return"](uuid);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-08-13 18:00:23 +00:00
|
|
|
}).call(this);
|