From 2d290818995ffa32e07b88058a542ad4b784f839 Mon Sep 17 00:00:00 2001 From: jiyinyiyong Date: Fri, 23 May 2014 17:51:20 +0800 Subject: [PATCH] make it look better --- .gitignore | 2 ++ README | 7 ------- README.md | 12 ++++++++++++ cofmon.coffee | 8 ++++---- index.js | 3 +-- 5 files changed, 19 insertions(+), 13 deletions(-) delete mode 100644 README create mode 100644 README.md mode change 100755 => 100644 cofmon.coffee mode change 100755 => 100644 index.js diff --git a/.gitignore b/.gitignore index 93f1361..05dad30 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules npm-debug.log + +cofmon.js \ No newline at end of file diff --git a/README b/README deleted file mode 100644 index e8a107b..0000000 --- a/README +++ /dev/null @@ -1,7 +0,0 @@ -A coffeescript shell for mongodb so that you can write coffeescript instead of javascript in the mongo shell. - -To use, just 'npm install -g cofmon' and then use `cofmon` as you would the mongo command. - -In additon to being able to write coffeescript instead of javascript, any 24 character hex string that's wrapped in double quotes is automatically made into an ObjectId. IE, -"51bb660191888d7acc355ed8" compiles to ObjectId("51bb660191888d7acc355ed8") -'51bb660191888d7acc355ed8' compiles to '51bb660191888d7acc355ed8' diff --git a/README.md b/README.md new file mode 100644 index 0000000..9cf2b83 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ + +A CoffeeScript Shell for MongoDB +------ + +so that you can write CoffeeScript instead of JavaScript in the Mongo Shell. + +To use, just `npm install -g cofmon` and then use `cofmon` as you would the Mongo command. + +In additon to being able to write CoffeeScript instead of JavaScript, any 24 character hex string that's wrapped in double quotes is automatically made into an `ObjectId`, i.e. + +`"51bb660191888d7acc355ed8"` compiles to `ObjectId("51bb660191888d7acc355ed8")` +`'51bb660191888d7acc355ed8'` compiles to `'51bb660191888d7acc355ed8'` diff --git a/cofmon.coffee b/cofmon.coffee old mode 100755 new mode 100644 index 0159796..b6bbde9 --- a/cofmon.coffee +++ b/cofmon.coffee @@ -9,7 +9,7 @@ shell = proc.spawn 'mongo', process.argv.slice 2 rl = readline.createInterface process.stdin, process.stdout query = -> - rl.question '>', (data) -> + rl.question '> ', (data) -> try data = data.replace /("[0-9a-f]{24}")/g, "ObjectId($1)" if data.match /^(show|use|it)( |\n)/ then c = data+"\n" @@ -22,12 +22,12 @@ query = -> shell.stdout.on 'data', (data) -> process.stdout.write data.toString() if tid then clearTimeout tid - tid = setTimeout query, 100 + tid = setTimeout query, 200 shell.stderr.on 'data', (data) -> process.stderr.write data.toString() if tid then clearTimeout tid - tid = setTimeout query, 100 + tid = setTimeout query, 200 -shell.on 'exit', -> +shell.on 'exit', -> process.exit(0) diff --git a/index.js b/index.js old mode 100755 new mode 100644 index 1e6f1b4..f9b0c26 --- a/index.js +++ b/index.js @@ -1,3 +1,2 @@ #!/usr/bin/env node -require('coffee-script/register') -require(__dirname+"/cofmon.coffee") +require("./cofmon")