[go: nahoru, domu]

Skip to content

Commit

Permalink
Clean up supported platform launcher.
Browse files Browse the repository at this point in the history
This drops our need to have the magic any here, since the index type is
explicitly defined, this also means that our compile will now break if
a function is renamed that we were depending on :)
  • Loading branch information
samccone committed May 15, 2017
1 parent 8a6c1aa commit 320614c
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions chrome-launcher/chrome-launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const execSync = childProcess.execSync;
const isWindows = process.platform === 'win32';

export class ChromeLauncher {
type SupportedPlatforms = 'darwin'|'linux'|'win32';
prepared = false;
pollInterval: number = 500;
autoSelectChrome: boolean;
Expand Down Expand Up @@ -75,8 +76,10 @@ export class ChromeLauncher {
return flags;
}

prepare() {
switch (process.platform) {
private prepare() {
const platform = process.platform as SupportedPlatforms;

switch (platform) {
case 'darwin':
case 'linux':
this.TMP_PROFILE_DIR = unixTmpDir();
Expand All @@ -87,7 +90,7 @@ export class ChromeLauncher {
break;

default:
throw new Error('Platform ' + process.platform + ' is not supported');
throw new Error(`Platform ${platform} is not supported`);
}

this.outFile = fs.openSync(`${this.TMP_PROFILE_DIR}/chrome-out.log`, 'a');
Expand All @@ -107,19 +110,13 @@ export class ChromeLauncher {
this.prepare();
}

return Promise.resolve()
.then(() => {
const installations = (<any>chromeFinder)[process.platform]();

if (installations.length < 1) {
return Promise.reject(new Error('No Chrome Installations Found'));
} else if (installations.length === 1 || this.autoSelectChrome) {
return installations[0];
}
const installations = await chromeFinder[process.platform as SupportedPlatforms]();
if (installations.length === 0) {
throw new Error('No Chrome Installations Found');
}

return ask('Choose a Chrome installation to use with Lighthouse', installations);
})
.then(execPath => this.spawn(execPath));
const chromePath = installations[0];
return await this.spawn(chromePath);
}

spawn(execPath: string) {
Expand Down

0 comments on commit 320614c

Please sign in to comment.