From 6298207130b5c0dc414c60687f681e2bb5621ab5 Mon Sep 17 00:00:00 2001 From: Radagaisus Date: Fri, 19 Jul 2013 06:32:25 +0300 Subject: [PATCH] yalla --- Cakefile | 40 ++++++++++++++++++++++++++++++++++++++++ index.js | 24 ++++++++++++++++++++++++ test/example/hello.js | 6 ++++++ test/example/hi.js | 6 ++++++ 4 files changed, 76 insertions(+) create mode 100644 Cakefile create mode 100644 index.js create mode 100644 test/example/hello.js create mode 100644 test/example/hi.js diff --git a/Cakefile b/Cakefile new file mode 100644 index 0000000..6249178 --- /dev/null +++ b/Cakefile @@ -0,0 +1,40 @@ +{spawn, exec} = require 'child_process' + +task 'build', -> + run 'coffee -c *.coffee test/**/*.coffee' + +# run spawns a bash process, sends it a +# command and hooks its stdout and sterr +# to the current process. We use this in +# our Cakefile. +# +# Parameters are used based on their type: +# - string - is the command +# - object - options passed to spawn +# - array - joined with spaces to form a +# command +# - function - callback to invoke if the +# process completed successfully +# +# Usage: +# run "echo hi", -> +# run "echo bye" +# > hi +# > bye +# +module.exports = run = (args...) -> + for a in args + switch typeof a + when 'string' then command = a + when 'object' + if a instanceof Array then params = a + else options = a + when 'function' then callback = a + + command += ' ' + params.join ' ' if params? + cmd = spawn '/bin/sh', ['-c', command], options + cmd.stdout.on 'data', (data) -> process.stdout.write data + cmd.stderr.on 'data', (data) -> process.stderr.write data + process.on 'SIGHUP', -> cmd.kill() + cmd.on 'exit', (code) -> callback() if callback? and code is 0 + diff --git a/index.js b/index.js new file mode 100644 index 0000000..d247fcd --- /dev/null +++ b/index.js @@ -0,0 +1,24 @@ +// Generated by CoffeeScript 1.4.0 +(function() { + var basename, fs, join, require_directory, resolve, _ref; + + fs = require('fs'); + + _ref = require('path'), join = _ref.join, resolve = _ref.resolve, basename = _ref.basename; + + module.exports = require_directory = function(directory) { + directory = resolve(directory); + return fs.readdirSync(directory).reduce(function(hash, file) { + var file_name, file_path; + file_path = join(directory, file); + file_name = file.substring(0, file.lastIndexOf('.')); + if (fs.statSync(file_path).isDirectory()) { + hash[basename(file_path)] = require_directory(file_path); + } else { + hash[file_name] = require(file_path); + } + return hash; + }, {}); + }; + +}).call(this); diff --git a/test/example/hello.js b/test/example/hello.js new file mode 100644 index 0000000..240b36c --- /dev/null +++ b/test/example/hello.js @@ -0,0 +1,6 @@ +// Generated by CoffeeScript 1.4.0 +(function() { + + module.exports = 'world'; + +}).call(this); diff --git a/test/example/hi.js b/test/example/hi.js new file mode 100644 index 0000000..81c47c0 --- /dev/null +++ b/test/example/hi.js @@ -0,0 +1,6 @@ +// Generated by CoffeeScript 1.4.0 +(function() { + + module.exports = 'you'; + +}).call(this);