Skip to content

Commit

Permalink
Switched streamlinejs dependency to cinch.
Browse files Browse the repository at this point in the history
  • Loading branch information
pguillory committed Feb 19, 2011
1 parent 95bbf5a commit f02f24d
Show file tree
Hide file tree
Showing 223 changed files with 3,192 additions and 4,301 deletions.
2 changes: 1 addition & 1 deletion bin/bundle-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ rm -rf deps-temp
mkdir deps-temp
pushd deps-temp
git clone https://github.com/pguillory/node-iniconf.git iniconf
git clone https://github.com/pguillory/streamlinejs.git streamlinejs
git clone https://github.com/pguillory/cinch.git cinch
git clone https://github.com/pguillory/node-web.git web
find . -name .git | xargs rm -rf
popd
Expand Down
1 change: 1 addition & 0 deletions deps/cinch/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
41 changes: 41 additions & 0 deletions deps/cinch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Cinch is a Javascript source transformation tool. It allows you to write asynchronous, non-blocking code in a clean, synchronous form.

Cinch modules use the extension `.js_` and contain regular Javascript syntax, with one bonus. The Cinch engine will transform any function whose name ends in an underscore into asynchronous form. The new function will have the same name (minus the underscore) and an extra callback parameter.

Inside a transformed function, you can call any asynchronous function (whether converted or hand-coded) as if it was synchronous by appending an underscore to its name. You can mix such function calls with language constructs like `while`, `for`, `try`/`catch`, `throw`, and `return`, and they'll work as you hope.

Cinch is 100% compatible with regular Javascript code. Transformed functions and regular functions can coexist in the same module and call each other freely.

Example
-------
var fs = require('fs');

fileLength(__filename, function(err, length) {
if (err) throw err;
console.log('I am ' + length + ' bytes long');
});

function fileLength_(path) {
return fs.readFile_(path).length;
};

The function `fileLength()` will be converted into the following:

function fileLength(path, callback) {
fs.readFile(path, function(err, contents) {
if (err) return callback(err);
return callback(null, contents.length);
});
};

Running Cinch code
------------------
The included script `bin/node-cinch` can be used in place of `node` to run `.js_` files directly. Or you can call `require('cinch').registerExtension()` from a running script to enable `.js_` modules to be `require()`-ed.

Alternatively, you can use `node-cinch-save` or `registerExtension({ saveSource: true })` to have it save pure-Javascript copies of your Cinch modules as `.js` files. These are regular Javascript modules and can be used without Cinch.

History
-------
Cinch started as a fork of [Streamline.js] [1] and turned into a full rewrite.

[1]: https://github.com/Sage/streamlinejs
File renamed without changes.
8 changes: 8 additions & 0 deletions deps/cinch/bin/node-cinch
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
if [ -h "$0" ]; then
self=`readlink $0`
else
self=$0
fi
dir=`dirname $self`
node $dir/../lib/run.js $*
8 changes: 8 additions & 0 deletions deps/cinch/bin/node-cinch-save
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
if [ -h "$0" ]; then
self=`readlink $0`
else
self=$0
fi
dir=`dirname $self`
node $dir/../lib/run-save.js $*
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions deps/cinch/examples/length.js_
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var fs = require('fs')

fileLength(__filename, function(err, length) {
if (err) throw err;
console.log('I am ' + length + ' bytes long');
});

function fileLength_(path) {
return fs.readFile_(path).length;
}
2 changes: 2 additions & 0 deletions deps/cinch/examples/print_argv.js_
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
var util = require('util')
console.log('argv: ' + util.inspect(process.argv))
22 changes: 22 additions & 0 deletions deps/cinch/examples/recursive_ls.js_
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*****************************************************************************/
/* Recursive directory listing (depth-first)
/*****************************************************************************/
var path = require('path')
var fs = require('fs')
var util = require('util')

recursive_ls(path.join(process.cwd(), process.argv[2]))

function recursive_ls_(dir, depth) {
var names = fs.readdir_(dir)

for (var i in names) {
if (names[i][0] !== '.') {
var name = path.join(dir, names[i])
console.log(name)
if (fs.stat_(name).isDirectory()) {
recursive_ls_(name, depth)
}
}
}
}
3 changes: 3 additions & 0 deletions deps/cinch/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exports.registerExtension = require('./lib/register').registerExtension;
exports.transform = require("./lib/transform").transform;
exports.transformFile = require("./lib/transform").transformFile;
34 changes: 34 additions & 0 deletions deps/cinch/lib/idents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var Narcissus = require('./narcissus')
eval(Narcissus.definitions.consts);

var ident_counter
var callback_idents

function reset() {
ident_counter = 0
callback_idents = []
exports.throw = get('throw')
}

function get(name) {
ident_counter += 1
return {
type: IDENTIFIER,
value: '__' + (name || 'ident') + '_' + ident_counter,
}
}


function push_callback() {
callback_idents.unshift(exports.callback)
exports.callback = get('callback')
}

function pop_callback() {
exports.callback = callback_idents.shift()
}

exports.reset = reset
exports.get = get
exports.push_callback = push_callback
exports.pop_callback = pop_callback
File renamed without changes.
16 changes: 16 additions & 0 deletions deps/cinch/lib/register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var cinch = require('..')

exports.registerExtension = function(options) {
options = options || {}

// force require() to check for .js_ before .js
var js_extension = require.extensions['.js']
delete require.extensions['.js']

require.extensions[options.extension || '.js_'] = function(module, filename) {
var content = cinch.transformFile(filename, options)
module._compile(content, filename)
}

require.extensions['.js'] = js_extension
}
21 changes: 21 additions & 0 deletions deps/cinch/lib/run-save.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var path = require('path');
require('..').registerExtension({ saveSource: true });

process.argv.splice(1, 1)

if (process.argv.length < 2) {
console.log("Syntax:");
console.log("node-cinch MYAPP.js_");
process.exit(1);
}

var filename = path.join(process.cwd(), process.argv[1])

path.exists(filename, function(exists) {
if (!exists) {
console.log('File not found: ' + process.argv[1])
process.exit(1)
}

require(filename);
})
21 changes: 21 additions & 0 deletions deps/cinch/lib/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var path = require('path');
require('..').registerExtension();

process.argv.splice(1, 1)

if (process.argv.length < 2) {
console.log("Syntax:");
console.log("node-cinch MYAPP.js_");
process.exit(1);
}

var filename = path.join(process.cwd(), process.argv[1])

path.exists(filename, function(exists) {
if (!exists) {
console.log('File not found: ' + process.argv[1])
process.exit(1)
}

require(filename);
})
Loading

0 comments on commit f02f24d

Please sign in to comment.