Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changing getCompiledChain output format to make it easier to parse

  • Loading branch information...
commit 7cbf51e572ba17f189ac523351efa55ef3423675 1 parent 76b90b0
@TrevorBurnham authored
View
2  README.mdown
@@ -35,7 +35,7 @@ You can get a list of compiled JavaScripts corresponding to the dependency chain
snockets.getCompiledChain 'dir/foo.coffee', (err, jsList) -> ...
-The result is in the format `[{"dependency1.js": "// code"}, ..., {"dir/foo.js": "// code"}]`. Note that those JavaScript files are not actually created by `getCompiledChain`.
+The result is in the format `[{filename: "dependency1.js", js: "// code"}, ...]`. Note that those JavaScript files are not actually created by `getCompiledChain`.
Snockets can also provide a single compiled, concatenated file (optionally run through [UglifyJS](https://github.com/mishoo/UglifyJS) if the `minify` option is passed in):
View
9 docs/snockets.html
@@ -38,12 +38,13 @@
<span class="k">if</span> <span class="nx">callback</span> <span class="k">then</span> <span class="nx">callback</span> <span class="nx">e</span> <span class="k">else</span> <span class="k">throw</span> <span class="nx">e</span>
<span class="nv">compiledChain = </span><span class="k">for</span> <span class="nx">link</span> <span class="k">in</span> <span class="nx">chain</span><span class="p">.</span><span class="nx">concat</span> <span class="nx">filePath</span>
- <span class="nv">pair = </span><span class="p">{}</span>
+ <span class="nv">o = </span><span class="p">{}</span>
<span class="k">if</span> <span class="nx">@compileFile</span> <span class="nx">link</span>
- <span class="nx">pair</span><span class="p">[</span><span class="nx">stripExt</span><span class="p">(</span><span class="nx">link</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;.js&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="nx">@cache</span><span class="p">[</span><span class="nx">link</span><span class="p">].</span><span class="nx">js</span><span class="p">.</span><span class="nx">toString</span> <span class="s1">&#39;utf8&#39;</span>
+ <span class="nv">o.filename = </span><span class="nx">stripExt</span><span class="p">(</span><span class="nx">link</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;.js&#39;</span>
<span class="k">else</span>
- <span class="nx">pair</span><span class="p">[</span><span class="nx">link</span><span class="p">]</span> <span class="o">=</span> <span class="nx">@cache</span><span class="p">[</span><span class="nx">link</span><span class="p">].</span><span class="nx">js</span><span class="p">.</span><span class="nx">toString</span> <span class="s1">&#39;utf8&#39;</span>
- <span class="nx">pair</span>
+ <span class="nv">o.filename = </span><span class="nx">link</span>
+ <span class="nv">o.js = </span><span class="nx">@cache</span><span class="p">[</span><span class="nx">link</span><span class="p">].</span><span class="nx">js</span><span class="p">.</span><span class="nx">toString</span> <span class="s1">&#39;utf8&#39;</span>
+ <span class="nx">o</span>
<span class="nx">callback</span><span class="o">?</span> <span class="kc">null</span><span class="p">,</span> <span class="nx">compiledChain</span>
<span class="nx">compiledChain</span>
View
11 lib/snockets.js
@@ -64,7 +64,7 @@
flags.async = this.options.async;
}
return this.updateDirectives(filePath, flags, __bind(function(err) {
- var chain, compiledChain, link, pair;
+ var chain, compiledChain, link, o;
if (err) {
if (callback) {
callback(err);
@@ -87,13 +87,14 @@
_results = [];
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
link = _ref2[_i];
- pair = {};
+ o = {};
if (this.compileFile(link)) {
- pair[stripExt(link) + '.js'] = this.cache[link].js.toString('utf8');
+ o.filename = stripExt(link) + '.js';
} else {
- pair[link] = this.cache[link].js.toString('utf8');
+ o.filename = link;
}
- _results.push(pair);
+ o.js = this.cache[link].js.toString('utf8');
+ _results.push(o);
}
return _results;
}).call(this);
View
9 src/snockets.coffee
@@ -44,12 +44,13 @@ module.exports = class Snockets
if callback then callback e else throw e
compiledChain = for link in chain.concat filePath
- pair = {}
+ o = {}
if @compileFile link
- pair[stripExt(link) + '.js'] = @cache[link].js.toString 'utf8'
+ o.filename = stripExt(link) + '.js'
else
- pair[link] = @cache[link].js.toString 'utf8'
- pair
+ o.filename = link
+ o.js = @cache[link].js.toString 'utf8'
+ o
callback? null, compiledChain
compiledChain
View
6 test/integration.coffee
@@ -47,9 +47,9 @@ testSuite =
snockets.getCompiledChain 'z.coffee', (err, chain) ->
throw err if err
test.deepEqual chain, [
- {'x.js': '(function() {\n "Double rainbow\\nSO INTENSE";\n}).call(this);\n'}
- {'y.js': '//= require x'}
- {'z.js': '(function() {\n\n}).call(this);\n'}
+ {filename: 'x.js', js: '(function() {\n "Double rainbow\\nSO INTENSE";\n}).call(this);\n'}
+ {filename: 'y.js', js: '//= require x'}
+ {filename: 'z.js', js: '(function() {\n\n}).call(this);\n'}
]
test.done()
Please sign in to comment.
Something went wrong with that request. Please try again.