From d11441884740d394f73f1a145b502e270482a2d2 Mon Sep 17 00:00:00 2001 From: s-ol Date: Thu, 8 Nov 2018 17:17:17 +1100 Subject: recursive tup stuff --- bundle_fileder.moon | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 bundle_fileder.moon (limited to 'bundle_fileder.moon') diff --git a/bundle_fileder.moon b/bundle_fileder.moon new file mode 100644 index 0000000..7c0fb26 --- /dev/null +++ b/bundle_fileder.moon @@ -0,0 +1,96 @@ +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' +import to_lua from require 'moonscript.base' + +-- usage: +-- moon bundle_fileder.moon ... -- ... +{ dirname } = arg + +assert dirname, "please specify the fileder dirname" + +facets = {} +children_bundles = {} + +do + addto = facets + for file in *arg[2,] + 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}' +-- to '#{new}' for execution in the browser. +-- refer to the original property as the source. +#{to_lua val}" + + _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}," + + for child in *fileder.children + code ..= "\n#{_dump child}," + + code ..= "\n}" + code + + + (fileder) -> " +local mmmfs = require 'mmm.mmmfs' +local Key, Fileder = mmmfs.Key, mmmfs.Fileder +local function fromcache(str, orig) + local key = Key(str) + key.original = Key(orig) + return key +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 + children = {} + + for facet in *facets + if facet == '$order' + order = [line for line in io.lines facet] + continue + key, value = load_property '', facet + .props[key] = value + + for child in *children_bundles + -- @BUG: child bundles are malformed due to Tup bug ($ symbol) + child = child\gsub '/%.lua$', '/$bundle.lua' + + dirname = assert child\match '^([%w-_%.]+)/%$bundle%.lua$' + children[dirname] = dofile child + + if order + -- order from order file + for i, name in pairs order + child = assert children[name], "child in $order but not fs: #{name} of #{path}" + table.insert .children, child + children[name] = nil + + -- sort remainder alphabeticalally + for name, child in opairs children + table.insert .children, child + warn "child #{name} of #{path} not in $order!" if order + + \close! -- cgit v1.2.3 From 95624c5cfae37bcd378263735daa16b2b0fb60c4 Mon Sep 17 00:00:00 2001 From: s-ol Date: Thu, 8 Nov 2018 19:53:27 +1100 Subject: cleanup --- bundle_fileder.moon | 53 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 16 deletions(-) (limited to 'bundle_fileder.moon') 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 ... -- ... @@ -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' -- cgit v1.2.3 From ac0306d69b12d7be910c0ec27093ec506d6349ce Mon Sep 17 00:00:00 2001 From: s-ol Date: Thu, 8 Nov 2018 21:31:28 +1100 Subject: rename properties to facets --- bundle_fileder.moon | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'bundle_fileder.moon') diff --git a/bundle_fileder.moon b/bundle_fileder.moon index 9ef2381..01aa0a4 100644 --- a/bundle_fileder.moon +++ b/bundle_fileder.moon @@ -29,12 +29,12 @@ readfile = (name) -> with file\read '*all' file\close! --- load a fs file as a fileder property -load_property = (path, filename) -> +-- load a fs file as a fileder facet +load_facet = (filename) -> key = (filename\match '(.*)%.%w+') or filename key = Key key\gsub '%$', '/' - value = readfile path .. filename + value = readfile filename key, value @@ -42,9 +42,9 @@ load_property = (path, filename) -> escape = (str) -> string.format '%q', tostring str -- compile a moonscript facet to lua -compile = (old, new, val) -> "-- this property has been transpiled from '#{old}' +compile = (old, new, val) -> "-- this facet has been transpiled from '#{old}' -- to '#{new}' for execution in the browser. --- refer to the original property as the source. +-- refer to the original facet as the source. #{to_lua val}" -- dump a fileder subtree as Lua source @@ -52,7 +52,7 @@ dump_fileder = do _dump = (fileder, root=false) -> code = "Fileder {" - for key, val in pairs fileder.props + for key, val in pairs fileder.facets if key.original key = "fromcache(#{escape key}, #{escape key.original})" else @@ -87,13 +87,13 @@ with io.open '$bundle.lua', 'w' if facet == '$order' order = [line for line in io.lines facet] continue - key, value = load_property '', facet - .props[key] = value + key, value = load_facet facet + .facets[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 + .facets[new_key] = compile key, new_key, value for child in *children_bundles -- @BUG: child bundles are malformed due to Tup bug ($ symbol) -- cgit v1.2.3