Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "rush-migrate-subspace-plugin",
"comment": "Supports external repository subspace migration",
"type": "minor"
}
],
"packageName": "rush-migrate-subspace-plugin"
}
5 changes: 2 additions & 3 deletions rush-plugins/rush-migrate-subspace-plugin/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,16 @@ program
Console.title(`🚀 Rush Migrate Subspace Plugin - version ${packageJson.version}`);
Console.newLine();

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Colorize } from '@rushstack/terminal';
import { IRushConfigurationProjectJson } from '@rushstack/rush-sdk/lib/api/RushConfigurationProject';
import { enterNewProjectLocationPrompt, moveProjectPrompt } from '../prompts/project';
import { RushConstants } from '@rushstack/rush-sdk';
import { addProjectToRushConfiguration } from './updateRushConfiguration';
import { addProjectToRushConfiguration, removeProjectFromRushConfiguration } from './updateRushConfiguration';
import {
getRushSubspacesConfigurationJsonPath,
isExternalMonorepo,
Expand Down Expand Up @@ -73,7 +73,7 @@ export const addProjectToSubspace = async (
targetMonorepoPath: string
): Promise<void> => {
Console.debug(
`Adding project ${Colorize.bold(sourceProject.packageName)} to subspace ${Colorize.bold(
`Adding source project ${Colorize.bold(sourceProject.packageName)} to target subspace ${Colorize.bold(
targetSubspace
)}...`
);
Expand All @@ -99,25 +99,21 @@ export const addProjectToSubspace = async (
}
}

/** WARN: Disabling different repositories for now.
addProjectToRushConfiguration(sourceProject, targetSubspace, targetProjectFolderPath);
removeProjectFromRushConfiguration(sourceProject, sourceMonorepoPath);
*/

const targetLegacySubspaceFolderPath: string = `${targetProjectFolderPath}/subspace`;
if (FileSystem.exists(targetLegacySubspaceFolderPath)) {
Console.debug(`Removing legacy subspace folder ${Colorize.bold(targetLegacySubspaceFolderPath)}...`);
FileSystem.deleteFolder(targetLegacySubspaceFolderPath);
}

addProjectToRushConfiguration(sourceProject, targetSubspace, targetProjectFolderPath, targetMonorepoPath);
removeProjectFromRushConfiguration(sourceProject, sourceMonorepoPath);
if (sourceProject.subspaceName) {
refreshSubspace(sourceProject.subspaceName, sourceMonorepoPath);
}

Console.success(
`Project ${Colorize.bold(
`Source project ${Colorize.bold(
sourceProject.packageName
)} has been successfully added to subspace ${Colorize.bold(targetSubspace)}.`
)} has been successfully added to target subspace ${Colorize.bold(targetSubspace)}.`
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export const removeProjectFromRushConfiguration = (

if (projectIndex < 0) {
Console.error(
`The project ${Colorize.bold(project.packageName)} wasn't found in ${RushConstants.rushJsonFilename}!`
`The source project ${Colorize.bold(project.packageName)} wasn't found in ${
RushConstants.rushJsonFilename
}!`
);
return;
}
Expand Down
4 changes: 2 additions & 2 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 (sourceMonorepoPath: string, targetMonorepoPath: string): Promise<void> => {
export const interactMenu = async (targetMonorepoPath: string): Promise<void> => {
let exitApplication: boolean = false;
do {
const nextCommand: string = await chooseCommandPrompt();
Expand All @@ -14,7 +14,7 @@ export const interactMenu = async (sourceMonorepoPath: string, targetMonorepoPat
break;

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

Expand Down
45 changes: 9 additions & 36 deletions rush-plugins/rush-migrate-subspace-plugin/src/migrateProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,13 @@ import {
} from './utilities/repository';
import { RushConstants } from '@rushstack/rush-sdk';
import { syncProjectMismatchedDependencies } from './functions/syncProjectDependencies';
import { chooseRepositoryPrompt } from './prompts/repository';

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

Console.title(`🔍 Analyzing if monorepo ${Colorize.underline(targetMonorepoPath)} supports subspaces...`);

/**
* WARN: Disabling auto subspace initialization for now.
* if (!isSubspaceSupported()) {
* Console.warn(
* `The monorepo ${Colorize.bold(rootPath)} doesn't contain subspaces. Initializing subspaces...`
*);
* await initSubspaces();
* }
*/

const targetSubspaces: string[] = querySubspaces(targetMonorepoPath);
if (!isSubspaceSupported(targetMonorepoPath) || targetSubspaces.length === 0) {
Console.error(
Expand All @@ -49,27 +37,12 @@ export const migrateProject = async (

Console.title(`🔍 Finding projects to migrate to ${Colorize.bold(targetMonorepoPath)}...`);

/**
* WARN: Disabling different repository selection for now.
* const sourceMonorepoPath: string = await chooseRepositoryPrompt();
* Console.warn(
* `The script will migrate from ${Colorize.bold(sourceMonorepoPath)} to ${Colorize.bold(getRootPath())}`
* );
*/

/**
* WARN: Disabling creating new subspaces for now.
* const subspaceSelectionType: string = await chooseCreateOrSelectSubspacePrompt(targetSubspaces);
*
* const targetSubspace: string =
* subspaceSelectionType === 'new'
* ? await createSubspacePrompt(targetSubspaces)
* : await chooseSubspacePrompt(targetSubspaces);
*
* if (!targetSubspaces.includes(targetSubspace)) {
* await createSubspace(targetSubspace);
*}
*/
const sourceMonorepoPath: string = await chooseRepositoryPrompt();
Console.warn(
`The script will migrate from ${Colorize.bold(sourceMonorepoPath)} to ${Colorize.bold(
targetMonorepoPath
)}`
);

const targetSubspace: string = await chooseSubspacePrompt(targetSubspaces);

Expand Down Expand Up @@ -101,7 +74,7 @@ export const migrateProject = async (
}

Console.title(
`🏃 Migrating project ${sourceProjectToMigrate.packageName} to subspace ${targetSubspace}...`
`🏃 Migrating source project ${sourceProjectToMigrate.packageName} to target subspace ${targetSubspace}...`
);

if (sourceProjectToMigrate.subspaceName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const enterNewProjectLocationPrompt = async (
export const chooseProjectPrompt = async (projects: string[]): Promise<string> => {
const { projectName } = await inquirer.prompt([
{
message: `Please select the project name (Type to filter).`,
message: `Please select the source project name (Type to filter).`,
type: 'search-list',
name: 'projectName',
choices: projects.sort().map((name) => ({ name, value: name }))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FileSystem } from '@rushstack/node-core-library';
export const chooseRepositoryPrompt = async (): Promise<string> => {
const { repoPathInput } = await inquirer.prompt([
{
message: 'Please enter the repository root path.',
message: 'Please enter the source repository root path.',
type: 'input',
name: 'repoPathInput',
default: getRootPath(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import inquirer from 'inquirer';
export const chooseSubspacePrompt = async (subspaces: string[]): Promise<string> => {
const { subspaceNameInput } = await inquirer.prompt([
{
message: 'Please select the subspace name (Type to filter).',
message: 'Please select the target subspace name (Type to filter).',
type: 'search-list',
name: 'subspaceNameInput',
choices: subspaces.sort().map((name) => ({ name, value: name }))
Expand Down