-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switched streamlinejs dependency to cinch.
- Loading branch information
Showing
223 changed files
with
3,192 additions
and
4,301 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 $* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
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.
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}) |
Oops, something went wrong.