2025-06-18 18:50:46 +02:00
"use strict" ;
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
exports . runProgram = exports . run = void 0 ;
const tslib _1 = require ( "tslib" ) ;
const commander _1 = require ( "commander" ) ;
const path _1 = require ( "path" ) ;
const colors _1 = tslib _1 . _ _importDefault ( require ( "./colors" ) ) ;
const config _1 = require ( "./config" ) ;
const errors _1 = require ( "./errors" ) ;
const ipc _1 = require ( "./ipc" ) ;
const log _1 = require ( "./log" ) ;
const telemetry _1 = require ( "./telemetry" ) ;
const cli _1 = require ( "./util/cli" ) ;
const emoji _1 = require ( "./util/emoji" ) ;
2025-07-06 20:20:48 +02:00
process . on ( 'unhandledRejection' , ( error ) => {
2025-06-18 18:50:46 +02:00
console . error ( colors _1 . default . failure ( '[fatal]' ) , error ) ;
} ) ;
process . on ( 'message' , ipc _1 . receive ) ;
async function run ( ) {
try {
const config = await ( 0 , config _1 . loadConfig ) ( ) ;
runProgram ( config ) ;
}
catch ( e ) {
process . exitCode = ( 0 , errors _1 . isFatal ) ( e ) ? e . exitCode : 1 ;
log _1 . logger . error ( e . message ? e . message : String ( e ) ) ;
}
}
exports . run = run ;
function runProgram ( config ) {
commander _1 . program . version ( config . cli . package . version ) ;
commander _1 . program
. command ( 'config' , { hidden : true } )
. description ( ` print evaluated Capacitor config ` )
. option ( '--json' , 'Print in JSON format' )
. action ( ( 0 , cli _1 . wrapAction ) ( async ( { json } ) => {
const { configCommand } = await Promise . resolve ( ) . then ( ( ) => tslib _1 . _ _importStar ( require ( './tasks/config' ) ) ) ;
await configCommand ( config , json ) ;
} ) ) ;
commander _1 . program
. command ( 'create [directory] [name] [id]' , { hidden : true } )
. description ( 'Creates a new Capacitor project' )
. action ( ( 0 , cli _1 . wrapAction ) ( async ( ) => {
const { createCommand } = await Promise . resolve ( ) . then ( ( ) => tslib _1 . _ _importStar ( require ( './tasks/create' ) ) ) ;
await createCommand ( ) ;
} ) ) ;
commander _1 . program
. command ( 'init [appName] [appId]' )
. description ( ` Initialize Capacitor configuration ` )
. option ( '--web-dir <value>' , 'Optional: Directory of your projects built web assets' )
2025-07-06 20:20:48 +02:00
. option ( '--skip-appid-validation' , 'Optional: Skip validating the app ID for iOS and Android compatibility' )
. action ( ( 0 , cli _1 . wrapAction ) ( ( 0 , telemetry _1 . telemetryAction ) ( config , async ( appName , appId , { webDir , skipAppidValidation } ) => {
2025-06-18 18:50:46 +02:00
const { initCommand } = await Promise . resolve ( ) . then ( ( ) => tslib _1 . _ _importStar ( require ( './tasks/init' ) ) ) ;
2025-07-06 20:20:48 +02:00
await initCommand ( config , appName , appId , webDir , skipAppidValidation ) ;
2025-06-18 18:50:46 +02:00
} ) ) ) ;
commander _1 . program
. command ( 'serve' , { hidden : true } )
. description ( 'Serves a Capacitor Progressive Web App in the browser' )
. action ( ( 0 , cli _1 . wrapAction ) ( async ( ) => {
const { serveCommand } = await Promise . resolve ( ) . then ( ( ) => tslib _1 . _ _importStar ( require ( './tasks/serve' ) ) ) ;
await serveCommand ( ) ;
} ) ) ;
commander _1 . program
. command ( 'sync [platform]' )
. description ( ` ${ colors _1 . default . input ( 'copy' ) } + ${ colors _1 . default . input ( 'update' ) } ` )
. option ( '--deployment' , 'Optional: if provided, pod install will use --deployment option' )
. option ( '--inline' , 'Optional: if true, all source maps will be inlined for easier debugging on mobile devices' , false )
. action ( ( 0 , cli _1 . wrapAction ) ( ( 0 , telemetry _1 . telemetryAction ) ( config , async ( platform , { deployment , inline } ) => {
const { syncCommand } = await Promise . resolve ( ) . then ( ( ) => tslib _1 . _ _importStar ( require ( './tasks/sync' ) ) ) ;
await syncCommand ( config , platform , deployment , inline ) ;
} ) ) ) ;
commander _1 . program
. command ( 'update [platform]' )
. description ( ` updates the native plugins and dependencies based on ${ colors _1 . default . strong ( 'package.json' ) } ` )
. option ( '--deployment' , 'Optional: if provided, pod install will use --deployment option' )
. action ( ( 0 , cli _1 . wrapAction ) ( ( 0 , telemetry _1 . telemetryAction ) ( config , async ( platform , { deployment } ) => {
const { updateCommand } = await Promise . resolve ( ) . then ( ( ) => tslib _1 . _ _importStar ( require ( './tasks/update' ) ) ) ;
await updateCommand ( config , platform , deployment ) ;
} ) ) ) ;
commander _1 . program
. command ( 'copy [platform]' )
. description ( 'copies the web app build into the native app' )
. option ( '--inline' , 'Optional: if true, all source maps will be inlined for easier debugging on mobile devices' , false )
. action ( ( 0 , cli _1 . wrapAction ) ( ( 0 , telemetry _1 . telemetryAction ) ( config , async ( platform , { inline } ) => {
const { copyCommand } = await Promise . resolve ( ) . then ( ( ) => tslib _1 . _ _importStar ( require ( './tasks/copy' ) ) ) ;
await copyCommand ( config , platform , inline ) ;
} ) ) ) ;
commander _1 . program
. command ( 'build <platform>' )
. description ( 'builds the release version of the selected platform' )
. option ( '--scheme <schemeToBuild>' , 'iOS Scheme to build' )
. option ( '--flavor <flavorToBuild>' , 'Android Flavor to build' )
. option ( '--keystorepath <keystorePath>' , 'Path to the keystore' )
. option ( '--keystorepass <keystorePass>' , 'Password to the keystore' )
. option ( '--keystorealias <keystoreAlias>' , 'Key Alias in the keystore' )
. option ( '--configuration <name>' , 'Configuration name of the iOS Scheme' )
. option ( '--keystorealiaspass <keystoreAliasPass>' , 'Password for the Key Alias' )
2025-07-06 20:20:48 +02:00
. addOption ( new commander _1 . Option ( '--androidreleasetype <androidreleasetype>' , 'Android release type; APK or AAB' ) . choices ( [
'AAB' ,
'APK' ,
] ) )
. addOption ( new commander _1 . Option ( '--signing-type <signingtype>' , 'Program used to sign apps (default: jarsigner)' ) . choices ( [
'apksigner' ,
'jarsigner' ,
] ) )
. addOption ( new commander _1 . Option ( '--xcode-team-id <xcodeTeamID>' , 'The Developer team to use for building and exporting the archive' ) )
. addOption ( new commander _1 . Option ( '--xcode-export-method <xcodeExportMethod>' , 'Describes how xcodebuild should export the archive (default: app-store-connect)' ) . choices ( [
'app-store-connect' ,
'release-testing' ,
'enterprise' ,
'debugging' ,
'developer-id' ,
'mac-application' ,
'validation' ,
] ) )
. addOption ( new commander _1 . Option ( '--xcode-signing-style <xcodeSigningStyle>' , 'The iOS signing style to use when building the app for distribution (default: automatic)' ) . choices ( [ 'automatic' , 'manual' ] ) )
. addOption ( new commander _1 . Option ( '--xcode-signing-certificate <xcodeSigningCertificate>' , 'A certificate name, SHA-1 hash, or automatic selector to use for signing for iOS builds' ) )
. addOption ( new commander _1 . Option ( '--xcode-provisioning-profile <xcodeProvisioningProfile>' , 'A provisioning profile name or UUID for iOS builds' ) )
. action ( ( 0 , cli _1 . wrapAction ) ( ( 0 , telemetry _1 . telemetryAction ) ( config , async ( platform , { scheme , flavor , keystorepath , keystorepass , keystorealias , keystorealiaspass , androidreleasetype , signingType , configuration , xcodeTeamId , xcodeExportMethod , xcodeSigningStyle , xcodeSigningCertificate , xcodeProvisioningProfile , } ) => {
2025-06-18 18:50:46 +02:00
const { buildCommand } = await Promise . resolve ( ) . then ( ( ) => tslib _1 . _ _importStar ( require ( './tasks/build' ) ) ) ;
await buildCommand ( config , platform , {
scheme ,
flavor ,
keystorepath ,
keystorepass ,
keystorealias ,
keystorealiaspass ,
androidreleasetype ,
signingtype : signingType ,
configuration ,
2025-07-06 20:20:48 +02:00
xcodeTeamId ,
xcodeExportMethod ,
xcodeSigningType : xcodeSigningStyle ,
xcodeSigningCertificate ,
xcodeProvisioningProfile ,
2025-06-18 18:50:46 +02:00
} ) ;
} ) ) ) ;
commander _1 . program
. command ( ` run [platform] ` )
. description ( ` runs ${ colors _1 . default . input ( 'sync' ) } , then builds and deploys the native app ` )
. option ( '--scheme <schemeName>' , 'set the scheme of the iOS project' )
. option ( '--flavor <flavorName>' , 'set the flavor of the Android project (flavor dimensions not yet supported)' )
. option ( '--list' , 'list targets, then quit' )
2025-07-06 20:20:48 +02:00
. addOption ( new commander _1 . Option ( '--json' ) . hideHelp ( ) )
2025-06-18 18:50:46 +02:00
. option ( '--target <id>' , 'use a specific target' )
. option ( '--no-sync' , ` do not run ${ colors _1 . default . input ( 'sync' ) } ` )
. option ( '--forwardPorts <port:port>' , 'Automatically run "adb reverse" for better live-reloading support' )
. option ( '-l, --live-reload' , 'Enable Live Reload' )
. option ( '--host <host>' , 'Host used for live reload' )
. option ( '--port <port>' , 'Port used for live reload' )
. option ( '--configuration <name>' , 'Configuration name of the iOS Scheme' )
2025-07-06 20:20:48 +02:00
. action ( ( 0 , cli _1 . wrapAction ) ( ( 0 , telemetry _1 . telemetryAction ) ( config , async ( platform , { scheme , flavor , list , json , target , sync , forwardPorts , liveReload , host , port , configuration } ) => {
2025-06-18 18:50:46 +02:00
const { runCommand } = await Promise . resolve ( ) . then ( ( ) => tslib _1 . _ _importStar ( require ( './tasks/run' ) ) ) ;
await runCommand ( config , platform , {
scheme ,
flavor ,
list ,
2025-07-06 20:20:48 +02:00
json ,
2025-06-18 18:50:46 +02:00
target ,
sync ,
forwardPorts ,
liveReload ,
host ,
port ,
configuration ,
} ) ;
} ) ) ) ;
commander _1 . program
. command ( 'open [platform]' )
. description ( 'opens the native project workspace (Xcode for iOS)' )
. action ( ( 0 , cli _1 . wrapAction ) ( ( 0 , telemetry _1 . telemetryAction ) ( config , async ( platform ) => {
const { openCommand } = await Promise . resolve ( ) . then ( ( ) => tslib _1 . _ _importStar ( require ( './tasks/open' ) ) ) ;
await openCommand ( config , platform ) ;
} ) ) ) ;
commander _1 . program
. command ( 'add [platform]' )
. description ( 'add a native platform project' )
2025-07-06 20:20:48 +02:00
. option ( '--packagemanager <packageManager>' , 'The package manager to use for dependency installs (CocoaPods or SPM)' )
2025-06-18 18:50:46 +02:00
. action ( ( 0 , cli _1 . wrapAction ) ( ( 0 , telemetry _1 . telemetryAction ) ( config , async ( platform , { packagemanager } ) => {
const { addCommand } = await Promise . resolve ( ) . then ( ( ) => tslib _1 . _ _importStar ( require ( './tasks/add' ) ) ) ;
const configWritable = config ;
if ( packagemanager === 'SPM' ) {
2025-07-06 20:20:48 +02:00
configWritable . cli . assets . ios . platformTemplateArchive = 'ios-spm-template.tar.gz' ;
2025-06-18 18:50:46 +02:00
configWritable . cli . assets . ios . platformTemplateArchiveAbs = ( 0 , path _1 . resolve ) ( configWritable . cli . assetsDirAbs , configWritable . cli . assets . ios . platformTemplateArchive ) ;
}
await addCommand ( configWritable , platform ) ;
} ) ) ) ;
commander _1 . program
. command ( 'ls [platform]' )
. description ( 'list installed Cordova and Capacitor plugins' )
. action ( ( 0 , cli _1 . wrapAction ) ( ( 0 , telemetry _1 . telemetryAction ) ( config , async ( platform ) => {
const { listCommand } = await Promise . resolve ( ) . then ( ( ) => tslib _1 . _ _importStar ( require ( './tasks/list' ) ) ) ;
await listCommand ( config , platform ) ;
} ) ) ) ;
commander _1 . program
. command ( 'doctor [platform]' )
. description ( 'checks the current setup for common errors' )
. action ( ( 0 , cli _1 . wrapAction ) ( ( 0 , telemetry _1 . telemetryAction ) ( config , async ( platform ) => {
const { doctorCommand } = await Promise . resolve ( ) . then ( ( ) => tslib _1 . _ _importStar ( require ( './tasks/doctor' ) ) ) ;
await doctorCommand ( config , platform ) ;
} ) ) ) ;
commander _1 . program
. command ( 'telemetry [on|off]' , { hidden : true } )
. description ( 'enable or disable telemetry' )
. action ( ( 0 , cli _1 . wrapAction ) ( async ( onOrOff ) => {
const { telemetryCommand } = await Promise . resolve ( ) . then ( ( ) => tslib _1 . _ _importStar ( require ( './tasks/telemetry' ) ) ) ;
await telemetryCommand ( onOrOff ) ;
} ) ) ;
commander _1 . program
. command ( '📡' , { hidden : true } )
. description ( 'IPC receiver command' )
. action ( ( ) => {
// no-op: IPC messages are received via `process.on('message')`
} ) ;
commander _1 . program
. command ( 'plugin:generate' , { hidden : true } )
. description ( 'start a new Capacitor plugin' )
. action ( ( 0 , cli _1 . wrapAction ) ( async ( ) => {
const { newPluginCommand } = await Promise . resolve ( ) . then ( ( ) => tslib _1 . _ _importStar ( require ( './tasks/new-plugin' ) ) ) ;
await newPluginCommand ( ) ;
} ) ) ;
commander _1 . 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 ( ( 0 , cli _1 . wrapAction ) ( async ( { noprompt , packagemanager } ) => {
const { migrateCommand } = await Promise . resolve ( ) . then ( ( ) => tslib _1 . _ _importStar ( require ( './tasks/migrate' ) ) ) ;
await migrateCommand ( config , noprompt , packagemanager ) ;
} ) ) ;
2025-07-06 20:20:48 +02:00
commander _1 . program
. command ( 'spm-migration-assistant' )
. description ( 'Remove Cocoapods from project and switch to Swift Package Manager' )
. action ( ( 0 , cli _1 . wrapAction ) ( async ( ) => {
const { migrateToSPM } = await Promise . resolve ( ) . then ( ( ) => tslib _1 . _ _importStar ( require ( './tasks/migrate-spm' ) ) ) ;
await migrateToSPM ( config ) ;
} ) ) ;
2025-06-18 18:50:46 +02:00
commander _1 . program . arguments ( '[command]' ) . action ( ( 0 , cli _1 . wrapAction ) ( async ( cmd ) => {
if ( typeof cmd === 'undefined' ) {
log _1 . output . write ( ` \n ${ ( 0 , emoji _1 . emoji ) ( '⚡️' , '--' ) } ${ colors _1 . default . strong ( 'Capacitor - Cross-Platform apps with JavaScript and the Web' ) } ${ ( 0 , emoji _1 . emoji ) ( '⚡️' , '--' ) } \n \n ` ) ;
commander _1 . program . outputHelp ( ) ;
}
else {
( 0 , errors _1 . fatal ) ( ` Unknown command: ${ colors _1 . default . input ( cmd ) } ` ) ;
}
} ) ) ;
commander _1 . program . parse ( process . argv ) ;
}
exports . runProgram = runProgram ;