File element.spec of Package element

#
# spec file for package element
#
# Copyright (c) 2020 Samu Voutilainen
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# TODO: matrix-js-sdk and such node modules should be their separate packages, not inside node_modules.tar.xz.

# I’m not sure if I should prepend the name with nodejs... This is standalone web app, which just happens to use nodejs as a tool.
Name:           element
%define dir_name element-web
Version:        v1.11.59
Release:        0
Summary:        Web client for Matrix network
License:        GPL-2.0-or-later
Group:          Productivity/Networking/System
URL:            https://element.io
Source0:        %{dir_name}.tar.gz
#Source1:        node_modules.tar.xz
Source2:        prepare-release.rb
Source3:        npm-packages-offline-cache.tar
Source4:        yarnrc
#Patch1:         bundled_jitsi.patch
Provides:       nodejs-element
# Required to have nodejs macros, e.g. nodejs_install.
BuildRequires:  nodejs-packaging
BuildRequires:  nodejs >= 18.0
BuildRequires:  ruby
BuildRequires:  yarn
BuildRequires:  fdupes
# TODO: probably should be made with a patch instead, but this is to have a version
BuildRequires:  git
BuildRoot:      %{_tmppath}/%{dir_name}-%{version}-build
BuildArch:      noarch
%{?nodejs_requires}

%description
All-in-one secure chat app for teams, friends and organisations. Keeps conversations in your control, safe from data-mining and ads. Talk to everyone through the open global Matrix network, protected by proper end-to-end encryption.

%prep
%setup -q -n %{dir_name}

#tar xf %%{S:1} -C %%{_builddir}/%%{dir_name}/

tar xf %{S:3} -C %{_builddir}/%{dir_name}/
cp %{S:4} %{_builddir}/%{dir_name}/.yarnrc

#%%patch1 -p1

%build
# NOTE: --production-true can’t be used as some modules seems to be missing with it.
yarn install --offline

yarn dist

%install
install -d -m 0755 %{buildroot}/srv/www/

tar xf dist/element-unknown.tar.gz
mv element-unknown %{buildroot}/srv/www/element

# NOTE: My main motivation for building element myself was to be able to conveniently change
# og:image to something else. If someone else happens to use this build, there probably should be a
# script to do the magic. I do have a Ruby script that could be customized for this, if someone is interested.
cd %{buildroot}/srv/www/element
ruby %{S:2}
cd -

%fdupes %{buildroot}/srv/www/element

install -D -m 0644 config.sample.json %{buildroot}%{_docdir}/config.sample.json
install -D -m 0644 config.sample.json %{buildroot}%{_sysconfdir}/%{name}/config.json

install -d -m 0755 %{buildroot}%{_sysconfdir}/%{name}

ln -s %{_sysconfdir}/%{name}/config.json %{buildroot}/srv/www/element/config.json

%files
%defattr(-,root,root)

/srv/www/element

%dir %{_sysconfdir}/%{name}
%config(noreplace) %{_sysconfdir}/%{name}/config.json

%doc %{_docdir}/config.sample.json

%changelog