Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
fix: Exit with code 1 on error
Browse files Browse the repository at this point in the history
  • Loading branch information
bokub committed Sep 3, 2018
1 parent aa1195d commit a046185
Show file tree
Hide file tree
Showing 10 changed files with 1,931 additions and 1,926 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Lyo
![Lyo](https://i.imgur.com/nt5bYNJ.png)

[![Npm version](https://badgen.net/npm/v/lyo)](https://npmjs.com/package/lyo)
> Node.js to browser. The easy way
[![Npm version](https://runkit.io/bokub/npm-version/branches/master/lyo)](https://npmjs.com/package/lyo)
[![Build status](https://badgen.net/travis/bokub/lyo)](https://travis-ci.org/bokub/lyo)
[![Build status](https://badgen.net/codecov/c/github/bokub/lyo)](https://codecov.io/gh/bokub/lyo)
[![Code coverage](https://badgen.net/codecov/c/github/bokub/lyo)](https://codecov.io/gh/bokub/lyo)
[![XO code style](https://badgen.net/badge/code%20style/XO/5ed9c7)](https://github.com/xojs/xo)

> Node.js to browser. The easy way
Lyo is the easiest way to publish Node.js modules as browser-compatible libraries.

No decision-making, no configuration needed, it just works!
Expand Down
6 changes: 5 additions & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ switch (cli.input[0]) {
init(cli.flags);
break;
case 'usage':
usage.getUsage(cli.flags);
try {
usage.getUsage(cli.flags);
} catch (err) {
process.exit(1);
}
break;
case undefined:
lyo(cli.flags);
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function lyo(flags) {
.then(() => display.succeed(opts))
.catch(err => {
display.fail(err);
process.exit(1);
});
}

Expand Down
2 changes: 1 addition & 1 deletion lib/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function succeed() {

function fail(err) {
console.error(chalk.red('\nLyo encountered an error\n'));
console.error(err);
console.error(err + '\n');
}

function options(opts) {
Expand Down
2 changes: 1 addition & 1 deletion lib/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const runBrowserify = opts => new Promise((resolve, reject) => {
resolve(result);
}).catch(err => {
spinner.fail();
reject(err);
reject(err.message);
});
});

Expand Down
13 changes: 6 additions & 7 deletions lib/usage.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#!/usr/bin/env node
'use strict';

const path = require('path');

const chalk = require('chalk');
Expand All @@ -10,13 +13,8 @@ const pkg = require(path.join(process.cwd(), 'package.json'));
function getUsage(flags) {
const opts = parseOptions(flags, pkg);
display.options(opts);
let signature = '';
try {
signature = getModuleSignature(opts);
} catch (err) {
display.fail(err.message);
return;
}
const signature = getModuleSignature(opts);

printUsage(opts, signature);
}

Expand Down Expand Up @@ -44,6 +42,7 @@ function getModuleSignature(opts) {
module = require(path.resolve(opts.input));
} catch (err) {
if (err.code === 'MODULE_NOT_FOUND') {
display.fail(err.message);
throw err;
}
return '';
Expand Down
Loading

0 comments on commit a046185

Please sign in to comment.