Skip to content
Browse files

expose .setup()

  • Loading branch information...
1 parent a3ed983 commit 9dc2696efda6252ff685912b0482f7d8e1429907 @substack committed Jun 30, 2012
Showing with 24 additions and 14 deletions.
  1. +21 −12 index.js
  2. +2 −1 lib/config.js
  3. +1 −1 package.json
View
33 index.js
@@ -3,6 +3,7 @@ var detect = require('./lib/detect');
var run = require('./lib/run');
var createProfiles = require('./lib/create_profiles');
+var path = require('path');
var spawn = require('child_process').spawn;
exports = module.exports = function (opts, cb) {
@@ -15,11 +16,9 @@ exports = module.exports = function (opts, cb) {
config.read(opts.config, function (err, cfg, configDir) {
if (err) return cb(err);
if (!cfg) {
- detect(function (avail) {
- createProfiles(avail, configDir, function (err) {
- if (err) cb(err)
- else write({ browsers : { local : avail } });
- })
+ exports.setup(configDir, function (err, cfg) {
+ if (err) console.error(err)
+ else cb(null, wrap(cfg))
});
}
else cb(null, wrap(cfg))
@@ -30,17 +29,27 @@ exports = module.exports = function (opts, cb) {
res.browsers = cfg.browsers;
return res;
}
-
- function write (cfg) {
- config.write(cfg, function (err) {
- if (err) cb(err)
- else cb(null, wrap(cfg))
- })
- }
};
exports.detect = detect;
exports.config = config;
+exports.setup = function (configDir, cb) {
+ if (typeof configDir === 'function') {
+ cb = configDir;
+ configDir = path.dirname(config.defaultConfigFile);
+ }
+ detect(function (avail) {
+ createProfiles(avail, configDir, function (err) {
+ if (err) return cb(err);
+ var cfg = { browsers : { local : avail } };
+ config.write(cfg, function (err) {
+ if (err) cb(err)
+ else cb(null, cfg)
+ });
+ })
+ });
+};
+
function launcher (cfg, uri, opts, cb) {
if (typeof opts === 'string') {
opts = { browser : opts };
View
3 lib/config.js
@@ -2,8 +2,9 @@ var mkdirp = require('mkdirp');
var fs = require('fs');
var path = require('path');
-var defaultConfigFile = (process.env.HOME || process.env.USERPROFILE)
+var defaultConfigFile = (process.env.HOME || process.env.USERDIR)
+ '/.config/browser-launcher/config.json';
+exports.defaultConfigFile = defaultConfigFile;
exports.read = function (configFile, cb) {
if (typeof configFile === 'function') {
View
2 package.json
@@ -1,6 +1,6 @@
{
"name" : "browser-launcher",
- "version" : "0.0.1",
+ "version" : "0.0.2",
"description" : "detect and launch browser versions, headlessly or otherwise",
"main" : "index.js",
"bin" : {},

0 comments on commit 9dc2696

Please sign in to comment.
Something went wrong with that request. Please try again.