2016-01-11 19:58:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Copyright 2016 Resin.io
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2015-08-13 18:00:23 +00:00
|
|
|
(function() {
|
2015-10-26 13:47:49 +00:00
|
|
|
var Promise, _, capitano, chalk, os, president;
|
2015-09-29 17:03:14 +00:00
|
|
|
|
|
|
|
Promise = require('bluebird');
|
2015-08-27 14:01:33 +00:00
|
|
|
|
2015-10-01 17:07:53 +00:00
|
|
|
capitano = Promise.promisifyAll(require('capitano'));
|
|
|
|
|
2015-08-27 14:01:33 +00:00
|
|
|
_ = require('lodash');
|
2015-08-13 18:00:23 +00:00
|
|
|
|
2015-08-20 19:54:42 +00:00
|
|
|
_.str = require('underscore.string');
|
2015-08-13 18:00:23 +00:00
|
|
|
|
2015-10-26 13:47:49 +00:00
|
|
|
president = Promise.promisifyAll(require('president'));
|
2015-10-26 12:34:07 +00:00
|
|
|
|
2015-08-20 19:54:42 +00:00
|
|
|
os = require('os');
|
2015-08-13 18:00:23 +00:00
|
|
|
|
2015-08-20 19:54:42 +00:00
|
|
|
chalk = require('chalk');
|
2015-08-27 14:01:33 +00:00
|
|
|
|
2015-10-19 17:38:09 +00:00
|
|
|
exports.getGroupDefaults = function(group) {
|
|
|
|
return _.chain(group).get('options').map(function(question) {
|
|
|
|
return [question.name, question["default"]];
|
|
|
|
}).object().value();
|
|
|
|
};
|
|
|
|
|
2015-08-20 19:54:42 +00:00
|
|
|
exports.stateToString = function(state) {
|
|
|
|
var percentage, result;
|
|
|
|
percentage = _.str.lpad(state.percentage, 3, '0') + '%';
|
|
|
|
result = (chalk.blue(percentage)) + " " + (chalk.cyan(state.operation.command));
|
|
|
|
switch (state.operation.command) {
|
|
|
|
case 'copy':
|
|
|
|
return result + " " + state.operation.from.path + " -> " + state.operation.to.path;
|
|
|
|
case 'replace':
|
|
|
|
return result + " " + state.operation.file.path + ", " + state.operation.copy + " -> " + state.operation.replace;
|
|
|
|
case 'run-script':
|
|
|
|
return result + " " + state.operation.script;
|
|
|
|
default:
|
|
|
|
throw new Error("Unsupported operation: " + state.operation.type);
|
|
|
|
}
|
2015-08-27 14:01:33 +00:00
|
|
|
};
|
|
|
|
|
2015-12-02 15:15:20 +00:00
|
|
|
exports.sudo = function(command, message) {
|
2015-10-01 17:07:53 +00:00
|
|
|
command = _.union(_.take(process.argv, 2), command);
|
2015-12-02 15:15:20 +00:00
|
|
|
console.log(message);
|
2015-11-12 17:30:48 +00:00
|
|
|
if (os.platform() !== 'win32') {
|
|
|
|
console.log('Type your computer password to continue');
|
|
|
|
}
|
2015-10-26 13:47:49 +00:00
|
|
|
return president.executeAsync(command);
|
2015-10-01 17:07:53 +00:00
|
|
|
};
|
|
|
|
|
2015-08-13 18:00:23 +00:00
|
|
|
}).call(this);
|