1
0
mirror of synced 2025-11-08 12:57:47 +00:00

fix(CLI): use placeholders for email, name, and GitHub username

This commit is contained in:
Jason Dreyzehner
2018-03-10 15:17:40 -05:00
parent 41ac31532f
commit abef54a412
2 changed files with 20 additions and 15 deletions

View File

@@ -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<string>;
readonly getGithubUsername: (email: string) => Promise<string>;
readonly getUserInfo: () => Promise<{
readonly gitEmail: string | undefined;
readonly gitName: string | undefined;
readonly gitEmail: string;
readonly gitName: string;
}>;
readonly initialCommit: (hash: string, projectDir: string) => Promise<void>;
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
};
}
};

View File

@@ -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
});
});