vue-poc/tools/compile.xq

72 lines
2.7 KiB
Plaintext
Raw Normal View History

2017-05-22 14:27:25 +01:00
(:~
2017-07-18 10:04:25 +01:00
: create app-gen.js from vue files
2017-05-22 14:27:25 +01:00
:)
import module namespace html5="text.html5" at "html5parse.xqm";
import module namespace fw="quodatum:file.walker";
declare namespace c="http://www.w3.org/ns/xproc-step";
declare namespace Document="java:ch.digitalfondue.jfiveparse.Document";
declare namespace Element="java:ch.digitalfondue.jfiveparse.Element";
declare namespace Node="java:ch.digitalfondue.jfiveparse.Node";
2017-06-01 12:42:13 +01:00
2017-05-22 14:27:25 +01:00
declare namespace functx = "http://www.functx.com";
2017-07-05 23:05:34 +01:00
declare variable $PROJ:="C:/Users/andy/git/vue-poc/src/vue-poc/";
declare variable $FEATURES:="features/"=>file:resolve-path($PROJ);
declare variable $COMPONENTS:="components/"=>file:resolve-path($PROJ);
declare variable $CORE:="components/core.js"=>file:resolve-path($PROJ);
declare variable $FILTERS:="components/filters.js"=>file:resolve-path($PROJ);
declare variable $DEST:="static/app-gen.js"=>file:resolve-path($PROJ);
2017-05-22 14:27:25 +01:00
(:~
2017-06-01 12:42:13 +01:00
: generate javascript vue call from vue files in source folder and core.js
2017-05-22 14:27:25 +01:00
:)
2017-07-05 23:05:34 +01:00
declare function local:feature($doc,$isComp as xs:boolean)
2017-05-22 14:27:25 +01:00
{
2017-07-05 23:05:34 +01:00
let $p:=local:vue-parse($doc)
let $script:= $p?script=>substring-after("{")
return if(empty($p?id)) then
()
2017-07-12 11:38:53 +01:00
else if($isComp) then
``[Vue.component('`{$p?id}`',{template:` `{$p?template}` `,
`{$script}`
);
]``
else
2017-07-05 23:05:34 +01:00
``[const `{functx:capitalize-first($p?id)}`=Vue.extend({template:` `{$p?template}` `,
`{$script}`
);
]``
};
declare function local:vue-parse($doc)
as map(*)
{
let $tempNode:= html5:getElementFirstByTagName($doc,"template")
let $template:= Node:getInnerHTML($tempNode)
let $id := Element:getAttribute($tempNode,"id")=>trace("ID")
let $script:= html5:getElementFirstByTagName($doc,"script")
let $script:= Node:getInnerHTML($script)
return map{"id":$id,"template":$template,"script":$script}
2017-05-22 14:27:25 +01:00
};
declare function functx:capitalize-first
( $arg as xs:string? ) as xs:string?
{
concat(upper-case(substring($arg,1,1)), substring($arg,2))
};
2017-06-01 12:42:13 +01:00
2017-07-05 23:05:34 +01:00
let $files:= fw:directory-list($FEATURES,map{"include-filter":".*\.vue"})
//c:file/@name/resolve-uri(.,base-uri(.))
let $feats:=$files!(fetch:text(.)=>html5:doc()=>local:feature(false()))
let $files:= fw:directory-list($COMPONENTS,map{"include-filter":".*\.vue"})
2017-06-01 12:42:13 +01:00
//c:file/@name/resolve-uri(.,base-uri(.))
2017-07-05 23:05:34 +01:00
let $comps:=$files!(fetch:text(.)=>html5:doc()=>local:feature(true()))
2017-06-01 12:42:13 +01:00
let $comment:="// generated " || current-dateTime() || "

"
2017-06-21 18:09:52 +01:00
return file:write-text($DEST,string-join(($comment,
2017-07-12 11:38:53 +01:00
$comps,
2017-06-21 18:09:52 +01:00
fetch:text($FILTERS),
2017-07-05 23:05:34 +01:00
$feats,
2017-06-21 18:09:52 +01:00
fetch:text($CORE))))