2021-11-08 15:35:26 +00:00
#!/bin/bash
2024-05-23 09:42:14 +00:00
# SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
#
# SPDX-License-Identifier: AGPL-3.0-only
2024-04-10 16:47:27 +00:00
NO_CONVERSEJS_LOC = ""
if [ " $1 " = "no-loc" ] ; then
echo "We won't generate ConverseJS localization files!"
NO_CONVERSEJS_LOC = "1"
fi
2021-11-08 15:35:26 +00:00
set -euo pipefail
set -x
2024-01-16 11:27:44 +00:00
# Set CONVERSE_VERSION and CONVERSE_REPO to select which repo and tag/commit/branch use.
# Defaults values:
2024-07-11 15:53:50 +00:00
CONVERSE_VERSION = "v11.0.0"
2023-08-08 07:56:00 +00:00
CONVERSE_REPO = "https://github.com/conversejs/converse.js.git"
2024-01-16 11:27:44 +00:00
# You can eventually set CONVERSE_COMMIT to a specific commit ID, if you want to apply some patches.
2024-08-05 13:54:03 +00:00
# 2024-08-05: using Converse upstream (v11 WIP).
CONVERSE_COMMIT = "5017efb780973d704f237c478ba52b23d901e1bf"
2024-01-16 11:27:44 +00:00
2024-07-15 15:35:26 +00:00
# It is possible to use another repository, if we want some customization that are not upstream (yet):
# CONVERSE_VERSION="livechat"
2024-07-11 15:53:50 +00:00
# # CONVERSE_COMMIT="4402fcc3fc60f6c9334f86528c33a0b463371d12"
2024-07-30 14:30:38 +00:00
# CONVERSE_REPO="https://github.com/JohnXLivingston/converse.js"
# CONVERSE_COMMIT="xxxx"
2023-08-08 07:56:00 +00:00
2024-08-05 13:54:03 +00:00
# 2024-08-06: including fix waiting for merge:
CONVERSE_VERSION = "livechat_converse_11"
2024-08-06 13:50:40 +00:00
CONVERSE_COMMIT = "1625f9b6ee81fa9ebd8df5cba306bde478f1943b"
2024-08-06 15:32:37 +00:00
# 2024-08-06: including new getOccupantActionButtons hook (waiting for merge in Converse upstream)
2024-08-12 16:17:31 +00:00
CONVERSE_COMMIT = "5b35bd31c7e26c1f5396cd65eef69293d8b388c1"
2024-08-05 13:54:03 +00:00
2021-11-08 15:35:26 +00:00
rootdir = " $( pwd ) "
src_dir = " $rootdir /conversejs "
2023-08-10 02:41:36 +00:00
converse_src_dir = " $rootdir /vendor/conversejs- $CONVERSE_VERSION "
2024-01-16 11:27:44 +00:00
if [ -n " $CONVERSE_COMMIT " ] ; then
converse_src_dir = " $converse_src_dir - $CONVERSE_COMMIT "
fi
2023-08-08 07:56:00 +00:00
converse_build_dir = " $rootdir /build/conversejs "
2021-11-08 15:35:26 +00:00
converse_destination_dir = " $rootdir /dist/client/conversejs "
if [ [ ! -d $src_dir ] ] ; then
2021-11-08 19:15:53 +00:00
echo " $0 must be called from the plugin livechat root dir. "
2021-11-08 15:35:26 +00:00
exit 1
fi
if [ [ ! -d " $converse_src_dir " ] ] ; then
2024-01-16 11:27:44 +00:00
if [ -n " $CONVERSE_COMMIT " ] ; then
echo " Fetching ConverseJS commit $CONVERSE_COMMIT . "
mkdir -p $converse_src_dir
cd $converse_src_dir
git init
git remote add origin $CONVERSE_REPO
git fetch --depth 1 origin $CONVERSE_COMMIT
git checkout $CONVERSE_COMMIT
2024-01-16 16:38:41 +00:00
# In order to be able to test if $converse_build_dir is up to date, we add the commit id in a file:
2024-01-16 11:27:44 +00:00
cd -
2024-01-16 16:38:41 +00:00
echo " $CONVERSE_COMMIT " > " $converse_src_dir /current "
2024-01-16 11:27:44 +00:00
else
echo "Shallow cloning ConverseJS."
git clone --depth= 1 --branch $CONVERSE_VERSION $CONVERSE_REPO $converse_src_dir
2024-01-16 16:38:41 +00:00
echo " $CONVERSE_VERSION " > " $converse_src_dir /current "
2024-01-16 11:27:44 +00:00
fi
2023-08-08 07:56:00 +00:00
rm -rf " $converse_build_dir "
2021-11-08 15:35:26 +00:00
fi
2024-01-16 16:38:41 +00:00
if cmp -s " $converse_src_dir /package.json " " $converse_build_dir /package.json " && cmp -s " $converse_src_dir /current " " $converse_build_dir /current " ; then
2021-11-08 19:15:53 +00:00
echo "ConverseJS files are already up to date in the build directory."
2021-11-08 15:35:26 +00:00
else
2021-11-08 19:15:53 +00:00
echo "ConverseJS files are not up to date in the build directory, copying them..."
2021-11-08 15:35:26 +00:00
rm -rf " $converse_build_dir "
mkdir -p " $converse_build_dir "
cp -R $converse_src_dir /* " $converse_build_dir "
fi
2021-11-08 19:15:53 +00:00
echo "Removing existing custom files..."
2021-11-08 18:06:53 +00:00
rm -rf " $converse_build_dir /custom/ "
2021-11-08 19:15:53 +00:00
echo "Adding the custom files..."
2021-11-08 18:06:53 +00:00
cp -r " $src_dir /custom/ " " $converse_build_dir /custom/ "
mv " $converse_build_dir /custom/webpack.livechat.js " " $converse_build_dir / "
2024-04-29 14:46:21 +00:00
# overriding original index.js file:
mv " $converse_build_dir /custom/index.js " " $converse_build_dir /src/ "
2024-04-08 17:02:56 +00:00
cp " $src_dir /loc.keys.js " " $converse_build_dir / "
2021-11-08 18:06:53 +00:00
2024-02-22 11:43:41 +00:00
echo "Patching i18n files to add custom labels..."
/bin/env node conversejs/build-conversejs-patch-i18n.js
2021-11-08 18:06:53 +00:00
if [ [ ! -d " $converse_build_dir /node_modules " ] ] ; then
2021-11-08 19:15:53 +00:00
echo "Missing node_modules directory, seems we have to call the makefile..."
2021-11-08 18:06:53 +00:00
cd " $converse_build_dir "
2023-08-22 10:04:29 +00:00
make node_modules src/*
2021-11-08 18:06:53 +00:00
cd $rootdir
fi
2021-11-08 19:15:53 +00:00
echo "Building ConverseJS..."
2021-11-08 15:35:26 +00:00
cd " $converse_build_dir "
2024-02-15 14:12:58 +00:00
2024-04-10 16:47:27 +00:00
if [ " $NO_CONVERSEJS_LOC " = "1" ] ; then
echo "Building without ConverseJS localization files!"
# shortcut to build more quickly for dev purpose (see npm run build:converjs-no-loc)
npx webpack --config webpack.livechat.js
else
# Note: following lines are from the ConverseJS Makefile (see "make dist" code), where we just replace the "npm run build" with our webpack.livechat.js.
# Ideally this should just be `npm run build`.
# The additional steps are necessary to properly generate JSON chunk files
# from the .po files. The nodeps config uses preset-env with IE11.
# Somehow this is necessary.
npm run nodeps
TMPD = $( mktemp -d)
mv dist/locales $TMPD && npx webpack --config webpack.livechat.js && mv $TMPD /locales/*-po.js dist/locales/ && rm -rf $TMPD
rm dist/converse-no-dependencies.js dist/converse-no-dependencies.js.map
fi
2024-02-15 14:12:58 +00:00
2021-11-08 15:35:26 +00:00
cd $rootdir
2021-11-08 19:15:53 +00:00
echo "Copying ConverseJS dist files..."
2021-11-08 15:35:26 +00:00
mkdir -p " $converse_destination_dir " && cp -r $converse_build_dir /dist/* " $converse_destination_dir / "
2021-11-08 19:15:53 +00:00
echo "ConverseJS OK."
2021-11-08 15:35:26 +00:00
exit 0