Skip to content

Commit

Permalink
feat(cli): non interactive migrate (#6461)
Browse files Browse the repository at this point in the history
  • Loading branch information
dtarnawsky authored and markemer committed Apr 17, 2023
1 parent e8c81b3 commit 79c2c55
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 35 deletions.
9 changes: 7 additions & 2 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,18 @@ export function runProgram(config: Config): void {

program
.command('migrate')
.option('--noprompt', 'do not prompt for confirmation')
.option(
'--packagemanager <packageManager>',
'The package manager to use for dependency installs (npm, pnpm, yarn)',
)
.description(
'Migrate your current Capacitor app to the latest major version of Capacitor.',
)
.action(
wrapAction(async () => {
wrapAction(async ({ noprompt, packagemanager }) => {
const { migrateCommand } = await import('./tasks/migrate');
await migrateCommand(config);
await migrateCommand(config, noprompt, packagemanager);
}),
);

Expand Down
73 changes: 40 additions & 33 deletions cli/src/tasks/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ const coreVersion = 'next'; // TODO: Update when Capacitor 5 releases
const pluginVersion = 'next'; // TODO: Update when Capacitor 5 releases
const gradleVersion = '7.5';

export async function migrateCommand(config: Config): Promise<void> {
export async function migrateCommand(
config: Config,
noprompt: boolean,
packagemanager: string,
): Promise<void> {
if (config === null) {
fatal('Config data missing');
}
Expand Down Expand Up @@ -92,51 +96,54 @@ export async function migrateCommand(config: Config): Promise<void> {

logger.info(monorepoWarning);

const { migrateconfirm } = await logPrompt(
`Capacitor 5 sets a deployment target of iOS 13 and Android 13 (SDK 33). \n`,
{
type: 'text',
name: 'migrateconfirm',
message: `Are you sure you want to migrate? (Y/n)`,
initial: 'y',
},
);
const { migrateconfirm } = noprompt
? { migrateconfirm: 'y' }
: await logPrompt(
`Capacitor 5 sets a deployment target of iOS 13 and Android 13 (SDK 33). \n`,
{
type: 'text',
name: 'migrateconfirm',
message: `Are you sure you want to migrate? (Y/n)`,
initial: 'y',
},
);

if (
typeof migrateconfirm === 'string' &&
migrateconfirm.toLowerCase() === 'y'
) {
try {
const { depInstallConfirm } = await logPrompt(
`Would you like the migrator to run npm, yarn, or pnpm install to install the latest versions of capacitor packages? (Those using other package managers should answer N)`,
{
type: 'text',
name: 'depInstallConfirm',
message: `Run Dependency Install? (Y/n)`,
initial: 'y',
},
);
const { depInstallConfirm } = noprompt
? { depInstallConfirm: 'y' }
: await logPrompt(
`Would you like the migrator to run npm, yarn, or pnpm install to install the latest versions of capacitor packages? (Those using other package managers should answer N)`,
{
type: 'text',
name: 'depInstallConfirm',
message: `Run Dependency Install? (Y/n)`,
initial: 'y',
},
);

const runNpmInstall =
typeof depInstallConfirm === 'string' &&
depInstallConfirm.toLowerCase() === 'y';

let installerType = 'npm';
if (runNpmInstall) {
const { manager } = await logPrompt(
'What dependency manager do you use?',
{
type: 'select',
name: 'manager',
message: `Dependency Management Tool`,
choices: [
{ title: 'NPM', value: 'npm' },
{ title: 'Yarn', value: 'yarn' },
{ title: 'PNPM', value: 'pnpm' },
],
initial: 0,
},
);
const { manager } = packagemanager
? { manager: packagemanager }
: await logPrompt('What dependency manager do you use?', {
type: 'select',
name: 'manager',
message: `Dependency Management Tool`,
choices: [
{ title: 'NPM', value: 'npm' },
{ title: 'Yarn', value: 'yarn' },
{ title: 'PNPM', value: 'pnpm' },
],
initial: 0,
});
installerType = manager;
}

Expand Down

0 comments on commit 79c2c55

Please sign in to comment.