diff --git a/core/cli.ts b/core/cli.ts index 8b79318..922d3bd 100644 --- a/core/cli.ts +++ b/core/cli.ts @@ -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'; @@ -87,7 +87,14 @@ async function sayHello() { useGracefulShutdown(); - const { version, help, projectName, template, branch, network, shareUsageData } = await parseFlags(globalOptions); + var { version, help, projectName, template, branch, network, shareUsageData } = await parseFlags(globalOptions); + + template = makeInputsLowercase(template); + network = makeInputsLowercase(network); + branch = makeInputsLowercase(branch); + + console.log('network', network); + const collectUsageData = await initializeUsageConfigIfneeded(); const config = loadConfig(); diff --git a/core/create-app.tsx b/core/create-app.tsx index 82eca8e..6d07fc5 100644 --- a/core/create-app.tsx +++ b/core/create-app.tsx @@ -71,7 +71,7 @@ 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!.toLowerCase()); if (config?.template && !isChosenTemplateValid) { printWarning(chalk`'{bold ${config.template}}' does not match any templates.`); @@ -113,6 +113,8 @@ export async function createApp(config: CreateMagicAppConfig) { ...config.data, }; + console.log('templateData', templateData); + const { gray, cyan } = chalk; const timer = createTimer(); diff --git a/core/flags.ts b/core/flags.ts index 8cb4e52..6b39f11 100644 --- a/core/flags.ts +++ b/core/flags.ts @@ -106,12 +106,8 @@ export async function parseFlags(flags: T, data?: {}): Promise< boolean: booleans, }); - const caseInsensitiveResults = Object.fromEntries( - Object.entries(results).map(([key, value]) => [convertArgToCamelCase(key), value]), - ); - const defaultResults = getFlagDefaults(flags); - const validatedResults = await validateFlagInputs(flags, caseInsensitiveResults); + const validatedResults = await validateFlagInputs(flags, results); const finalResults = { ...defaultResults, ...validatedResults }; // If `data` is provided (in other words, if the flow is programmatic rather @@ -188,13 +184,9 @@ async function validateFlagInputs(flags: T, inputs: {} = {}) { ); } -function convertArgToCamelCase(arg: string) { - const tokens = arg.split('-'); - return tokens.reduce((camelCase, token, index) => { - if (index === 0) { - return token.toLowerCase(); - } - - return camelCase + token.charAt(0).toUpperCase() + token.slice(1).toLowerCase(); - }, ''); +export function makeInputsLowercase(arg: string | undefined): string | undefined { + if (arg === undefined) { + return undefined; + } + return arg.toLowerCase(); } diff --git a/core/utils/templateMappings.ts b/core/utils/templateMappings.ts index 51935c0..f88bf88 100644 --- a/core/utils/templateMappings.ts +++ b/core/utils/templateMappings.ts @@ -21,6 +21,7 @@ import SolanaDedicatedScaffold, { } from '../../scaffolds/nextjs-solana-dedicated-wallet/scaffold'; import UniversalScaffold, { flags as universalFlags } from '../../scaffolds/nextjs-universal-wallet/scaffold'; import { Timer } from './timer'; +import { makeInputsLowercase } from 'core/flags'; export type Chain = 'evm' | 'solana' | 'flow'; export type Template = @@ -75,6 +76,7 @@ export async function mapTemplateToScaffold( timer: Timer, ): Promise { const data = appData; + data.network = makeInputsLowercase(data.network); pauseTimerAndSpinner(timer, spinner); if (!data.publishableApiKey) { data.publishableApiKey = await PublishableApiKeyPrompt.publishableApiKeyPrompt(); diff --git a/scaffolds/nextjs-dedicated-wallet/scaffold.tsx b/scaffolds/nextjs-dedicated-wallet/scaffold.tsx index 90b6d23..27b56a1 100644 --- a/scaffolds/nextjs-dedicated-wallet/scaffold.tsx +++ b/scaffolds/nextjs-dedicated-wallet/scaffold.tsx @@ -57,8 +57,9 @@ export default class DedicatedScaffold extends BaseScaffold { this.data = data; if (typeof this.source !== 'string') { + data.loginMethods = data.loginMethods.map((authType) => AuthTypePrompt.mapInputToLoginMethods(authType)); data.loginMethods.forEach((authType) => { - (this.source as string[]).push(`./src/components/magic/auth/${authType.replaceAll(' ', '')}.tsx`); + (this.source as string[]).push(`./src/components/magic/auth/${authType}.tsx`); if ( authType === 'Discord' || authType === 'Facebook' || @@ -67,12 +68,12 @@ 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.replaceAll(' ', '') === 'SMSOTP') { + if (authType === 'SMSOTP') { (this.source as string[]).push('./src/components/magic/wallet-methods/UpdatePhone.tsx'); } }); diff --git a/scaffolds/nextjs-flow-dedicated-wallet/scaffold.tsx b/scaffolds/nextjs-flow-dedicated-wallet/scaffold.tsx index 6f2f8c5..d6976eb 100644 --- a/scaffolds/nextjs-flow-dedicated-wallet/scaffold.tsx +++ b/scaffolds/nextjs-flow-dedicated-wallet/scaffold.tsx @@ -57,6 +57,7 @@ export default class FlowDedicatedScaffold extends BaseScaffold { this.data = data; if (typeof this.source !== 'string') { + data.loginMethods = data.loginMethods.map((authType) => AuthTypePrompt.mapInputToLoginMethods(authType)); data.loginMethods.forEach((authType) => { (this.source as string[]).push(`./src/components/magic/auth/${authType.replaceAll(' ', '')}.tsx`); if ( diff --git a/scaffolds/nextjs-solana-dedicated-wallet/scaffold.tsx b/scaffolds/nextjs-solana-dedicated-wallet/scaffold.tsx index 6c31bd7..002f26a 100644 --- a/scaffolds/nextjs-solana-dedicated-wallet/scaffold.tsx +++ b/scaffolds/nextjs-solana-dedicated-wallet/scaffold.tsx @@ -57,6 +57,7 @@ export default class SolanaDedicatedScaffold extends BaseScaffold { this.data = data; if (typeof this.source !== 'string') { + data.loginMethods = data.loginMethods.map((authType) => AuthTypePrompt.mapInputToLoginMethods(authType)); data.loginMethods.forEach((authType) => { (this.source as string[]).push(`./src/components/magic/auth/${authType.replaceAll(' ', '')}.tsx`); if ( diff --git a/scaffolds/prompts.ts b/scaffolds/prompts.ts index 784f1e3..ebd19b3 100644 --- a/scaffolds/prompts.ts +++ b/scaffolds/prompts.ts @@ -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; + }; }