From 91e36a3e56e712af2c104eafc45eeeba5997ad6a Mon Sep 17 00:00:00 2001 From: Sammy Jelin Date: Fri, 18 Nov 2016 10:38:32 -0800 Subject: [PATCH] feat(android on windows): Support android VMs on windows (#154) Closes https://github.com/angular/webdriver-manager/issues/51 --- lib/cmds/initialize.ts | 27 +++++++++------------------ lib/cmds/start.ts | 4 ++-- lib/cmds/update.ts | 3 ++- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/lib/cmds/initialize.ts b/lib/cmds/initialize.ts index 20229093..6eef2c82 100644 --- a/lib/cmds/initialize.ts +++ b/lib/cmds/initialize.ts @@ -69,27 +69,16 @@ function downloadAndroidUpdates( // Setup hardware acceleration for x86-64 emulation function setupHardwareAcceleration(sdkPath: string) { - // TODO(sjelin): check that the BIOS option is set properly on linux + // TODO(sjelin): linux setup + let toolDir = path.resolve(sdkPath, 'extras', 'intel', 'Hardware_Accelerated_Execution_Manager'); if (os.type() == 'Darwin') { console.log('Enabling hardware acceleration (requires root access)'); // We don't need the wrapped spawnSync because we know we're on OSX - spawnSync( - 'sudo', [path.resolve( - sdkPath, 'extras', 'intel', 'Hardware_Accelerated_Execution_Manager', - 'silent_install.sh')], - {stdio: 'inherit'}); + spawnSync('sudo', ['silent_install.sh'], {stdio: 'inherit', cwd: toolDir}); } else if (os.type() == 'Windows_NT') { console.log('Enabling hardware acceleration (requires admin access)'); - // We don't need the wrapped spawnSync because we know we're on Windows - spawnSync( - 'cmd', - [ - '/c', 'runas', '/noprofile', '/user:Administrator', - path.resolve( - sdkPath, 'extras', 'intel', 'Hardware_Accelerated_Execution_Manager', - 'silent_install.bat') - ], - {stdio: 'inherit'}); + // We don't need the wrapped spawnSync because we know we're on windows + spawnSync('silent_install.bat', [], {stdio: 'inherit', cwd: toolDir}); } } @@ -169,12 +158,14 @@ class AVDDescriptor { // SDKs which were downloaded function getAVDDescriptors(sdkPath: string): q.Promise { let deferred = q.defer(); - glob(path.resolve(sdkPath, 'system-images', '*', '*', '*'), (err: Error, files: string[]) => { + // `glob` package always prefers patterns to use `/` + glob('system-images/*/*/*', {cwd: sdkPath}, (err: Error, files: string[]) => { if (err) { deferred.reject(err); } else { deferred.resolve(files.map((file: string) => { - let info = file.split(path.sep).slice(-3); + // `file` could use `/` or `\`, so we use `path.normalize` + let info = path.normalize(file).split(path.sep).slice(-3); return new AVDDescriptor(info[0], info[1], info[2]); })); } diff --git a/lib/cmds/start.ts b/lib/cmds/start.ts index e2fa915e..57d17c09 100644 --- a/lib/cmds/start.ts +++ b/lib/cmds/start.ts @@ -277,8 +277,8 @@ function startAppium(outputDir: string, binary: Binary, androidSDK: Binary, port process.env.ANDROID_HOME = path.resolve(outputDir, androidSDK.executableFilename(os.type())); } appiumProcess = spawn( - path.resolve(outputDir, binary.filename(), 'node_modules', '.bin', 'appium'), - port ? ['--port', port] : []); + 'npm', ['run', 'appium'].concat(port ? ['--', '--port', port] : []), null, + {cwd: path.resolve(outputDir, binary.filename())}); } function killAppium() { diff --git a/lib/cmds/update.ts b/lib/cmds/update.ts index 7675b6f5..2c603ee0 100644 --- a/lib/cmds/update.ts +++ b/lib/cmds/update.ts @@ -249,6 +249,7 @@ function installAppium(binary: Binary, outputDir: string): void { } fs.mkdirSync(folder); - fs.writeFileSync(path.resolve(folder, 'package.json'), '{}'); + fs.writeFileSync( + path.resolve(folder, 'package.json'), JSON.stringify({scripts: {appium: 'appium'}})); spawn('npm', ['install', 'appium@' + binary.version()], null, {cwd: folder}); }