Permalink
Browse files

Throw a more user-friendly exception (#107)

  • Loading branch information...
1 parent 858f3c6 commit 078779931a2b223d09cefc56532d1ad71415e4ff @gillesdemey gillesdemey committed with Nov 29, 2016
Showing with 19 additions and 4 deletions.
  1. +2 −1 cli.js
  2. +2 −1 index.js
  3. +2 −2 lib/ui.js
  4. +12 −0 lib/util.js
  5. +1 −0 package.json
View
@@ -1,5 +1,6 @@
#!/usr/bin/env node
'use strict';
+const logSymbols = require('log-symbols');
const meow = require('meow');
const updateNotifier = require('update-notifier');
const version = require('./lib/version');
@@ -52,6 +53,6 @@ Promise
console.log(`\n ${pkg.name} ${pkg.version} published 🎉`);
})
.catch(err => {
- console.error(`\n${err.message}`);
+ console.error(`\n${logSymbols.error} ${err.message}`);
process.exit(1);
});
View
@@ -9,6 +9,7 @@ const streamToObservable = require('stream-to-observable');
const readPkgUp = require('read-pkg-up');
const prerequisiteTasks = require('./lib/prerequisite');
const gitTasks = require('./lib/git');
+const util = require('./lib/util');
const exec = (cmd, args) => {
// Use `Observable` support if merged https://github.com/sindresorhus/execa/pull/26
@@ -26,7 +27,7 @@ module.exports = (input, opts) => {
const runTests = !opts.yolo;
const runCleanup = !opts.skipCleanup && !opts.yolo;
- const pkg = readPkgUp.sync().pkg;
+ const pkg = util.readPkg();
const tasks = new Listr([
{
View
@@ -1,12 +1,12 @@
'use strict';
const execa = require('execa');
const inquirer = require('inquirer');
-const readPkgUp = require('read-pkg-up');
const chalk = require('chalk');
+const util = require('./util');
const version = require('./version');
module.exports = options => {
- const pkg = readPkgUp.sync().pkg;
+ const pkg = util.readPkg();
const oldVersion = pkg.version;
console.log(`\nPublish a new version of ${chalk.bold.magenta(pkg.name)} ${chalk.dim(`(${oldVersion})`)}\n`);
View
@@ -0,0 +1,12 @@
+'use strict';
+const readPkgUp = require('read-pkg-up');
+
+exports.readPkg = () => {
+ const pkg = readPkgUp.sync().pkg;
+
+ if (!pkg) {
+ throw new Error(`No package.json found. Make sure you're in the correct project.`);
+ }
+
+ return pkg;
+};
View
@@ -46,6 +46,7 @@
"execa": "^0.4.0",
"inquirer": "^1.2.1",
"listr": "^0.6.1",
+ "log-symbols": "^1.0.2",
"meow": "^3.7.0",
"read-pkg-up": "^1.0.1",
"rxjs": "^5.0.0-beta.9",

0 comments on commit 0787799

Please sign in to comment.