-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildx.xqm
69 lines (65 loc) · 1.7 KB
/
buildx.xqm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
(:~
: build utils
: @author Andy Bunce
: @copyright Quodatum Ltd
: @licence Apache 2
: @since may-2015
:)
module namespace build = 'quodatum.utils.build';
declare default function namespace 'quodatum.utils.build';
declare namespace pkg="http://expath.org/ns/pkg";
(:~
: file paths below $src
: $src typically from resolve-uri
:)
declare function files($src as xs:string) as xs:string*
{
fn:filter(file:list($src,fn:true()),
function ($f){file:is-file($src || $f)}
)
!fn:translate(.,"\","/")
};
(:~
: read data with uri from items in $paths using $fetch
: then save using $write
:)
declare function transform($paths as xs:string*,
$fetch,
$write )
{
for $path in $paths
let $data:=$fetch($path)
return $write($path,$data)
};
(:~
: read data with uri from items in $paths using $fetch
: then apply $merge to paths and data matching sequences
:)
declare function merge($paths as xs:string*,
$fetch ,
$merge)
{
let $data:= $paths!$fetch(.)
return $merge($paths,$data)
};
declare function xar($package as element(pkg:package)) as xs:string
{
fn:concat($package/@abbrev , "-" ,$package/@version, ".xar")
};
(:
: update package.xml located at $cxan to ensure has entry for package $pkg
:)
declare function publish($pkg as element(pkg:package),$cxan)
{
copy $c:=fn:doc($cxan)
modify(
let $pack:=$c/repo/pkg[name=$pkg/@name]
let $hit:= $pack/version[@num=$pkg/@version]
let $new:=<version num="{$pkg/@version}">
<!-- generated: {fn:current-dateTime()} -->
</version>
return if($hit)then ()
else insert node $new into $pack
)
return fn:put($c,$cxan)
};