Skip to content

Commit

Permalink
feat: remove ios-deploy (appium#1009)
Browse files Browse the repository at this point in the history
  • Loading branch information
umutuzgur authored Jul 23, 2019
1 parent da48205 commit e351eb3
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 24 deletions.
81 changes: 68 additions & 13 deletions lib/ios-deploy.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import { exec } from 'teen_process';
/* eslint-disable promise/prefer-await-to-callbacks */
import { fs } from 'appium-support';
import logger from './logger';
import { retryInterval } from 'asyncbox';
import path from 'path';
import { services } from 'appium-ios-device';
import B from 'bluebird';

const IOSDEPLOY_PATH = `ios-deploy`;
const APPLICATION_INSTALLED_NOTIFICATION = 'com.apple.mobile.application_installed';
const INSTALLATION_STAGING_DIR = 'PublicStaging';
const APPLICATION_PUSH_TIMEOUT = 60 * 1000;

class IOSDeploy {

constructor (udid) {
this.udid = udid;
this.cmd = IOSDEPLOY_PATH; // this.cmd is in accordance with iDevice
}

async checkStatus () {
// make sure we actually have the program
await fs.which(this.cmd);
}

async remove (bundleid) {
Expand All @@ -32,15 +28,74 @@ class IOSDeploy {
}

async install (app) {
const args = [`--id`, this.udid, `--bundle`, app];
try {
await retryInterval(5, 500, exec, this.cmd, args);
const bundlePathOnPhone = await this.pushAppBundle(app);
await this.installApplcation(bundlePathOnPhone);
} catch (err) {
logger.debug(`Stdout: '${err.stdout}'. Stderr: '${err.stderr}'.`);
throw new Error(`Could not install app: '${err.message}'`);
}
}

async installApplcation (bundlePathOnPhone) {
const notificationService = await services.startNotificationProxyService(this.udid);
const installationService = await services.startInstallationProxyService(this.udid);
const appInstalledNotification = new B((resolve) => {
notificationService.observeNotification(APPLICATION_INSTALLED_NOTIFICATION, { notification: resolve });
});
try {
await installationService.installApplication(bundlePathOnPhone, { PackageType: 'Developer'});
await appInstalledNotification;
} finally {
installationService.close();
notificationService.close();
}
}

async pushAppBundle (app) {
const afcService = await services.startAfcService(this.udid);
try {
const bundlePathOnPhone = await this.createAppPath(afcService, app);
const promises = [];
await this.walkDir(app, async (itemPath, isDir) => {
const pathOnPhone = path.join(bundlePathOnPhone, path.relative(app, itemPath));
if (isDir) {
await afcService.createDirectory(pathOnPhone);
} else {
const readStream = fs.createReadStream(itemPath, {autoClose: true});
const writeStream = await afcService.createWriteStream(pathOnPhone, {autoDestroy: true });
promises.push(new B((resolve) => writeStream.on('close', resolve)));
readStream.pipe(writeStream);
}
});
await B.all(promises).timeout(APPLICATION_PUSH_TIMEOUT);
return bundlePathOnPhone;
} finally {
afcService.close();
}
}

async createAppPath (afcService, localAppPath) {
const basename = path.basename(localAppPath);
const relativePath = path.join(INSTALLATION_STAGING_DIR, basename);
try {
await afcService.deleteDirectory(relativePath);
} catch (ign) {}
await afcService.createDirectory(relativePath);
return relativePath;
}

async walkDir (dir, callback) {
for (const file of await fs.readdir(dir, { withFileTypes: true })) {
const itemPath = path.join(dir, file.name);
const isDirectory = file.isDirectory();
await callback(itemPath, isDirectory);
if (!isDirectory) {
continue;
}
await this.walkDir(itemPath, callback);
}
}

async installApp (app) {
await this.install(app);
}
Expand Down
13 changes: 2 additions & 11 deletions lib/real-device-management.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,9 @@ async function installToRealDevice (device, app, bundleId, noReset = true) {
log.debug('The app has been installed successfully.');
}

async function getRealDeviceObj (udid) {
function getRealDeviceObj (udid) {
log.debug(`Creating iDevice object with udid '${udid}'`);
try {
//This iDevice object could be ideviceinstaller (node-idevice) for future once we have ideviceinstaller working for ios 10
let device = new IOSDeploy(udid);
await device.checkStatus();
return device;
} catch (e) {
let msg = 'Could not initialize ios-deploy make sure it is installed ' +
'(npm install -g ios-deploy) and works on your system.';
log.errorAndThrow(msg);
}
return new IOSDeploy(udid);
}

export { getConnectedDevices, getOSVersion, runRealDeviceReset, installToRealDevice,
Expand Down

0 comments on commit e351eb3

Please sign in to comment.