Skip to content

Commit

Permalink
fix: reduce fetch components (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
winchesHe authored Dec 7, 2024
1 parent 0863d3b commit 6fca076
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/constants/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type NextUIComponentsMap = Record<string, Components[0]>;

export type Store = {
debug: boolean;
beta: boolean;
cliLatestVersion: string;
latestVersion: string;
betaVersion: string;
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ nextui.hook('preAction', async (command) => {
initCache(noCache);
// Init debug
store.debug = debug;
store.beta = options.includes('-b') || options.includes('--beta');

if (args && commandList.includes(args as CommandName)) {
// Before run the command init the components.json
Expand Down
10 changes: 5 additions & 5 deletions src/scripts/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ora, {oraPromise} from 'ora';

import {Logger} from '@helpers/logger';
import {COMPONENTS_PATH} from 'src/constants/path';
import {getStore} from 'src/constants/store';
import {getStore, getStoreSync} from 'src/constants/store';

import {getPackageVersion} from './cache/cache';

Expand Down Expand Up @@ -147,7 +147,7 @@ export async function autoUpdateComponents(latestVersion?: string, betaVersion?:

const [components, betaComponents] = await Promise.all([
downloadFile(url),
downloadFile(getUnpkgUrl(betaVersion), false)
getStoreSync('beta') ? downloadFile(getUnpkgUrl(betaVersion), false) : Promise.resolve([])
]);

const filterMissingComponents = betaComponents.filter(
Expand Down Expand Up @@ -201,9 +201,9 @@ export async function downloadFile(url: string, log = true): Promise<Components>
log && Logger.prefix('error', `Update components data error: ${error}`);
process.exit(1);
},
successText: (() => {
return chalk.greenBright('Components data updated successfully!\n');
})(),
successText() {
return log ? chalk.greenBright('Components data updated successfully!\n') : '';
},
text: 'Fetching components data...'
}
);
Expand Down

0 comments on commit 6fca076

Please sign in to comment.