From abef54a4126c052a187e958be58c69e68e228ed5 Mon Sep 17 00:00:00 2001 From: Jason Dreyzehner Date: Sat, 10 Mar 2018 15:17:40 -0500 Subject: [PATCH] fix(CLI): use placeholders for email, name, and GitHub username --- src/cli/tasks.ts | 24 ++++++++++++++---------- src/cli/tests/cli.unit.spec.ts | 11 ++++++----- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/cli/tasks.ts b/src/cli/tasks.ts index c77de38..2b8ffed 100644 --- a/src/cli/tasks.ts +++ b/src/cli/tasks.ts @@ -8,6 +8,12 @@ import { Runner } from './primitives'; // TODO: await https://github.com/DefinitelyTyped/DefinitelyTyped/pull/24209 const inherit = 'inherit' as StdIOOption; +export enum Placeholders { + email = 'YOUR_EMAIL', + name = 'YOUR_NAME', + username = 'YOUR_GITHUB_USER_NAME' +} + const repo = process.env.TYPESCRIPT_STARTER_REPO_URL || 'https://github.com/bitjson/typescript-starter.git'; @@ -15,10 +21,10 @@ export interface Tasks { readonly cloneRepo: ( dir: string ) => Promise<{ readonly commitHash: string; readonly gitHistoryDir: string }>; - readonly getGithubUsername: (email: string | undefined) => Promise; + readonly getGithubUsername: (email: string) => Promise; readonly getUserInfo: () => Promise<{ - readonly gitEmail: string | undefined; - readonly gitName: string | undefined; + readonly gitEmail: string; + readonly gitName: string; }>; readonly initialCommit: (hash: string, projectDir: string) => Promise; readonly install: ( @@ -68,13 +74,11 @@ export const cloneRepo = (spawner: ExecaStatic) => async (dir: string) => { export const getGithubUsername = (fetcher: any) => async ( email: string | undefined ) => { - const placeholder = 'YOUR_USER_NAME'; - if (email === undefined) { - return placeholder; + if (email === Placeholders.email) { + return Placeholders.username; } return fetcher(email).catch(() => { - // if username isn't found, just return a placeholder - return placeholder; + return Placeholders.username; }); }; @@ -92,8 +96,8 @@ export const getUserInfo = (spawner: ExecaStatic) => async () => { }; } catch (err) { return { - gitEmail: undefined, - gitName: undefined + gitEmail: Placeholders.email, + gitName: Placeholders.name }; } }; diff --git a/src/cli/tests/cli.unit.spec.ts b/src/cli/tests/cli.unit.spec.ts index 3bd1939..8ac24b5 100644 --- a/src/cli/tests/cli.unit.spec.ts +++ b/src/cli/tests/cli.unit.spec.ts @@ -10,7 +10,8 @@ import { getGithubUsername, getUserInfo, initialCommit, - install + install, + Placeholders } from '../tasks'; test('errors if outdated', async t => { @@ -107,14 +108,14 @@ test('getGithubUsername: returns placeholder if not found', async t => { const username: string = await getGithubUsername(mockFetcher)( 'bitjson@github.com' ); - t.is(username, 'YOUR_USER_NAME'); + t.is(username, Placeholders.username); }); -test('getUserInfo: suppresses errors and returns undefined', async t => { +test('getUserInfo: suppresses errors and returns empty strings', async t => { const result = await getUserInfo(mockErr(1))(); t.deepEqual(result, { - gitEmail: undefined, - gitName: undefined + gitEmail: Placeholders.email, + gitName: Placeholders.name }); });