@@ -20,7 +20,11 @@ EDITOR_OUTPUT_DIR := $(CURDIR)/dist/static
2020EDITOR_REPO_DEFAULT := https://github.com/exelearning/exelearning.git
2121EDITOR_REF_DEFAULT := main
2222
23- # Fetch editor source code from remote repository (branch/tag, shallow clone)
23+ # Fetch editor source code from remote repository (branch/tag, shallow + sparse clone)
24+ # Optimizations:
25+ # - Reuses existing checkout if repo URL + ref haven't changed (.fetched-ref marker)
26+ # - sparse-checkout excludes test/, doc/, app/, packaging/ (~323 MB saved)
27+ # - --filter=blob:none avoids downloading blobs for excluded paths
2428fetch-editor-source :
2529 @set -e; \
2630 get_env () { \
@@ -35,34 +39,59 @@ fetch-editor-source:
3539 if [ -z " $$ REF" ]; then REF=" $$ {EXELEARNING_EDITOR_DEFAULT_BRANCH:-$$ (get_env EXELEARNING_EDITOR_DEFAULT_BRANCH)}" ; fi ; \
3640 if [ -z " $$ REF" ]; then REF=" $( EDITOR_REF_DEFAULT) " ; fi ; \
3741 if [ -z " $$ REF_TYPE" ]; then REF_TYPE=" auto" ; fi ; \
42+ MARKER=" $( EDITOR_SUBMODULE_PATH) /.fetched-ref" ; \
43+ WANTED=" $$ REPO_URL $$ REF $$ REF_TYPE" ; \
44+ if [ -f " $$ MARKER" ] && [ " $$ (cat " $$ MARKER" )" = " $$ WANTED" ]; then \
45+ echo " Editor source already at $$ REF, skipping fetch." ; \
46+ exit 0; \
47+ fi ; \
3848 echo " Fetching editor source from $$ REPO_URL (ref=$$ REF, type=$$ REF_TYPE)" ; \
39- rm -rf $(EDITOR_SUBMODULE_PATH ) ; \
40- git init -q $(EDITOR_SUBMODULE_PATH ) ; \
41- git -C $(EDITOR_SUBMODULE_PATH ) remote add origin " $$ REPO_URL" ; \
42- case " $$ REF_TYPE" in \
43- tag) \
44- git -C $(EDITOR_SUBMODULE_PATH ) fetch --depth 1 origin " refs/tags/$$ REF:refs/tags/$$ REF" ; \
45- git -C $(EDITOR_SUBMODULE_PATH ) checkout -q " tags/$$ REF" ; \
46- ;; \
47- branch) \
48- git -C $(EDITOR_SUBMODULE_PATH ) fetch --depth 1 origin " $$ REF" ; \
49- git -C $(EDITOR_SUBMODULE_PATH ) checkout -q FETCH_HEAD; \
50- ;; \
51- auto) \
52- if git -C $( EDITOR_SUBMODULE_PATH) fetch --depth 1 origin " refs/tags/$$ REF:refs/tags/$$ REF" > /dev/null 2>&1 ; then \
53- echo " Resolved $$ REF as tag" ; \
49+ setup_sparse () { \
50+ git -C $(EDITOR_SUBMODULE_PATH ) sparse-checkout init --cone; \
51+ git -C $(EDITOR_SUBMODULE_PATH ) sparse-checkout set src public assets views translations scripts; \
52+ }; \
53+ do_fetch_and_checkout () { \
54+ case " $$ REF_TYPE" in \
55+ tag) \
56+ git -C $(EDITOR_SUBMODULE_PATH ) fetch --depth 1 --filter=blob:none origin " refs/tags/$$ REF:refs/tags/$$ REF" ; \
5457 git -C $(EDITOR_SUBMODULE_PATH ) checkout -q " tags/$$ REF" ; \
55- else \
56- echo " Resolved $$ REF as branch" ; \
57- git -C $(EDITOR_SUBMODULE_PATH ) fetch --depth 1 origin " $$ REF" ; \
58+ ;; \
59+ branch) \
60+ git -C $(EDITOR_SUBMODULE_PATH ) fetch --depth 1 --filter=blob:none origin " $$ REF" ; \
5861 git -C $(EDITOR_SUBMODULE_PATH ) checkout -q FETCH_HEAD; \
59- fi ; \
60- ;; \
61- * ) \
62- echo " Error: EXELEARNING_EDITOR_REF_TYPE must be one of: auto, branch, tag" ; \
63- exit 1; \
64- ;; \
65- esac
62+ ;; \
63+ auto) \
64+ if git -C $( EDITOR_SUBMODULE_PATH) fetch --depth 1 --filter=blob:none origin " refs/tags/$$ REF:refs/tags/$$ REF" > /dev/null 2>&1 ; then \
65+ echo " Resolved $$ REF as tag" ; \
66+ git -C $(EDITOR_SUBMODULE_PATH ) checkout -q " tags/$$ REF" ; \
67+ else \
68+ echo " Resolved $$ REF as branch" ; \
69+ git -C $(EDITOR_SUBMODULE_PATH ) fetch --depth 1 --filter=blob:none origin " $$ REF" ; \
70+ git -C $(EDITOR_SUBMODULE_PATH ) checkout -q FETCH_HEAD; \
71+ fi ; \
72+ ;; \
73+ * ) \
74+ echo " Error: EXELEARNING_EDITOR_REF_TYPE must be one of: auto, branch, tag" ; \
75+ exit 1; \
76+ ;; \
77+ esac ; \
78+ }; \
79+ if [ -d " $( EDITOR_SUBMODULE_PATH) /.git" ]; then \
80+ echo " Reusing existing checkout, updating to $$ REF..." ; \
81+ CURRENT_URL=$$(git -C $(EDITOR_SUBMODULE_PATH ) remote get-url origin 2>/dev/null || echo "" ) ; \
82+ if [ " $$ CURRENT_URL" != " $$ REPO_URL" ]; then \
83+ git -C $(EDITOR_SUBMODULE_PATH ) remote set-url origin " $$ REPO_URL" ; \
84+ fi ; \
85+ setup_sparse; \
86+ do_fetch_and_checkout; \
87+ else \
88+ rm -rf $(EDITOR_SUBMODULE_PATH ) ; \
89+ git init -q $(EDITOR_SUBMODULE_PATH ) ; \
90+ git -C $(EDITOR_SUBMODULE_PATH ) remote add origin " $$ REPO_URL" ; \
91+ setup_sparse; \
92+ do_fetch_and_checkout; \
93+ fi ; \
94+ echo " $$ WANTED" > " $$ MARKER"
6695
6796# Build static version of eXeLearning editor
6897build-editor : check-bun fetch-editor-source
@@ -83,11 +112,16 @@ build-editor: check-bun fetch-editor-source
83112# Backward-compatible alias
84113build-editor-no-update : build-editor
85114
86- # Clean editor build
115+ # Clean editor build (use clean-editor-all to also remove the fetched source)
87116clean-editor :
88117 rm -rf dist/static
89118 rm -rf $(EDITOR_SUBMODULE_PATH ) /dist/static
90119 rm -rf $(EDITOR_SUBMODULE_PATH ) /node_modules
120+ rm -f $(EDITOR_SUBMODULE_PATH ) /.fetched-ref
121+
122+ # Clean editor build AND remove the fetched source entirely
123+ clean-editor-all : clean-editor
124+ rm -rf $(EDITOR_SUBMODULE_PATH )
91125
92126# ============================================
93127# WORDPRESS ENVIRONMENT
@@ -397,7 +431,8 @@ help:
397431 @echo " eXeLearning Static Editor:"
398432 @echo " build-editor - Build static eXeLearning editor from configured repo/ref"
399433 @echo " build-editor-no-update - Alias of build-editor"
400- @echo " clean-editor - Remove static editor build and fetched source node_modules"
434+ @echo " clean-editor - Remove static editor build, node_modules, and ref marker"
435+ @echo " clean-editor-all - Same as clean-editor + remove fetched source entirely"
401436 @echo " fetch-editor-source - Download editor source from configured repo/ref"
402437 @echo " "
403438 @echo " General:"
0 commit comments