use individual methods promisification instead of promisifyAll

This commit is contained in:
Eugene Mirotin 2017-03-27 12:14:55 +03:00
parent 6cf32e445a
commit 08b3db717e
22 changed files with 135 additions and 127 deletions

View File

@ -49,10 +49,9 @@ exports.login = {
],
primary: true,
action: function(params, options, done) {
var Promise, _, auth, capitano, form, login, messages, patterns, resin;
var Promise, _, auth, form, login, messages, patterns, resin;
_ = require('lodash');
Promise = require('bluebird');
capitano = Promise.promisifyAll(require('capitano'));
resin = require('resin-sdk-preconfigured');
auth = require('resin-cli-auth');
form = require('resin-cli-form');
@ -77,8 +76,10 @@ exports.login = {
return auth.login();
}
return patterns.askLoginType().then(function(loginType) {
var capitanoRunAsync;
if (loginType === 'register') {
return capitano.runAsync('signup');
capitanoRunAsync = Promise.promisify(require('capitano').run);
return capitanoRunAsync('signup');
}
options[loginType] = true;
return login(options);

View File

@ -40,15 +40,15 @@ exports.read = {
permission: 'user',
root: true,
action: function(params, options, done) {
var Promise, config, prettyjson, umount, visuals;
var Promise, config, prettyjson, umountAsync, visuals;
Promise = require('bluebird');
config = require('resin-config-json');
visuals = require('resin-cli-visuals');
umount = Promise.promisifyAll(require('umount'));
umountAsync = Promise.promisify(require('umount').umount);
prettyjson = require('prettyjson');
return Promise["try"](function() {
return options.drive || visuals.drive('Select the device drive');
}).tap(umount.umountAsync).then(function(drive) {
}).tap(umountAsync).then(function(drive) {
return config.read(drive, options.type);
}).tap(function(configJSON) {
return console.info(prettyjson.render(configJSON));
@ -77,21 +77,21 @@ exports.write = {
permission: 'user',
root: true,
action: function(params, options, done) {
var Promise, _, config, umount, visuals;
var Promise, _, config, umountAsync, visuals;
Promise = require('bluebird');
_ = require('lodash');
config = require('resin-config-json');
visuals = require('resin-cli-visuals');
umount = Promise.promisifyAll(require('umount'));
umountAsync = Promise.promisify(require('umount').umount);
return Promise["try"](function() {
return options.drive || visuals.drive('Select the device drive');
}).tap(umount.umountAsync).then(function(drive) {
}).tap(umountAsync).then(function(drive) {
return config.read(drive, options.type).then(function(configJSON) {
console.info("Setting " + params.key + " to " + params.value);
_.set(configJSON, params.key, params.value);
return configJSON;
}).tap(function() {
return umount.umountAsync(drive);
return umountAsync(drive);
}).then(function(configJSON) {
return config.write(drive, options.type, configJSON);
});
@ -122,16 +122,16 @@ exports.inject = {
permission: 'user',
root: true,
action: function(params, options, done) {
var Promise, config, fs, umount, visuals;
var Promise, config, readFileAsync, umountAsync, visuals;
Promise = require('bluebird');
config = require('resin-config-json');
visuals = require('resin-cli-visuals');
umount = Promise.promisifyAll(require('umount'));
fs = Promise.promisifyAll(require('fs'));
umountAsync = Promise.promisify(require('umount').umount);
readFileAsync = Promise.promisify(require('fs').readFile);
return Promise["try"](function() {
return options.drive || visuals.drive('Select the device drive');
}).tap(umount.umountAsync).then(function(drive) {
return fs.readFileAsync(params.file, 'utf8').then(JSON.parse).then(function(configJSON) {
}).tap(umountAsync).then(function(drive) {
return readFileAsync(params.file, 'utf8').then(JSON.parse).then(function(configJSON) {
return config.write(drive, options.type, configJSON);
});
}).tap(function() {
@ -166,24 +166,24 @@ exports.reconfigure = {
permission: 'user',
root: true,
action: function(params, options, done) {
var Promise, capitano, config, umount, visuals;
var Promise, capitanoRunAsync, config, umountAsync, visuals;
Promise = require('bluebird');
config = require('resin-config-json');
visuals = require('resin-cli-visuals');
capitano = Promise.promisifyAll(require('capitano'));
umount = Promise.promisifyAll(require('umount'));
capitanoRunAsync = Promise.promisify(require('capitano').run);
umountAsync = Promise.promisify(require('umount').umount);
return Promise["try"](function() {
return options.drive || visuals.drive('Select the device drive');
}).tap(umount.umountAsync).then(function(drive) {
}).tap(umountAsync).then(function(drive) {
return config.read(drive, options.type).get('uuid').tap(function() {
return umount.umountAsync(drive);
return umountAsync(drive);
}).then(function(uuid) {
var configureCommand;
configureCommand = "os configure " + drive + " " + uuid;
if (options.advanced) {
configureCommand += ' --advanced';
}
return capitano.runAsync(configureCommand);
return capitanoRunAsync(configureCommand);
});
}).then(function() {
return console.info('Done');
@ -205,9 +205,9 @@ exports.generate = {
],
permission: 'user',
action: function(params, options, done) {
var Promise, _, deviceConfig, form, fs, prettyjson, resin;
var Promise, _, deviceConfig, form, prettyjson, resin, writeFileAsync;
Promise = require('bluebird');
fs = Promise.promisifyAll(require('fs'));
writeFileAsync = Promise.promisify(require('fs').writeFile);
resin = require('resin-sdk-preconfigured');
_ = require('lodash');
form = require('resin-cli-form');
@ -230,7 +230,7 @@ exports.generate = {
});
}).then(function(config) {
if (options.output != null) {
return fs.writeFileAsync(options.output, JSON.stringify(config));
return writeFileAsync(options.output, JSON.stringify(config));
}
return console.log(prettyjson.render(config));
}).nodeify(done);

View File

@ -274,11 +274,12 @@ exports.init = {
],
permission: 'user',
action: function(params, options, done) {
var Promise, capitano, helpers, patterns, resin, rimraf, tmp;
var Promise, capitanoRunAsync, helpers, patterns, resin, rimraf, tmp, tmpNameAsync;
Promise = require('bluebird');
capitano = Promise.promisifyAll(require('capitano'));
capitanoRunAsync = Promise.promisify(require('capitano').run);
rimraf = Promise.promisify(require('rimraf'));
tmp = Promise.promisifyAll(require('tmp'));
tmp = require('tmp');
tmpNameAsync = Promise.promisify(tmp.tmpName);
tmp.setGracefulCleanup();
resin = require('resin-sdk-preconfigured');
helpers = require('../utils/helpers');
@ -291,23 +292,23 @@ exports.init = {
}).then(resin.models.application.get).then(function(application) {
var download;
download = function() {
return tmp.tmpNameAsync().then(function(tempPath) {
return capitano.runAsync("os download " + application.device_type + " --output '" + tempPath + "' --version default");
return tmpNameAsync().then(function(tempPath) {
return capitanoRunAsync("os download " + application.device_type + " --output '" + tempPath + "' --version default");
}).disposer(function(tempPath) {
return rimraf(tempPath);
});
};
return Promise.using(download(), function(tempPath) {
return capitano.runAsync("device register " + application.app_name).then(resin.models.device.get).tap(function(device) {
return capitanoRunAsync("device register " + application.app_name).then(resin.models.device.get).tap(function(device) {
var configureCommand;
configureCommand = "os configure '" + tempPath + "' " + device.uuid;
if (options.advanced) {
configureCommand += ' --advanced';
}
return capitano.runAsync(configureCommand).then(function() {
return capitanoRunAsync(configureCommand).then(function() {
var osInitCommand;
osInitCommand = "os initialize '" + tempPath + "' --type " + application.device_type;
return capitano.runAsync(osInitCommand);
return capitanoRunAsync(osInitCommand);
})["catch"](function(error) {
return resin.models.device.remove(device.uuid)["finally"](function() {
throw error;

View File

@ -72,15 +72,15 @@ exports.add = {
help: 'Use this command to associate a new SSH key with your account.\n\nIf `path` is omitted, the command will attempt\nto read the SSH key from stdin.\n\nExamples:\n\n $ resin key add Main ~/.ssh/id_rsa.pub\n $ cat ~/.ssh/id_rsa.pub | resin key add Main',
permission: 'user',
action: function(params, options, done) {
var Promise, _, capitano, fs, resin;
var Promise, _, capitano, readFileAsync, resin;
_ = require('lodash');
Promise = require('bluebird');
fs = Promise.promisifyAll(require('fs'));
readFileAsync = Promise.promisify(require('fs').readFile);
capitano = require('capitano');
resin = require('resin-sdk-preconfigured');
return Promise["try"](function() {
if (params.path != null) {
return fs.readFileAsync(params.path, {
return readFileAsync(params.path, {
encoding: 'utf8'
});
}

View File

@ -66,18 +66,20 @@ module.exports = {
help: 'Use this command to configure or reconfigure a resinOS drive or image.\n\nExamples:\n\n $ resin local configure /dev/sdc\n $ resin local configure path/to/image.img',
root: true,
action: function(params, options, done) {
var Promise, _, denymount, inquirer, reconfix, umount;
var Promise, _, denymount, inquirer, isMountedAsync, reconfix, umount, umountAsync;
_ = require('lodash');
Promise = require('bluebird');
umount = Promise.promisifyAll(require('umount'));
umount = require('umount');
umountAsync = Promise.promisify(umount.umount);
isMountedAsync = Promise.promisify(umount.isMounted);
inquirer = require('inquirer');
reconfix = require('reconfix');
denymount = Promise.promisify(require('denymount'));
return umount.isMountedAsync(params.target).then(function(isMounted) {
return isMountedAsync(params.target).then(function(isMounted) {
if (!isMounted) {
return;
}
return umount.umountAsync(params.target);
return umountAsync(params.target);
}).then(function() {
return denymount(params.target, function(cb) {
return reconfix.readConfiguration(CONFIGURATION_SCHEMA, params.target).then(function(data) {

View File

@ -34,13 +34,13 @@ module.exports = {
],
root: true,
action: function(params, options, done) {
var Promise, _, chalk, drivelist, form, fs, imageWrite, os, umount, visuals;
var Promise, _, chalk, driveListAsync, form, fs, imageWrite, os, umountAsync, visuals;
_ = require('lodash');
os = require('os');
Promise = require('bluebird');
umount = Promise.promisifyAll(require('umount'));
umountAsync = Promise.promisify(require('umount').umount);
fs = Promise.promisifyAll(require('fs'));
drivelist = Promise.promisifyAll(require('drivelist'));
driveListAsync = Promise.promisify(require('drivelist').list);
chalk = require('chalk');
visuals = require('resin-cli-visuals');
form = require('resin-cli-form');
@ -71,7 +71,7 @@ module.exports = {
console.log(chalk.red.bold('Aborted image flash'));
process.exit(0);
}
return drivelist.listAsync().then(function(drives) {
return driveListAsync().then(function(drives) {
var selectedDrive;
selectedDrive = _.find(drives, {
device: answers.drive
@ -87,7 +87,7 @@ module.exports = {
write: new visuals.Progress('Flashing'),
check: new visuals.Progress('Validating')
};
return umount.umountAsync(selectedDrive.device).then(function() {
return umountAsync(selectedDrive.device).then(function() {
return Promise.props({
imageSize: fs.statAsync(params.image).get('size'),
imageStream: Promise.resolve(fs.createReadStream(params.image)),
@ -113,12 +113,12 @@ module.exports = {
return writer.on('done', resolve);
});
}).then(function() {
var removedrive;
var ejectAsync;
if ((os.platform() === 'win32') && (selectedDrive.mountpoint != null)) {
removedrive = Promise.promisifyAll(require('removedrive'));
return removedrive.ejectAsync(selectedDrive.mountpoint);
ejectAsync = Promise.promisify(require('removedrive').eject);
return ejectAsync(selectedDrive.mountpoint);
}
return umount.umountAsync(selectedDrive.device);
return umountAsync(selectedDrive.device);
});
}).asCallback(done);
}

View File

@ -185,9 +185,9 @@ exports.initialize = {
}
],
action: function(params, options, done) {
var Promise, form, helpers, patterns, umount;
var Promise, form, helpers, patterns, umountAsync;
Promise = require('bluebird');
umount = Promise.promisifyAll(require('umount'));
umountAsync = Promise.promisify(require('umount').umount);
form = require('resin-cli-form');
patterns = require('../utils/patterns');
helpers = require('../utils/helpers');
@ -207,14 +207,14 @@ exports.initialize = {
return;
}
message = "This will erase " + answers.drive + ". Are you sure?";
return patterns.confirm(options.yes, message)["return"](answers.drive).then(umount.umountAsync);
return patterns.confirm(options.yes, message)["return"](answers.drive).then(umountAsync);
}).tap(function(answers) {
return helpers.sudo(['internal', 'osinit', params.image, options.type, JSON.stringify(answers)]);
}).then(function(answers) {
if (answers.drive == null) {
return;
}
return umount.umountAsync(answers.drive).tap(function() {
return umountAsync(answers.drive).tap(function() {
return console.info("You can safely remove " + answers.drive + " now");
});
}).nodeify(done);

View File

@ -21,9 +21,9 @@ exports.wizard = {
help: 'Use this command to run a friendly wizard to get started with resin.io.\n\nThe wizard will guide you through:\n\n - Create an application.\n - Initialise an SDCard with the resin.io operating system.\n - Associate an existing project directory with your resin.io application.\n - Push your project to your devices.\n\nExamples:\n\n $ resin quickstart\n $ resin quickstart MyApp',
primary: true,
action: function(params, options, done) {
var Promise, capitano, patterns, resin;
var Promise, capitanoRunAsync, patterns, resin;
Promise = require('bluebird');
capitano = Promise.promisifyAll(require('capitano'));
capitanoRunAsync = Promise.promisify(require('capitano').run);
resin = require('resin-sdk-preconfigured');
patterns = require('../utils/patterns');
return resin.auth.isLoggedIn().then(function(isLoggedIn) {
@ -32,7 +32,7 @@ exports.wizard = {
}
console.info('Looks like you\'re not logged in yet!');
console.info('Lets go through a quick wizard to get you started.\n');
return capitano.runAsync('login');
return capitanoRunAsync('login');
}).then(function() {
if (params.name != null) {
return;
@ -42,15 +42,15 @@ exports.wizard = {
if (hasApplication) {
return applicationName;
}
return capitano.runAsync("app create " + applicationName);
return capitanoRunAsync("app create " + applicationName);
});
}).then(function(applicationName) {
return params.name = applicationName;
});
}).then(function() {
return capitano.runAsync("device init --application " + params.name);
return capitanoRunAsync("device init --application " + params.name);
}).tap(patterns.awaitDevice).then(function(uuid) {
return capitano.runAsync("device " + uuid);
return capitanoRunAsync("device " + uuid);
}).then(function() {
return resin.models.application.get(params.name);
}).then(function(application) {

View File

@ -15,7 +15,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var Promise, Raven, _, actions, capitano, errors, events, plugins, resin, update;
var Promise, Raven, _, actions, capitano, capitanoExecuteAsync, errors, events, plugins, resin, update;
Raven = require('raven');
@ -30,7 +30,9 @@ _ = require('lodash');
Promise = require('bluebird');
capitano = Promise.promisifyAll(require('capitano'));
capitano = require('capitano');
capitanoExecuteAsync = Promise.promisify(capitano.execute);
resin = require('resin-sdk-preconfigured');
@ -189,10 +191,10 @@ plugins.register(/^resin-plugin-(.+)$/).then(function() {
return events.trackCommand(cli).then(function() {
var ref, ref1;
if ((ref = cli.global) != null ? ref.help : void 0) {
return capitano.executeAsync({
return capitanoExecuteAsync({
command: "help " + ((ref1 = cli.command) != null ? ref1 : '')
});
}
return capitano.executeAsync(cli);
return capitanoExecuteAsync(cli);
});
})["catch"](errors.handle);

View File

@ -1,5 +1,5 @@
// Generated by CoffeeScript 1.12.4
var Mixpanel, Promise, _, capitanoState, packageJSON, resin;
var Mixpanel, Promise, _, packageJSON, resin;
_ = require('lodash');
@ -9,8 +9,6 @@ Promise = require('bluebird');
resin = require('resin-sdk-preconfigured');
capitanoState = Promise.promisifyAll(require('capitano').state);
packageJSON = require('../package.json');
exports.getLoggerInstance = _.memoize(function() {
@ -18,12 +16,14 @@ exports.getLoggerInstance = _.memoize(function() {
});
exports.trackCommand = function(capitanoCommand) {
var capitanoStateGetMatchCommandAsync;
capitanoStateGetMatchCommandAsync = Promise.promisify(require('capitano').state.getMatchCommand);
return Promise.props({
resinUrl: resin.settings.get('resinUrl'),
username: resin.auth.whoami(),
mixpanel: exports.getLoggerInstance()
}).then(function(data) {
return capitanoState.getMatchCommandAsync(capitanoCommand.command).then(function(command) {
return capitanoStateGetMatchCommandAsync(capitanoCommand.command).then(function(command) {
return data.mixpanel.track("[CLI] " + (command.signature.toString()), {
distinct_id: data.username,
argv: process.argv.join(' '),

View File

@ -15,14 +15,10 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var Promise, capitano, president;
var Promise;
Promise = require('bluebird');
capitano = Promise.promisifyAll(require('capitano'));
president = Promise.promisifyAll(require('president'));
exports.getGroupDefaults = function(group) {
var _;
_ = require('lodash');
@ -50,14 +46,15 @@ exports.stateToString = function(state) {
};
exports.sudo = function(command) {
var _, os;
var _, os, presidentExecuteAsync;
_ = require('lodash');
os = require('os');
if (os.platform() !== 'win32') {
console.log('If asked please type your computer password to continue');
}
command = _.union(_.take(process.argv, 2), command);
return president.executeAsync(command);
presidentExecuteAsync = Promise.promisify(require('president').execute);
return presidentExecuteAsync(command);
};
exports.getManifest = function(image, deviceType) {

View File

@ -73,7 +73,6 @@ exports.login =
action: (params, options, done) ->
_ = require('lodash')
Promise = require('bluebird')
capitano = Promise.promisifyAll(require('capitano'))
resin = require('resin-sdk-preconfigured')
auth = require('resin-cli-auth')
form = require('resin-cli-form')
@ -98,7 +97,8 @@ exports.login =
return patterns.askLoginType().then (loginType) ->
if loginType is 'register'
return capitano.runAsync('signup')
capitanoRunAsync = Promise.promisify(require('capitano').run)
return capitanoRunAsync('signup')
options[loginType] = true
return login(options)

View File

@ -48,12 +48,12 @@ exports.read =
Promise = require('bluebird')
config = require('resin-config-json')
visuals = require('resin-cli-visuals')
umount = Promise.promisifyAll(require('umount'))
umountAsync = Promise.promisify(require('umount').umount)
prettyjson = require('prettyjson')
Promise.try ->
return options.drive or visuals.drive('Select the device drive')
.tap(umount.umountAsync)
.tap(umountAsync)
.then (drive) ->
return config.read(drive, options.type)
.tap (configJSON) ->
@ -94,18 +94,18 @@ exports.write =
_ = require('lodash')
config = require('resin-config-json')
visuals = require('resin-cli-visuals')
umount = Promise.promisifyAll(require('umount'))
umountAsync = Promise.promisify(require('umount').umount)
Promise.try ->
return options.drive or visuals.drive('Select the device drive')
.tap(umount.umountAsync)
.tap(umountAsync)
.then (drive) ->
config.read(drive, options.type).then (configJSON) ->
console.info("Setting #{params.key} to #{params.value}")
_.set(configJSON, params.key, params.value)
return configJSON
.tap ->
return umount.umountAsync(drive)
return umountAsync(drive)
.then (configJSON) ->
return config.write(drive, options.type, configJSON)
.tap ->
@ -144,14 +144,14 @@ exports.inject =
Promise = require('bluebird')
config = require('resin-config-json')
visuals = require('resin-cli-visuals')
umount = Promise.promisifyAll(require('umount'))
fs = Promise.promisifyAll(require('fs'))
umountAsync = Promise.promisify(require('umount').umount)
readFileAsync = Promise.promisify(require('fs').readFile)
Promise.try ->
return options.drive or visuals.drive('Select the device drive')
.tap(umount.umountAsync)
.tap(umountAsync)
.then (drive) ->
fs.readFileAsync(params.file, 'utf8').then(JSON.parse).then (configJSON) ->
readFileAsync(params.file, 'utf8').then(JSON.parse).then (configJSON) ->
return config.write(drive, options.type, configJSON)
.tap ->
console.info('Done')
@ -196,21 +196,21 @@ exports.reconfigure =
Promise = require('bluebird')
config = require('resin-config-json')
visuals = require('resin-cli-visuals')
capitano = Promise.promisifyAll(require('capitano'))
umount = Promise.promisifyAll(require('umount'))
capitanoRunAsync = Promise.promisify(require('capitano').run)
umountAsync = Promise.promisify(require('umount').umount)
Promise.try ->
return options.drive or visuals.drive('Select the device drive')
.tap(umount.umountAsync)
.tap(umountAsync)
.then (drive) ->
config.read(drive, options.type).get('uuid')
.tap ->
umount.umountAsync(drive)
umountAsync(drive)
.then (uuid) ->
configureCommand = "os configure #{drive} #{uuid}"
if options.advanced
configureCommand += ' --advanced'
return capitano.runAsync(configureCommand)
return capitanoRunAsync(configureCommand)
.then ->
console.info('Done')
.nodeify(done)
@ -241,7 +241,7 @@ exports.generate =
permission: 'user'
action: (params, options, done) ->
Promise = require('bluebird')
fs = Promise.promisifyAll(require('fs'))
writeFileAsync = Promise.promisify(require('fs').writeFile)
resin = require('resin-sdk-preconfigured')
_ = require('lodash')
form = require('resin-cli-form')
@ -271,7 +271,7 @@ exports.generate =
return deviceConfig.getByApplication(resource.app_name, answers)
.then (config) ->
if options.output?
return fs.writeFileAsync(options.output, JSON.stringify(config))
return writeFileAsync(options.output, JSON.stringify(config))
console.log(prettyjson.render(config))
.nodeify(done)

View File

@ -376,9 +376,10 @@ exports.init =
permission: 'user'
action: (params, options, done) ->
Promise = require('bluebird')
capitano = Promise.promisifyAll(require('capitano'))
capitanoRunAsync = Promise.promisify(require('capitano').run)
rimraf = Promise.promisify(require('rimraf'))
tmp = Promise.promisifyAll(require('tmp'))
tmp = require('tmp')
tmpNameAsync = Promise.promisify(tmp.tmpName)
tmp.setGracefulCleanup()
resin = require('resin-sdk-preconfigured')
@ -392,23 +393,23 @@ exports.init =
.then (application) ->
download = ->
tmp.tmpNameAsync().then (tempPath) ->
tmpNameAsync().then (tempPath) ->
# TODO: allow version selection
capitano.runAsync("os download #{application.device_type} --output '#{tempPath}' --version default")
capitanoRunAsync("os download #{application.device_type} --output '#{tempPath}' --version default")
.disposer (tempPath) ->
return rimraf(tempPath)
Promise.using download(), (tempPath) ->
capitano.runAsync("device register #{application.app_name}")
capitanoRunAsync("device register #{application.app_name}")
.then(resin.models.device.get)
.tap (device) ->
configureCommand = "os configure '#{tempPath}' #{device.uuid}"
if options.advanced
configureCommand += ' --advanced'
capitano.runAsync(configureCommand)
capitanoRunAsync(configureCommand)
.then ->
osInitCommand = "os initialize '#{tempPath}' --type #{application.device_type}"
capitano.runAsync(osInitCommand)
capitanoRunAsync(osInitCommand)
# Make sure the device resource is removed if there is an
# error when configuring or initializing a device image
.catch (error) ->

View File

@ -107,13 +107,14 @@ exports.add =
action: (params, options, done) ->
_ = require('lodash')
Promise = require('bluebird')
fs = Promise.promisifyAll(require('fs'))
readFileAsync = Promise.promisify(require('fs').readFile)
capitano = require('capitano')
resin = require('resin-sdk-preconfigured')
Promise.try ->
return fs.readFileAsync(params.path, encoding: 'utf8') if params.path?
return readFileAsync(params.path, encoding: 'utf8') if params.path?
# TODO: should this be promisified for consistency?
Promise.fromNode (callback) ->
capitano.utils.getStdin (data) ->
return callback(null, data)

View File

@ -67,14 +67,16 @@ module.exports =
action: (params, options, done) ->
_ = require('lodash')
Promise = require('bluebird')
umount = Promise.promisifyAll(require('umount'))
umount = require('umount')
umountAsync = Promise.promisify(umount.umount)
isMountedAsync = Promise.promisify(umount.isMounted)
inquirer = require('inquirer')
reconfix = require('reconfix')
denymount = Promise.promisify(require('denymount'))
umount.isMountedAsync(params.target).then (isMounted) ->
isMountedAsync(params.target).then (isMounted) ->
return if not isMounted
umount.umountAsync(params.target)
umountAsync(params.target)
.then ->
denymount params.target, (cb) ->
reconfix.readConfiguration(CONFIGURATION_SCHEMA, params.target).then (data) ->

View File

@ -43,15 +43,15 @@ module.exports =
_ = require('lodash')
os = require('os')
Promise = require('bluebird')
umount = Promise.promisifyAll(require('umount'))
umountAsync = Promise.promisify(require('umount').umount)
fs = Promise.promisifyAll(require('fs'))
drivelist = Promise.promisifyAll(require('drivelist'))
driveListAsync = Promise.promisify(require('drivelist').list)
chalk = require('chalk')
visuals = require('resin-cli-visuals')
form = require('resin-cli-form')
# XXX: Find a better ES6 module loading story/contract between resin.io modules
# TODO: Find a better ES6 module loading story/contract between resin.io modules
require('babel-register')({
only: /etcher-image-write|bmapflash/
presets: ['es2015']
@ -84,7 +84,7 @@ module.exports =
console.log(chalk.red.bold('Aborted image flash'))
process.exit(0)
drivelist.listAsync().then (drives) ->
driveListAsync().then (drives) ->
selectedDrive = _.find(drives, device: answers.drive)
if not selectedDrive?
@ -96,7 +96,7 @@ module.exports =
write: new visuals.Progress('Flashing')
check: new visuals.Progress('Validating')
umount.umountAsync(selectedDrive.device).then ->
umountAsync(selectedDrive.device).then ->
Promise.props
imageSize: fs.statAsync(params.image).get('size'),
imageStream: Promise.resolve(fs.createReadStream(params.image))
@ -119,8 +119,8 @@ module.exports =
writer.on('done', resolve)
.then ->
if (os.platform() is 'win32') and selectedDrive.mountpoint?
removedrive = Promise.promisifyAll(require('removedrive'))
return removedrive.ejectAsync(selectedDrive.mountpoint)
ejectAsync = Promise.promisify(require('removedrive').eject)
return ejectAsync(selectedDrive.mountpoint)
return umount.umountAsync(selectedDrive.device)
return umountAsync(selectedDrive.device)
.asCallback(done)

View File

@ -212,7 +212,7 @@ exports.initialize =
]
action: (params, options, done) ->
Promise = require('bluebird')
umount = Promise.promisifyAll(require('umount'))
umountAsync = Promise.promisify(require('umount').umount)
form = require('resin-cli-form')
patterns = require('../utils/patterns')
helpers = require('../utils/helpers')
@ -234,7 +234,7 @@ exports.initialize =
message = "This will erase #{answers.drive}. Are you sure?"
patterns.confirm(options.yes, message)
.return(answers.drive)
.then(umount.umountAsync)
.then(umountAsync)
.tap (answers) ->
return helpers.sudo([
'internal'
@ -245,6 +245,6 @@ exports.initialize =
])
.then (answers) ->
return if not answers.drive?
umount.umountAsync(answers.drive).tap ->
umountAsync(answers.drive).tap ->
console.info("You can safely remove #{answers.drive} now")
.nodeify(done)

View File

@ -35,7 +35,7 @@ exports.wizard =
primary: true
action: (params, options, done) ->
Promise = require('bluebird')
capitano = Promise.promisifyAll(require('capitano'))
capitanoRunAsync = Promise.promisify(require('capitano').run)
resin = require('resin-sdk-preconfigured')
patterns = require('../utils/patterns')
@ -43,20 +43,20 @@ exports.wizard =
return if isLoggedIn
console.info('Looks like you\'re not logged in yet!')
console.info('Lets go through a quick wizard to get you started.\n')
return capitano.runAsync('login')
return capitanoRunAsync('login')
.then ->
return if params.name?
patterns.selectOrCreateApplication().tap (applicationName) ->
resin.models.application.has(applicationName).then (hasApplication) ->
return applicationName if hasApplication
capitano.runAsync("app create #{applicationName}")
capitanoRunAsync("app create #{applicationName}")
.then (applicationName) ->
params.name = applicationName
.then ->
return capitano.runAsync("device init --application #{params.name}")
return capitanoRunAsync("device init --application #{params.name}")
.tap(patterns.awaitDevice)
.then (uuid) ->
return capitano.runAsync("device #{uuid}")
return capitanoRunAsync("device #{uuid}")
.then ->
return resin.models.application.get(params.name)
.then (application) ->

View File

@ -24,7 +24,8 @@ Raven.config(
_ = require('lodash')
Promise = require('bluebird')
capitano = Promise.promisifyAll(require('capitano'))
capitano = require('capitano')
capitanoExecuteAsync = Promise.promisify(capitano.execute)
resin = require('resin-sdk-preconfigured')
actions = require('./actions')
errors = require('./errors')
@ -152,7 +153,7 @@ plugins.register(/^resin-plugin-(.+)$/).then ->
events.trackCommand(cli).then ->
if cli.global?.help
return capitano.executeAsync(command: "help #{cli.command ? ''}")
capitano.executeAsync(cli)
return capitanoExecuteAsync(command: "help #{cli.command ? ''}")
capitanoExecuteAsync(cli)
.catch(errors.handle)

View File

@ -2,19 +2,20 @@ _ = require('lodash')
Mixpanel = require('mixpanel')
Promise = require('bluebird')
resin = require('resin-sdk-preconfigured')
capitanoState = Promise.promisifyAll(require('capitano').state)
packageJSON = require('../package.json')
exports.getLoggerInstance = _.memoize ->
return resin.models.config.getMixpanelToken().then(Mixpanel.init)
exports.trackCommand = (capitanoCommand) ->
capitanoStateGetMatchCommandAsync = Promise.promisify(require('capitano').state.getMatchCommand)
return Promise.props
resinUrl: resin.settings.get('resinUrl')
username: resin.auth.whoami()
mixpanel: exports.getLoggerInstance()
.then (data) ->
return capitanoState.getMatchCommandAsync(capitanoCommand.command).then (command) ->
return capitanoStateGetMatchCommandAsync(capitanoCommand.command).then (command) ->
data.mixpanel.track "[CLI] #{command.signature.toString()}",
distinct_id: data.username
argv: process.argv.join(' ')

View File

@ -15,8 +15,6 @@ limitations under the License.
###
Promise = require('bluebird')
capitano = Promise.promisifyAll(require('capitano'))
president = Promise.promisifyAll(require('president'))
exports.getGroupDefaults = (group) ->
_ = require('lodash')
@ -53,7 +51,8 @@ exports.sudo = (command) ->
console.log('If asked please type your computer password to continue')
command = _.union(_.take(process.argv, 2), command)
return president.executeAsync(command)
presidentExecuteAsync = Promise.promisify(require('president').execute)
return presidentExecuteAsync(command)
exports.getManifest = (image, deviceType) ->
rindle = require('rindle')