summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 09d2ba639f7a3c4b8ec6229721f2ece825029c41 (plain)
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
#
# Maintainer: Rosetta Roberts <rosettafroberts at gmail>
# 

pkgname=graphite-cli-git
pkgver=0.19.2.r0.9df94d9d
pkgrel=3
pkgdesc="CLI that makes creating stacked git changes fast & intuitive"
url=https://graphite.dev/
license=('AGPL3')
arch=('any')
depends=('nodejs' 'git')
makedepends=('npm' 'yarn' 'findutils')
provides=('graphite-cli')
conflicts=('graphite-cli')
source=('git+https://github.com/withgraphite/graphite-cli' 'graphite-cli.patch')
md5sums=('SKIP'
         '2ac3a50dfce2a35dba19f355b4a308f8')

_srcname="graphite-cli"

prepare() {
    cd "$srcdir/$_srcname"
    patch --forward --strip=1 --input="$srcdir/graphite-cli.patch"
}

pkgver() {
    cd "$srcdir/$_srcname"
    VERSION=`node -p "require('./package.json').version"`
    echo "$VERSION".r`git rev-list --count "v$VERSION^.."`.`git rev-parse --short HEAD`
}

build() {
    cd "$srcdir/$_srcname"
    export YARN_CACHE_FOLDER="$srcdir/yarn-cache"
    yarn install --immutable
    yarn run build
    rm -r dist/scripts
    rm -r dist/test
    find dist -type f \( -name '*.map' -o -name '*.d.ts' \) -delete

    # graphite uses the values in the SHELL and ZSH_NAME environmental variables to detect which shell it is running within
    # when generating completions
    SHELL=bash node ./dist/src/index.js completion > "$srcdir/pre-bash-graphite-completions"
    SHELL=zsh node ./dist/src/index.js completion > "$srcdir/pre-zsh-graphite-completions"
    
    # make the completion script suitable to be a loadable function
    sed 's/compdef _index.js_yargs_completions index.js/_index.js_yargs_completions/' -i "$srcdir/pre-zsh-graphite-completions"

    # make it so autocompletion works for both graphite and gt on both zsh and bash
    
    sed 's/\(.\/dist\/src\/\)\{0,1\}index.js/graphite/g' "$srcdir/pre-bash-graphite-completions" > "$srcdir/bash-graphite-completions"
    sed 's/\(.\/dist\/src\/\)\{0,1\}index.js/gt/g' "$srcdir/pre-bash-graphite-completions" > "$srcdir/bash-gt-completions"
    sed 's/\(.\/dist\/src\/\)\{0,1\}index.js/graphite/g' "$srcdir/pre-zsh-graphite-completions" > "$srcdir/zsh-graphite-completions"
    sed 's/\(.\/dist\/src\/\)\{0,1\}index.js/gt/g' "$srcdir/pre-zsh-graphite-completions" > "$srcdir/zsh-gt-completions"
    
    yarn pack --filename "../graphite-cli.tgz"
}

package() {
    # npm is a lot better than yarn at installing global packages in a way that is friendly to packages.
    npm install -g --no-audit --prefix "$pkgdir/usr" "$srcdir/graphite-cli.tgz"
    install -D --mode=u=rw,go=r "$srcdir/zsh-graphite-completions" "$pkgdir/usr/share/zsh/site-functions/_graphite"
    install -D --mode=u=rw,go=r "$srcdir/zsh-gt-completions" "$pkgdir/usr/share/zsh/site-functions/_gt"
    install -D --mode=u=rw,go=r "$srcdir/bash-graphite-completions" "$pkgdir/usr/share/bash-completion/completions/graphite"
    install -D --mode=u=rw,go=r "$srcdir/bash-gt-completions" "$pkgdir/usr/share/bash-completion/completions/gt"
    chown -R root:root "$pkgdir"
}