Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add main pkg when upgrade #62

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/actions/upgrade-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {Logger} from '@helpers/logger';
import {colorMatchRegex} from '@helpers/output-info';
import {getPackageInfo} from '@helpers/package';
import {upgrade} from '@helpers/upgrade';
import {getColorVersion, getPackageManagerInfo} from '@helpers/utils';
import {getColorVersion, getPackageManagerInfo, transformPeerVersion} from '@helpers/utils';
import {type NextUIComponents} from 'src/constants/component';
import {resolver} from 'src/constants/path';
import {NEXT_UI} from 'src/constants/required';
Expand All @@ -25,15 +25,17 @@ interface UpgradeActionOptions {
patch?: boolean;
}

type TransformComponent = Required<
AppendKeyValue<NextUIComponents[0], 'latestVersion', string> & {isLatest: boolean}
>;

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

const isNextUIAll = !!allDependencies[NEXT_UI];

const transformComponents: Required<
AppendKeyValue<NextUIComponents[0], 'latestVersion', string> & {isLatest: boolean}
>[] = [];
const transformComponents: TransformComponent[] = [];

for (const component of currentComponents) {
const latestVersion =
Expand Down Expand Up @@ -63,6 +65,17 @@ export async function upgradeAction(components: string[], options: UpgradeAction
process.exit(0);
}

// If have the main nextui then add
if (isNextUIAll) {
const nextuiData = {
latestVersion: store.latestVersion,
package: NEXT_UI,
version: transformPeerVersion(allDependencies[NEXT_UI])
} as TransformComponent;

transformComponents.push(nextuiData);
}

components = await getAutocompleteMultiselect(
'Select the components to upgrade',
transformComponents.map((component) => {
Expand Down
10 changes: 8 additions & 2 deletions src/scripts/cache/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export interface CacheData {
[packageName: string]: {
version: string;
date: Date;
formatDate: string;
expiredDate: number;
expiredFormatDate: string;
execResult: SAFE_ANY;
};
}
Expand Down Expand Up @@ -46,11 +48,15 @@ export function cacheData(
initCache();

const data = cacheData ?? getCacheData();
const now = new Date();
const expiredDate = +now + cacheTTL;

data[packageName] = {
...(packageData as SAFE_ANY),
date: new Date(),
expiredDate: +new Date() + cacheTTL
date: now,
expiredDate,
expiredFormatDate: new Date(expiredDate).toString(),
formatDate: now.toString()
};

writeFileSync(CACHE_PATH, JSON.stringify(data, undefined, 2), 'utf-8');
Expand Down