Skip to content

Commit

Permalink
feat: add warn attention in add and remove command (#38)
Browse files Browse the repository at this point in the history
* feat: add warn attention in add and remove command

* feat: optimize
  • Loading branch information
winchesHe committed Apr 22, 2024
1 parent c06c52c commit 5aa7d23
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
10 changes: 9 additions & 1 deletion src/actions/add-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,14 @@ export async function addAction(components: string[], options: AddActionOptions)
Logger.newLine();
Logger.info(`Tailwind CSS configuration file created at: ${tailwindPath}`);
} else {
const [, ...errorInfoList] = checkTailwind(type, tailwindPath, currentComponents, isPnpm);
const [, ...errorInfoList] = checkTailwind(
type,
tailwindPath,
currentComponents,
isPnpm,
undefined,
true
);

fixTailwind(type, {errorInfoList, format: prettier, tailwindPath});

Expand Down Expand Up @@ -202,6 +209,7 @@ export async function addAction(components: string[], options: AddActionOptions)
Logger.success('✅ Components added successfully');

// Warn the user to check the NextUIProvider whether in the correct place
Logger.newLine();
Logger.warn(
`Please check the ${chalk.bold(
'NextUIProvider'
Expand Down
1 change: 1 addition & 0 deletions src/actions/doctor-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export async function doctorAction(options: DoctorActionOptions) {

/** ======================== Return when there is no problem ======================== */
if (!problemRecord.length) {
Logger.newLine();
Logger.success('✅ Your project has no detected issues.');

return;
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ export function checkTailwind(

if (logWarning && isHaveAllContent) {
Logger.warn(
`Attention: Individual components from NextUI do not require the "${chalk.bold(
`\nAttention: Individual components from NextUI do not require the "${chalk.bold(
tailwindRequired.content
)}" in the tailwind config\nFor optimized bundle sizes, consider using "${chalk.bold(
individualContent
)}" instead\n`
)}" instead`
);
}

Expand Down
26 changes: 18 additions & 8 deletions src/helpers/remove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type {NextUIComponents} from 'src/constants/component';

import {existsSync, readFileSync, writeFileSync} from 'fs';

import {tailwindRequired} from 'src/constants/required';

import {type CheckType, checkTailwind} from './check';
import {exec} from './exec';
import {fixTailwind} from './fix';
Expand Down Expand Up @@ -44,6 +46,8 @@ export async function removeTailwind(
const contentMatch = getMatchArray('content', tailwindContent);
const pluginsMatch = getMatchArray('plugins', tailwindContent);

const insIncludeAll = contentMatch.some((c) => c.includes(tailwindRequired.content));

// Not installed NextUI components then remove the tailwind content about nextui
if (!currentComponents.length && !isNextUIAll) {
const index = pluginsMatch.findIndex((c) => c.includes('nextui'));
Expand All @@ -54,14 +58,18 @@ export async function removeTailwind(
// Remove the import nextui content
tailwindContent = tailwindContent.replace(/(const|var|let|import)[\w\W]+?nextui.*?;\n/, '');
}
// Remove the nextui content
while (contentMatch.some((c) => c.includes('nextui'))) {
contentMatch.splice(
contentMatch.findIndex((c) => c.includes('nextui')),
1
);

// If there are already have all nextui content include then don't need to remove the content
if (!insIncludeAll) {
// Remove the nextui content
while (contentMatch.some((c) => c.includes('nextui'))) {
contentMatch.splice(
contentMatch.findIndex((c) => c.includes('nextui')),
1
);
}
tailwindContent = replaceMatchArray('content', tailwindContent, contentMatch);
}
tailwindContent = replaceMatchArray('content', tailwindContent, contentMatch);
// if (!currentComponents.length && isNextUIAll) {
// const index = contentMatch.findIndex(c => c.includes('nextui'));

Expand All @@ -86,7 +94,9 @@ export async function removeTailwind(
type as 'partial',
tailwindPath!,
currentComponents,
isPnpm
isPnpm,
undefined,
true
);

fixTailwind(type, {errorInfoList, format: prettier, tailwindPath: tailwindPath!});
Expand Down

0 comments on commit 5aa7d23

Please sign in to comment.