1+ import * as path from 'path' ;
2+
13import { BaseIntegration } from '../' ;
2- import { IIntegrationAddOptions , InfoItem , IntegrationName } from '../../../definitions' ;
4+ import { IIntegrationAddOptions , InfoItem , IntegrationName , ProjectPersonalizationDetails } from '../../../definitions' ;
35import { pkgManagerArgs } from '../../utils/npm' ;
46
7+ import { CAPACITOR_CONFIG_FILE , CapacitorConfig } from './config' ;
8+
59export class Integration extends BaseIntegration {
610 readonly name : IntegrationName = 'capacitor' ;
711 readonly summary = `Target native iOS and Android with Capacitor, Ionic's new native layer` ;
812 readonly archiveUrl = undefined ;
913
1014 async add ( options ?: IIntegrationAddOptions ) : Promise < void > {
15+ let name = this . e . project . config . get ( 'name' ) ;
16+ let packageId = 'io.ionic.starter' ;
17+
18+ if ( options && options . enableArgs ) {
19+ if ( options . enableArgs [ 0 ] ) {
20+ name = options . enableArgs [ 0 ] ;
21+ }
22+
23+ if ( options . enableArgs [ 1 ] ) {
24+ packageId = options . enableArgs [ 1 ] ;
25+ }
26+ }
27+
1128 await this . installCapacitorCore ( ) ;
1229 await this . installCapacitorCLI ( ) ;
1330
14- await this . e . shell . run ( 'capacitor' , [ 'init' , this . e . project . config . get ( ' name' ) , 'io.ionic.starter' ] , { cwd : this . e . project . directory } ) ;
31+ await this . e . shell . run ( 'capacitor' , [ 'init' , name , packageId ] , { cwd : this . e . project . directory } ) ;
1532
1633 await super . add ( options ) ;
1734 }
@@ -26,6 +43,16 @@ export class Integration extends BaseIntegration {
2643 await this . e . shell . run ( manager , managerArgs , { cwd : this . e . project . directory } ) ;
2744 }
2845
46+ async personalize ( { name, packageId } : ProjectPersonalizationDetails ) {
47+ const conf = new CapacitorConfig ( path . resolve ( this . e . project . directory , CAPACITOR_CONFIG_FILE ) ) ;
48+
49+ conf . set ( 'appName' , name ) ;
50+
51+ if ( packageId ) {
52+ conf . set ( 'appId' , packageId ) ;
53+ }
54+ }
55+
2956 async getInfo ( ) : Promise < InfoItem [ ] > {
3057 const [
3158 [ capacitorCorePkg , capacitorCorePkgPath ] ,
0 commit comments