Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

bin and basic book-keeping

  • Loading branch information...
commit 0a4d27387fc7019c0c80ec5791c68dc48eb48f86 1 parent e4aaf49
@substack authored
Showing with 81 additions and 1 deletion.
  1. +29 −0 bin/cmd.js
  2. +49 −0 index.js
  3. +3 −1 readme.markdown
View
29 bin/cmd.js
@@ -0,0 +1,29 @@
+var codebux = require('../');
+var dir = process.argv[2] || process.cwd();
+var Stream = require('stream');
+
+var priceStream = new Stream;
+priceStream.writable = true;
+priceStream.write = function (rec) {
+ var p = formatPrice(rec.price);
+ console.log(
+ Array(10 - p.length).join(' ')
+ + p + ' # ' + rec.description
+ );
+};
+priceStream.end = function () {};
+priceStream.destroy = function () {};
+
+var s = codebux(dir, function (err, total) {
+ if (err) console.error(err)
+ else console.log('\ntotal: ' + formatPrice(total))
+});
+s.pipe(priceStream);
+
+function formatPrice (n) {
+ return (n >= 0 ? '+' : '') + String(n)
+ .replace(/(\.\d{,2}|)$/, function (_, x) {
+ return ('.' + (x || '') + '00').slice(0,3);
+ })
+ ;
+}
View
49 index.js
@@ -0,0 +1,49 @@
+var detective = require('detective');
+var fs = require('fs');
+var path = require('path');
+var Stream = require('stream');
+
+module.exports = function (dir, cb) {
+ var stream = new Stream;
+ stream.readable = true;
+
+ var total = 0;
+
+ if (typeof cb === 'function') {
+ stream.once('error', function (err) {
+ cb(err);
+ });
+
+ stream.on('end', function () {
+ cb(null, total);
+ });
+ }
+
+ function record (price, desc) {
+ total += price;
+ stream.emit('data', {
+ price : price,
+ description : desc,
+ total : total
+ });
+ }
+
+ process.nextTick(function () {
+ record(100, 'initial stipend');
+ });
+
+ var pending = 0;
+ (function walk (file) {
+ pending ++;
+ fs.readFile(file, function (err, src) {
+ if (err) return stream.emit('error', err);
+
+ var deps = detective(src);
+ console.dir(deps);
+
+ if (--pending === 0) stream.emit('end');
+ });
+ })(require.resolve(dir + '/'));
+
+ return stream;
+};
View
4 readme.markdown
@@ -5,7 +5,9 @@ This module computes technical debt for node programs.
Lines of code are spent. You start at $100. You don't get any more codebux. You
can only lose codebux by fucking up somehow. There are many ways to fuck up:
-* having too much code
+* too much code
+* too much indentation
+* too much nested state
* not having tests
* not having a readme
* not having examples
Please sign in to comment.
Something went wrong with that request. Please try again.