From fa35c561bb21ff8cf46cfc367112035a98e9c33f Mon Sep 17 00:00:00 2001 From: Rodrigo Ferreira de Souza Date: Thu, 29 Nov 2018 15:58:27 -0200 Subject: [PATCH] Use webpack (#826) * Add changelog * Move static files to webpack * Review resources registry * Review compose view * Review content chooser * Test fixes * Initialize carousel tile after drop content * Move static files to viewlet * Move unload code into webpack * Fix layout preview * Add upgrade step * Fix tests * Review static resources for Plone 5 * Code review * Update docs * Code review --- .gitignore | 1 + CHANGES.rst | 7 +- README.rst | 36 + buildout.cfg | 21 +- src/collective/cover/browser/__init__.py | 5 + src/collective/cover/browser/configure.zcml | 15 + .../cover/browser/static/README.rst | 3 + .../cover/browser/templates/compose.pt | 22 - .../cover/browser/templates/layoutedit.pt | 22 - src/collective/cover/configure.zcml | 5 - .../cover/profiles/default/cssregistry.xml | 9 - .../cover/profiles/default/jsregistry.xml | 12 - .../cover/profiles/default/metadata.xml | 2 +- .../cover/static/css/contentchooser.css | 197 ----- src/collective/cover/static/css/cover.css | 278 ------ .../static/css/layout_edit_201806251610.css | 788 ----------------- src/collective/cover/static/js/compose.js | 207 ----- src/collective/cover/static/js/layout_base.js | 34 - src/collective/cover/static/js/layout_edit.js | 746 ---------------- src/collective/cover/static/js/main.js | 46 - .../cover/static/js/selectlayoutpreview.js | 46 - .../static/js/vendor/jquery.endless-scroll.js | 343 ------- .../cover/static/js/vendor/jss.min.js | 1 - .../cover/tests/test_resources_viewlet.py | 49 + src/collective/cover/tests/test_setup.py | 23 +- src/collective/cover/tests/test_upgrades.py | 37 + .../cover/tiles/templates/carousel.pt | 2 +- src/collective/cover/upgrades/configure.zcml | 1 + src/collective/cover/upgrades/v24/__init__.py | 32 + .../cover/upgrades/v24/configure.zcml | 28 + src/collective/cover/widgets/selectpreview.py | 14 +- .../cover/widgets/selectpreview_input.pt | 3 +- webpack/.gitignore | 5 + webpack/app/cover.js | 43 + webpack/app/cover.scss | 3 + .../app/galleria/theme.css | 0 .../app/galleria/theme.js | 2 +- .../static => webpack/app}/img/arrow-left.gif | Bin .../app}/img/arrow-right.gif | Bin .../static => webpack/app}/img/columns.png | Bin .../cover/static => webpack/app}/img/conf.png | Bin .../cover/static => webpack/app}/img/dot.png | Bin .../static => webpack/app}/img/drophere.png | Bin .../app}/img/frontpage_icon.png | Bin .../cover/static => webpack/app}/img/move.png | Bin webpack/app/img/pb_close.png | Bin 0 -> 1910 bytes .../static => webpack/app}/img/remove.png | Bin .../static => webpack/app}/img/resize-hor.png | Bin .../cover/static => webpack/app}/img/rows.png | Bin .../static => webpack/app}/img/spinner.gif | Bin .../app}/img/tile-banner.png | Bin .../static => webpack/app}/img/tile-basic.png | Bin .../app}/img/tile-calendar.png | Bin .../app}/img/tile-carousel.png | Bin .../app}/img/tile-collection.png | Bin .../app}/img/tile-contentbody.png | Bin .../static => webpack/app}/img/tile-embed.png | Bin .../static => webpack/app}/img/tile-file.png | Bin .../app}/img/tile-generic.png | Bin .../static => webpack/app}/img/tile-list.png | Bin .../static => webpack/app}/img/tile-pfg.png | Bin .../app}/img/tile-richtext.png | Bin .../static => webpack/app}/img/tiles.png | Bin .../static => webpack/app}/img/visibility.png | Bin webpack/app/js/add.js | 44 + webpack/app/js/compose.js | 218 +++++ .../app}/js/contentchooser.js | 836 +++++++++--------- webpack/app/js/cssclasswidget.js | 106 +++ webpack/app/js/layout.js | 644 ++++++++++++++ webpack/app/js/tiles/calendar.js | 28 + webpack/app/js/tiles/carousel.js | 20 + .../static => webpack/app}/js/vendor/jss.js | 3 +- webpack/app/resources.pt | 6 + webpack/app/scss/_contentchooser.scss | 142 +++ webpack/app/scss/_cover.scss | 222 +++++ webpack/app/scss/_layout.scss | 604 +++++++++++++ webpack/package.json | 30 + webpack/postcss.config.js | 7 + webpack/webpack.config.js | 44 + 79 files changed, 2821 insertions(+), 3221 deletions(-) create mode 100644 src/collective/cover/browser/static/README.rst delete mode 100644 src/collective/cover/profiles/default/cssregistry.xml delete mode 100644 src/collective/cover/static/css/contentchooser.css delete mode 100644 src/collective/cover/static/css/cover.css delete mode 100644 src/collective/cover/static/css/layout_edit_201806251610.css delete mode 100644 src/collective/cover/static/js/compose.js delete mode 100644 src/collective/cover/static/js/layout_base.js delete mode 100644 src/collective/cover/static/js/layout_edit.js delete mode 100644 src/collective/cover/static/js/main.js delete mode 100644 src/collective/cover/static/js/selectlayoutpreview.js delete mode 100644 src/collective/cover/static/js/vendor/jquery.endless-scroll.js delete mode 100644 src/collective/cover/static/js/vendor/jss.min.js create mode 100644 src/collective/cover/tests/test_resources_viewlet.py create mode 100644 src/collective/cover/upgrades/v24/__init__.py create mode 100644 src/collective/cover/upgrades/v24/configure.zcml create mode 100644 webpack/.gitignore create mode 100644 webpack/app/cover.js create mode 100644 webpack/app/cover.scss rename src/collective/cover/static/css/galleria.cover_theme.css => webpack/app/galleria/theme.css (100%) rename src/collective/cover/static/js/galleria.cover_theme.js => webpack/app/galleria/theme.js (98%) rename {src/collective/cover/static => webpack/app}/img/arrow-left.gif (100%) rename {src/collective/cover/static => webpack/app}/img/arrow-right.gif (100%) rename {src/collective/cover/static => webpack/app}/img/columns.png (100%) rename {src/collective/cover/static => webpack/app}/img/conf.png (100%) rename {src/collective/cover/static => webpack/app}/img/dot.png (100%) rename {src/collective/cover/static => webpack/app}/img/drophere.png (100%) rename {src/collective/cover/static => webpack/app}/img/frontpage_icon.png (100%) rename {src/collective/cover/static => webpack/app}/img/move.png (100%) create mode 100644 webpack/app/img/pb_close.png rename {src/collective/cover/static => webpack/app}/img/remove.png (100%) rename {src/collective/cover/static => webpack/app}/img/resize-hor.png (100%) rename {src/collective/cover/static => webpack/app}/img/rows.png (100%) rename {src/collective/cover/static => webpack/app}/img/spinner.gif (100%) rename {src/collective/cover/static => webpack/app}/img/tile-banner.png (100%) rename {src/collective/cover/static => webpack/app}/img/tile-basic.png (100%) rename {src/collective/cover/static => webpack/app}/img/tile-calendar.png (100%) rename {src/collective/cover/static => webpack/app}/img/tile-carousel.png (100%) rename {src/collective/cover/static => webpack/app}/img/tile-collection.png (100%) rename {src/collective/cover/static => webpack/app}/img/tile-contentbody.png (100%) rename {src/collective/cover/static => webpack/app}/img/tile-embed.png (100%) rename {src/collective/cover/static => webpack/app}/img/tile-file.png (100%) rename {src/collective/cover/static => webpack/app}/img/tile-generic.png (100%) rename {src/collective/cover/static => webpack/app}/img/tile-list.png (100%) rename {src/collective/cover/static => webpack/app}/img/tile-pfg.png (100%) rename {src/collective/cover/static => webpack/app}/img/tile-richtext.png (100%) rename {src/collective/cover/static => webpack/app}/img/tiles.png (100%) rename {src/collective/cover/static => webpack/app}/img/visibility.png (100%) create mode 100644 webpack/app/js/add.js create mode 100644 webpack/app/js/compose.js rename {src/collective/cover/static => webpack/app}/js/contentchooser.js (54%) create mode 100644 webpack/app/js/cssclasswidget.js create mode 100644 webpack/app/js/layout.js create mode 100644 webpack/app/js/tiles/calendar.js create mode 100644 webpack/app/js/tiles/carousel.js rename {src/collective/cover/static => webpack/app}/js/vendor/jss.js (99%) create mode 100644 webpack/app/resources.pt create mode 100644 webpack/app/scss/_contentchooser.scss create mode 100644 webpack/app/scss/_cover.scss create mode 100644 webpack/app/scss/_layout.scss create mode 100644 webpack/package.json create mode 100644 webpack/postcss.config.js create mode 100644 webpack/webpack.config.js diff --git a/.gitignore b/.gitignore index 7b134ce5f..7c51cb7b1 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ parts/ report.html selenium* var/ +src/collective/cover/browser/static/ diff --git a/CHANGES.rst b/CHANGES.rst index 7c9f5467e..66a28e560 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,7 +6,12 @@ There's a frood who really knows where his towel is. 2.1b3 (unreleased) ^^^^^^^^^^^^^^^^^^ -- Nothing changed yet. +- Deprecate resource registries; instead, we now use a viewlet in plone.htmlhead to load JavaScript code. + This simplifies maintainance of the add-on among multiple Plone versions. + [rodfersou] + +- Process static resources using webpack. + [rodfersou] 2.1b2 (2018-10-04) diff --git a/README.rst b/README.rst index ffa7591eb..ee5e1a4ec 100644 --- a/README.rst +++ b/README.rst @@ -153,6 +153,42 @@ Check the box next to ``collective.cover`` and click the 'Activate' button. You may have to empty your browser cache and save your resource registries in order to see the effects of the product installation. +Development +----------- + +We use `webpack `_ to process static resources on this package. +`webpack`_ processes SCSS and JS files, minifies the resulting CSS and JS, and optimizes all images. + +To contribute, you should start the instance in one shell and start webpack watcher on another with the following command: + +.. code-block:: console + + $ bin/watch-cover + +Then go to ``webpack/app`` folder and edit SCSS and JS files; +`webpack`_ watcher will automatically create the final resources in the right place. + +There are also other commands added to handle more complex scenarios. + +The following command will set the buildout node installation in the system PATH, +this way you can use `webpack`_ as described on their documentation. + +.. code-block:: console + + $ bin/env-cover + +The following command generates JS and CSS without the minify step (it can be used to check the code being generated in a human readable way). + +.. code-block:: console + + $ bin/debug-cover + +The following command rebuilds static files and exit (insted of keep watching the changes): + +.. code-block:: console + + $ bin/build-cover + Upgrading from 1.x to 2.x ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/buildout.cfg b/buildout.cfg index 686382b73..0a963657c 100644 --- a/buildout.cfg +++ b/buildout.cfg @@ -17,6 +17,7 @@ parts += pylint rebuild_i18n-sh robot + staticresources [checkversions] recipe = zc.recipe.egg @@ -26,14 +27,10 @@ eggs = z3c.checkversions [buildout] recipe = plone.recipe.codeanalysis[recommended] directory = ${buildout:directory}/src/collective/cover clean-lines = True -clean-lines-exclude = ${buildout:directory}/src/collective/cover/static/js/vendor/ -csslint = True -csslint-bin = bin/csslint +clean-lines-exclude = ${:directory}/browser/static debug-statements = True flake8-ignore = B901,D001,E501,P001,T000 flake8-max-complexity = 12 -jshint = True -jshint-bin = bin/jshint multiprocessing = True pre-commit-hook = True prefer-single-quotes = True @@ -70,3 +67,17 @@ eggs = scripts = robot-server robot + +[node] +recipe = gp.recipe.node +version = 8.11.2 +npms = npm yarn +scripts = npm yarn + +[staticresources] +recipe = sc.recipe.staticresources +name = collective.cover +short_name = cover + +[versions] +sc.recipe.staticresources = 1.1b5 diff --git a/src/collective/cover/browser/__init__.py b/src/collective/cover/browser/__init__.py index 40a96afc6..43d584716 100644 --- a/src/collective/cover/browser/__init__.py +++ b/src/collective/cover/browser/__init__.py @@ -1 +1,6 @@ # -*- coding: utf-8 -*- +from plone.app.layout.viewlets import ViewletBase + + +class ResourcesViewlet(ViewletBase): + """This viewlet inserts static resources on page header.""" diff --git a/src/collective/cover/browser/configure.zcml b/src/collective/cover/browser/configure.zcml index 41bb6e024..51a135b53 100644 --- a/src/collective/cover/browser/configure.zcml +++ b/src/collective/cover/browser/configure.zcml @@ -154,4 +154,19 @@ permission="zope2.View" /> + + + + diff --git a/src/collective/cover/browser/static/README.rst b/src/collective/cover/browser/static/README.rst new file mode 100644 index 000000000..a0f03accb --- /dev/null +++ b/src/collective/cover/browser/static/README.rst @@ -0,0 +1,3 @@ +.. note:: + Content on this folder is generated automatically by `webpack `_. + Check package documentation for more information. diff --git a/src/collective/cover/browser/templates/compose.pt b/src/collective/cover/browser/templates/compose.pt index 22e8a999f..cf81650cc 100644 --- a/src/collective/cover/browser/templates/compose.pt +++ b/src/collective/cover/browser/templates/compose.pt @@ -7,28 +7,6 @@ i18n:domain="collective.cover"> - - - - - - - - - -
diff --git a/src/collective/cover/browser/templates/layoutedit.pt b/src/collective/cover/browser/templates/layoutedit.pt index d08152d05..e841bd053 100644 --- a/src/collective/cover/browser/templates/layoutedit.pt +++ b/src/collective/cover/browser/templates/layoutedit.pt @@ -6,28 +6,6 @@ metal:use-macro="context/main_template/macros/master" i18n:domain="collective.cover"> - - - - - - - -