pages 2.51 KB
Newer Older
1
#!/bin/bash
2
make -C curly/doc || exit
3
# make doc || exit
Marc Coiffier's avatar
Marc Coiffier committed
4
5
6
7
8
9
10
function has_cmd() { which "$1" 2>/dev/null; }

if has_cmd sass; then scss=sass
elif has_cmd sassc; then scss=sassc
elif has_cmd scss; then scss=scss
fi

11
mkdir -p public/doc && {
12
13
14
15
16
17
18
19
20
21
22
    packages=( )
    ispackage=
    while read line; do
        case "$line" in
            packages:*) ispackage=true;;
            -*) if [ "$ispackage" = true ]; then
                    packages+=( ${line#-} )
                fi;;
            *) ispackage=;;
        esac
    done < stack.yaml
23
24
25
26
27

    executables=( )
    for pkg in "${packages[@]}"; do
        executables+=( $(sed -rn 's/^executable\s+(\S+).*$/\1/p' "$pkg/$pkg.cabal") )
    done
28
    stack_path="$(stack path --local-install-root)"
Marc Coiffier's avatar
Marc Coiffier committed
29
    
30
    cp "$stack_path"/doc/ocean.css public/doc
31
32
33
34
    {
        cat <<EOF
<!DOCTYPE html>
<html>
Marc Coiffier's avatar
Marc Coiffier committed
35
36
37
  <head>
    <link rel="stylesheet" href="ocean.css" type="text/css" />
  </head>
38
  <body>
Marc Coiffier's avatar
Marc Coiffier committed
39
40
    <div id="package-header">
      <ul class="links">
Marc Coiffier's avatar
Marc Coiffier committed
41
        <li><a href="https://git.curly-lang.org/marc/curly">Source repository</a></li>
42
	<li><a href="../index.html">Back to the main page</a></li>
Marc Coiffier's avatar
Marc Coiffier committed
43
44
45
46
47
48
      </ul>
      <div class="caption">Curly packages</div></div>
    <div id="content">
      <h1>Curly packages</h1>
      <p>Here is a list of all local packages in the Curly repositories</p>
      <ul>
49
50
EOF
        for pkg in "${packages[@]}"; do
51
            fullpkg=( "$stack_path"/doc/$pkg-[0-9]* )
52
53
            fullpkg=( ${fullpkg[@]: -1:1} )
            fullpkg="${fullpkg##*/}"
54
55
            cp -r "$stack_path"/doc/$fullpkg public/doc
            if [ -e public/doc/$fullpkg/index.html ]; then
56
57
                printf '<li><a href="%s/index.html">%s</a></li>\n' "$fullpkg" "$pkg"
            fi
58
        done
59
        find public/doc -name src | xargs rm -r
60
        cat <<EOF
Marc Coiffier's avatar
Marc Coiffier committed
61
      </ul>
62
      <h2>Packages</h2>
63
64
      <ul>
EOF
65
        mkdir -p public/pkg
66
        for exe in "${executables[@]}"; do
67
68
	    version="$(sed -n 's/^version:\s*//p' "$exe/$exe.cabal")"
	    full="$exe-$version"
69
	    shopt -s nullglob
70
71
72
73
	    (
	    	tmp="$(mktemp -d)"
	    	mkdir -p "$tmp/$full"
	    	cd "$stack_path"
74
	    	cp -r bin/$exe share/*/$full/* "$tmp/$full"
75
76
	    	tar -C "$tmp" -c .
	    	rm -r "$tmp"
Marc Coiffier's avatar
Marc Coiffier committed
77
78
	    ) | xz > public/pkg/$full.tar.xz
	    ln -fs $full.tar.xz public/pkg/$exe.tar.xz
79
            printf '<li><a href="pkg/%s.tar.xz">%s.tar.xz</a></li>\n' "$exe" "$full"
80
81
82
        done
        cat <<EOF
      </ul>
Marc Coiffier's avatar
Marc Coiffier committed
83
    </div>
84
85
86
  </body>
</html>
EOF
87
    } > public/doc/custom-index.html
88

89
90
    mkdir -p public
    tar -xvzf curly/doc/bundle.tar.gz -C public
91
}