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

Feat/27 rearchitecture #113

Merged
merged 22 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Removed scaffold helper zombi dependency
  • Loading branch information
AdityaKulkarni committed Oct 10, 2023
commit 87cc5c67f72af6802001b345adc8f2ad9b879137
3 changes: 2 additions & 1 deletion core/help-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import wrapAnsi from 'wrap-ansi';
import { BINARY } from './config';
import { Flags, Flag } from './flags';
import { mapTemplateToFlags } from './utils/templateMappings';
import { c } from 'tar';

const styled = {
Usage: chalk.bold.inverse(' USAGE '),
Expand Down Expand Up @@ -43,7 +44,7 @@ export function printHelp(globalOptions: Flags, scaffoldName?: string) {

// Template-specific options
try {
const { flags } = mapTemplateToFlags(scaffoldName!);
const flags = mapTemplateToFlags(scaffoldName!);
helpSections.push(
createHelpSection({
heading: styled.Options + chalk.bold(' ❯ ') + chalk.bold.hex('#b93fff').inverse(` ${scaffoldName} `),
Expand Down
44 changes: 2 additions & 42 deletions core/utils/scaffold-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@ import type { CreateMagicAppData } from '../create-app';
import type { Flags, ValueType } from '../flags';
import fs from 'fs';

/**
* The render function for a `make-magic` scaffold.
* This is bound to some default props required by the underlying `<Zombi>`.
*/
type ScaffoldRender<T extends Record<string, ValueType> = Record<string, any>> = (props: {
name: string;
templateRoot: string;
data: T & CreateMagicAppData;
}) => JSX.Element;

/**
* Metadata about the scaffold being defined.
*/
Expand Down Expand Up @@ -53,45 +43,15 @@ type ScaffoldMetadata<T extends Record<string, ValueType> = Record<string, any>>
flags: Flags<Partial<T>>;
};

export type ScaffoldDefinition<T extends Record<string, ValueType> = Record<string, any>> = ScaffoldRender<T> &
ScaffoldMetadata<T>;

/**
* Creates the definition object for a scaffolding template.
*
* The return value of this function should be the default export
* of a `[root]/scaffolds/[scaffoldName]/scaffold.{ts,tsx}` file.
*/
export function createScaffold<T extends Record<string, ValueType>>(
scaffoldRender: ScaffoldRender<T>,
metadata: ScaffoldMetadata<T>,
): ScaffoldDefinition<T> {
return Object.assign(scaffoldRender, { ...metadata });
}
export type ScaffoldDefinition<T extends Record<string, ValueType> = Record<string, any>> = ScaffoldMetadata<T>;

/**
* Gets the definition object for a scaffolding template.
*/
export function getScaffoldDefinition(scaffoldName: string): ScaffoldDefinition {
// We are requiring this file in context of the
// transpiled `/dist` output, so we use a JS extension...
return require(resolveToDist('scaffolds', scaffoldName, 'scaffold.js')).default;
}

/**
* Gets the render function for a scaffolding template.
* The returned function is bound with `data` and some initial `Zombi` props.
*/
export function getScaffoldRender(data: CreateMagicAppData & Record<string, any>): () => JSX.Element {
// We are requiring this file in context of the
// transpiled `/dist`, so we use a JS extension...
const scaffoldModule = getScaffoldDefinition(data.template);

return scaffoldModule.bind(scaffoldModule, {
data,
name: data.template,
templateRoot: getAbsoluteTemplatePath(data.template),
});
return require(resolveToDist('scaffolds', scaffoldName, 'scaffold.js')).definition;
}

/**
Expand Down
5 changes: 5 additions & 0 deletions scaffolds/nextjs-dedicated-wallet/scaffold.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export const flags: Flags<Partial<Data>> = {
...AuthTypePrompt.flags,
};

export const definition = {
shortDescription: 'A dedicated wallet scaffold for Next.js',
featured: true,
};

export default class DedicatedScaffold extends BaseScaffold {
public templateName = 'nextjs-dedicated-wallet';
private data: Data;
Expand Down
5 changes: 5 additions & 0 deletions scaffolds/nextjs-flow-dedicated-wallet/scaffold.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export const flags: Flags<Partial<Data>> = {
...AuthTypePrompt.flags,
};

export const definition = {
shortDescription: 'A dedicated wallet scaffold for Next.js using Flow',
featured: true,
};

export default class FlowDedicatedScaffold extends BaseScaffold {
public templateName = 'nextjs-flow-dedicated-wallet';
private data: Data;
Expand Down
6 changes: 5 additions & 1 deletion scaffolds/nextjs-flow-universal-wallet/scaffold.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ export const flags: Flags<Partial<Data>> = {
...PublishableApiKeyPrompt.flags,
};

export const definition = {
shortDescription: 'A universal wallet scaffold for Next.js using Flow',
featured: true,
};

export default class FlowUniversalScaffold extends BaseScaffold {
public templateName = 'nextjs-flow-universal-wallet';
private data: Data;
public installationCommand: string[] = ['npm', 'install'];
public startCommand: string[] = ['npm', 'run', 'dev'];

public source: string | string[] = './';

constructor(data: Data) {
Expand Down
5 changes: 5 additions & 0 deletions scaffolds/nextjs-solana-dedicated-wallet/scaffold.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export const flags: Flags<Partial<Data>> = {
...AuthTypePrompt.flags,
};

export const definition = {
shortDescription: 'A dedicated wallet scaffold for Next.js using Solana',
featured: true,
};

export default class SolanaDedicatedScaffold extends BaseScaffold {
public templateName = 'nextjs-solana-dedicated-wallet';
private data: Data;
Expand Down
5 changes: 5 additions & 0 deletions scaffolds/nextjs-universal-wallet/scaffold.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export type Data = BlockchainNetworkPrompt.Data & PublishableApiKeyPrompt.Data;

export const flags: Flags<Partial<Data>> = { ...BlockchainNetworkPrompt.flags, ...PublishableApiKeyPrompt.flags };

export const definition = {
shortDescription: 'A Universal Wallet scaffold for Next.js',
featured: true,
};

export default class UniversalScaffold extends BaseScaffold {
public templateName = 'nextjs-universal-wallet';
private data: Data;
Expand Down
6 changes: 3 additions & 3 deletions scaffolds/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ export namespace AuthTypePrompt {
export const flags: Flags<Partial<Data>> = {
loginMethods: {
type: [String],
description: `The auth method(s) of your choice. You can provide this flag multiple times to select multiple methods. (one of: ${authMethods.join(
', ',
)})`,
description: `The auth method(s) of your choice. You can provide this flag multiple times to select multiple methods. (one of: ${authMethods
.map((method) => (method.choices ? method.choices.map((choice) => choice).join(', ') : method.name))
.join(', ')})`,
validate: (value) => {
const invalid: string[] = [];

Expand Down