Skip to content

Commit

Permalink
Merge pull request #12 from f3lang/module_list
Browse files Browse the repository at this point in the history
Module list
  • Loading branch information
f3lang authored Nov 17, 2018
2 parents f5bab3f + 616258d commit 902bc7d
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 6 deletions.
4 changes: 4 additions & 0 deletions docmd/injection.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,7 @@ circular depencencies will issue a warning in the console and the injected argum
### prototype inheritance
cdi can work with prototype inheritance and will also resolve dependencies in parent prototypes.
For more details visit {@tutorial prototype_inheritance}


### Find your module
The ModuleResolver has a method **getModuleNames(regex)**. With this method you can query all existing modules and their alias with a regular expression to find modules like controller, models etc.
167 changes: 162 additions & 5 deletions docs/ModuleResolver.html
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ModuleResolver.js.html">ModuleResolver.js</a>, <a href="ModuleResolver.js.html#line46">line 46</a>
<a href="ModuleResolver.js.html">ModuleResolver.js</a>, <a href="ModuleResolver.js.html#line45">line 45</a>
</li></ul></dd>


Expand Down Expand Up @@ -469,7 +469,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ModuleResolver.js.html">ModuleResolver.js</a>, <a href="ModuleResolver.js.html#line94">line 94</a>
<a href="ModuleResolver.js.html">ModuleResolver.js</a>, <a href="ModuleResolver.js.html#line93">line 93</a>
</li></ul></dd>


Expand Down Expand Up @@ -519,6 +519,163 @@ <h5>Returns:</h5>



<h4 class="name" id="getModuleNames"><span class="type-signature"></span>getModuleNames<span class="signature">(regex)</span><span class="type-signature"> &rarr; {Array}</span></h4>






<div class="description">
<p>Retrieves a list of module names which match a regular expression</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>regex</code></td>


<td class="type">


<span class="param-type">RegExp</span>



</td>





<td class="description last"></td>
</tr>


</tbody>
</table>






<dl class="details">




























<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ModuleResolver.js.html">ModuleResolver.js</a>, <a href="ModuleResolver.js.html#line135">line 135</a>
</li></ul></dd>





</dl>













<h5>Returns:</h5>


<div class="param-desc">
<p>An array of matched module names</p>
</div>



<dl>
<dt>
Type
</dt>
<dd>

<span class="param-type">Array</span>


</dd>
</dl>













<h4 class="name" id="getResolvedModules"><span class="type-signature"></span>getResolvedModules<span class="signature">()</span><span class="type-signature"> &rarr; {<a href="global.html#Object">Object</a>|*}</span></h4>


Expand Down Expand Up @@ -573,7 +730,7 @@ <h4 class="name" id="getResolvedModules"><span class="type-signature"></span>get

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ModuleResolver.js.html">ModuleResolver.js</a>, <a href="ModuleResolver.js.html#line120">line 120</a>
<a href="ModuleResolver.js.html">ModuleResolver.js</a>, <a href="ModuleResolver.js.html#line119">line 119</a>
</li></ul></dd>


Expand Down Expand Up @@ -742,7 +899,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ModuleResolver.js.html">ModuleResolver.js</a>, <a href="ModuleResolver.js.html#line68">line 68</a>
<a href="ModuleResolver.js.html">ModuleResolver.js</a>, <a href="ModuleResolver.js.html#line67">line 67</a>
</li></ul></dd>


Expand Down Expand Up @@ -828,7 +985,7 @@ <h4 class="name" id="writeCache"><span class="type-signature"></span>writeCache<

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="ModuleResolver.js.html">ModuleResolver.js</a>, <a href="ModuleResolver.js.html#line127">line 127</a>
<a href="ModuleResolver.js.html">ModuleResolver.js</a>, <a href="ModuleResolver.js.html#line126">line 126</a>
</li></ul></dd>


Expand Down
10 changes: 9 additions & 1 deletion docs/ModuleResolver.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ <h1 class="page-title">Source: ModuleResolver.js</h1>
this.moduleAnalyzer = moduleAnalyzer;
this.nameCollisionMap = [];

let modulePathList = [];
let i = moduleSrc.length;
while (i--) {
this.addModuleSrcDir(moduleSrc[i]);
Expand Down Expand Up @@ -156,6 +155,15 @@ <h1 class="page-title">Source: ModuleResolver.js</h1>
fs.writeFileSync(this.cacheFile, JSON.stringify(this.cache, null, '\t'));
}

/**
* Retrieves a list of module names which match a regular expression
* @param {RegExp} regex
* @return {Array} An array of matched module names
*/
getModuleNames(regex) {
return Object.keys(this.cache.moduleMap).filter(name => regex.test(name));
}

}

module.exports = ModuleResolver;
Expand Down
1 change: 1 addition & 0 deletions docs/tutorial-injection.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ <h3>example</h3><p>So lets look at it in action:
// now you got your bike with injected wheels, which got the size information injected</code></pre><h3>circular dependency</h3><p>circular depencencies will issue a warning in the console and the injected argument will be null.</p>
<h3>prototype inheritance</h3><p>cdi can work with prototype inheritance and will also resolve dependencies in parent prototypes.
For more details visit <a href="tutorial-prototype_inheritance.html">Prototype Inheritance</a></p>
<h3>Find your module</h3><p>The ModuleResolver has a method <strong>getModuleNames(regex)</strong>. With this method you can query all existing modules and their alias with a regular expression to find modules like controller, models etc.</p>
</article>

</section>
Expand Down
9 changes: 9 additions & 0 deletions src/ModuleResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ class ModuleResolver {
fs.writeFileSync(this.cacheFile, JSON.stringify(this.cache, null, '\t'));
}

/**
* Retrieves a list of module names which match a regular expression
* @param {RegExp} regex
* @return {Array} An array of matched module names
*/
getModuleNames(regex) {
return Object.keys(this.cache.moduleMap).filter(name => regex.test(name));
}

}

module.exports = ModuleResolver;
Expand Down
6 changes: 6 additions & 0 deletions test/ModuleResolver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ describe("Module Resolver", function () {
expect(moduleResolver.getResolvedModules().fileCache['gibberish.md']).not.exist;
});

it("searching for modules by regex", function() {
let moduleResolver = new ModuleResolver([simpleClassPath], null, moduleAnalyzerMock);
expect(moduleResolver.getModuleNames(/class.*/)).to.eql([]);
expect(moduleResolver.getModuleNames(/Class.*/)).to.have.members(["Class6", "Class7", "Class8"]);
});

});

describe("Caching", function () {
Expand Down

0 comments on commit 902bc7d

Please sign in to comment.