summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: efc964826f89ea8732860e77ff7ebbdea706e60e (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# Maintainer: BrLi <brli at chakralinux dot org>
# Maintainer: Caleb Maclennan <caleb@alerque.com>

pkgname=zettlr
pkgver=1.8.8
pkgrel=1
pkgdesc="A markdown editor for writing academic texts and taking notes"
arch=('x86_64')
url='https://www.zettlr.com'
license=('GPL' 'custom') # Noted that the icon and name are copyrighted
depends=(electron)
makedepends=(pandoc git yarn)
optdepends=('pandoc: For exporting to various format'
            'texlive-bin: For Latex support'
            'ttf-lato: Display output in a more comfortable way')
_csl_locale_commit=ecb8e70233e9a68e8b1dda4586061be8f8611a38 # Dec 12, 2020
_csl_style_commit=a7899732910f5e69aae7799bf4e61505716c211b
options=(!strip)
install=install
source=("$pkgname-$pkgver.tar.gz::https://github.com/Zettlr/Zettlr/archive/v$pkgver.tar.gz"
        # citation style
        "locales-$pkgrel-$pkgver.zip::https://github.com/citation-style-language/locales/archive/$_csl_locale_commit.zip"
        "chicago-author-date-$pkgver-$pkgrel.csl::https://github.com/citation-style-language/styles/raw/$_csl_style_commit/chicago-author-date.csl")
sha256sums=('cce11cca98358dbe48a7f42bafaa789dba77add711b9e37f155ee8c956085938'
            '24503a6cd5b3651a7003353811ae82d3ed707ec8ff932d341668c2ad377434b6'
            '2b7cd6c1c9be4add8c660fb9c6ca54f1b6c3c4f49d6ed9fa39c9f9b10fcca6f4')

prepare() {
    cd "Zettlr-$pkgver"

    # csl:refresh from package.json
    find "$srcdir/locales-$_csl_locale_commit" -name "*.xml" \
        -exec cp {} source/app/service-providers/assets/csl-locales/ \;
    cp "$srcdir/locales-$_csl_locale_commit/locales.json" source/app/service-providers/assets/csl-locales/
    cp "$srcdir/chicago-author-date-$pkgver-$pkgrel.csl" source/app/service-providers/assets/csl-styles/chicago-author-date.csl

    # fake Pandoc
    ln -sf /usr/bin/pandoc resources/pandoc
}

build() {
    local _electronVersion=$(electron --version | sed -e 's/^v//')
    cd "Zettlr-$pkgver"
    local NODE_ENV=''
    yarn install --cache-folder "$srcdir/cache" \
                 --link-folder "$srcdir/link" \
                 --ignore-scripts
    yarn reveal:build

    rm -rf node_modules/electron
    yarn add -D "electron@$_electronVersion" --cache-folder "$srcdir/cache" --link-folder "$srcdir/link"

    node node_modules/.bin/electron-forge package

    # Remove fonts
    cd "$srcdir/Zettlr-$pkgver/.webpack"
    find . -type d -name "fonts" -exec rm -rf {} +
}

# check() {
#     cd "${srcdir}/Zettlr-${pkgver}"
#     # Require electron module to test
#     yarn add --cache-folder "${srcdir}/cache" --link-folder "${srcdir}/link" electron
#     # The "test" function in package.json
#     node node_modules/mocha/bin/mocha
#     # The "test-gui" function in package.json, not useful in our case
#     node scripts/test-gui.js
#     # Clean up
#     yarn remove electron
#     rm yarn.lock
#     rm node_modules/.bin -rf
# }

package() {
    local _destdir=usr/lib/"$pkgname"
    install -dm755 "$pkgdir/$_destdir"

    cd "$srcdir/Zettlr-$pkgver"

    # Copy the generated electron project
    cp -r --no-preserve=ownership --preserve=mode ./.webpack "$pkgdir/$_destdir/"
    cp -r --no-preserve=ownership --preserve=mode ./resources "$pkgdir/$_destdir/"
    cp -r --no-preserve=ownership --preserve=mode ./package.json "$pkgdir/$_destdir/"

    # Install start script to /usr/bin
    install -Dm755 /dev/stdin "$pkgdir/usr/bin/$pkgname" <<END
#!/bin/sh
exec electron /${_destdir} "\$@"
END

    # install icons of various sizes to hi-color theme
    for px in 16 24 32 48 64 96 128 256 512; do
        install -Dm644 "$srcdir/Zettlr-$pkgver/resources/icons/png/${px}x$px.png" \
            "$pkgdir/usr/share/icons/hicolor/${px}x$px/apps/$pkgname.png"
    done

    # generate freedesktop entry files, aligned with description in package.json and forge.config.js
    install -Dm644 /dev/stdin "$pkgdir/usr/share/applications/$pkgname.desktop" <<END
[Desktop Entry]
Name=Zettlr
Comment=A powerful Markdown Editor with integrated tree view
Exec=${pkgname} %U
Terminal=false
Type=Application
Icon=${pkgname}
StartupWMClass=Zettlr
MimeType=text/markdown;
Categories=Office;
END

    # license
    install -Dm644 -t "$pkgdir/usr/share/licenses/$pkgname/" "$srcdir/Zettlr-$pkgver/LICENSE"
}