Skip to content

Commit

Permalink
fix: modal tailwindcss config (#97)
Browse files Browse the repository at this point in the history
* fix: modal tailwindcss config

* fix: reviews

* fix: type
  • Loading branch information
winchesHe authored Sep 19, 2024
1 parent 5573805 commit 14ac5ac
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 11 deletions.
11 changes: 10 additions & 1 deletion src/actions/add-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
checkRequiredContentInstalled,
checkTailwind
} from '@helpers/check';
import {debugExecAddAction} from '@helpers/debug';
import {debugAddedPkg, debugExecAddAction, debugRemovedPkg} from '@helpers/debug';
import {detect} from '@helpers/detect';
import {fixPnpm, fixProvider, fixTailwind} from '@helpers/fix';
import {Logger} from '@helpers/logger';
Expand Down Expand Up @@ -150,6 +150,11 @@ export async function addAction(components: string[], options: AddActionOptions)
);
}

if (getStoreSync('debug')) {
// Temporarily add the components to the package.json file
debugAddedPkg(components, packagePath);
}

// After install the required dependencies, get the latest package information
var {allDependenciesKeys, currentComponents} = getPackageInfo(packagePath);

Expand Down Expand Up @@ -238,5 +243,9 @@ export async function addAction(components: string[], options: AddActionOptions)
)} whether in the correct place (ignore if added)\nSee more info here: ${DOCS_PROVIDER_SETUP}`
);

if (getStoreSync('debug')) {
// Temporarily remove the added components from the package.json file
debugRemovedPkg(components, packagePath);
}
process.exit(0);
}
9 changes: 2 additions & 7 deletions src/actions/upgrade-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,8 @@ type TransformComponent = Required<

export async function upgradeAction(components: string[], options: UpgradeActionOptions) {
const {all = false, packagePath = resolver('package.json'), write = false} = options;
const {
allDependencies,
currentComponents,
dependencies,
devDependencies,
package: packageJson
} = getPackageInfo(packagePath, false);
const {allDependencies, currentComponents, dependencies, devDependencies, packageJson} =
getPackageInfo(packagePath, false);

const isNextUIAll = !!allDependencies[NEXT_UI];

Expand Down
2 changes: 1 addition & 1 deletion src/constants/required.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const individualTailwindRequired = {
];

if (outputComponents.length === 1) {
return `./node_modules/@nextui-org/theme/dist/components/${currentComponents[0]}.js`;
return `./node_modules/@nextui-org/theme/dist/components/${outputComponents[0]}.js`;
}
const requiredContent = outputComponents
.reduce((acc, component) => {
Expand Down
54 changes: 53 additions & 1 deletion src/helpers/debug.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import {getStoreSync} from 'src/constants/store';
import {writeFileSync} from 'node:fs';

import {getStoreSync, store} from 'src/constants/store';

import {exec} from './exec';
import {Logger} from './logger';
import {getPackageInfo} from './package';

export async function debugExecAddAction(cmd: string, components: string[] = []) {
if (getStoreSync('debug')) {
Expand All @@ -12,3 +15,52 @@ export async function debugExecAddAction(cmd: string, components: string[] = [])
await exec(cmd);
}
}

export function debugAddedPkg(components: string[], packagePath: string) {
if (!components.length || !getStoreSync('debug')) return;

const {dependencies, packageJson} = getPackageInfo(packagePath);

for (const component of components) {
const compData = store.nextUIComponentsMap[component];

if (!compData) continue;

dependencies[compData.package] = `${compData.package}@${compData.version}`;
}
writeFileSync(
packagePath,
JSON.stringify(
{
...packageJson,
dependencies
},
null,
2
)
);
}

export function debugRemovedPkg(components: string[], packagePath: string) {
if (!components.length || !getStoreSync('debug')) return;

const {dependencies, packageJson} = getPackageInfo(packagePath);

for (const component of components) {
const compData = store.nextUIComponentsMap[component];

if (!compData) continue;
delete dependencies[compData.package];
}
writeFileSync(
packagePath,
JSON.stringify(
{
...packageJson,
dependencies
},
null,
2
)
);
}
2 changes: 1 addition & 1 deletion src/helpers/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function getPackageInfo(packagePath: string, transformVersion = true) {
dependencies,
devDependencies,
isAllComponents,
package: pkg
packageJson: pkg
};
}

Expand Down

0 comments on commit 14ac5ac

Please sign in to comment.