Skip to content

Commit

Permalink
Added option to beautify generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-martin committed Sep 4, 2013
1 parent 4b75ea6 commit f56d41e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
19 changes: 10 additions & 9 deletions bin/nools
Expand Up @@ -10,13 +10,15 @@ var nools = require(".."),
uglifyjs = require("uglify-js"), uglifyjs = require("uglify-js"),
program = require('commander'); program = require('commander');


function uglify(source) { function uglify(source, program) {
try { try {
if (program.no_minification) { if (program.no_minification) {
return source; return source;
} else { } else if (program.beautify) {
return uglifyjs.minify(source, {fromString: true, mangle: false, output: {beautify: true}}).code; return uglifyjs.minify(source, {fromString: true, mangle: false, compress: false, output: {beautify: true}}).code;
} } else {
return uglifyjs.minify(source, {fromString: true, mangle: false}).code;
}
} catch (e) { } catch (e) {
console.error(e.message); console.error(e.message);
console.error(e.stack); console.error(e.stack);
Expand All @@ -33,18 +35,17 @@ program.command("compile")
.option("-n --name [value]", "name of the flow to compile, defaults to the name of the file less the extension") .option("-n --name [value]", "name of the flow to compile, defaults to the name of the file less the extension")
.option("-l --nools_location [value]", "location to look for nools when requiring it") .option("-l --nools_location [value]", "location to look for nools when requiring it")
.option("-u --no_minification", "Do not minify the generated script") .option("-u --no_minification", "Do not minify the generated script")
.option("-b --beautify", "beautify the generated source")
.action(function () { .action(function () {
var files = Array.prototype.slice.call(arguments); var files = Array.prototype.slice.call(arguments);
var program = files.pop(); var program = files.pop();
var noolsLocation = program["nools_location"] || "nools"; var noolsLocation = program["nools_location"] || "nools";
files.forEach(function (file) { files.forEach(function (file) {
var name = program.name || path.basename(file, path.extname(file)); var name = program.name || path.basename(file, path.extname(file));
console.log(str.format(template, { source: uglify(nools.transpile(path.resolve(process.cwd(), file), {name: name})), noolsLocation: noolsLocation}).replace(/\s+/g, " ")); console.log(uglify(str.format(template, { source: nools.transpile(path.resolve(process.cwd(), file), {name: name}), noolsLocation: noolsLocation}), program));
}); });
}); });


//return uglifyjs.minify(ret.join(""), {fromString: true, mangle: false, output: {beautify: true}}).code;

program.parse(process.argv); program.parse(process.argv);




Expand Down
4 changes: 2 additions & 2 deletions docs/History.html
Expand Up @@ -186,8 +186,8 @@ <h1>0.1.10</h1>
<li>Fixed issue <a href="https://github.com/C2FO/nools/issues/61">#61</a> where transpile would not properly escape <code>&quot;</code> character.</li> <li>Fixed issue <a href="https://github.com/C2FO/nools/issues/61">#61</a> where transpile would not properly escape <code>&quot;</code> character.</li>
<li>Fixed issue <a href="https://github.com/C2FO/nools/issues/66">#66</a> and <a href="https://github.com/C2FO/nools/issues/67">#67</a> where regular expression matching was too greedy.</li> <li>Fixed issue <a href="https://github.com/C2FO/nools/issues/66">#66</a> and <a href="https://github.com/C2FO/nools/issues/67">#67</a> where regular expression matching was too greedy.</li>
<li>Fixed issue <a href="https://github.com/C2FO/nools/issues/62">#62</a> where constraints with a <code>&quot;</code> character would produce invalid javascript when <code>transpiling</code>.</li> <li>Fixed issue <a href="https://github.com/C2FO/nools/issues/62">#62</a> where constraints with a <code>&quot;</code> character would produce invalid javascript when <code>transpiling</code>.</li>
<li>Fixed issue <a href="https://github.com/C2FO/nools/issues/69">#69</a> where rules names with a <code>&#39;</code> character in a rule would produce invalid javascript when <code>transpiling</code>. <li>Fixed issue <a href="https://github.com/C2FO/nools/issues/69">#69</a> where rules names with a <code>&#39;</code> character in a rule would produce invalid javascript when <code>transpiling</code>.</li>
*</li> <li>Added option to beautify generated code</li>
</ul> </ul>
<h1>0.1.9</h1> <h1>0.1.9</h1>
<ul> <ul>
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Expand Up @@ -216,7 +216,7 @@ <h1>Usage</h1>
<li><a href="#fib">Fibonacci</a></li> <li><a href="#fib">Fibonacci</a></li>
</ul> </ul>
<p>The <a href="https://github.com/C2FO/nools/tree/master/examples">examples</a> and <a href="https://github.com/C2FO/nools/tree/master/test">tests</a> are a <p>The <a href="https://github.com/C2FO/nools/tree/master/examples">examples</a> and <a href="https://github.com/C2FO/nools/tree/master/test">tests</a> are a
great place to get started.</p> great place to get started. You can ask your questions on the <a href="https://groups.google.com/forum/#!forum/nools">Nools Google group</a>.</p>
<p><a name="flow"></a></p> <p><a name="flow"></a></p>
<h2>Defining a flow</h2> <h2>Defining a flow</h2>
<p>When using nools you define a <strong>flow</strong> which acts as a container for rules that can later be used to get <p>When using nools you define a <strong>flow</strong> which acts as a container for rules that can later be used to get
Expand Down
2 changes: 1 addition & 1 deletion history.md
Expand Up @@ -7,7 +7,7 @@
* Fixed issue [#66](https://github.com/C2FO/nools/issues/66) and [#67](https://github.com/C2FO/nools/issues/67) where regular expression matching was too greedy. * Fixed issue [#66](https://github.com/C2FO/nools/issues/66) and [#67](https://github.com/C2FO/nools/issues/67) where regular expression matching was too greedy.
* Fixed issue [#62](https://github.com/C2FO/nools/issues/62) where constraints with a `"` character would produce invalid javascript when `transpiling`. * Fixed issue [#62](https://github.com/C2FO/nools/issues/62) where constraints with a `"` character would produce invalid javascript when `transpiling`.
* Fixed issue [#69](https://github.com/C2FO/nools/issues/69) where rules names with a `'` character in a rule would produce invalid javascript when `transpiling`. * Fixed issue [#69](https://github.com/C2FO/nools/issues/69) where rules names with a `'` character in a rule would produce invalid javascript when `transpiling`.
* * Added option to beautify generated code


# 0.1.9 # 0.1.9


Expand Down

0 comments on commit f56d41e

Please sign in to comment.