forked from benderjs/browser-launcher2
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from mitchhentges/cleanup-darwin
Cleanup darwin section
- Loading branch information
Showing
10 changed files
with
89 additions
and
241 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,7 +1,16 @@ | ||
exports.safari = require( './safari' ); | ||
exports.firefox = require( './firefox' ); | ||
exports.chrome = require( './chrome' ); | ||
exports.chromium = require( './chromium' ); | ||
exports[ 'chrome-canary' ] = require( './chrome-canary' ); | ||
exports.opera = require( './opera' ); | ||
exports.phantomjs = require( './phantomjs' ); | ||
var util = require('./util'); | ||
|
||
function browser(id, versionKey) { | ||
return { | ||
path: util.find.bind(null, id), | ||
version: util.getInfoKey.bind(null, id, versionKey) | ||
}; | ||
} | ||
|
||
exports.chrome = browser('com.google.Chrome', 'KSVersion'); | ||
exports[ 'chrome-canary' ] = browser('com.google.Chrome.canary', 'KSVersion'); | ||
exports.chromium = browser('org.chromium.Chromium', 'CFBundleShortVersionString'); | ||
exports.firefox = browser('org.mozilla.firefox', 'CFBundleShortVersionString'); | ||
exports['firefox-developer'] = browser('org.mozilla.firefoxdeveloperedition', 'CFBundleShortVersionString'); | ||
exports.safari = browser('com.apple.Safari', 'CFBundleShortVersionString'); | ||
exports.opera = browser('com.operasoftware.Opera', 'CFBundleVersion'); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,87 +1,75 @@ | ||
var exec = require( 'child_process' ).exec, | ||
fs = require( 'fs' ), | ||
path = require( 'path' ), | ||
plist = require( 'plist' ); | ||
var exec = require('child_process').exec, | ||
fs = require('fs'), | ||
path = require('path'), | ||
plist = require('plist'); | ||
|
||
exports.exists = fs.exists; | ||
exports.parse = parse; | ||
exports.find = find; | ||
exports.getInfoPath = getInfoPath; | ||
exports.getInfoKey = getInfoKey; | ||
exports.findBin = findBin; | ||
exports.getBinVersion = getBinVersion; | ||
|
||
var infoCache = Object.create(null); | ||
|
||
function parse( file, callback ) { | ||
if (infoCache[file] !== void 0) { | ||
return callback(null, infoCache[file]); | ||
} | ||
fs.readFile( file, { | ||
encoding: 'utf8' | ||
}, function( err, data ) { | ||
if ( !err ) { | ||
infoCache[ file ] = data = plist.parse( data ); | ||
} | ||
|
||
callback( err, data ); | ||
} ); | ||
} | ||
|
||
var bundleCache = Object.create(null); | ||
|
||
function find( id, callback ) { | ||
if (bundleCache[id] !== void 0) { | ||
return callback(null, bundleCache[id]); | ||
} | ||
var pathQuery = 'mdfind "kMDItemCFBundleIdentifier=="' + id + '"" | head -1'; | ||
function parse(file, callback) { | ||
if (infoCache[file]) { | ||
return callback(null, infoCache[file]); | ||
} | ||
|
||
exec( pathQuery, function( err, stdout ) { | ||
var loc = stdout.trim(); | ||
fs.exists(file, function(exists) { | ||
if (!exists) { | ||
return callback('cannot parse non-existant plist', null); | ||
} | ||
|
||
if ( loc === '' ) { | ||
loc = null; | ||
err = 'not installed'; | ||
} else { | ||
bundleCache[id] = loc; | ||
} | ||
fs.readFile(file, { | ||
encoding: 'utf8' | ||
}, function (err, data) { | ||
if (!err) { | ||
infoCache[file] = data = plist.parse(data); | ||
} | ||
|
||
callback( err, loc ); | ||
} ); | ||
callback(err, data); | ||
}); | ||
}); | ||
} | ||
|
||
function findBin(id, callback) { | ||
exec('which ' + id, function( err, path ) { | ||
callback( err, path ? path.trim() : path ); | ||
}); | ||
} | ||
function find(id, callback) { | ||
if (bundleCache[id]) { | ||
return callback(null, bundleCache[id]); | ||
} | ||
|
||
var pathQuery = 'mdfind kMDItemCFBundleIdentifier=="' + id + '" | head -1'; | ||
exec(pathQuery, function (err, stdout) { | ||
var loc = stdout.trim(); | ||
|
||
function getBinVersion(id, callback) { | ||
exec(id + ' --version', function( err, version ) { | ||
callback( err, version ? version.trim() : version ); | ||
}); | ||
if (loc === '') { | ||
loc = null; | ||
err = 'not installed'; | ||
} else { | ||
bundleCache[id] = loc; | ||
} | ||
|
||
callback(err, loc); | ||
}); | ||
} | ||
|
||
function getInfoPath( p ) { | ||
return path.join( p, 'Contents', 'Info.plist' ); | ||
function getInfoPath(p) { | ||
return path.join(p, 'Contents', 'Info.plist'); | ||
} | ||
|
||
function getInfoKey( bundleId, key, callback ) { | ||
find( bundleId, function( err, path ) { | ||
if ( err ) { | ||
return callback( err, null ); | ||
} | ||
function getInfoKey(bundleId, key, callback) { | ||
find(bundleId, function (err, path) { | ||
if (err) { | ||
return callback(err, null); | ||
} | ||
|
||
var pl = getInfoPath( path ); | ||
parse(getInfoPath(path), function (err, data) { | ||
if (err) { | ||
return callback(err, null); | ||
} | ||
|
||
fs.exists( pl, function( exists ) { | ||
if ( exists ) { | ||
parse( pl, function( err, data ) { | ||
callback( err, data[key] ); | ||
} ); | ||
} else { | ||
callback( 'not installed', null ); | ||
} | ||
} ); | ||
} ); | ||
} | ||
callback(null, data[key]); | ||
}); | ||
}); | ||
} |
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