From b7168ade460dbb0931ac0ed71d471f92d4804b6b Mon Sep 17 00:00:00 2001 From: Yasuaki Uechi Date: Tue, 4 Aug 2020 22:19:32 +0900 Subject: [PATCH] feat: init epicfail inside create function --- package.json | 6 +++--- src/cli.ts | 5 ----- src/index.ts | 7 ++++++- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index c6bbb8f..1587013 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,10 @@ "version": "5.7.0", "author": "Yasuaki Uechi ", "scripts": { - "build": "shx rm -rf lib && npm run build:ts --minify --dts", + "build": "shx rm -rf lib && yarn build:ts --minify --dts", "build:ts": "tsup src/index.ts src/cli.ts -d lib", - "dev": "npm run build:ts --watch", - "prepublishOnly": "npm run build", + "dev": "yarn build:ts --watch", + "prepublishOnly": "yarn build", "release": "release-it", "test": "echo notest" }, diff --git a/src/cli.ts b/src/cli.ts index 249bfb8..bb4e505 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,14 +1,9 @@ #!/usr/bin/env node import chalk from 'chalk'; -import epicfail from 'epicfail'; import { resolve } from 'path'; import { AfterHookOptions, create } from '.'; -epicfail({ - assertExpected: (err) => err.name === 'CLIError', -}); - const templateRoot = resolve(__dirname, '..', 'templates'); const caveat = ({ name, template }: AfterHookOptions) => { let text = ` diff --git a/src/index.ts b/src/index.ts index 0bb29fd..64beff7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ import chalk from 'chalk'; import { CommonSpawnOptions } from 'child_process'; import { spawn } from 'cross-spawn'; +import epicfail from 'epicfail'; import execa, { CommonOptions, ExecaChildProcess } from 'execa'; import fs from 'fs'; import gitconfig from 'gitconfig'; @@ -65,7 +66,7 @@ export interface AfterHookOptions { installNpmPackage: (packageName: string) => Promise; } -class CLIError extends Error { +export class CLIError extends Error { constructor(message: string) { super(message); this.name = 'CLIError'; @@ -196,6 +197,10 @@ async function getYargsOptions( } export async function create(appName: string, options: Options) { + epicfail({ + assertExpected: (err) => err.name === 'CLIError', + }); + const firstArg = process.argv[2]; if (firstArg === undefined) { throw new CLIError(`${appName} `);