Permalink
Browse files

initial commit

  • Loading branch information...
poelzi committed Sep 18, 2011
0 parents commit 4a36d43c4f25e469ba1cc806bb398c900f872a53
Showing with 865 additions and 0 deletions.
  1. +676 −0 LICENCE
  2. +18 −0 README.md
  3. +2 −0 bin/inode
  4. +26 −0 package.json
  5. +110 −0 src/inode.coffee
  6. +33 −0 wscript
676 LICENCE

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,18 @@
+inode
+=======
+
+inode tries to become the ipython for node, one day ;-)
+at least it is already much better then nodes default shell.
+
+
+# Installation
+
+
+ npm install inode
+
+
+best done globaly with `npm install -g inode`
+
+
+## FIXME
+
@@ -0,0 +1,2 @@
+#!/usr/bin/env node
+require("../build/default/inode.js")
@@ -0,0 +1,26 @@
+{ "name": "inode"
+, "description": "inode is a better interactive shell"
+, "version": "0.0.1"
+, "homepage": "https://github.com/poelzi/node-inode"
+, "author": "poelzi (http://poelzi.org)"
+, "repository": {"type": "git", "url": "git://github.com/poelzi/node-inode.git"}
+, "bin": "bin/inode"
+, "engines": {"node": "0.4.x"}
+, "keywords": ["cache", "async", "redis"]
+, "scripts": {
+ "preinstall": "#preinstall DO NOTHING",
+ "install": "node-waf configure build",
+ "update": "node-waf build",
+ "test": "node-waf && ./node_modules/nodeunit/bin/nodeunit test"}
+, "dependencies": {
+ "coffee-script": ">= 1.1.1",
+ "eyes": "*",
+ "colors": "*",
+ "async": "0.1.x",
+ "eyes": "0.1.x",
+ "quack-array": "0.0.x"
+ }
+, "devDependencies": {
+ "nodeunit": "0.5.x"
+ }
+}
@@ -0,0 +1,110 @@
+###
+Flexcache
+
+Copyright (c) 2011 Daniel Poelzleithner
+
+BSD License
+###
+
+async = require 'async'
+quack = require 'quack-array'
+assert = require 'assert'
+colors = require 'colors'
+eyes = require 'eyes'
+fs = require 'fs'
+{ EventEmitter } = require('events')
+
+net = require "net"
+repl = require "repl"
+path = require "path"
+mkdirp = require "mkdirp"
+vm = require 'vm'
+config_base = path.join(process.env.HOME, ".config", "inode")
+history_file = path.join(config_base, "history")
+history = null
+util = require 'util'
+
+log = eyes.inspector()
+
+old_history = []
+
+command_nr = 0
+
+nice_error = (err) ->
+ return if not err
+ self.rli.write('\n')
+ self.rli.write('Caught exception: '.red.bold + err.message.red + "\n")
+ self.rli.write(String(err.stack) + "\n")
+ self.rli.prompt()
+
+
+process.on 'uncaughtException', nice_error
+
+shell = repl.start("> ")
+
+# fix the most annoying default sigint handler
+shell.rli.removeAllListeners('SIGINT')
+
+self = shell
+
+mkdirp config_base, 0755, (err) ->
+ fs.open history_file, "a+", (err, fd) ->
+ history = fd
+
+ fs.readFile history_file, "utf-8", (err, data) ->
+ if not data
+ return
+ dat = data.split("\n")
+ for line in dat
+ self.rli.history.unshift String(line)
+ self.rli.history_index = -1
+
+shell.rli.write("inode".yellow.bold + " type ".grey + ".help".white.bold + " for help".grey + "\n")
+shell.rli.bufferedCommand = ""
+
+shell.eval ?= (code, context, file, cb) ->
+ try
+ [err, result] = vm.runInContext(code, context, file)
+ catch e
+ err = e
+ cb(err, result)
+
+
+shell.rli.on 'SIGINT', () ->
+ self.rli.write('\n(^C abort command)'.red)
+
+ self.rli.line = ''
+ self.rli.write('\n')
+ self.bufferedCommand = ''
+ self.displayPrompt()
+
+shell.rli.on 'line', (line) ->
+ if line.trim() == ""
+ self.bufferedCommand = self.bufferedCommand.trimRight()
+ else
+ command_nr += 1
+ if history
+ buf = new Buffer(line + "\n")
+ fs.write(history, buf, 0, buf.length, null)
+
+shell.displayPrompt = () ->
+ if self.bufferedCommand.length
+ self.rli.setPrompt('... '.white, 4)
+ else
+ pure = 'In [' + command_nr + ']: '
+ self.rli.setPrompt('In ['.cyan + String(command_nr).cyan.bold + ']: '.cyan, pure.length)
+ self.rli.prompt()
+
+shell.context["_shell"] = shell
+shell.context["log"] = log
+
+shell.defineCommand 'req',
+ help: 'requires a module: ARG = require("ARG") or ARG1 = require("ARG2")',
+ action: (args) ->
+ args = args.split(" ")
+ if args.length == 1
+ self.eval args[0] + " = require('" + args[0] + "');", self.context, 'repl', (e, ret) ->
+ nice_error(e)
+ else if args.length == 2
+ self.eval args[0] + " = require('" + args[1] + "');", self.context, 'repl', (e, ret) ->
+ nice_error(e)
33 wscript
@@ -0,0 +1,33 @@
+from os.path import dirname, join
+import os
+
+top = "."
+out = "build"
+
+class Dummy: pass
+
+
+def configure(ctx):
+ ctx.env.PATH = os.environ['PATH'].split(os.pathsep)
+ ctx.env.PATH.append(join(ctx.cwd, "node_modules", "coffee-script", "bin"))
+ ctx.find_program("coffee", var="COFFEE", path_list=ctx.env.PATH)
+ ctx.env.ARGS = "-co"
+
+
+def build(ctx):
+ env = Dummy()
+ env.variant = lambda: ""
+ for top in ("src", "test"):
+ for file in ctx.path.find_dir(top).ant_glob("**/*.coffee", flat=False):
+ #print file.change_ext(".js").bldpath(env)
+ tgtpath = file.change_ext(".js").bldpath(env)
+ if top == "src":
+ tgtpath = tgtpath[len(top)+2:]
+ else:
+ tgtpath = tgtpath[1:]
+ ctx.path.exclusive_build_node(tgtpath)
+ #print tgtpath
+ ctx(name = "coffee",
+ rule = "${COFFEE} ${ARGS} default/%s ${SRC}" %(dirname(tgtpath)),
+ source = file.srcpath()[3:],
+ target = tgtpath)

0 comments on commit 4a36d43

Please sign in to comment.