Skip to content

Commit

Permalink
feat: upgrade command add setup pnpm (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
winchesHe committed Jun 14, 2024
1 parent 5c3c3f7 commit 1beb52c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/actions/upgrade-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {exec} from '@helpers/exec';
import {Logger} from '@helpers/logger';
import {colorMatchRegex} from '@helpers/output-info';
import {getPackageInfo} from '@helpers/package';
import {setupPnpm} from '@helpers/setup';
import {upgrade} from '@helpers/upgrade';
import {getColorVersion, getPackageManagerInfo, transformPeerVersion} from '@helpers/utils';
import {type NextUIComponents} from 'src/constants/component';
Expand Down Expand Up @@ -121,6 +122,7 @@ export async function upgradeAction(components: string[], options: UpgradeAction
upgradeOptionList
});
let ignoreList: string[] = [];
const packageManager = await detect();

if (result.length) {
const isExecute = await getSelect('Would you like to proceed with the upgrade?', [
Expand All @@ -135,7 +137,6 @@ export async function upgradeAction(components: string[], options: UpgradeAction
}
]);

const packageManager = await detect();
const {install} = getPackageManagerInfo(packageManager);

if (!isExecute) {
Expand Down Expand Up @@ -184,6 +185,9 @@ export async function upgradeAction(components: string[], options: UpgradeAction
);
}

/** ======================== Setup Pnpm ======================== */
setupPnpm(packageManager);

Logger.newLine();
Logger.success('✅ Upgrade complete. All components are up to date.');

Expand Down
4 changes: 2 additions & 2 deletions src/helpers/fix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ export function fixPnpm(

if (!logger) {
Logger.newLine();
Logger.info(`Added the required content in file: ${npmrcPath}`);
Logger.log(`Added the required content in file: ${npmrcPath}`);

if (runInstall) {
Logger.newLine();
Logger.info('Pnpm restructure will be run now');
Logger.log('Pnpm restructure will be run now');
runInstall && execSync('pnpm install', {stdio: 'inherit'});
}

Expand Down
25 changes: 25 additions & 0 deletions src/helpers/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

import { existsSync, writeFileSync } from 'node:fs';

import { resolver } from 'src/constants/path';
import { pnpmRequired } from 'src/constants/required';

import { checkPnpm } from './check';
import { type Agent } from './detect';
import { fixPnpm } from './fix';

export async function setupPnpm(packageManager: Agent) {
if (packageManager === 'pnpm') {
const npmrcPath = resolver('.npmrc');

if (!existsSync(npmrcPath)) {
writeFileSync(resolver('.npmrc'), pnpmRequired.content, 'utf-8');
} else {
const [isCorrectPnpm] = checkPnpm(npmrcPath);

if (!isCorrectPnpm) {
fixPnpm(npmrcPath);
}
}
}
}

0 comments on commit 1beb52c

Please sign in to comment.