From c91937897a1ad987768a98e96e7a67954e2009c7 Mon Sep 17 00:00:00 2001 From: Santhosh Thottingal Date: Fri, 14 May 2021 17:45:18 +0530 Subject: [PATCH] Bundle jquery.uls and use language-data as dependency Changes ======= Introduce rollup based bundler to create single js, css files. This allows easy usage and no need to include every source code files explicitly. Fixes issue #326 Add language-data as dependency to the library Instead of using scripts to clone the language-data repo and then create our javascript files from it, directly use language-data as dev-dependency. The final bundle will include language-data. So it is not an external dependency for bundle. Approach ======== To avoid any breakage in consumers, no change in jquery plugins were introduced. No method signature change too. All plugin definitions moved to src/index.js. index.js also import the language-data and alias that to $.uls.data. So, jquery.uls.data.js and jquery.uls.data.utils.js files were deleted. The scripts to generate this files was also deleted. All other changes in jquery.uls.*.js is just indendation change because of the removal of IIFE. The resuling bundle will have IIFE. IIFE block has to be removed to expose the classes for exporting as modules. Examples were updated to refer javascript, css and styles from dist folder. Future steps ============ Introduction of build step allows * To modernize the codebase to new versions of javascript * To drop jquery dependency and optionally keep the jquery plugins * Remove grunt based CI system --- .eslintignore | 4 +- .eslintrc.json | 13 +- Gruntfile.js | 7 +- examples/index-i18n.html | 11 +- examples/index-mobile.html | 11 +- examples/index-narrow.html | 10 +- examples/index.html | 10 +- examples/limitedLanguageList.html | 10 +- examples/test-no-results.html | 10 +- package-lock.json | 27683 ++++++++++++++++++++------ package.json | 20 +- rollup.config.js | 52 + scripts/.eslintrc.json | 6 - scripts/fetch-language-data.sh | 26 - scripts/jquery.uls.data.template.js | 10 - src/index.js | 232 + src/jquery.uls.core.js | 759 +- src/jquery.uls.data.js | 6104 ------ src/jquery.uls.data.utils.js | 335 - src/jquery.uls.languagefilter.js | 547 +- src/jquery.uls.lcd.js | 740 +- test/index.html | 12 +- 22 files changed, 23230 insertions(+), 13382 deletions(-) create mode 100644 rollup.config.js delete mode 100644 scripts/.eslintrc.json delete mode 100755 scripts/fetch-language-data.sh delete mode 100644 scripts/jquery.uls.data.template.js create mode 100644 src/index.js delete mode 100644 src/jquery.uls.data.js delete mode 100644 src/jquery.uls.data.utils.js diff --git a/.eslintignore b/.eslintignore index 66a729cb..c97c7797 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,3 @@ -src/jquery.uls.data.js \ No newline at end of file +src/jquery.uls.data.js +dist/ +node_modules/ \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index b71c91aa..116a0c33 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -4,8 +4,19 @@ "wikimedia/client", "wikimedia/jquery" ], + "parserOptions": { + "ecmaVersion": 12, + "sourceType": "module" + }, + "env": { + "es6": true, + "browser": true, + "jquery": true, + "qunit": true, + "node": true + }, "globals": { "jQuery": "readonly", - "$": "off" + "$": "readonly" } } diff --git a/Gruntfile.js b/Gruntfile.js index 71d014b1..5e75908a 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -14,11 +14,9 @@ module.exports = function ( grunt ) { }, all: [ '**/*.{js,json,html}', - '!src/jquery.uls.data.js', - '!scripts/jquery.uls.data.template.js', '!examples/resources/*.min.js', '!node_modules/**', - '!vendor/**' + '!dist/**' ] }, stylelint: { @@ -27,7 +25,8 @@ module.exports = function ( grunt ) { }, src: [ '**/*.css', - '!node_modules/**' + '!node_modules/**', + '!dist/**' ] }, qunit: { diff --git a/examples/index-i18n.html b/examples/index-i18n.html index 1254cd42..0ad1b4a0 100644 --- a/examples/index-i18n.html +++ b/examples/index-i18n.html @@ -4,20 +4,13 @@ Universal Language Selector - - - + - - - - - - + - - - - - + - - - - - + - - - - - + - - - - - + - - - - - + + - - - - - + - - + +