summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: ff7ab65864e5f733fc0ab08d53ee205e74c7a2a5 (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
69
70
71
72
73
74
75
# Maintainer: zoorat <zoorat [at] protonmail [dot] com>

_npmname=graphite-cli
pkgname=$_npmname
pkgver=1.4.4
pkgrel=1

pkgdesc="Graphite helps you create smaller pull requests, stay unblocked, and ship faster."
arch=(any)
url="https://graphite.dev/"
license=("None")

depends=("nodejs")
makedepends=("npm" "jq")
# provides=("$_npmname")
# conflicts=("$_npmname")

changelog="changelog.md"

source=("https://registry.npmjs.org/@withgraphite/${_npmname}/-/${_npmname}-${pkgver}.tgz")
noextract=("${_npmname}-${pkgver}.tgz")
b2sums=('a29d0553bce3f1744ed10bcad11c1e5012d7d62263dae086d34d3215b32febc37ebf0b7804f80c6a02aebee597c63f36e5c6ba0c4ccec8b58605cedec53505e9')

# Document: https://wiki.archlinux.org/title/Node.js_package_guidelines
package() {
	# Install using Using npm
	npm install -s -g \
		--cache "${srcdir}/npm-cache" \
		--prefix "${pkgdir}/usr" \
		"${srcdir}/${_npmname}-${pkgver}.tgz"

	# Fix ownership of ALL FILES
	find "${pkgdir}/usr" -type d -exec chmod 755 {} +
	chown -R root:root "${pkgdir}"

	# Remove references to $pkgdir
	find "$pkgdir" -name package.json -print0 | xargs -r -0 sed -i '/_where/d'

	local tmppackage="$(mktemp)"
	local pkgjson="$pkgdir/usr/lib/node_modules/@withgraphite/$_npmname/package.json"
	jq '.|=with_entries(select(.key|test("_.+")|not))' "$pkgjson" >"$tmppackage"
	mv "$tmppackage" "$pkgjson"
	chmod 644 "$pkgjson"

	find "$pkgdir" -type f -name package.json | while read pkgjson; do
		local tmppackage="$(mktemp)"
		jq 'del(.man)' "$pkgjson" >"$tmppackage"
		mv "$tmppackage" "$pkgjson"
		chmod 644 "$pkgjson"
	done

	#
	# taken from https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=graphite-cli-git

	# 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 $pkgdir/usr/bin/graphite completion >"$srcdir/pre-bash-graphite-completions"
	SHELL=zsh node $pkgdir/usr/bin/graphite 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"

	install -Dm 644 "$srcdir/bash-graphite-completions" "$pkgdir/usr/share/bash-completion/completions/graphite"
	install -Dm 644 "$srcdir/bash-gt-completions" "$pkgdir/usr/share/bash-completion/completions/gt"
	install -Dm 644 "$srcdir/zsh-graphite-completions" "$pkgdir/usr/share/zsh/site-functions/_graphite"
	install -Dm 644 "$srcdir/zsh-gt-completions" "$pkgdir/usr/share/zsh/site-functions/_gt"
	install -Dm 644 "$pkgdir/usr/lib/node_modules/@withgraphite/graphite-cli/gt.fish" "$pkgdir/usr/share/fish/completions/gt.fish"
}