aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2018-11-08 07:16:35 +0000
committers-ol <s-ol@users.noreply.github.com>2018-11-08 07:16:35 +0000
commitf14faf29401cda74dfc8c21f8c2975ce26f03700 (patch)
tree2b8dc84e8de7a5b1550c8dbcbe0984b331e0d644
parentrecursive tup stuff (diff)
downloadmmm-f14faf29401cda74dfc8c21f8c2975ce26f03700.tar.gz
mmm-f14faf29401cda74dfc8c21f8c2975ce26f03700.zip
move tree into dist, recurive tup rendering etc.
-rw-r--r--.gitignore1
-rw-r--r--Tupfile14
-rw-r--r--bundle.moon31
-rw-r--r--mmm/Tupdefault2
-rw-r--r--mmm/mmmfs/init.moon4
-rw-r--r--render.moon25
-rw-r--r--root/Tupdefault.lua11
-rw-r--r--root/articles/mmmfs/gallery/preview: text$moonscript -> fn -> mmm$dom.moon9
-rw-r--r--tup.moon48
9 files changed, 48 insertions, 97 deletions
diff --git a/.gitignore b/.gitignore
index 83fa34b..e783c29 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,4 +3,3 @@
##### Do not edit.
.tup
/.gitignore
-/dist
diff --git a/Tupfile b/Tupfile
index 5cc419d..30ea402 100644
--- a/Tupfile
+++ b/Tupfile
@@ -4,16 +4,12 @@ include_rules
!sassc = |> ^ SCSS %b^ sassc -mauto %f %o |> | %o.map
# download fengari dependencies
-: |> !download |> dist/fengari-web.js
-: |> !download |> dist/fengari-web.js.map
-: static/* |> cp %f dist/ |> dist/%b
+: |> !download |> root/fengari-web.js
+: |> !download |> root/fengari-web.js.map
+: static/* |> cp %f root/ |> root/%b
# render stylesheet
-: scss/main.scss |> !sassc |> dist/main.css
+: scss/main.scss |> !sassc |> root/main.css
# bundle for client loading
-: mmm/.bundle.lua | <modules> |> ^ WRAP %d^ moon bundle.moon %o --wrap %f |> dist/mmm.bundle.lua
-: root/$bundle.lua | <children> |> ^ WRAP %d^ cp '%f' '%o' |> dist/root.lua
-
-# render static content and compile sources
-run moon tup.moon
+: mmm/.bundle.lua | <modules> |> ^ WRAP %d^ moon bundle.moon %o --wrap %f |> root/mmm.bundle.lua
diff --git a/bundle.moon b/bundle.moon
index 8e277c7..1c6b5f6 100644
--- a/bundle.moon
+++ b/bundle.moon
@@ -23,29 +23,28 @@ with io.open output_name, 'w'
else
\write "return {\n"
- for i=2, #arg
- file = arg[i]
+ this = assert arg[2]
+ addmod = (module, file, source) ->
+ modname = "#{this}.#{module}"
+ modname = this if module == 'init'
+ \write "
+{
+ module = #{escape modname},
+ file = #{escape "#{this}/#{file}"},
+ source = #{escape source},
+},"
+ for file in *arg[3,]
if dirname = file\match '^([%w-_]+)/%.bundle%.lua$'
bundle = dofile file
for { :module, :file, :source } in *bundle
- \write "
-{
- module = #{escape dirname .. '.' .. module},
- file = #{escape dirname .. '/' .. file},
- source = #{escape source},
-},
- "
+ addmod module, file, source
else
module = file\gsub '%.lua$', ''
+ continue if module\match '%.server'
+ module = module\gsub '%.client$', ''
module = module\gsub '%.init$', ''
- \write "
-{
- module = #{escape module},
- file = #{escape file},
- source = #{escape readfile file},
-},
- "
+ addmod module, file, readfile file
\write "}"
diff --git a/mmm/Tupdefault b/mmm/Tupdefault
index 1b4dde6..b98f543 100644
--- a/mmm/Tupdefault
+++ b/mmm/Tupdefault
@@ -1,4 +1,4 @@
include_rules
: foreach *.moon |> ^ MOON %f^ moonc -o %o %f 2>/dev/null |> %B.lua <modules>
-: <modules> |> ^ BNDL %d^ moon &(root)/bundle.moon %o %<modules> |> .bundle.lua ../<modules>
+: <modules> |> ^ BNDL %d^ moon &(root)/bundle.moon %o %d %<modules> |> .bundle.lua ../<modules>
diff --git a/mmm/mmmfs/init.moon b/mmm/mmmfs/init.moon
index 94823d9..4dd5c32 100644
--- a/mmm/mmmfs/init.moon
+++ b/mmm/mmmfs/init.moon
@@ -15,8 +15,8 @@ render = (root, path) ->
table.insert(on_load, function()
local path = #{string.format '%q', path}
local browser = require 'mmm.mmmfs.browser'
- local root = require 'root'
- root:mount()
+ local root = dofile '/$bundle.lua'
+ root:mount('', true)
BROWSER = browser.Browser(root, path, true)
end)
diff --git a/render.moon b/render.moon
index 66272ec..681b1db 100644
--- a/render.moon
+++ b/render.moon
@@ -4,19 +4,27 @@ import render from require 'mmm.mmmfs'
import load_fileder from require 'mmm.mmmfs.fs'
-- usage:
--- moon render.moon <output> <fileder_path>
-{ output_name, path } = arg
+-- moon render.moon <path_to_root>
+{ root } = arg
-assert output_name, "please specify the output filename as an argument"
-assert path, "please specify the path name to build as an argument"
+assert root, "please specify the relative root path as an argument"
-root = load_fileder 'root' .. path
-root\mount path
+require 'lfs'
+cwd = lfs.currentdir!
+path = ''
+
+while root\find '^%.%./'
+ root = root\match '^%.%./(.*)'
+ cwd, trimmed = cwd\match '(.*)(/[^/]+)$'
+ path = trimmed .. path
+
+root = dofile '$bundle.lua'
+root\mount path, true
content, rehydrate = render root, path
assert content, "no content"
-with io.open output_name, 'w'
+with io.open 'index.html', 'w'
\write "<!DOCTYPE html>
<html>
<head>
@@ -39,8 +47,7 @@ with io.open output_name, 'w'
<script src=\"//cdnjs.cloudflare.com/ajax/libs/svg.js/2.6.6/svg.min.js\"></script>
<script src=\"/fengari-web.js\"></script>
<script type=\"application/lua\" src=\"/mmm.bundle.lua\"></script>
- <script type=\"application/lua\" src=\"/root.bundle.lua\"></script>
- <script defer type=\"application/lua\" src=\"/mmm/init.lua\"></script>
+ <script type=\"application/lua\">require 'mmm'</script>
#{rehydrate}
</body>
diff --git a/root/Tupdefault.lua b/root/Tupdefault.lua
index b6cf700..e4e433c 100644
--- a/root/Tupdefault.lua
+++ b/root/Tupdefault.lua
@@ -11,13 +11,20 @@ LUA_PATH += root .. '/?/init.lua'
LUA_PATH += root .. '/?/init.server.lua'
LUA_PATH = 'LUA_PATH="' .. table.concat(LUA_PATH, ';') .. '"'
-exec = LUA_PATH .. ' moon ' .. root .. '/bundle_fileder.moon'
+bundle = LUA_PATH .. ' moon ' .. root .. '/bundle_fileder.moon'
+render = LUA_PATH .. ' moon ' .. root .. '/render.moon'
facets += '<children>'
facets += root .. '/<modules>'
tup.rule(
facets,
- '^ BNDL %d^ ' .. exec .. ' %d ' .. inputs .. ' -- %<children>',
+ '^ BNDL %d^ ' .. bundle .. ' %d ' .. inputs .. ' -- %<children>',
{ '$bundle.lua', '../<children>' }
)
+
+tup.rule(
+ '$bundle.lua',
+ '^ HTML %d^ ' .. render .. ' ' .. root,
+ 'index.html'
+)
diff --git a/root/articles/mmmfs/gallery/preview: text$moonscript -> fn -> mmm$dom.moon b/root/articles/mmmfs/gallery/preview: text$moonscript -> fn -> mmm$dom.moon
index 83aa7d4..5285629 100644
--- a/root/articles/mmmfs/gallery/preview: text$moonscript -> fn -> mmm$dom.moon
+++ b/root/articles/mmmfs/gallery/preview: text$moonscript -> fn -> mmm$dom.moon
@@ -5,12 +5,3 @@ import div, img, br from require 'mmm.dom'
br!,
img src: @children[1]\get 'preview', 'URL -> image/png'
}
- }
-
--- for i=1,25
--- id = 120 + i
--- .children[i] = Fileder {
--- 'name: alpha': "image#{id}"
--- 'URL -> image/png': "https://picsum.photos/600/600/?image=#{id}"
--- 'preview: URL -> image/png': "https://picsum.photos/200/200/?image=#{id}"
--- }
diff --git a/tup.moon b/tup.moon
deleted file mode 100644
index 2a3aadd..0000000
--- a/tup.moon
+++ /dev/null
@@ -1,48 +0,0 @@
-package.moonpath = './?.server.moon;./?/init.server.moon;' .. package.moonpath
-require 'lfs'
-require 'mmm.init'
-
--- enumerate moonscript source files
-enum_dir = do
- yieldtree = (dir) ->
- for entry in lfs.dir dir
- if entry != '.' and entry != '..' then
- entry = dir .. "/" .. entry
- attr = lfs.attributes entry
- switch attr.mode
- when 'file' then coroutine.yield entry, attr
- when 'directory' yieldtree entry
-
- (dir) ->
- assert dir and dir ~= '', "directory parameter is missing or empty"
- dir = dir\sub 1, -2 if '/' == dir\sub -1
-
- coroutine.wrap -> yieldtree dir
-
--- COMPILE MOONSCRIPT
--- for file in enum_dir 'mmm'
--- continue if file\match '%.server%.moon$'
--- basename = assert file\match '(.*)%.moon$'
--- basename = (file\match '(.*)%.client') or basename
--- print ": #{file} |> ^ MOON %b > %o^ moonc -o %o %f |> dist/#{basename}.lua {mmm_src}"
---
--- -- GENERATE BUNDLES
--- print ": {mmm_src} |> ^ BUNDLE mmm^ moon bundle.moon %o %f |> dist/mmm.bundle.lua"
-
--- COMPILE AND DUMP TREE
--- print ": |> ^ DUMP root^ moon dump_tree.moon %o |> dist/root.lua"
-
--- PRE-RENDER TREE
--- import load_fileder from require 'mmm.mmmfs.fs'
---
--- root = load_fileder!
-root = dofile 'root/$bundle.lua'
-root\mount!
-
-for fileder in coroutine.wrap root\iterate
- name = fileder\gett 'name: alpha'
- { :path, :source_module } = fileder
-
- path = '/' if path == ''
-
- print ": |> ^ HTML #{path}^ moon render.moon %o '#{path}' |> dist#{path}/index.html"