@@ -2,21 +2,18 @@ import * as fs from 'fs';
22import { Answers , prompt } from 'inquirer' ;
33import * as _ from 'lodash' ;
44import * as path from 'path' ;
5- import { Args , getPlatformChoices } from '../../Constants' ;
5+ import { Args } from '../../Constants' ;
66import { exists , matchesContent , patchMatchingFile } from '../../Helper/File' ;
77import { dim , green , l , nl , red } from '../../Helper/Logging' ;
88import { SentryCli } from '../../Helper/SentryCli' ;
9- import { MobileProject } from './MobileProject ' ;
9+ import { BaseIntegration } from './BaseIntegration ' ;
1010
1111const xcode = require ( 'xcode' ) ;
1212
13- export class Cordova extends MobileProject {
13+ export class Cordova extends BaseIntegration {
1414 protected sentryCli : SentryCli ;
1515 protected folderPrefix = 'platforms' ;
16- protected pluginFolder = [ 'plugins' , 'sentry-cordova' ] ;
17- // We need this whenever scoped packages are supported
18- // https://issues.apache.org/jira/browse/CB-10239?jql=labels%20%3D%20cordova-8.0.0
19- // protected pluginFolder = ['plugins', '@sentry', 'cordova'];
16+ protected pluginFolder = [ '.' ] ;
2017
2118 constructor ( protected argv : Args ) {
2219 super ( argv ) ;
@@ -32,27 +29,15 @@ export class Cordova extends MobileProject {
3229 answers ,
3330 ) ;
3431
35- return new Promise ( async ( resolve , reject ) => {
36- const promises = this . getPlatforms ( answers ) . map (
37- async ( platform : string ) => {
38- try {
39- if ( platform === 'ios' ) {
40- await patchMatchingFile (
41- `${ this . folderPrefix } /ios/*.xcodeproj/project.pbxproj` ,
42- this . patchXcodeProj . bind ( this ) ,
43- ) ;
44- }
45- await this . addSentryProperties ( platform , sentryCliProperties ) ;
46- green ( `Successfully set up ${ platform } for cordova` ) ;
47- } catch ( e ) {
48- red ( e ) ;
49- }
50- } ,
51- ) ;
52- Promise . all ( promises )
53- . then ( resolve )
54- . catch ( reject ) ;
55- } ) ;
32+ await patchMatchingFile (
33+ `${ this . folderPrefix } /ios/*.xcodeproj/project.pbxproj` ,
34+ this . patchXcodeProj . bind ( this ) ,
35+ ) ;
36+
37+ await this . addSentryProperties ( sentryCliProperties ) ;
38+ green ( `Successfully set up for cordova` ) ;
39+
40+ return { } ;
5641 }
5742
5843 public async uninstall ( answers : Answers ) : Promise < Answers > {
@@ -64,29 +49,31 @@ export class Cordova extends MobileProject {
6449 return { } ;
6550 }
6651
67- protected async shouldConfigurePlatform ( platform : string ) : Promise < boolean > {
52+ public async shouldConfigure ( answers : Answers ) : Promise < Answers > {
53+ if ( this . _shouldConfigure ) {
54+ return this . _shouldConfigure ;
55+ }
56+
6857 let result = false ;
69- if ( ! exists ( path . join ( ... this . pluginFolder , 'sentry.properties' ) ) ) {
58+ if ( ! exists ( path . join ( 'sentry.properties' ) ) ) {
7059 result = true ;
71- this . debug ( `${ this . pluginFolder } / sentry.properties not exists` ) ;
60+ this . debug ( `sentry.properties not exists` ) ;
7261 }
7362
74- if ( platform === 'ios' ) {
75- if (
76- ! matchesContent ( '**/*.xcodeproj/project.pbxproj' , / S E N T R Y _ P R O P E R T I E S / gi)
77- ) {
78- result = true ;
79- this . debug ( '**/*.xcodeproj/project.pbxproj not matched' ) ;
80- }
63+ if (
64+ ! matchesContent ( '**/*.xcodeproj/project.pbxproj' , / S E N T R Y _ P R O P E R T I E S / gi)
65+ ) {
66+ result = true ;
67+ this . debug ( '**/*.xcodeproj/project.pbxproj not matched' ) ;
8168 }
8269
8370 if ( this . argv . uninstall ) {
8471 // if we uninstall we need to invert the result so we remove already patched
85- // but leave untouched platforms as they are
86- return ! result ;
72+ result = ! result ;
8773 }
8874
89- return result ;
75+ this . _shouldConfigure = Promise . resolve ( { cordova : result } ) ;
76+ return this . shouldConfigure ;
9077 }
9178
9279 private unpatchXcodeProj (
@@ -191,7 +178,7 @@ export class Cordova extends MobileProject {
191178 return ;
192179 }
193180 }
194-
181+ const cwd = path . join ( process . cwd ( ) , 'sentry.properties' ) ;
195182 proj . addBuildPhase (
196183 [ ] ,
197184 'PBXShellScriptBuildPhase' ,
@@ -200,12 +187,18 @@ export class Cordova extends MobileProject {
200187 {
201188 shellPath : '/bin/sh' ,
202189 shellScript :
203- 'export SENTRY_PROPERTIES=sentry.properties\\n' +
190+ 'export SENTRY_PROPERTIES=' +
191+ cwd +
192+ '\\n' +
204193 'function getProperty {\\n' +
205194 ' PROP_KEY=$1\\n' +
206195 ' PROP_VALUE=`cat $SENTRY_PROPERTIES | grep "$PROP_KEY" | cut -d\'=\' -f2`\\n' +
207196 ' echo $PROP_VALUE\\n' +
208197 '}\\n' +
198+ 'if [ ! -f $SENTRY_PROPERTIES ]; then\\n' +
199+ ' echo "warning: SENTRY: sentry.properties file not found! Skipping symbol upload."\\n' +
200+ ' exit 0\\n' +
201+ 'fi\\n' +
209202 'echo "# Reading property from $SENTRY_PROPERTIES"\\n' +
210203 'SENTRY_CLI=$(getProperty "cli.executable")\\n' +
211204 'SENTRY_COMMAND="../../$SENTRY_CLI upload-dsym"\\n' +
@@ -259,25 +252,12 @@ export class Cordova extends MobileProject {
259252 // tslint:enable:no-invalid-template-strings
260253 }
261254
262- private addSentryProperties (
263- platform : string ,
264- properties : any ,
265- ) : Promise < void > {
255+ private addSentryProperties ( properties : any ) : Promise < void > {
266256 let rv = Promise . resolve ( ) ;
267- // This will create the ios/android folder before trying to write
268- // sentry.properties in it which would fail otherwise
269-
270- let allFolders = '' ;
271- this . pluginFolder . map ( folderPath => {
272- allFolders = path . join ( allFolders , folderPath ) ;
273- if ( ! fs . existsSync ( allFolders ) ) {
274- dim ( `intermediate ${ allFolders } folder did not exist, creating it.` ) ;
275- fs . mkdirSync ( allFolders ) ;
276- }
277- } ) ;
278-
279- const fn = path . join ( allFolders , 'sentry.properties' ) ;
280-
257+ const fn = path . join ( 'sentry.properties' ) ;
258+ if ( exists ( fn ) ) {
259+ return rv ;
260+ }
281261 rv = rv . then ( ( ) =>
282262 fs . writeFileSync ( fn , this . sentryCli . dumpProperties ( properties ) ) ,
283263 ) ;
0 commit comments