2025-06-18 18:50:46 +02:00
"use strict" ;
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
exports . addCommand = void 0 ;
const tslib _1 = require ( "tslib" ) ;
const utils _terminal _1 = require ( "@ionic/utils-terminal" ) ;
2025-07-06 20:20:48 +02:00
const fs _extra _1 = require ( "fs-extra" ) ;
2025-06-18 18:50:46 +02:00
const add _1 = require ( "../android/add" ) ;
const common _1 = require ( "../android/common" ) ;
const colors _1 = tslib _1 . _ _importDefault ( require ( "../colors" ) ) ;
const common _2 = require ( "../common" ) ;
const errors _1 = require ( "../errors" ) ;
const add _2 = require ( "../ios/add" ) ;
const common _3 = require ( "../ios/common" ) ;
const log _1 = require ( "../log" ) ;
const sync _1 = require ( "./sync" ) ;
async function addCommand ( config , selectedPlatformName ) {
var _a ;
if ( selectedPlatformName && ! ( await ( 0 , common _2 . isValidPlatform ) ( selectedPlatformName ) ) ) {
const platformDir = ( 0 , common _2 . resolvePlatform ) ( config , selectedPlatformName ) ;
if ( platformDir ) {
await ( 0 , common _2 . runPlatformHook ) ( config , selectedPlatformName , platformDir , 'capacitor:add' ) ;
}
else {
let msg = ` Platform ${ colors _1 . default . input ( selectedPlatformName ) } not found. ` ;
if ( await ( 0 , common _2 . isValidCommunityPlatform ) ( selectedPlatformName ) ) {
msg += ` \n Try installing ${ colors _1 . default . strong ( ` @capacitor-community/ ${ selectedPlatformName } ` ) } and adding the platform again. ` ;
}
if ( await ( 0 , common _2 . isValidEnterprisePlatform ) ( selectedPlatformName ) ) {
msg +=
` \n This is an enterprise platform and @ionic-enterprise/capacitor- ${ selectedPlatformName } is not installed. \n ` +
` To learn how to use this platform, visit https://ionic.io/docs/ ${ selectedPlatformName } ` ;
}
log _1 . logger . error ( msg ) ;
}
}
else {
const knownPlatforms = await ( 0 , common _2 . getKnownPlatforms ) ( ) ;
const platformName = await ( 0 , common _2 . promptForPlatform ) ( knownPlatforms , ` Please choose a platform to add: ` , selectedPlatformName ) ;
if ( platformName === config . web . name ) {
webWarning ( ) ;
return ;
}
const existingPlatformDir = await ( 0 , common _2 . getProjectPlatformDirectory ) ( config , platformName ) ;
if ( existingPlatformDir ) {
( 0 , errors _1 . fatal ) ( ` ${ colors _1 . default . input ( platformName ) } platform already exists. \n ` +
` To re-add this platform, first remove ${ colors _1 . default . strong ( ( 0 , utils _terminal _1 . prettyPath ) ( existingPlatformDir ) ) } , then run this command again. \n ` +
` ${ colors _1 . default . strong ( 'WARNING' ) } : Your native project will be completely removed. ` ) ;
}
try {
2025-07-06 20:20:48 +02:00
await ( 0 , common _2 . check ) ( [ ( ) => ( 0 , common _2 . checkPackage ) ( ) , ( ) => ( 0 , common _2 . checkAppConfig ) ( config ) , ... addChecks ( config , platformName ) ] ) ;
2025-06-18 18:50:46 +02:00
await doAdd ( config , platformName ) ;
await editPlatforms ( config , platformName ) ;
2025-07-06 20:20:48 +02:00
if ( await ( 0 , fs _extra _1 . pathExists ) ( config . app . webDirAbs ) ) {
2025-06-18 18:50:46 +02:00
await ( 0 , sync _1 . sync ) ( config , platformName , false , false ) ;
if ( platformName === config . android . name ) {
await ( 0 , common _2 . runTask ) ( 'Syncing Gradle' , async ( ) => {
return ( 0 , add _1 . createLocalProperties ) ( config . android . platformDirAbs ) ;
} ) ;
}
}
else {
log _1 . logger . warn ( ` ${ colors _1 . default . success ( colors _1 . default . strong ( 'sync' ) ) } could not run--missing ${ colors _1 . default . strong ( config . app . webDir ) } directory. ` ) ;
}
printNextSteps ( platformName ) ;
}
catch ( e ) {
if ( ! ( 0 , errors _1 . isFatal ) ( e ) ) {
( 0 , errors _1 . fatal ) ( ( _a = e . stack ) !== null && _a !== void 0 ? _a : e ) ;
}
throw e ;
}
}
}
exports . addCommand = addCommand ;
function printNextSteps ( platformName ) {
( 0 , log _1 . logSuccess ) ( ` ${ colors _1 . default . strong ( platformName ) } platform added! ` ) ;
log _1 . output . write ( ` Follow the Developer Workflow guide to get building: \n ${ colors _1 . default . strong ( ` https://capacitorjs.com/docs/basics/workflow ` ) } \n ` ) ;
}
function addChecks ( config , platformName ) {
if ( platformName === config . ios . name ) {
2025-07-06 20:20:48 +02:00
return [ ( ) => ( 0 , common _3 . checkIOSPackage ) ( config ) , ( ) => ( 0 , common _3 . checkBundler ) ( config ) || ( 0 , common _3 . checkCocoaPods ) ( config ) ] ;
2025-06-18 18:50:46 +02:00
}
else if ( platformName === config . android . name ) {
return [ ( ) => ( 0 , common _1 . checkAndroidPackage ) ( config ) ] ;
}
else if ( platformName === config . web . name ) {
return [ ] ;
}
else {
throw ` Platform ${ platformName } is not valid. ` ;
}
}
async function doAdd ( config , platformName ) {
await ( 0 , common _2 . runTask ) ( colors _1 . default . success ( colors _1 . default . strong ( 'add' ) ) , async ( ) => {
if ( platformName === config . ios . name ) {
await ( 0 , add _2 . addIOS ) ( config ) ;
}
else if ( platformName === config . android . name ) {
await ( 0 , add _1 . addAndroid ) ( config ) ;
}
} ) ;
}
async function editPlatforms ( config , platformName ) {
if ( platformName === config . ios . name ) {
await ( 0 , common _3 . editProjectSettingsIOS ) ( config ) ;
}
else if ( platformName === config . android . name ) {
await ( 0 , common _1 . editProjectSettingsAndroid ) ( config ) ;
}
}
function webWarning ( ) {
log _1 . logger . error ( ` Not adding platform ${ colors _1 . default . strong ( 'web' ) } . \n ` +
` In Capacitor, the web platform is just your web app! For example, if you have a React or Angular project, the web platform is that project. \n ` +
` To add Capacitor functionality to your web app, follow the Web Getting Started Guide: ${ colors _1 . default . strong ( 'https://capacitorjs.com/docs/web' ) } ` ) ;
}