Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exit 1 in case of CLI error #209

Merged
merged 7 commits into from
Mar 15, 2016
5 changes: 3 additions & 2 deletions cli/facade/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var npmInstaller = require('../domain/npm-installer');
var oc = require('../../index');
var strings = require('../../resources/index');
var watch = require('../domain/watch');
var wrapCliCallback = require('../wrap-cli-callback');

module.exports = function(dependencies){
var local = dependencies.local,
Expand All @@ -26,13 +27,13 @@ module.exports = function(dependencies){

return function(opts, callback){

callback = callback || _.noop;

var componentsDir = opts.dirName,
port = opts.port || 3000,
baseUrl = opts.baseUrl || format('http://localhost:{0}/', port),
packaging = false,
errors = strings.errors.cli;

callback = wrapCliCallback(callback);

var installMissingDeps = function(missing, cb){
if(_.isEmpty(missing)){ return cb(); }
Expand Down
8 changes: 4 additions & 4 deletions cli/facade/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

var colors = require('colors/safe');
var format = require('stringformat');
var _ = require('underscore');

var strings = require('../../resources/index');
var wrapCliCallback = require('../wrap-cli-callback');

module.exports = function(dependencies){

Expand All @@ -13,12 +13,12 @@ module.exports = function(dependencies){

return function(opts, callback){

callback = callback || _.noop;

var componentName = opts.componentName,
templateType = opts.templateType,
errors = strings.errors.cli;

callback = wrapCliCallback(callback);

local.init(componentName, templateType, function(err, res){
if(err){
if(err === 'name not valid'){
Expand All @@ -33,7 +33,7 @@ module.exports = function(dependencies){
} else {
logger.log(colors.green(format(strings.messages.cli.COMPONENT_INITED, componentName)));
}

callback(err, componentName);
});
};
Expand Down
4 changes: 2 additions & 2 deletions cli/facade/mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

var colors = require('colors/safe');
var format = require('stringformat');
var _ = require('underscore');

var strings = require('../../resources/index');
var wrapCliCallback = require('../wrap-cli-callback');

module.exports = function(dependencies){

Expand All @@ -13,7 +13,7 @@ module.exports = function(dependencies){

return function(opts, callback){

callback = callback || _.noop;
callback = wrapCliCallback(callback);

local.mock(opts, function(err, res){
logger.log(colors.green(format(strings.messages.cli.MOCKED_PLUGIN, opts.targetName, opts.targetValue)));
Expand Down
4 changes: 2 additions & 2 deletions cli/facade/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

var colors = require('colors/safe');
var opn = require('opn');
var _ = require('underscore');

var strings = require('../../resources/index');
var wrapCliCallback = require('../wrap-cli-callback');

module.exports = function(dependencies){

Expand All @@ -13,7 +13,7 @@ module.exports = function(dependencies){

return function(opts, callback){

callback = callback || _.noop;
callback = wrapCliCallback(callback);

registry.getComponentPreviewUrlByUrl(opts.componentHref, function(err, href){
if(err){
Expand Down
5 changes: 3 additions & 2 deletions cli/facade/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var semver = require('semver');
var _ = require('underscore');

var strings = require('../../resources/index');
var wrapCliCallback = require('../wrap-cli-callback');

module.exports = function(dependencies){

Expand All @@ -24,13 +25,13 @@ module.exports = function(dependencies){

return function(opts, callback){

callback = callback || _.noop;

var componentPath = opts.componentPath,
packageDir = path.resolve(componentPath, '_package'),
compressedPackagePath = path.resolve(componentPath, 'package.tar.gz'),
errorMessage;

callback = wrapCliCallback(callback);

var getCredentials = function(cb){
if(opts.username && opts.password){
log.ok(strings.messages.cli.USING_CREDS);
Expand Down
3 changes: 2 additions & 1 deletion cli/facade/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var format = require('stringformat');
var _ = require('underscore');

var strings = require('../../resources/index');
var wrapCliCallback = require('../wrap-cli-callback');

module.exports = function(dependencies){

Expand All @@ -19,7 +20,7 @@ module.exports = function(dependencies){

return function(opts, callback){

callback = callback || _.noop;
callback = wrapCliCallback(callback);

if(opts.command === 'ls'){
registry.get(function(err, registries){
Expand Down
15 changes: 15 additions & 0 deletions cli/wrap-cli-callback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

var _ = require('underscore');

module.exports = function(callback){
if(_.isFunction(callback)){
return callback;
}

return function(error){
if(!!error){
return process.exit(1);
}
};
};
2 changes: 1 addition & 1 deletion test/unit/cli-facade-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('cli : facade : dev', function(){
var execute = function(dirName, port){
logSpy.logNoNewLine = sinon.spy();
logSpy.log = sinon.spy();
devFacade({ dirName: dirName, port: port });
devFacade({ dirName: dirName, port: port }, function(){});
};

describe('when running a dev version of the registry', function(){
Expand Down
2 changes: 1 addition & 1 deletion test/unit/cli-facade-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('cli : facade : init', function(){

var execute = function(componentName, templateType){
logSpy.log = sinon.spy();
initFacade({ componentName: componentName, templateType: templateType });
initFacade({ componentName: componentName, templateType: templateType }, function(){});
};

describe('when initialising a new component', function(){
Expand Down
2 changes: 1 addition & 1 deletion test/unit/cli-facade-mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('cli : facade : mock', function(){

var execute = function(){
logSpy.log = sinon.spy();
mockFacade({ targetType: 'plugin', targetName: 'getValue', targetValue: 'value' });
mockFacade({ targetType: 'plugin', targetName: 'getValue', targetValue: 'value' }, function(){});
};

describe('when mocking plugin', function(){
Expand Down
2 changes: 1 addition & 1 deletion test/unit/cli-facade-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('cli : facade : preview', function(){
var PreviewFacade = injectr('../../cli/facade/preview.js', { opn: opnSpy }),
previewFacade = new PreviewFacade({ logger: logSpy, registry: registryStub });

previewFacade({ componentHref: 'http://components.com/component' });
previewFacade({ componentHref: 'http://components.com/component' }, function(){});
};

describe('when previewing not valid component', function(){
Expand Down
6 changes: 5 additions & 1 deletion test/unit/cli-facade-publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ describe('cli : facade : publish', function(){
var execute = function(creds){
creds = creds || {};
logSpy.log = sinon.stub();
publishFacade({ componentPath: path.resolve('test/fixtures/components/hello-world/'), username: creds.username, password: creds.password });
publishFacade({
componentPath: path.resolve('test/fixtures/components/hello-world/'),
username: creds.username,
password: creds.password
}, function(){});
};

describe('when publishing component', function(){
Expand Down
2 changes: 1 addition & 1 deletion test/unit/cli-facade-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('cli : facade : registry', function(){

var execute = function(command){
logSpy.log = sinon.spy();
registryFacade({ command: command });
registryFacade({ command: command }, function(){});
};

describe('when using ls command', function(){
Expand Down