Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #123 from magiclabs/staging
Browse files Browse the repository at this point in the history
Making flag inputs case insensitive
  • Loading branch information
jamesrp13 authored Jan 22, 2024
2 parents 84bd04d + af1f9e2 commit 4073bb8
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 10 deletions.
19 changes: 17 additions & 2 deletions core/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createApp } from './create-app';
import { printHelp } from './help-text';
import { resolveToRoot } from './utils/path-helpers';
import { CreateMagicAppError, CreateMagicAppErrorCode } from './utils/errors-warnings';
import { parseFlags } from './flags';
import { makeInputsLowercase, parseFlags } from './flags';
import { globalOptions } from './global-options';
import { shutdown, useGracefulShutdown } from './utils/shutdown';
import { SharedAnalytics } from './analytics';
Expand Down Expand Up @@ -47,6 +47,11 @@ export const ConsoleMessages = {

return msg.join('\n');
},

gitHubIssuesLink: () => {
const msg = chalk`For feedback/questions/issues, please use {rgb(0,255,255) https://github.com/magiclabs/create-magic-app/issues/new/choose}`;
return msg;
},
};

async function sayHello() {
Expand All @@ -71,6 +76,9 @@ async function sayHello() {
} else {
console.log(chalk`\n {dim v${getMakeMagicVersion()}}\n\n`);
}

console.log(ConsoleMessages.gitHubIssuesLink());
console.log();
}

(async () => {
Expand All @@ -79,7 +87,14 @@ async function sayHello() {

useGracefulShutdown();

const { version, help, projectName, template, branch, network, shareUsageData } = await parseFlags(globalOptions);
const parsedFlags = await parseFlags(globalOptions);
const { version, help, projectName, shareUsageData } = parsedFlags;
let { template, network, branch } = parsedFlags;

template = makeInputsLowercase(template);
network = makeInputsLowercase(network);
branch = makeInputsLowercase(branch);

const collectUsageData = await initializeUsageConfigIfneeded();
const config = loadConfig();

Expand Down
4 changes: 3 additions & 1 deletion core/create-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ export async function createApp(config: CreateMagicAppConfig) {
};
});

const isChosenTemplateValid = availableScaffolds.map((i) => i.name).includes(config?.template!);
const isChosenTemplateValid = availableScaffolds
.map((i) => i.name)
.includes((config?.template ? config.template : '').toLowerCase());

if (config?.template && !isChosenTemplateValid) {
printWarning(chalk`'{bold ${config.template}}' does not match any templates.`);
Expand Down
9 changes: 8 additions & 1 deletion core/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export async function parseFlags<T extends Flags>(flags: T, data?: {}): Promise<

Object.entries(flags).forEach(([flag, options]) => {
if (options.alias) {
aliases[flag] = [options.alias];
aliases[flag] = [options.alias.toLowerCase()];
}

if (options.type === Boolean) {
Expand Down Expand Up @@ -183,3 +183,10 @@ async function validateFlagInputs<T extends Flags>(flags: T, inputs: {} = {}) {
),
);
}

export function makeInputsLowercase(arg: string | undefined): string | undefined {
if (arg === undefined) {
return undefined;
}
return arg.toLowerCase();
}
2 changes: 2 additions & 0 deletions core/utils/templateMappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
PublishableApiKeyPrompt,
} from 'scaffolds/prompts';
import { CreateMagicAppConfig, pauseTimerAndSpinner } from 'core/create-app';
import { makeInputsLowercase } from 'core/flags';
import BaseScaffold from '../types/BaseScaffold';
import DedicatedScaffold, { flags as dedicatedFlags } from '../../scaffolds/nextjs-dedicated-wallet/scaffold';
import FlowDedicatedScaffold, {
Expand Down Expand Up @@ -75,6 +76,7 @@ export async function mapTemplateToScaffold(
timer: Timer,
): Promise<BaseScaffold> {
const data = appData;
data.network = makeInputsLowercase(data.network);
pauseTimerAndSpinner(timer, spinner);
if (!data.publishableApiKey) {
data.publishableApiKey = await PublishableApiKeyPrompt.publishableApiKeyPrompt();
Expand Down
14 changes: 10 additions & 4 deletions scaffolds/nextjs-dedicated-wallet/scaffold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ export default class DedicatedScaffold extends BaseScaffold {
this.data = data;

if (typeof this.source !== 'string') {
data.loginMethods.forEach((authType) => {
(this.source as string[]).push(`./src/components/magic/auth/${authType.replaceAll(' ', '')}.tsx`);
this.data.loginMethods = this.data.loginMethods.map((authType) =>
AuthTypePrompt.mapInputToLoginMethods(authType),
);
this.data.loginMethods.forEach((authType) => {
(this.source as string[]).push(`./src/components/magic/auth/${authType}.tsx`);
if (
authType === 'Discord' ||
authType === 'Facebook' ||
Expand All @@ -67,11 +70,14 @@ export default class DedicatedScaffold extends BaseScaffold {
authType === 'Twitch' ||
authType === 'Twitter'
) {
(this.source as string[]).push(`./public/social/${authType.replaceAll(' ', '')}.svg`);
(this.source as string[]).push(`./public/social/${authType}.svg`);
}
if (authType.replaceAll(' ', '') === 'EmailOTP') {
if (authType === 'EmailOTP') {
(this.source as string[]).push('./src/components/magic/wallet-methods/UpdateEmail.tsx');
}
if (authType === 'SMSOTP') {
(this.source as string[]).push('./src/components/magic/wallet-methods/UpdatePhone.tsx');
}
});
}
}
Expand Down
5 changes: 4 additions & 1 deletion scaffolds/nextjs-flow-dedicated-wallet/scaffold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ export default class FlowDedicatedScaffold extends BaseScaffold {
this.data = data;

if (typeof this.source !== 'string') {
data.loginMethods.forEach((authType) => {
this.data.loginMethods = this.data.loginMethods.map((authType) =>
AuthTypePrompt.mapInputToLoginMethods(authType),
);
this.data.loginMethods.forEach((authType) => {
(this.source as string[]).push(`./src/components/magic/auth/${authType.replaceAll(' ', '')}.tsx`);
if (
authType === 'Discord' ||
Expand Down
5 changes: 4 additions & 1 deletion scaffolds/nextjs-solana-dedicated-wallet/scaffold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ export default class SolanaDedicatedScaffold extends BaseScaffold {
this.data = data;

if (typeof this.source !== 'string') {
data.loginMethods.forEach((authType) => {
this.data.loginMethods = this.data.loginMethods.map((authType) =>
AuthTypePrompt.mapInputToLoginMethods(authType),
);
this.data.loginMethods.forEach((authType) => {
(this.source as string[]).push(`./src/components/magic/auth/${authType.replaceAll(' ', '')}.tsx`);
if (
authType === 'Discord' ||
Expand Down
32 changes: 32 additions & 0 deletions scaffolds/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,36 @@ export namespace AuthTypePrompt {
},
},
};

export const mapInputToLoginMethods = (input: string) => {
if (input.replaceAll(' ', '').toLocaleLowerCase().includes('emailotp')) {
return 'EmailOTP';
}

if (input.replaceAll(' ', '').toLocaleLowerCase().includes('smsotp')) {
return 'SMSOTP';
}

if (input.replaceAll(' ', '').toLocaleLowerCase().includes('google')) {
return 'Google';
}

if (input.replaceAll(' ', '').toLocaleLowerCase().includes('github')) {
return 'Github';
}

if (input.replaceAll(' ', '').toLocaleLowerCase().includes('discord')) {
return 'Discord';
}

if (input.replaceAll(' ', '').toLocaleLowerCase().includes('twitter')) {
return 'Twitter';
}

if (input.replaceAll(' ', '').toLocaleLowerCase().includes('twitch')) {
return 'Twitch';
}

return input;
};
}

0 comments on commit 4073bb8

Please sign in to comment.