Skip to content

Commit

Permalink
fix: add error catch and optimize output
Browse files Browse the repository at this point in the history
  • Loading branch information
winchesHe committed Mar 29, 2024
1 parent f2302ed commit bc88222
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions src/actions/list-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,31 @@ export async function listAction(options: ListActionOptions) {

let components = nextUIComponents as NextUIComponents;

/** ======================== Get the installed components ======================== */
if (current) {
const pkg = await import(packagePath);
const devDependencies = pkg.devDependencies || {};
const dependencies = pkg.dependencies || {};
const allDependencies = { ...devDependencies, ...dependencies };
const dependenciesKeys = new Set(Object.keys(allDependencies));

components = components.filter((component) => dependenciesKeys.has(component.name));
}
try {
/** ======================== Get the installed components ======================== */
if (current) {
const pkg = await import(packagePath);
const devDependencies = pkg.devDependencies || {};
const dependencies = pkg.dependencies || {};
const allDependencies = { ...devDependencies, ...dependencies };
const dependenciesKeys = new Set(Object.keys(allDependencies));

components = components.filter((component) => dependenciesKeys.has(component.name));
}

if (!components.length) {
Logger.warn(
`No installed NextUI components found, reference package.json path: ${packagePath}`
);

if (!components.length) {
Logger.warn(
`No installed NextUI components found, reference package.json path: ${packagePath}`
);
return;
}

return;
/** ======================== Output the components ======================== */
outputComponents(components);
} catch (error) {
Logger.error(`NextUI CLI Error occurred while listing the components: ${error}`);
}

/** ======================== Output the components ======================== */
outputComponents(components);
}

function outputComponents(components: NextUIComponents) {
Expand All @@ -78,7 +82,7 @@ function outputComponents(components: NextUIComponents) {
}
}

const transformComponentsOutput = components.reduce((acc, component) => {
let transformComponentsOutput = components.reduce((acc, component) => {
let outputData = padStart;

for (const key of orderNextUIComponentKeys) {
Expand Down Expand Up @@ -125,10 +129,13 @@ function outputComponents(components: NextUIComponents) {

boxFooter = boxFooter.slice(0, -2) + rounded.br;

transformComponentsOutput.unshift(boxHeaderTrd);
transformComponentsOutput.unshift(boxHeaderSec);
transformComponentsOutput.unshift(boxHeader);
transformComponentsOutput.push(boxFooter);
transformComponentsOutput = [
boxHeader,
boxHeaderSec,
boxHeaderTrd,
...transformComponentsOutput,
boxFooter
];

Logger.info('Current NextUI Components:\n');

Expand Down

0 comments on commit bc88222

Please sign in to comment.