1
1
import _ from 'lodash' ;
2
2
import path from 'path' ;
3
- import { plist , fs , util , tempDir , zip } from 'appium/support' ;
3
+ import { plist , fs , util , tempDir , zip } from 'appium/support' ;
4
4
import log from './logger.js' ;
5
5
6
6
const STRINGSDICT_RESOURCE = '.stringsdict' ;
@@ -19,7 +19,7 @@ const PLIST_CACHE = new WeakMap();
19
19
* @returns {Promise<any | undefined> } Either the extracted value or undefined if no such key has been found in the plist.
20
20
* @throws {Error } If the application's Info.plist cannot be parsed.
21
21
*/
22
- async function extractPlistEntry ( app , entryName ) {
22
+ async function extractPlistEntry ( app , entryName ) {
23
23
const plistPath = path . resolve ( app , 'Info.plist' ) ;
24
24
25
25
const parseFile = async ( ) => {
@@ -47,17 +47,17 @@ async function extractPlistEntry (app, entryName) {
47
47
return plistObj [ entryName ] ;
48
48
}
49
49
50
- async function extractBundleId ( app ) {
50
+ async function extractBundleId ( app ) {
51
51
const bundleId = await extractPlistEntry . bind ( this ) ( app , 'CFBundleIdentifier' ) ;
52
52
log . debug ( `Getting bundle ID from app '${ app } ': '${ bundleId } '` ) ;
53
53
return bundleId ;
54
54
}
55
55
56
- async function extractBundleVersion ( app ) {
56
+ async function extractBundleVersion ( app ) {
57
57
return await extractPlistEntry . bind ( this ) ( app , 'CFBundleVersion' ) ;
58
58
}
59
59
60
- async function fetchSupportedAppPlatforms ( app ) {
60
+ async function fetchSupportedAppPlatforms ( app ) {
61
61
try {
62
62
const result = await extractPlistEntry . bind ( this ) ( app , 'CFBundleSupportedPlatforms' ) ;
63
63
if ( ! _ . isArray ( result ) ) {
@@ -67,7 +67,7 @@ async function fetchSupportedAppPlatforms (app) {
67
67
return result ;
68
68
} catch ( err ) {
69
69
log . warn (
70
- `Cannot extract the list of supported platforms from '${ path . basename ( app ) } ': ${ err . message } `
70
+ `Cannot extract the list of supported platforms from '${ path . basename ( app ) } ': ${ err . message } ` ,
71
71
) ;
72
72
return [ ] ;
73
73
}
@@ -88,26 +88,27 @@ async function fetchSupportedAppPlatforms (app) {
88
88
* @param {PlatformOpts } expectedPlatform
89
89
* @throws {Error } If bundle architecture does not match the expected device architecture.
90
90
*/
91
- async function verifyApplicationPlatform ( app , expectedPlatform ) {
91
+ async function verifyApplicationPlatform ( app , expectedPlatform ) {
92
92
log . debug ( 'Verifying application platform' ) ;
93
93
94
94
const supportedPlatforms = await fetchSupportedAppPlatforms . bind ( this ) ( app ) ;
95
95
log . debug ( `CFBundleSupportedPlatforms: ${ JSON . stringify ( supportedPlatforms ) } ` ) ;
96
96
97
- const {
98
- isSimulator,
99
- isTvOS,
100
- } = expectedPlatform ;
97
+ const { isSimulator, isTvOS} = expectedPlatform ;
101
98
const prefix = isTvOS ? 'AppleTV' : 'iPhone' ;
102
99
const suffix = isSimulator ? 'Simulator' : 'OS' ;
103
100
const dstPlatform = `${ prefix } ${ suffix } ` ;
104
101
if ( ! supportedPlatforms . includes ( dstPlatform ) ) {
105
- throw new Error ( `${ isSimulator ? 'Simulator' : 'Real device' } architecture is unsupported by the '${ app } ' application. ` +
106
- `Make sure the correct deployment target has been selected for its compilation in Xcode.` ) ;
102
+ throw new Error (
103
+ `${
104
+ isSimulator ? 'Simulator' : 'Real device'
105
+ } architecture is unsupported by the '${ app } ' application. ` +
106
+ `Make sure the correct deployment target has been selected for its compilation in Xcode.` ,
107
+ ) ;
107
108
}
108
109
}
109
110
110
- async function readResource ( resourcePath ) {
111
+ async function readResource ( resourcePath ) {
111
112
const data = await plist . parsePlistFile ( resourcePath ) ;
112
113
const result = { } ;
113
114
for ( const [ key , value ] of _ . toPairs ( data ) ) {
@@ -116,14 +117,8 @@ async function readResource (resourcePath) {
116
117
return result ;
117
118
}
118
119
119
- async function parseLocalizableStrings ( opts ) {
120
- const {
121
- app,
122
- language = 'en' ,
123
- localizableStringsDir,
124
- stringFile,
125
- strictMode,
126
- } = opts ;
120
+ async function parseLocalizableStrings ( opts ) {
121
+ const { app, language = 'en' , localizableStringsDir, stringFile, strictMode} = opts ;
127
122
128
123
if ( ! app ) {
129
124
const message = `Strings extraction is not supported if 'app' capability is not set` ;
@@ -163,7 +158,7 @@ async function parseLocalizableStrings (opts) {
163
158
}
164
159
}
165
160
166
- if ( _ . isEmpty ( resourcePaths ) && await fs . exists ( String ( lprojRoot ) ) ) {
161
+ if ( _ . isEmpty ( resourcePaths ) && ( await fs . exists ( String ( lprojRoot ) ) ) ) {
167
162
const resourceFiles = ( await fs . readdir ( String ( lprojRoot ) ) )
168
163
. filter ( ( name ) => _ . some ( [ STRINGS_RESOURCE , STRINGSDICT_RESOURCE ] , ( x ) => name . endsWith ( x ) ) )
169
164
. map ( ( name ) => path . resolve ( lprojRoot , name ) ) ;
@@ -203,10 +198,12 @@ async function parseLocalizableStrings (opts) {
203
198
* @param {string } appPath Possible .app bundle root
204
199
* @returns {Promise<boolean> } Whether the given path points to an .app bundle
205
200
*/
206
- async function isAppBundle ( appPath ) {
207
- return _ . endsWith ( _ . toLower ( appPath ) , APP_EXT )
208
- && ( await fs . stat ( appPath ) ) . isDirectory ( )
209
- && await fs . exists ( path . join ( appPath , 'Info.plist' ) ) ;
201
+ async function isAppBundle ( appPath ) {
202
+ return (
203
+ _ . endsWith ( _ . toLower ( appPath ) , APP_EXT ) &&
204
+ ( await fs . stat ( appPath ) ) . isDirectory ( ) &&
205
+ ( await fs . exists ( path . join ( appPath , 'Info.plist' ) ) )
206
+ ) ;
210
207
}
211
208
212
209
/**
@@ -218,16 +215,18 @@ async function isAppBundle (appPath) {
218
215
* a temporary folder root where the archive has been extracted and the second item
219
216
* contains a list of relative paths to matched items
220
217
*/
221
- async function findApps ( archivePath , appExtensions ) {
218
+ async function findApps ( archivePath , appExtensions ) {
222
219
const useSystemUnzipEnv = process . env . APPIUM_PREFER_SYSTEM_UNZIP ;
223
- const useSystemUnzip = _ . isEmpty ( useSystemUnzipEnv )
224
- || ! [ '0' , 'false' ] . includes ( _ . toLower ( useSystemUnzipEnv ) ) ;
220
+ const useSystemUnzip =
221
+ _ . isEmpty ( useSystemUnzipEnv ) || ! [ '0' , 'false' ] . includes ( _ . toLower ( useSystemUnzipEnv ) ) ;
225
222
const tmpRoot = await tempDir . openDir ( ) ;
226
223
await zip . extractAllTo ( archivePath , tmpRoot , { useSystemUnzip} ) ;
227
224
const globPattern = `**/*.+(${ appExtensions . map ( ( ext ) => ext . replace ( / ^ \. / , '' ) ) . join ( '|' ) } )` ;
228
- const sortedBundleItems = ( await fs . glob ( globPattern , {
229
- cwd : tmpRoot ,
230
- } ) ) . sort ( ( a , b ) => a . split ( path . sep ) . length - b . split ( path . sep ) . length ) ;
225
+ const sortedBundleItems = (
226
+ await fs . glob ( globPattern , {
227
+ cwd : tmpRoot ,
228
+ } )
229
+ ) . sort ( ( a , b ) => a . split ( path . sep ) . length - b . split ( path . sep ) . length ) ;
231
230
return [ tmpRoot , sortedBundleItems ] ;
232
231
}
233
232
@@ -238,15 +237,23 @@ async function findApps (archivePath, appExtensions) {
238
237
* @returns {Promise<string> } The new path to the app bundle.
239
238
* The name of the app bundle remains though
240
239
*/
241
- async function isolateAppBundle ( appRoot ) {
240
+ async function isolateAppBundle ( appRoot ) {
242
241
const tmpRoot = await tempDir . openDir ( ) ;
243
242
const dstRoot = path . join ( tmpRoot , path . basename ( appRoot ) ) ;
244
243
await fs . mv ( appRoot , dstRoot , { mkdirp : true } ) ;
245
244
return dstRoot ;
246
245
}
247
246
248
247
export {
249
- extractBundleId , verifyApplicationPlatform , parseLocalizableStrings ,
250
- SAFARI_BUNDLE_ID , fetchSupportedAppPlatforms , APP_EXT , IPA_EXT ,
251
- isAppBundle , findApps , isolateAppBundle , extractBundleVersion ,
248
+ extractBundleId ,
249
+ verifyApplicationPlatform ,
250
+ parseLocalizableStrings ,
251
+ SAFARI_BUNDLE_ID ,
252
+ fetchSupportedAppPlatforms ,
253
+ APP_EXT ,
254
+ IPA_EXT ,
255
+ isAppBundle ,
256
+ findApps ,
257
+ isolateAppBundle ,
258
+ extractBundleVersion ,
252
259
} ;
0 commit comments