Skip to content

Commit

Permalink
chore: improve mr after review (II)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedro-gomes-92 committed Dec 20, 2024
1 parent 38d22be commit b372387
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 36 deletions.
25 changes: 11 additions & 14 deletions rush-plugins/rush-migrate-subspace-plugin/src/cleanSubspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
scanForAllDependenciesPrompt
} from './prompts/subspace';
import Console from './providers/console';
import { getRootPath } from './utilities/path';
import { Colorize } from '@rushstack/terminal';
import {
getRushSubspaceCommonVersionsFilePath,
Expand Down Expand Up @@ -246,16 +245,14 @@ const removeSupersetDependencyVersions = async (
} while (multipleVersionDependencies.length > 0 && (await confirmNextDependencyPrompt()));
};

export const cleanSubspace = async (targetMonorepoPath: string = getRootPath()): Promise<void> => {
export const cleanSubspace = async (rootPath: string): Promise<void> => {
Console.debug('Executing clean subspace command...');

const targetSubspaces: string[] = querySubspaces(targetMonorepoPath);
if (!isSubspaceSupported(targetMonorepoPath)) {
const targetSubspaces: string[] = querySubspaces(rootPath);
if (!isSubspaceSupported(rootPath)) {
Console.error(
`The monorepo ${Colorize.bold(
targetMonorepoPath
)} doesn't support subspaces! Make sure you have ${Colorize.bold(
getRushSubspacesConfigurationJsonPath(targetMonorepoPath)
`The monorepo ${Colorize.bold(rootPath)} doesn't support subspaces! Make sure you have ${Colorize.bold(
getRushSubspacesConfigurationJsonPath(rootPath)
)} with the ${Colorize.bold(RushConstants.defaultSubspaceName)} subspace. Exiting...`
);
return;
Expand All @@ -266,20 +263,20 @@ export const cleanSubspace = async (targetMonorepoPath: string = getRootPath()):

let subspaceDependencies: Map<string, Map<string, string[]>> = getSubspaceDependencies(
targetSubspace,
targetMonorepoPath
rootPath
);
if (await scanForDuplicatedDependenciesPrompt()) {
removeDuplicatedDependencies(targetSubspace, targetMonorepoPath);
subspaceDependencies = getSubspaceDependencies(targetSubspace, targetMonorepoPath);
removeDuplicatedDependencies(targetSubspace, rootPath);
subspaceDependencies = getSubspaceDependencies(targetSubspace, rootPath);
}

if (await scanForSupersetDependencyVersionsPrompt()) {
await removeSupersetDependencyVersions(targetSubspace, subspaceDependencies, targetMonorepoPath);
subspaceDependencies = getSubspaceDependencies(targetSubspace, targetMonorepoPath);
await removeSupersetDependencyVersions(targetSubspace, subspaceDependencies, rootPath);
subspaceDependencies = getSubspaceDependencies(targetSubspace, rootPath);
}

if (await scanForUnusedDependencyVersionsPrompt()) {
removeUnusedAlternativeVersions(targetSubspace, subspaceDependencies, targetMonorepoPath);
removeUnusedAlternativeVersions(targetSubspace, subspaceDependencies, rootPath);
}

Console.warn(
Expand Down
12 changes: 8 additions & 4 deletions rush-plugins/rush-migrate-subspace-plugin/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { migrateProject } from './migrateProject';
import Console from './providers/console';
import { interactMenu } from './interactMenu';
import { cleanSubspace } from './cleanSubspace';
import { getRootPath } from './utilities/path';

inquirer.registerPrompt('search-list', inquirerSearchList);

Expand All @@ -26,14 +27,17 @@ program
Console.title(`🚀 Rush Migrate Subspace Plugin - version ${packageJson.version}`);
Console.newLine();

const sourceMonorepoPath: string = getRootPath();
const targetMonorepoPath: string = getRootPath();

if (sync) {
await syncVersions();
await syncVersions(targetMonorepoPath);
} else if (move) {
await migrateProject();
await migrateProject(sourceMonorepoPath, targetMonorepoPath);
} else if (clean) {
await cleanSubspace();
await cleanSubspace(targetMonorepoPath);
} else {
await interactMenu();
await interactMenu(sourceMonorepoPath, targetMonorepoPath);
}
});

Expand Down
8 changes: 4 additions & 4 deletions rush-plugins/rush-migrate-subspace-plugin/src/interactMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { chooseCommandPrompt } from './prompts/command';
import Console from './providers/console';
import { syncVersions } from './syncVersions';

export const interactMenu = async (): Promise<void> => {
export const interactMenu = async (sourceMonorepoPath: string, targetMonorepoPath: string): Promise<void> => {
let exitApplication: boolean = false;
do {
const nextCommand: string = await chooseCommandPrompt();
Expand All @@ -14,17 +14,17 @@ export const interactMenu = async (): Promise<void> => {
break;

case 'move':
await migrateProject();
await migrateProject(sourceMonorepoPath, targetMonorepoPath);
Console.newLine();
break;

case 'sync':
await syncVersions();
await syncVersions(targetMonorepoPath);
Console.newLine();
break;

case 'clean':
await cleanSubspace();
await cleanSubspace(targetMonorepoPath);
Console.newLine();
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { chooseSubspacePrompt } from './prompts/subspace';
import { addProjectToSubspace } from './functions/addProjectToSubspace';
import { chooseProjectPrompt, confirmNextProjectToAddPrompt } from './prompts/project';
import Console from './providers/console';
import { getRootPath } from './utilities/path';
import { Colorize } from '@rushstack/terminal';
import { updateSubspace } from './functions/updateSubspace';
import { getRushSubspaceConfigurationFolderPath, isSubspaceSupported } from './utilities/subspace';
Expand All @@ -16,7 +15,10 @@ import {
import { RushConstants } from '@rushstack/rush-sdk';
import { syncProjectMismatchedDependencies } from './functions/syncProjectDependencies';

export const migrateProject = async (targetMonorepoPath: string = getRootPath()): Promise<void> => {
export const migrateProject = async (
sourceMonorepoPath: string,
targetMonorepoPath: string
): Promise<void> => {
Console.debug('Executing project migration command...');

Console.title(`🔍 Analyzing if monorepo ${Colorize.underline(targetMonorepoPath)} supports subspaces...`);
Expand Down Expand Up @@ -55,8 +57,6 @@ export const migrateProject = async (targetMonorepoPath: string = getRootPath())
* );
*/

const sourceMonorepoPath: string = getRootPath();

/**
* WARN: Disabling creating new subspaces for now.
* const subspaceSelectionType: string = await chooseCreateOrSelectSubspacePrompt(targetSubspaces);
Expand Down
16 changes: 6 additions & 10 deletions rush-plugins/rush-migrate-subspace-plugin/src/syncVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { VersionMismatchFinderEntity } from '@rushstack/rush-sdk/lib/logic/versi
import Console from './providers/console';
import { Colorize } from '@rushstack/terminal';
import { querySubspaces } from './utilities/repository';
import { getRootPath } from './utilities/path';
import { getSubspaceMismatches } from './utilities/subspace';
import { chooseProjectPrompt, confirmNextProjectToSyncPrompt } from './prompts/project';
import { syncProjectMismatchedDependencies } from './functions/syncProjectDependencies';
Expand Down Expand Up @@ -32,34 +31,31 @@ const fetchSubspaceMismatchedProjects = (subspaceName: string, rootPath: string)
return mismatchedProjects;
};

export const syncVersions = async (targetMonorepoPath: string = getRootPath()): Promise<void> => {
export const syncVersions = async (rootPath: string): Promise<void> => {
Console.debug('Synching project version...');

const sourceSubspaces: string[] = querySubspaces(targetMonorepoPath);
const sourceSubspaces: string[] = querySubspaces(rootPath);
if (sourceSubspaces.length === 0) {
Console.error(`No subspaces found in the monorepo ${Colorize.bold(targetMonorepoPath)}! Exiting...`);
Console.error(`No subspaces found in the monorepo ${Colorize.bold(rootPath)}! Exiting...`);
return;
}

const selectedSubspaceName: string = await chooseSubspacePrompt(sourceSubspaces);
Console.title(`🔄 Syncing version mismatches for subspace ${Colorize.bold(selectedSubspaceName)}...`);

let mismatchedProjects: string[] = fetchSubspaceMismatchedProjects(
selectedSubspaceName,
targetMonorepoPath
);
let mismatchedProjects: string[] = fetchSubspaceMismatchedProjects(selectedSubspaceName, rootPath);
if (mismatchedProjects.length === 0) {
Console.success(`No mismatches found in the subspace ${Colorize.bold(selectedSubspaceName)}! Exiting...`);
return;
}

do {
const selectedProjectName: string = await chooseProjectPrompt(mismatchedProjects);
if (!(await syncProjectMismatchedDependencies(selectedProjectName, targetMonorepoPath))) {
if (!(await syncProjectMismatchedDependencies(selectedProjectName, rootPath))) {
return;
}

mismatchedProjects = fetchSubspaceMismatchedProjects(selectedSubspaceName, targetMonorepoPath);
mismatchedProjects = fetchSubspaceMismatchedProjects(selectedSubspaceName, rootPath);
} while (mismatchedProjects.length > 0 && (await confirmNextProjectToSyncPrompt(selectedSubspaceName)));

if (mismatchedProjects.length === 0) {
Expand Down

0 comments on commit b372387

Please sign in to comment.