22argparse = require " argparse"
33
44parser = argparse " splat.moon" , " Concatenate a collection of Lua modules into a single file"
5- parser\ option( " --load -l" , " Module names that will be load on require" ) \ count " *"
5+ parser :: option( " --load -l" , " Module names that will be load on require" ) :: count " *"
66
7- parser\ argument( " directories" , " Directories to scan for Lua modules" ) \ args " +"
7+ parser :: argument( " directories" , " Directories to scan for Lua modules" ) :: args " +"
88
9- args = parser\ parse [ v for _, v in ipairs _G . arg]
9+ args = parser :: parse [ v for _, v in ipairs _G . arg]
1010dirs = args. directories
1111
1212normalize = ( path) ->
13- path\ match( " (.-)/*$" ) .. " /"
13+ path :: match( " (.-)/*$" ) .. " /"
1414
1515lfs = require " lfs"
1616scan_directory = ( root, patt, collected= {} ) ->
1717 root = normalize root
1818 for fname in lfs. dir root
19- if not fname\ match " ^%."
19+ if not fname :: match " ^%."
2020 full_path = root.. fname
2121
2222 if lfs. attributes( full_path, " mode" ) == " directory"
2323 scan_directory full_path, patt, collected
2424 else
25- if full_path\ match patt
25+ if full_path :: match patt
2626 table.insert collected, full_path
2727
2828 collected
2929
3030path_to_module_name = ( path) ->
31- ( path\ match( " (.-)%.lua" ) \ gsub( " /" , " ." ))
31+ (path :: match( " (.-)%.lua" ) :: gsub( " /" , " ." ))
3232
3333each_line = ( text) ->
3434 coroutine.wrap ->
3535 start = 1
3636 while true
37- pos, after = text\ find " \n " , start, true
37+ pos, after = text :: find " \n " , start, true
3838 break if not pos
39- coroutine.yield text\ sub start, pos - 1
39+ coroutine.yield text :: sub start, pos - 1
4040 start = after + 1
41- coroutine.yield text\ sub start, # text
41+ coroutine.yield text :: sub start, # text
4242 nil
4343
4444write_module = ( name, text) ->
@@ -52,19 +52,19 @@ for dir in *dirs
5252 files = scan_directory dir, " %.lua$"
5353 chunks = for path in * files
5454 module_name = path_to_module_name path
55- content = io.open ( path) \ read" *a"
55+ content = io.open ( path) :: read" *a"
5656 modules[ module_name] = true
5757 { module_name, content}
5858
5959 for chunk in * chunks
6060 name, content = unpack chunk
61- base = name\ match" (.-)%.init"
61+ base = name :: match" (.-)%.init"
6262 if base and not modules[ base] then
6363 modules[ base] = true
6464 name = base
6565 write_module name, content
6666
6767for module_name in * args. load
6868 if modules[ module_name]
69- print ( [[ package.preload["%s"]()]] ) \ format module_name
69+ print ( [[ package.preload["%s"]()]] ) :: format module_name
7070
0 commit comments