-
Notifications
You must be signed in to change notification settings - Fork 49
/
ck.sh
executable file
·421 lines (345 loc) · 9.14 KB
/
ck.sh
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
#!/bin/bash
set -e
function usage() {
echo
echo "Usage: ck.sh COMMAND [OPTIONS]"
echo
echo " Where COMMAND is either:"
echo
echo " 🔧 setup: prepare your local clone for patching, building or updating"
echo " 💉 patch: recreate \"patches/\" contents based on current \"liferay\" branch"
echo " 🔥 build: build CKEditor, writing output to the \"ckeditor/\" directory"
echo " 🌶 update: update the CKEditor base version"
echo " 🎭 createskin: create a new custom skin based on moono-lisa"
echo
echo
}
function downloadPlugin() {
local NAME=$1
local VERSION=$2
local OUTPUT
OUTPUT=$(mktemp)
curl \
"https://ckeditor.com/cke4/sites/default/files/${NAME}/releases/${NAME}_${VERSION}.zip" \
-o "$OUTPUT"
rm -rf "plugins/$NAME"
unzip "$OUTPUT" -d plugins
}
# Check arguments
if [ $# -ne 1 ]; then
usage
exit 1
fi
trap "echo \"\n\nAborting.\n\"; exit" SIGHUP SIGINT SIGTERM
COMMAND=$1
case "$COMMAND" in
build)
echo
echo "⚠️ WARNING"
echo
echo "This will generate a patched version of CKEditor"
if [ -z "$CI" ]; then
read -r -p "Are you sure you want to continue? [y/n] " yn
else
yn=y
fi
case $yn in
[Yy]*)
# Copy custom skin to ckeditor-dev
cp -r skins/moono-lexicon ckeditor-dev/skins/moono-lexicon
# Copy custom plugins to ckeditor-dev
cp -r plugins ckeditor-dev
# Copy skin files for plugins
pluginsWithSkins=$(find ckeditor-dev/plugins -maxdepth 2 -mindepth 2 -type d -name skins)
for plugin in $pluginsWithSkins; do
pluginDir=$(dirname "$plugin")
pluginName=$(basename "$pluginDir")
pluginSkinPath="skins/moono-lexicon/plugins/$pluginName/skins/moono-lexicon"
if [[ -d "$pluginSkinPath" ]]; then
cp -r "$pluginSkinPath" "$pluginDir/skins"
fi
done
cd ckeditor-dev
# Run every plugin build script
pluginsWithDeps=$(find plugins -maxdepth 2 -mindepth 2 -type f -name deps.json)
for pluginDepsFile in $pluginsWithDeps ; do
pluginDir=$(dirname "$pluginDepsFile")
node ../support/copyPluginDependencies.js $pluginDir
done
# Generate SVG icons CSS Classes
node ../support/iconsClassesGenerator.js skins/moono-lexicon/icons/icons.json skins/moono-lexicon/icons.css
if [ -n "$DEBUG" ]; then
dev/builder/build.sh --build-config ../../../support/build-config.js \
--leave-css-unminified --leave-js-unminified
else
dev/builder/build.sh --build-config ../../../support/build-config.js
fi
# Remove custom skin from ckeditor-dev
rm -rf skins/moono-lexicon
# Remove old build files.
rm -rf ../ckeditor/*
# Replace with new build files.
cp -r dev/builder/release/ckeditor/* ../ckeditor/
cd ..
if [ -n "$DEBUG" ]; then
echo
echo "✅ DONE"
echo
echo "⚠️ WARNING"
echo
echo "Updated build artifacts have NOT been committed, because this is a DEBUG build."
echo
else
if [ -z "$CI" ]; then
git add ckeditor
git commit -m 'chore: update ckeditor build artifacts' \
-m 'This commit autogenerated with "./ck.sh".'
fi
echo
echo "✅ DONE"
echo
if [ -z "$CI" ]; then
echo "Updated build artifacts have been committed."
echo
echo "Please review them with \`git show\`"
echo
fi
fi
;;
*)
echo
echo "Aborting."
echo
exit
esac
;;
createskin)
read -r -p "What is the name of the new skin? " skinName
baseSkin="moono-lisa"
# Create folder for the new skin
mkdir skins/"$skinName"
# Create a copy of the selected skin.
cp -r ckeditor-dev/skins/"$baseSkin"/* skins/"$skinName"/
# Replace name of the base skin with new one
sed -i -e "s/$baseSkin/$skinName/g" skins/"$skinName"/skin.js
sed -i -e "s/$baseSkin/$skinName/g" skins/"$skinName"/dialog.css
sed -i -e "s/$baseSkin/$skinName/g" skins/"$skinName"/readme.md
sed -i -e "s/$baseSkin/$skinName/g" skins/"$skinName"/dev/locations.json
git add skins/"$skinName"
;;
patch)
# Make sure submodule is registered and up-to-date.
git submodule update --init
cd ckeditor-dev
if ! git rev-parse --verify liferay &>/dev/null; then
echo
echo "❌ ERROR"
echo
echo "It seems that there's no 'liferay' branch in the 'ckeditor-dev' submodule."
echo
echo "Please run './ck.sh setup' to set up everything correctly."
echo
exit 1
fi
cd ..
# Save SHA1 for later
sha1=$(git submodule status --cached -- ckeditor-dev | awk '{print $1}' | sed -e s/[^0-9a-f]//)
cd ckeditor-dev
git checkout liferay --quiet
# Check for existing patches
if ! ls ../patches/*.patch &>/dev/null ; then
echo
echo "No patches found."
echo
else
echo
echo "⚠️ WARNING"
echo
echo "This will reset the \"patches\" directory and replace these patches:"
echo
find ../patches -name '*.patch'
echo
echo "with patches corresponding to these commits:"
echo
git log --oneline "$sha1"..HEAD
echo
# Prompt the user to confirm he wants to delete existing patches
read -r -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
;;
esac
fi
echo "Generating patches."
echo
git format-patch --diff-algorithm=histogram --no-numbered --no-signature "$sha1" -o ../patches
echo
echo "✅ DONE"
echo
echo "You can now build CKEditor with your patches."
echo
echo "Here are the steps to follow:"
echo
echo "1. Run './ck.sh build' to generate a patched version."
echo
;;
setup)
echo
echo "⚠️ WARNING"
echo
echo "❗ This will reset any changes you currently have in the 'ckeditor-dev' submodule"
echo
echo
read -r -p "Are you sure you want to continue? [y/n] " yn
case $yn in
[Yy]*)
yarn
# 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
git checkout --detach HEAD --quiet
git branch -f liferay HEAD
git checkout liferay --quiet
VERSION=$(git describe --tags --abbrev=0)
echo
echo "Downloading plugins for v$VERSION"
echo
downloadPlugin scayt "$VERSION"
downloadPlugin wsc "$VERSION"
echo
echo "Checking for existing patches"
echo
if ! ls ../patches/*.patch; then
echo "There doesn't seem to be any patch"
else
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 './ck.sh patch' to update the contents of \"patches/\"."
echo
exit 1
fi
fi
echo
echo "✅ DONE"
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. Return to the repository root (\`cd ..\`)"
echo "5. Run './ck.sh patch' to generate updated patches"
echo
;;
*)
echo
echo "Aborting."
echo
exit
;;
esac
;;
update)
git submodule update --init
cd ckeditor-dev
git fetch
echo
echo "Listing current tags: "
tags=$(git tag -l --sort=creatordate | grep -v ee- | grep -v liferay | \
sort -t. -k 1,1nr -k 2,2nr -k 3,3nr -k 4,4nr | head -6)
echo "$tags"
echo
read -r -p "Please enter the tag you want to update to: " tag
if ! git describe --exact-match --tags "$tag" &>/dev/null ; then
echo
echo "❌ ERROR"
echo
echo "Sorry, the \`$tag\` tag does not exist."
echo
exit 1
fi
echo
echo "⚠️ WARNING"
echo
echo "This will update the \`ckeditor-dev\` submodule to point to the $tag tag"
echo
read -r -p "Are you sure you want to continue? [y/n] " yn
case $yn in
[Yy]*)
git reset --hard HEAD
git clean -fdx
git checkout "$tag"
commitmsg=$(git log -1 --pretty=format:"chore: update ckeditor-dev to $tag%n%n%h (tag: $tag) %s")
cd ..
git add -f ckeditor-dev
git commit -m "$commitmsg"
echo
echo "Downloading plugins for v$tag"
echo
downloadPlugin scayt "$tag"
downloadPlugin wsc "$tag"
echo "Do you want to rebase the updated ckeditor submodule with the liferay branch?"
echo
echo "⚠️ WARNING"
echo
echo "This might cause conflicts, which will have to be solved manually"
echo
read -r -p "Are you sure you want to continue? [y/n] " yn
case $yn in
[Yy]*)
cd ckeditor-dev
git rebase HEAD liferay
echo
echo "✅ DONE"
echo
;;
*)
echo
echo "Aborting."
echo
exit
;;
esac
;;
*)
echo
echo "Aborting."
echo
exit
;;
esac
;;
*)
usage
;;
esac