File tree Expand file tree Collapse file tree 4 files changed +28
-2
lines changed
Expand file tree Collapse file tree 4 files changed +28
-2
lines changed Original file line number Diff line number Diff line change 11#!/usr/bin/env node
22const chalk = require ( "chalk" ) ;
3+ const UsageError = require ( "../errors" ) . UsageError ;
4+ const onlyInstancesOf = require ( "../errors" ) . onlyInstancesOf ;
5+
36
47const USAGE_MSG = `Usage: create-webextension project_dir_name` ;
58
@@ -11,4 +14,7 @@ if (!process.argv[2]) {
1114
1215require ( ".." ) . main ( process . argv [ 2 ] )
1316 . then ( console . log )
14- . catch ( err => console . log ( err . message ) ) ;
17+ . catch ( onlyInstancesOf ( UsageError , ( error ) => {
18+ console . log ( `${ chalk . red ( error . message ) } \n` ) ;
19+ process . exit ( 1 ) ;
20+ } ) ) ;
Original file line number Diff line number Diff line change 1+ const ES6Error = require ( "es6-error" ) ;
2+
3+ exports . onlyInstancesOf = function ( errorType , handler ) {
4+ return ( error ) => {
5+ if ( error instanceof errorType ) {
6+ return handler ( error ) ;
7+ } else {
8+ console . log ( error . stack ) ;
9+ process . exit ( 1 ) ;
10+ }
11+ }
12+ }
13+
14+ exports . UsageError = class UsageError extends ES6Error {
15+ constructor ( message ) {
16+ super ( message ) ;
17+ }
18+ }
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ const path = require("path");
44const chalk = require ( "chalk" ) ;
55const fs = require ( "mz/fs" ) ;
66const stripAnsi = require ( "strip-ansi" ) ;
7+ const UsageError = require ( "./errors" ) . UsageError ;
78
89const README = `
910This project contains a blank WebExtension addon, a "white canvas" for your new experiment of
@@ -110,7 +111,7 @@ exports.main = function main(dirPath) {
110111 } , error => {
111112 if ( error . code === "EEXIST" ) {
112113 const msg = `Unable to create a new WebExtension: ${ chalk . bold . underline ( projectPath ) } dir already exist.` ;
113- throw new Error ( msg ) ;
114+ throw new UsageError ( msg ) ;
114115 }
115116 } ) . catch ( ( error ) => {
116117 throw error ;
Original file line number Diff line number Diff line change 3333 "homepage" : " https://github.com/rpl/create-webextension#readme" ,
3434 "dependencies" : {
3535 "chalk" : " ^1.1.3" ,
36+ "es6-error" : " ^4.0.2" ,
3637 "mz" : " ^2.6.0" ,
3738 "strip-ansi" : " ^3.0.1"
3839 },
You can’t perform that action at this time.
0 commit comments