diff --git a/cli/src/index.ts b/cli/src/index.ts index 87b4c17876..c1661b3bba 100644 --- a/cli/src/index.ts +++ b/cli/src/index.ts @@ -301,13 +301,18 @@ export function runProgram(config: Config): void { program .command('migrate') + .option('--noprompt', 'do not prompt for confirmation') + .option( + '--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); }), ); diff --git a/cli/src/tasks/migrate.ts b/cli/src/tasks/migrate.ts index baf5e5cfbc..18cdc2eed4 100644 --- a/cli/src/tasks/migrate.ts +++ b/cli/src/tasks/migrate.ts @@ -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 { +export async function migrateCommand( + config: Config, + noprompt: boolean, + packagemanager: string, +): Promise { if (config === null) { fatal('Config data missing'); } @@ -92,30 +96,34 @@ export async function migrateCommand(config: Config): Promise { 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' && @@ -123,20 +131,19 @@ export async function migrateCommand(config: Config): Promise { 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; }