Skip to content

Commit

Permalink
feat: add project name prompt to init-action (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
DM1-1 committed Apr 19, 2024
1 parent 5cfe1f8 commit 3166252
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/actions/init-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ import {downloadTemplate} from '@helpers/fetch';
import {Logger} from '@helpers/logger';

import {ROOT} from '../../src/constants/path';
import {APP_DIR, APP_REPO, PAGES_DIR, PAGES_REPO} from '../../src/constants/templates';
import {getSelect} from '../../src/prompts';
import {
APP_DIR,
APP_NAME,
APP_REPO,
PAGES_DIR,
PAGES_NAME,
PAGES_REPO
} from '../../src/constants/templates';
import {getSelect, getText} from '../../src/prompts';

export interface InitActionOptions {
template?: 'app' | 'pages';
Expand Down Expand Up @@ -53,6 +60,12 @@ export async function initAction(projectName: string, options: InitActionOptions
// ]);
}

if (!projectName) {
const templateTitle = template === 'app' ? APP_NAME : PAGES_NAME;

projectName = await getText('Enter the project name', templateTitle);
}

/** ======================== Generate template ======================== */
if (template === 'app') {
await generateTemplate(APP_REPO);
Expand Down
3 changes: 3 additions & 0 deletions src/constants/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export const PAGES_REPO = 'https://codeload.github.com/nextui-org/next-pages-tem
export const APP_DIR = 'next-app-template-main';
export const PAGES_DIR = 'next-pages-template-main';

export const APP_NAME = 'next-app-template';
export const PAGES_NAME = 'next-pages-template';

export function tailwindTemplate(type: 'all', content?: string): string;
export function tailwindTemplate(type: 'partial', content: string): string;
export function tailwindTemplate(type: CheckType, content?: string) {
Expand Down
16 changes: 15 additions & 1 deletion src/prompts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,21 @@ const defaultPromptOptions: prompts.Options = {
}
};

export async function getInput(message: string, choices?: prompts.Choice[]) {
export async function getText(message: string, initial: string) {
const result = await prompts(
{
initial,
message,
name: 'value',
type: 'text'
},
defaultPromptOptions
);

return result.value;
}

export async function getAutocomplete(message: string, choices?: prompts.Choice[]) {
const result = await prompts(
{
message,
Expand Down

0 comments on commit 3166252

Please sign in to comment.