Skip to content

Commit

Permalink
fix: repair add and remove issues (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
winchesHe committed Apr 15, 2024
1 parent e5155c3 commit 8a5e536
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/actions/add-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export async function addAction(components: string[], options: AddActionOptions)
tailwindPath = findFiles('**/tailwind.config.(j|t)s')[0]
} = options;

var {allDependenciesKeys, currentComponents} = getPackageInfo(packagePath);
var {allDependencies, allDependenciesKeys, currentComponents} = getPackageInfo(packagePath);

const isNextUIAll = !!allDependencies[NEXT_UI];

if (!components.length && !all) {
components = await getAutocompleteMultiselect(
Expand Down Expand Up @@ -79,7 +81,9 @@ export async function addAction(components: string[], options: AddActionOptions)
var {allDependenciesKeys, currentComponents} = getPackageInfo(packagePath);

const currentComponentsKeys = currentComponents.map((c) => c.name);
const filterCurrentComponents = components.filter((c) => currentComponentsKeys.includes(c));
const filterCurrentComponents = components.filter(
(c) => currentComponentsKeys.includes(c) || (isNextUIAll && c === NEXT_UI)
);

if (filterCurrentComponents.length) {
Logger.prefix(
Expand Down
2 changes: 1 addition & 1 deletion src/actions/remove-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function removeAction(components: string[], options: RemoveOptionsA
return;
}

if (all) {
if (all || isNextUIAll) {
components = isNextUIAll ? [NEXT_UI] : currentComponents.map((component) => component.package);
} else if (!components.length) {
components = await getAutocompleteMultiselect(
Expand Down
7 changes: 7 additions & 0 deletions src/constants/required.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ export const DOCS_PROVIDER_SETUP = 'https://nextui.org/docs/guide/installation#p
export const tailwindRequired = {
content: './node_modules/@nextui-org/theme/dist/**/*.{js,ts,jsx,tsx}',
darkMode: 'darkMode: "class"',
importContent: (isTypescript = false) => {
if (isTypescript) {
return `import {nextui} from '@nextui-org/theme';`;
}

return `const {nextui} = require('@nextui-org/theme');`;
},
plugins: 'nextui()'
} as const;

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export function checkTailwind(
isPnpm?: boolean,
content?: string
): CheckResult {
if (!currentComponents!.length) {
if (type === 'partial' && !currentComponents!.length) {
return [true];
}

Expand Down
7 changes: 6 additions & 1 deletion src/helpers/fix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ export function fixTailwind(type: CheckType, options: FixTailwind) {
} else if (errorType === 'plugins') {
pluginsMatch.push(info);
tailwindContent = replaceMatchArray('plugins', tailwindContent, pluginsMatch);

// Add import content
const importContent = tailwindRequired.importContent(tailwindPath.endsWith('.ts'));

tailwindContent = `${importContent}\n${tailwindContent}`;
}

if (type === 'all' && errorType === 'darkMode') {
Expand All @@ -102,7 +107,7 @@ export function fixTailwind(type: CheckType, options: FixTailwind) {
tailwindContent = `${tailwindContent.slice(
0,
darkModeIndex
)}${darkModeContent},\n${tailwindContent.slice(darkModeIndex)}`;
)} ${darkModeContent},\n${tailwindContent.slice(darkModeIndex)}`;
}
}

Expand Down

0 comments on commit 8a5e536

Please sign in to comment.