Skip to content

Commit

Permalink
fix(dir): check selenium dir and warn user that the folder does not e…
Browse files Browse the repository at this point in the history
…xist (#17)

closes #11
  • Loading branch information
cnishina committed Apr 26, 2016
1 parent 8d6e459 commit 70d32df
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
11 changes: 11 additions & 0 deletions lib/cmds/start.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as fs from 'fs';
import * as minimist from 'minimist';
import * as path from 'path';
import * as os from 'os';
Expand Down Expand Up @@ -51,6 +52,16 @@ function start(options: Options) {
outputDir = path.resolve(Config.getBaseDir(), options[Opt.OUT_DIR].getString());
}
}

try {
// check if folder exists
fs.statSync(outputDir).isDirectory();
} catch (e) {
// if the folder does not exist, quit early.
logger.warn('the out_dir path ' + outputDir + ' does not exist, run webdriver-manager update');
return;
}

let chromeLogs: string = null;
if (options[Opt.CHROME_LOGS].getString()) {
if (path.isAbsolute(options[Opt.CHROME_LOGS].getString())) {
Expand Down
12 changes: 12 additions & 0 deletions lib/cmds/status.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as fs from 'fs';
import * as minimist from 'minimist';
import * as path from 'path';

Expand Down Expand Up @@ -37,6 +38,17 @@ function status(options: Options) {
outputDir = path.resolve(Config.getBaseDir(), options[Opt.OUT_DIR].getString());
}
}

try {
// check if folder exists
fs.statSync(outputDir).isDirectory();
} catch (e) {
// if the folder does not exist, quit early.
logger.warn('the out_dir path ' + outputDir + ' does not exist');
return;
}


let downloadedBinaries = FileManager.downloadedBinaries(outputDir);
// log which binaries have been downloaded
for (let bin in downloadedBinaries) {
Expand Down
8 changes: 7 additions & 1 deletion lib/files/file_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ export class FileManager {
* @param outputDir The directory where binaries are saved
* @returns A list of existing files.
*/
static getExistngFiles(outputDir: string): string[] { return fs.readdirSync(outputDir); }
static getExistngFiles(outputDir: string): string[] {
try {
return fs.readdirSync(outputDir);
} catch (e) {
return [];
}
}

/**
* For the binary, operating system, and system architecture, look through
Expand Down

0 comments on commit 70d32df

Please sign in to comment.