Permalink
Browse files

Merge pull request #72 from doug-martin/master

Added option to beautify generated code
  • Loading branch information...
doug-martin committed Sep 4, 2013
2 parents 4b75ea6 + f56d41e commit 49e352d23bf177eb34c3f6ed0382d9042461ebd9
Showing with 14 additions and 13 deletions.
  1. +10 −9 bin/nools
  2. +2 −2 docs/History.html
  3. +1 −1 docs/index.html
  4. +1 −1 history.md
View
@@ -10,13 +10,15 @@ var nools = require(".."),
uglifyjs = require("uglify-js"),
program = require('commander');
-function uglify(source) {
+function uglify(source, program) {
try {
- if (program.no_minification) {
- return source;
- } else {
- return uglifyjs.minify(source, {fromString: true, mangle: false, output: {beautify: true}}).code;
- }
+ if (program.no_minification) {
+ return source;
+ } else if (program.beautify) {
+ 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) {
console.error(e.message);
console.error(e.stack);
@@ -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("-l --nools_location [value]", "location to look for nools when requiring it")
.option("-u --no_minification", "Do not minify the generated script")
+ .option("-b --beautify", "beautify the generated source")
.action(function () {
var files = Array.prototype.slice.call(arguments);
var program = files.pop();
var noolsLocation = program["nools_location"] || "nools";
files.forEach(function (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);
View
@@ -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/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/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>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>Added option to beautify generated code</li>
</ul>
<h1>0.1.9</h1>
<ul>
View
@@ -216,7 +216,7 @@ <h1>Usage</h1>
<li><a href="#fib">Fibonacci</a></li>
</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
-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>
<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
View
@@ -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 [#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`.
-*
+* Added option to beautify generated code
# 0.1.9

0 comments on commit 49e352d

Please sign in to comment.