From 0f44808158a6b11103f9205b037a18a46da29e4e Mon Sep 17 00:00:00 2001 From: leaf corcoran Date: Sun, 11 Dec 2011 17:12:17 -0800 Subject: [PATCH] splat.moon can do multiple directories --- bin/splat.moon | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/bin/splat.moon b/bin/splat.moon index 2a230d6..eada7c7 100755 --- a/bin/splat.moon +++ b/bin/splat.moon @@ -8,10 +8,10 @@ import insert, concat from table import dump from require "moonscript.util" if not arg[1] - print "usage: splat directory" + print "usage: splat directory [directories...]" os.exit! -dir = arg[1] +dirs = [a for a in *arg[,]] normalize = (path) -> path\match("(.-)/*$").."/" @@ -30,10 +30,6 @@ scan_directory = (root, patt, collected={}) -> collected -files = scan_directory dir, "%.lua$" - -modules = {} - path_to_module_name = (path) -> (path\match("(.-)%.lua")\gsub("/", ".")) @@ -56,25 +52,24 @@ write_module = (name, text) -> print "end" modules = {} -chunks = for path in *files - module_name = path_to_module_name path - content = io.open(path)\read"*a" - modules[module_name] = true - {module_name, content} +for dir in *dirs + files = scan_directory dir, "%.lua$" + chunks = for path in *files + module_name = path_to_module_name path + content = io.open(path)\read"*a" + modules[module_name] = true + {module_name, content} -for chunk in *chunks - name, content = unpack chunk - base, init = name\match"(.-)%.init" - if base and not modules[base] then - modules[base] = true - name = base - write_module name, content + for chunk in *chunks + name, content = unpack chunk + base = name\match"(.-)%.init" + if base and not modules[base] then + modules[base] = true + name = base + write_module name, content -default_name = if arg[2] - arg[2] -else - dir\gsub("/", ".")\gsub("%.$", "") - -if modules[default_name] - print ([[return package.preload["%s"]()]])\format default_name +for dir in *dirs + module_name = dir\gsub("/", ".")\gsub("%.$", "") + if modules[module_name] + print ([[package.preload["%s"]()]])\format module_name