Skip to content

Commit

Permalink
fix: rename error
Browse files Browse the repository at this point in the history
  • Loading branch information
winchesHe committed Mar 28, 2024
1 parent 1b163c0 commit 57da5ab
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/actions/init-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { downloadTemplate } from '@helpers/fetch';
import { Logger } from '@helpers/logger';

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

export interface InitActionOptions {
Expand Down Expand Up @@ -56,17 +56,10 @@ export async function initAction(projectName: string, options: InitActionOptions
/** ======================== Generate template ======================== */
if (template === 'app') {
await generateTemplate(APP_REPO);
renameTemplate(APP_DIR, projectName);
} else if (template === 'pages') {
await generateTemplate(PAGES_REPO);
}

/** ======================== Change project name ======================== */
if (projectName) {
rename(`${ROOT}/next-app-template-main`, `${ROOT}/${projectName}`, (err) => {
if (err) {
Logger.warn(`NextUI CLI rename Error: ${err}`);
}
});
renameTemplate(PAGES_DIR, projectName);
}
}

Expand All @@ -84,3 +77,11 @@ async function generateTemplate(url: string) {
text: 'Creating template...'
});
}

function renameTemplate(originName: string, projectName: string) {
rename(`${ROOT}/${originName}`, `${ROOT}/${projectName}`, (err) => {
if (err) {
Logger.warn(`NextUI CLI rename Error: ${err}`);
}
});
}

0 comments on commit 57da5ab

Please sign in to comment.