Skip to content

Instantly share code, notes, and snippets.

@Jonahss
Created July 28, 2015 20:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jonahss/679474eae9fa709949e0 to your computer and use it in GitHub Desktop.
Save Jonahss/679474eae9fa709949e0 to your computer and use it in GitHub Desktop.
getAppDataDir
// 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