diff --git a/README.md b/README.md index 760be93426..5dcbd1984e 100644 --- a/README.md +++ b/README.md @@ -74,3 +74,42 @@ To update CKEditor in liferay-portal: 3. Re-deploy the module with `gradlew clean deploy`. An example of this can be seen in [this](https://github.com/liferay/liferay-portal/commit/5b2ae3732d96f7f0dec6d35cb4de99f9d389c248) commit (look at the [`package.json`](https://github.com/liferay/liferay-portal/blob/5b2ae3732d96f7f0dec6d35cb4de99f9d389c248/modules/apps/frontend-editor/frontend-editor-ckeditor-web/package.json) file) + +## Patching + +- Make sure you're update to date with the [superproject](https://github.com/liferay/liferay-ckeditor) repository: + + ```sh + git pull origin master + ``` + +- Set up everything to start working on a patch: + + ```sh + sh ck.sh setup + ``` + +- Work on your changes: + + `cd` into the `ckeditor-dev/` submodule and prepare your desired changes on the `liferay` branch. + + This could be `cherry-pick`ing a previously created commit or manually editing a file, so this can't be automated. + +- Create your commit, add your changes and write a good commit message. + +- Navigate back to the superproject's root directory and create the patch: + + ```sh + cd .. + sh ck.sh patch + ``` + +- Create a build of CKEditor containing the patches: + + From the root of the superproject's directory, run + + ```sh + sh ck.sh build + ``` + +- Don't forget to add the changes and commit diff --git a/ck.sh b/ck.sh new file mode 100755 index 0000000000..7f1f527698 --- /dev/null +++ b/ck.sh @@ -0,0 +1,220 @@ +#!/bin/sh + +set -e + +function init() { + # Make sure submodule is registered and up-to-date. + git submodule update --init + + # Fetch remote changes. + cd ckeditor-dev + + # Make sure our working copy is clean. + git reset --hard HEAD --quiet + git clean -fdx +} + +function usage() { + echo "Usage: ck.sh COMMAND" + echo + echo " Where COMMAND is either:" + echo + echo " ๐Ÿ”ง setup: Setup everything to start working on a patch" + echo " ๐Ÿ’‰ patch: Generate patches " + echo " ๐Ÿ”ฅ build: Generate a patched version of CKEditor" + echo + echo +} + +# Check arguments +if [ $# -ne 1 ]; then + usage + exit 1 +fi + +COMMAND=$1 + +case "$COMMAND" in + build) + echo + echo "*---------------------------------------------------------*" + echo "| โš ๏ธ WARNING |" + echo "*---------------------------------------------------------*" + echo + + echo "This will generate a patched version of CKEditor" + read -p "Are you sure you want to continue? [y/n]" yn + + case $yn in + [Yy]*) + init + git checkout --detach HEAD --quiet + git branch -f liferay HEAD + git checkout liferay + + echo + echo "Checking for existing patches" + echo + + if ! ls ../patches/*; then + echo "There doesn't seem to be any patch" + fi + + echo + echo "Applying patches from \"patches/\" directory." + echo + + if ! git am ../patches/*; then + echo + echo "โš ๏ธ There was a problem applying patches:" + echo + echo "To retry manually and fix:" + echo + echo " cd ckeditor-dev" + echo " git am --abort" + echo " git am ../patches/*" + echo + echo "Once you are happy with the result, run `sh ck.sh patch` to update the contents of \"patches/\"." + echo + exit 1 + fi + + if [ -n "$DEBUG" ]; then + dev/builder/build.sh --build-config ../../../build-config.js \ + --leave-css-unminified --leave-js-unminified + else + dev/builder/build.sh --build-config ../../../build-config.js + fi + + # Remove old build files. + rm -rf ../ckeditor/* + + # Replace with new build files. + cp -r dev/builder/release/ckeditor/* ../ckeditor/ + + echo + echo "*---------------------------------------------------------*" + echo "| โœ… DONE |" + echo "*---------------------------------------------------------*" + echo + echo "Don't forget to commit the result!" + echo + ;; + *) + echo + echo "Aborting." + echo + esac + ;; + patch) + init + # Navigate back to superproject + cd .. + + # Save SHA1 for later + sha1=`git submodule | grep ckeditor-dev | awk '{print $1}' | sed -e s/[^0-9a-f]//` + + cd ckeditor-dev + + # Check for the existence of the liferay branch in the submodule + if ! git rev-parse --verify liferay &>/dev/null; then + echo + echo "*---------------------------------------------------------*" + echo "| โŒ ERROR |" + echo "*---------------------------------------------------------*" + echo + echo "It seems that there's no `liferay` branch in the `ckeditor-dev` submodule." + echo + echo "Please run `sh ck.sh setup` to set up everything correctly." + echo + + exit 1 + fi + + git checkout liferay --quiet + + # Check for existing patches + patches=$(find ../patches -name *.patch -type f) + + if [[ $(echo "$patches" | wc -l) -ne 0 ]]; then + echo + echo "*---------------------------------------------------------*" + echo "| โš ๏ธ WARNING |" + echo "*---------------------------------------------------------*" + echo + echo + echo "This will replace any existing patches..." + echo + echo "$patches" + echo + + # Prompt the user to confirm he wants to delete existing patches + read -p "Are you sure you want to continue [y/n]? " yn + case $yn in + [Yy]*) + echo + echo "Removing existing patches." + echo + + mkdir -p ../patches + rm -rf ../patches/* + ;; + *) + echo + echo "Aborting." + echo + exit 1 + ;; + esac + else + echo + echo "No patches found." + echo + fi + + echo "Generating patches." + echo + + git format-patch $sha1 -o ../patches + + echo + echo "*---------------------------------------------------------*" + echo "| โœ… DONE |" + echo "*---------------------------------------------------------*" + echo + echo + echo "You can now build CKEditor with your patches." + echo + echo + echo "Here are the steps to follow:" + echo + echo "1. Run `sh ./ck.sh build` to generate a patched version." + echo + ;; + setup) + init + git checkout --detach HEAD + git branch -f liferay HEAD + git checkout liferay + + echo + echo "*---------------------------------------------------------*" + echo "| โœ… DONE |" + echo "*---------------------------------------------------------*" + echo + echo + echo "You can now start working on your patch(es)." + echo + echo + echo "Here are the steps to follow:" + echo + echo "1. Navigate to the ckeditor-dev submodule directory (`cd ckeditor-dev`)" + echo "2.ย Work on your changes" + echo "3. Commit your changes" + echo "4. Run `sh ck.sh patch` to generate the patches" + echo + ;; + *) + usage + ;; +esac