forked from appium/appium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a basic vesion of Appium Doctor that checks for Xcode, Xcode Command Line Tools, JAVA_HOME, and ANDROID_HOME
- Loading branch information
Showing
7 changed files
with
290 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env node | ||
"use strict"; | ||
var ios = require('../lib/doctor/ios.js') | ||
, android = require('../lib/doctor/android.js') | ||
, common = require("../lib/doctor/common.js") | ||
, log = require('../lib/doctor/common.js').log | ||
, eol = require('os').EOL | ||
, async = require('async'); | ||
|
||
var argv = process.argv | ||
, doAndroid = argv.indexOf('--android') > -1 | ||
, doIOS = argv.indexOf('--ios') > -1 | ||
, verbose = argv.indexOf('--verbose') > -1; | ||
|
||
if (!doIOS && !doAndroid) { | ||
doIOS = true; | ||
doAndroid = true; | ||
} | ||
|
||
var runiOSChecks = function(cb) { | ||
if (doIOS) { | ||
log.comment("Running iOS Checks"); | ||
ios.runAllChecks(function(err) { | ||
if (!err) { | ||
log.pass("iOS Checks were successful." + eol); | ||
cb(); | ||
} else { | ||
common.exitDoctor(); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
var runAndroidChecks = function(cb) { | ||
if (doAndroid) { | ||
log.comment("Running Android Checks"); | ||
android.runAllChecks(function(err) { | ||
if (!err) { | ||
log.pass("Android Checks were successful." + eol); | ||
cb(); | ||
} else { | ||
common.exitDoctor(); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
if (require.main === module) { | ||
async.series([ | ||
runiOSChecks, | ||
runAndroidChecks | ||
], function(err) { | ||
if (!err) { | ||
log.pass("All Checks were successful"); | ||
} else { | ||
common.exitDoctor(); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"use strict"; | ||
var path = require('path') | ||
, fs = require('fs') | ||
, env = process.env | ||
, exec = require('child_process').exec | ||
, common = require("./common.js") | ||
, log = require('./common.js').log | ||
, async = require('async'); | ||
|
||
exports.runAllChecks = function(cb) { | ||
async.series([ | ||
exports.IsAndroidHomeExported, | ||
exports.IsJavaHomeExported | ||
], cb); | ||
}; | ||
|
||
exports.IsAndroidHomeExported = function(cb) { | ||
var msg; | ||
if (env.ANDROID_HOME === null) { | ||
msg = 'ANDROID_HOME is not set'; | ||
log.fail(msg); | ||
cb(msg, msg); | ||
} else if (fs.existsSync(env.ANDROID_HOME)) { | ||
msg = 'ANDROID_HOME is set to "' + env.ANDROID_HOME + '."'; | ||
log.pass(msg); | ||
cb(null, msg); | ||
} else { | ||
msg = 'ANDROID_HOME is set but does not exist on the file system at "' + env.ANDROID_HOME + '"'; | ||
log.fail(msg); | ||
cb(msg, msg); | ||
} | ||
}; | ||
|
||
exports.IsJavaHomeExported = function(cb) { | ||
var msg; | ||
if (env.JAVA_HOME === null) { | ||
log.fail(msg); | ||
msg = 'JAVA_HOME is not set'; | ||
cb(msg, msg); | ||
} else if (fs.existsSync(env.JAVA_HOME)) { | ||
msg = 'JAVA_HOME is set to "' + env.JAVA_HOME + '."'; | ||
log.pass(msg); | ||
cb(null, msg); | ||
} else { | ||
msg = 'JAVA_HOME is set but does not exist on the file system at "' + env.JAVA_HOME + '"'; | ||
log.fail(msg); | ||
cb(msg, msg); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
"use strict"; | ||
var prompt = require("prompt") | ||
, colors = require("colors"); | ||
|
||
prompt.message = ''; | ||
prompt.delimiter = ''; | ||
|
||
var log = { | ||
pass : function(msg) { | ||
console.log('\u2714 '.green + msg.white); | ||
}, | ||
|
||
fail : function(msg) { | ||
console.log('\u2716 '.red + msg.white); | ||
}, | ||
|
||
warning : function(msg) { | ||
console.log(msg.yellow); | ||
}, | ||
|
||
error : function(msg) { | ||
console.log(msg.red); | ||
}, | ||
|
||
comment : function(msg) { | ||
console.log(msg.cyan); | ||
}, | ||
|
||
info : function(msg) { | ||
console.log(msg.white); | ||
}, | ||
|
||
verbose : function(msg) { | ||
console.log(msg.grey); | ||
}, | ||
|
||
debug : function(msg) { | ||
console.log(msg.darkgrey); | ||
} | ||
}; | ||
exports.log = Object.create(log); | ||
|
||
exports.exitDoctor = function() { | ||
log.error("Appium-Doctor detected problems. Please fix and rerun Appium-Doctor."); | ||
process.exit(-1); | ||
}; | ||
|
||
exports.promptYesOrNo = function(message, yesCb, noCb) { | ||
prompt.start(); | ||
var promptSchema = { | ||
properties: { | ||
continue: { | ||
description: (message + ' (y/n) ').white, | ||
delimiter: '', | ||
type: 'string', | ||
pattern: /^(y|n)/, | ||
message: 'Please enter y or n!', | ||
required: true | ||
} | ||
} | ||
}; | ||
prompt.get(promptSchema, function(err, result) { | ||
if (result.continue == 'y') { | ||
yesCb(); | ||
} else { | ||
noCb(); | ||
} | ||
}); | ||
}; | ||
|
||
exports.promptForAnyKey = function(cb) { | ||
prompt.start(); | ||
var promptSchema = { | ||
properties: { | ||
continue: { | ||
description: 'Press any key to continue:'.white, | ||
type: 'string' | ||
} | ||
} | ||
}; | ||
prompt.get(promptSchema, function() { | ||
cb(); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
"use strict"; | ||
var path = require('path') | ||
, fs = require('fs') | ||
, env = process.env | ||
, exec = require('child_process').exec | ||
, common = require("./common.js") | ||
, log = require('./common.js').log | ||
, async = require('async'); | ||
|
||
exports.runAllChecks = function(cb) { | ||
async.series([ | ||
exports.checkForXcode, | ||
exports.checkForXcodeCommandLineTools | ||
], cb); | ||
}; | ||
|
||
exports.checkForXcode = function(cb) { | ||
var msg; | ||
exec("xcode-select -p", { maxBuffer: 524288}, function(err, stdout) { | ||
if (err === null) { | ||
var xcodePath = stdout.replace("\n",""); | ||
if(fs.existsSync(xcodePath)) { | ||
msg = "Xcode is installed at " + xcodePath; | ||
log.pass(msg); | ||
cb(null, msg); | ||
} else { | ||
msg = "Xcode is not installed."; | ||
log.fail(msg); | ||
common.promptYesOrNo("Fix it?", function() { | ||
exports.installXcode(cb); | ||
}, function() { | ||
cb(msg, msg); | ||
}); | ||
} | ||
} else { | ||
msg = "Xcode is not installed: " + err; | ||
log.fail(msg); | ||
common.promptYesOrNo("Fix it?", function() { | ||
exports.installXcode(cb); | ||
}, function() { | ||
cb(msg, msg); | ||
}); | ||
} | ||
}); | ||
}; | ||
|
||
exports.checkForXcodeCommandLineTools = function(cb) { | ||
var msg; | ||
exec("pkgutil --pkg-info=com.apple.pkg.CLTools_Executables", { maxBuffer: 524288}, function(err, stdout) { | ||
if (err === null) { | ||
var match = stdout.match(/install-time/); | ||
if (match !== null) { | ||
msg = "Xcode Command Line Tools are installed."; | ||
cb(null, msg); | ||
} else { | ||
msg = "Xcode Command Line Tools are NOT installed."; | ||
log.fail(msg); | ||
common.promptYesOrNo("Fix it?", function() { | ||
exports.installXcodeCommandLineTools(cb); | ||
}, function() { | ||
cb(msg, msg); | ||
}); | ||
} | ||
} else { | ||
msg = "Xcode Command Line Tools are NOT installed: " + err; | ||
log.fail(msg); | ||
common.promptYesOrNo("Fix it?", function() { | ||
exports.installXcodeCommandLineTools(cb); | ||
}, function() { | ||
cb(msg, msg); | ||
}); | ||
} | ||
}); | ||
}; | ||
|
||
exports.installXcode = function(cb) { | ||
exec("xcode-select --install", { maxBuffer: 524288}, function() { | ||
common.promptForAnyKey(function() { | ||
exports.checkForXcode(cb); | ||
}); | ||
}); | ||
}; | ||
|
||
exports.installXcodeCommandLineTools = function(cb) { | ||
exec("xcode-select --install", { maxBuffer: 524288}, function() { | ||
common.promptForAnyKey(function() { | ||
exports.checkForXcodeCommandLineTools(cb); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters