Skip to content

Commit

Permalink
refactor(cli/migrate): convenience function for resolving general all…
Browse files Browse the repository at this point in the history
… migration inputs
  • Loading branch information
pcattori committed Apr 9, 2022
1 parent fa93bd2 commit 6087b24
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
24 changes: 22 additions & 2 deletions packages/remix-dev/cli/migrate/resolveInput.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import inquirer from "inquirer";

import { checkGitStatus } from "../checkGitStatus";
import type { Flags } from "./flags";
import { migrations } from "./migrations";

export const resolveProjectDir = (input?: string): string => {
const resolveProjectDir = (input?: string): string => {
return input || process.env.REMIX_ROOT || process.cwd();
};

export const resolveMigrationId = async (input?: string): Promise<string> => {
const resolveMigrationId = async (input?: string): Promise<string> => {
if (input !== undefined) return input;
let { migrationId } = await inquirer.prompt<{ migrationId?: string }>([
{
Expand All @@ -33,3 +35,21 @@ export const resolveMigrationId = async (input?: string): Promise<string> => {
}
return migrationId;
};

export const resolveInput = async (
input: {
projectId: string;
migrationId?: string;
},
flags: Flags
) => {
let projectDir = resolveProjectDir(input.projectId);
if (!flags.dry) {
checkGitStatus(projectDir, { force: flags.force });
}
let migrationId = await resolveMigrationId(input.migrationId);
return {
projectDir,
migrationId,
};
};
13 changes: 6 additions & 7 deletions packages/remix-dev/cli/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import inquirer from "inquirer";
import * as colors from "../colors";
import * as commands from "./commands";
import { validateNewProjectPath, validateTemplate } from "./create";
import { checkGitStatus } from "./checkGitStatus";

const helpText = `
${colors.logoBlue("R")} ${colors.logoGreen("E")} ${colors.logoYellow(
Expand Down Expand Up @@ -346,12 +345,12 @@ export async function run(argv: string[] = process.argv.slice(2)) {
await commands.setup(input[1]);
break;
case "migrate": {
let projectDir = commands.migrate.resolveProjectDir(input[1]);
if (!flags.dry) {
checkGitStatus(projectDir, { force: flags.force });
}
let migrationId = await commands.migrate.resolveMigrationId(
flags.migration
let { projectDir, migrationId } = await commands.migrate.resolveInput(
{
projectId: input[1],
migrationId: flags.migration,
},
flags
);
await commands.migrate.run({ migrationId, projectDir, flags });
break;
Expand Down

0 comments on commit 6087b24

Please sign in to comment.