Created
July 28, 2015 20:56
-
-
Save Jonahss/679474eae9fa709949e0 to your computer and use it in GitHub Desktop.
getAppDataDir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the xcode 6 simulators are really annoying, and bury the main app | |
// directories inside directories just named with Hashes. | |
// This function finds the proper directory by traversing all of them | |
// and reading a metadata plist (Mobile Container Manager)to get the | |
// bundle id. | |
async getAppDataDir (bundleId) { | |
if (await this.isFresh()) { | |
log.info('Attempted to get an app path from a fresh simulator ' + | |
'quickly launching the sim to populate its directories'); | |
await this.launchAndQuit(); | |
} | |
const applicationList = path.resolve(this.getDir(), 'Containers', 'Data', 'Application'); | |
let readBundleId = async function (dir) { | |
let plist = path.resolve(dir, '.com.apple.mobile_container_manager.metadata.plist'); | |
let metadata = await parseFile(plist); | |
return metadata[0].MCMMetadataIdentifier; | |
}; | |
let bundlePathPair = async function (dir) { | |
dir = path.resolve(applicationList, dir); | |
return {path: dir, bundleId: await readBundleId(dir)}; | |
}; | |
let bundleIdMap = await directories(applicationList).map(bundlePathPair).then((pairs) => { | |
return pairs.reduce((a,b) => { | |
a[b.bundleId] = b.path; | |
return a; | |
}, {}); | |
}); | |
return bundleIdMap[bundleId]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment