Comparing version 0.2.0 to 0.3.0
'use strict'; | ||
var findShip = require('../') | ||
var mothership = require('../') | ||
, path = require('path'); | ||
findShip( | ||
mothership( | ||
path.join(__dirname, 'uno', 'dos', 'tres') | ||
@@ -17,3 +17,3 @@ , function ismothership (pack) { | ||
findShip( | ||
mothership( | ||
path.join(__dirname, 'uno', 'dos', 'tres') | ||
@@ -20,0 +20,0 @@ , function ismothership (pack) { |
25
index.js
@@ -41,1 +41,26 @@ 'use strict'; | ||
} | ||
/** | ||
* Synchronous version of mothership. | ||
* | ||
* @name mothership::sync | ||
* @function | ||
* @param {string} start full path at which to start looking for the mothership | ||
* @param {function} ismothership invoked with the package object, needs to return true if it is the mothership | ||
* @return {string} full path to package.json that is the mothership or `null` if it wasn't found | ||
*/ | ||
go.sync = function sync(start, ismothership) { | ||
return (function findShip (root) { | ||
var packageDir = findParentDir.sync(root, 'package.json') | ||
var pack; | ||
try { | ||
pack = require(path.join(packageDir, 'package.json')); | ||
if (ismothership(pack)) return { path: path.join(packageDir, 'package.json'), pack: pack }; | ||
return findShip(path.resolve(root, '..')); | ||
} catch (e) { | ||
return false | ||
} | ||
})(start); | ||
} |
{ | ||
"name": "mothership", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Helps a module find its package.json mothership.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -6,6 +6,6 @@ # mothership [![build status](https://secure.travis-ci.org/thlorenz/mothership.png)](http://travis-ci.org/thlorenz/mothership) | ||
```js | ||
var findShip = require('mothership') | ||
var mothership = require('mothership') | ||
, path = require('path'); | ||
findShip( | ||
mothership( | ||
path.join(__dirname, 'uno', 'dos', 'tres') | ||
@@ -20,2 +20,12 @@ , function ismothership (pack) { | ||
) | ||
// Synchronous | ||
var res = mothership.sync( | ||
path.join(__dirname, 'uno', 'dos', 'tres') | ||
, function ismothership (pack) { | ||
return !!(pack.dependencies && pack.dependencies.unodep); | ||
} | ||
) | ||
console.log('found mothership', res.path); // => [..]/example/uno/package.json | ||
``` | ||
@@ -99,3 +109,59 @@ | ||
</dd> | ||
<dt> | ||
<h4 class="name" id="mothership::sync"><span class="type-signature"></span>mothership::sync<span class="signature">(start, ismothership)</span><span class="type-signature"> → {string}</span></h4> | ||
</dt> | ||
<dd> | ||
<div class="description"> | ||
<p>Synchronous version of mothership.</p> | ||
</div> | ||
<h5>Parameters:</h5> | ||
<table class="params"> | ||
<thead> | ||
<tr> | ||
<th>Name</th> | ||
<th>Type</th> | ||
<th class="last">Description</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td class="name"><code>start</code></td> | ||
<td class="type"> | ||
<span class="param-type">string</span> | ||
</td> | ||
<td class="description last"><p>full path at which to start looking for the mothership</p></td> | ||
</tr> | ||
<tr> | ||
<td class="name"><code>ismothership</code></td> | ||
<td class="type"> | ||
<span class="param-type">function</span> | ||
</td> | ||
<td class="description last"><p>invoked with the package object, needs to return true if it is the mothership</p></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<dl class="details"> | ||
<dt class="tag-source">Source:</dt> | ||
<dd class="tag-source"><ul class="dummy"> | ||
<li> | ||
<a href="https://github.com/thlorenz/mothership/blob/master/index.js">index.js</a> | ||
<span>, </span> | ||
<a href="https://github.com/thlorenz/mothership/blob/master/index.js#L42">lineno 42</a> | ||
</li> | ||
</ul></dd> | ||
</dl> | ||
<h5>Returns:</h5> | ||
<div class="param-desc"> | ||
<p>full path to package.json that is the mothership or <code>null</code> if it wasn't found</p> | ||
</div> | ||
<dl> | ||
<dt> | ||
Type | ||
</dt> | ||
<dd> | ||
<span class="param-type">string</span> | ||
</dd> | ||
</dl> | ||
</dd> | ||
</dl> | ||
</article> | ||
@@ -102,0 +168,0 @@ </section> |
15207
16
200
175
2