summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile44
1 files changed, 23 insertions, 21 deletions
diff --git a/Makefile b/Makefile
index d203df92..24f71507 100644
--- a/Makefile
+++ b/Makefile
@@ -110,41 +110,41 @@ static/f/vndb.js: data/js/*.js lib/VNDB/Types.pm util/jsgen.pl data/conf.pl | st
util/jsgen.pl
static/f/vndb.min.js: static/f/vndb.js
- uglifyjs $< --compress --mangle -o $@
+ uglifyjs $< --compress --mangle --comments '/(@license|@source|SPDX-)/' -o $@
# v2-rw
-# Order matters!
-JS_FILES=\
- elm/polyfills.js \
- elm/pagevars.js \
- elm/UList/LabelEdit.js \
- elm/UList/ManageLabels.js \
- elm/UList/Opt.js \
- elm/UList/VoteEdit.js \
- elm/Lib/Ffi.js \
- elm/elm-init.js \
- elm/checkall.js \
- elm/checkhidden.js
-
+# Order of JS files matters, so we read an '//order:x' comment from the files and sort by that.
+# Files without that comment are assumed to have '//order:4'.
+# (This trick will not work if we ever add JS files generated by this Makefile)
+JS_FILES=$(shell find elm \! -path 'elm/elm-stuff/*' -name '*.js' -exec sh -c "echo \`grep -Po '(?<=^//order:)[0-9]' \"{}\" || echo 4\` \"{}\"" \; | sort | sed 's/..//')
ELM_FILES=elm/*.elm elm/*/*.elm
ELM_MODULES=$(shell grep -l '^main =' ${ELM_FILES} | sed 's/^elm\///')
-# Patch the Javascript generated by Elm and append the elm/**.js files to it.
+# Patch the Javascript generated by Elm and append the $JS_FILES to it.
# Patches include:
+# - Add @license and @source comments
# - Redirect calls from Lib.Ffi.* to window.elmFfi_*
# - Patch the virtualdom diffing algorithm to always apply the 'selected' attribute
define fix-js
- sed -i 's/var \$$author\$$project\$$Lib\$$Ffi\$$/var __unused__/g' $@
- sed -Ei 's/\$$author\$$project\$$Lib\$$Ffi\$$([a-zA-Z0-9_]+)/window.elmFfi_\1(_Json_wrap,_Browser_call)/g' $@
- sed -Ei "s/([^ ]+) !== 'checked'/\\1 !== 'checked' \&\& \\1 !== 'selected'/g" $@
+ ( echo '// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0-only'; \
+ echo '// @license magnet:?xt=urn:btih:c80d50af7d3db9be66a4d0a86db0286e4fd33292&dn=bsd-3-clause.txt BSD-3-Clause'; \
+ echo '// @source: https://code.blicky.net/yorhel/vndb/src/branch/master/elm'; \
+ echo '// SPDX-License-Identifier: AGPL-3.0-only and BSD-3-Clause'; \
+ cat $@ \
+ ) | sed 's/var \$$author\$$project\$$Lib\$$Ffi\$$/var __unused__/g' \
+ | sed -E 's/\$$author\$$project\$$Lib\$$Ffi\$$([a-zA-Z0-9_]+)/window.elmFfi_\1(_Json_wrap,_Browser_call)/g' \
+ | sed -E "s/([^ ]+) !== 'checked'/\\1 !== 'checked' \&\& \\1 !== 'selected'/g" >$@~
for fn in ${JS_FILES}; do \
- echo "(function(){'use strict';"; \
+ echo; \
+ echo "(function(){'use strict'; /* $$fn */"; \
cat $$fn; \
echo "})();"; \
- done >>$@
+ done >>$@~
+ echo '// @license-end' >>$@~
+ mv $@~ $@
endef
elm/Gen/.generated: lib/VNWeb/*.pm lib/VNWeb/*/*.pm lib/VNDB/Types.pm lib/VNDB/Config.pm data/conf.pl
@@ -157,7 +157,9 @@ static/f/v2rw.js: ${ELM_FILES} ${JS_FILES} elm/Gen/.generated | static/f
static/f/v2rw.min.js: ${ELM_FILES} ${JS_FILES} elm/Gen/.generated | static/f
cd elm && ELM_HOME=elm-stuff elm make --optimize ${ELM_MODULES} --output ../$@
${fix-js}
- uglifyjs $@ --compress 'pure_funcs="F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9",pure_getters,keep_fargs=false,unsafe_comps,unsafe' | uglifyjs --mangle -o $@~
+ uglifyjs $@ --comments '/(@license|@source|SPDX-)/' --compress \
+ 'pure_funcs="F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9",pure_getters,keep_fargs=false,unsafe_comps,unsafe'\
+ | uglifyjs --mangle --comments all -o $@~
mv $@~ $@