sicksync
Version:
Don’t accept the available as the preferable. Go extra mile with extra speed.
149 lines (123 loc) • 4.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.info = exports.remove = exports.add = undefined;
var _lodash = require('lodash');
var _lodash2 = _interopRequireDefault(_lodash);
var _path = require('path');
var _prompt = require('prompt');
var _prompt2 = _interopRequireDefault(_prompt);
var _chalk = require('chalk');
var _package = require('../package.json');
var _util = require('./util');
var util = _interopRequireWildcard(_util);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const sicksyncSetup = util.setupPrompter(_prompt2.default);
function printProjectInfo(project) {
console.info((0, _chalk.green)(project.project));
_lodash2.default.forIn(project, (value, key) => {
console.info(' ', (0, _chalk.yellow)(_lodash2.default.startCase(key)), value);
});
}
const add = exports.add = config => {
const questions = {
project: {
description: 'What would you like to name this project?',
required: true,
default: _lodash2.default.last(process.cwd().split(_path.sep)),
message: 'Please enter a name for this project'
},
hostname: {
description: 'What is the hostname or IP address of the machine you\'d like to sync this to?',
required: true,
message: 'Please enter a hostname or IP address'
},
username: {
description: 'What is the username you use to shell into your remote machine?',
required: true,
default: process.env.LOGNAME || process.env.USER || process.env.LNAME || process.env.USERNAME,
message: 'Please enter a username.'
},
sourceLocation: {
description: 'What is the absolute path of the directory you would like to sync from?',
message: 'Please enter a valid path.',
default: process.cwd(),
required: true
},
destinationLocation: {
description: 'What is the absolute path of the directory you wish to sync to?',
message: 'Please enter a valid path.',
default: process.cwd(),
required: true
},
excludes: {
description: 'Are there any files you\'d like to exclude? Use a comma separated list (supports globbing)',
default: '.git,.idea,*.swp,*.svn',
before: csv => csv.split(',')
},
excludesFile: {
description: 'Would you like to load excludes from file?',
default: '.gitignore,~/.gitignore',
before: csv => csv.split(',')
},
prefersEncrypted: {
description: 'Would you like to encrypt the sync messages? (yes/no):',
before: util.toBoolean,
default: 'no'
},
websocketPort: {
description: 'What port should sicksync use for this project?',
default: 8675
},
followSymLinks: {
description: 'Should sicksync follow symlinks?',
default: 'no',
before: util.toBoolean
}
};
if (_lodash2.default.isUndefined(config.debug)) {
questions.debug = {
description: 'Would you like to see debug messages? (yes/no):',
before: util.toBoolean,
default: 'yes'
};
}
sicksyncSetup.get({
properties: questions
}, (err, result) => {
if (err) return console.info('\nLooks we had a problem setting up: ' + err);
if (_lodash2.default.isUndefined(config.debug)) {
config.debug = result.debug;
delete result.debug;
}
// Save our project in the main config
config.version = _package.version;
config.projects = config.projects || [];
config.projects.push(result);
// Write
util.writeConfig(config);
});
};
const remove = exports.remove = (config, projects) => {
const updatedConfig = _lodash2.default.clone(config);
updatedConfig.projects = _lodash2.default.filter(config.projects, projectConf => {
if (_lodash2.default.includes(projects, projectConf.project)) return false;
return true;
});
util.writeConfig(updatedConfig);
};
const info = exports.info = (config, projects) => {
if (_lodash2.default.isEmpty(config) || _lodash2.default.isEmpty(config.projects)) {
return console.info('No projects! Add some by running', (0, _chalk.green)('`sicksync add-project`'));
}
if (_lodash2.default.isEmpty(projects)) {
_lodash2.default.each(config.projects, project => {
printProjectInfo(project);
});
}
_lodash2.default.each(projects, project => {
printProjectInfo(_lodash2.default.find(config.projects, { project: project }));
});
};