aboutsummaryrefslogtreecommitdiffstats
path: root/bundle_fileder.moon
diff options
context:
space:
mode:
Diffstat (limited to 'bundle_fileder.moon')
-rw-r--r--bundle_fileder.moon53
1 files changed, 37 insertions, 16 deletions
diff --git a/bundle_fileder.moon b/bundle_fileder.moon
index 7c0fb26..9ef2381 100644
--- a/bundle_fileder.moon
+++ b/bundle_fileder.moon
@@ -1,8 +1,8 @@
-package.moonpath = './?.server.moon;./?/init.server.moon;' .. package.moonpath
-require 'mmm.init'
-import Key from require 'mmm.mmmfs'
-import load_fileder, load_property from require 'mmm.mmmfs.fs'
+require 'mmm'
+import Fileder, Key from require 'mmm.mmmfs.fileder'
+import opairs from require 'mmm.ordered'
import to_lua from require 'moonscript.base'
+require 'lfs'
-- usage:
-- moon bundle_fileder.moon <dirname> <facets>... -- <children>...
@@ -16,29 +16,48 @@ children_bundles = {}
do
addto = facets
for file in *arg[2,]
+ continue if file == 'Tupdefault.lua'
+
if file == '--'
addto = children_bundles
continue
table.insert addto, file
--- dump a fileder subtree as Lua source
-dump_fileder = do
- escape = (str) -> string.format '%q', tostring str
- compile = (old, new, val) -> escape "-- this property has been transpiled from '#{old}'
+readfile = (name) ->
+ file = io.open name, 'r'
+ with file\read '*all'
+ file\close!
+
+-- load a fs file as a fileder property
+load_property = (path, filename) ->
+ key = (filename\match '(.*)%.%w+') or filename
+ key = Key key\gsub '%$', '/'
+
+ value = readfile path .. filename
+
+ key, value
+
+-- escape a string for lua aparser
+escape = (str) -> string.format '%q', tostring str
+
+-- compile a moonscript facet to lua
+compile = (old, new, val) -> "-- this property has been transpiled from '#{old}'
-- to '#{new}' for execution in the browser.
-- refer to the original property as the source.
#{to_lua val}"
+-- dump a fileder subtree as Lua source
+dump_fileder = do
_dump = (fileder, root=false) ->
code = "Fileder {"
for key, val in pairs fileder.props
- code ..= "\n[#{escape key}] = #{escape val},"
-
- if root and key.type\match '^text/moonscript %->'
- newkey = Key key.name, key.type\gsub '^text/moonscript %-> (.*)', 'text/lua -> %1'
- code ..= "\n[fromcache(#{escape newkey}, #{escape key})] = #{compile key, newkey, val},"
+ if key.original
+ key = "fromcache(#{escape key}, #{escape key.original})"
+ else
+ key = escape key
+ code ..= "\n[#{key}] = #{escape val},"
for child in *fileder.children
code ..= "\n#{_dump child},"
@@ -59,9 +78,6 @@ end
return #{_dump fileder, true}
"
-import Fileder from require 'mmm.mmmfs.fileder'
-import opairs from require 'mmm.ordered'
-
with io.open '$bundle.lua', 'w'
\write dump_fileder with Fileder 'name: alpha': dirname
order = nil
@@ -74,6 +90,11 @@ with io.open '$bundle.lua', 'w'
key, value = load_property '', facet
.props[key] = value
+ if key.type\match '^text/moonscript %->'
+ new_key = Key key.name, key.type\gsub '^text/moonscript %-> (.*)', 'text/lua -> %1'
+ new_key.original = key
+ .props[new_key] = compile key, new_key, value
+
for child in *children_bundles
-- @BUG: child bundles are malformed due to Tup bug ($ symbol)
child = child\gsub '/%.lua$', '/$bundle.lua'