Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WordCamp Barcelona – Front End Workflow Automation for WordPress Theme and Plugin Development

WordCamp Barcelona – Front End Workflow Automation for WordPress Theme and Plugin Development

Slides from the updated talk given at WordCamp Barcelona on April 25, 2015.

I describe a workflow and tools I use to streamline my front-end development process when working on WordPress projects. It relies on using Yeoman generator called WPZest, Grunt, Bower and WP-CLI.

WPZest is built on top of Wesley Todd's YeoPress and adds WP-CLI-Deploy configuration and adds a plugin scaffolder based on Tom Macfarlin's WordPress Plugin Boilerplate.

The presentation outlines steps you'd follow to scaffold a WordPress install with with a theme and a plugin ready to process front-end assets (SASS, image minification, JS minification), JS Linting etc.

The plugin generator comes with and option to add a Grunt task for for processing you front-end assets.

Milos Soskic

April 25, 2015
Tweet

More Decks by Milos Soskic

Other Decks in Programming

Transcript

  1. Front End Workflow Automation for Theme and Plugin Development a.k.a.

    How to Make the Computer do the Boring Stuff
  2. Small outfit Wear many hats Still code a fair bit

    esp. in WP context 1 2 3 4 1 Created by Alex Berkowitz from the Noun Project 2 Created by Nicolas Molès from the Noun Project 3 Created by Evert Jan Boon from the Nount Project 4 Created by Norbert de Graaf from the Noun Project
  3. WP projects highly bespoke brochure / marketing sites for SME's.

    Have an opinion on design Until something goes wrong not as concerned about build quality Even less on best practices Small changes end up taking time due to process – minify, concat, upload etc.
  4. Even I sometimes feel my time is better spent doing

    something else I want to use best practices, but shouldn't lose hours in the process
  5. Do Some Work › Optmise Imgs, JS & CSS ›

    Deploy via Git › Export DB › Upload DB › Search & Replace CodeKit () Terminal phpMyAdmin Search Replace }
  6. Design a workflow which uses a streamlined singular interface for

    project scaffolding, asset processing and deployment. Needs to work on shared hosting. GOAL
  7. REQUIREMENTS WP scaffolding Theme scaffolding LiveReload Code linting Theme asset

    processing Plugin scaffolding Plugin asset processing Deployment Conditional asset loading
  8. Grunt: task runner – automator gruntjs.com Bower: front-end pkg manager

    bower.io Lots of info on using Grunt for theme dev. Not as much for plugin dev—until recently. roots.io/sage github.com/mattbanks/ WordPress-Starter-Theme github.com/citrusmist/ YeoPress/tree/template Requires: node.js with npm
  9. WordPress Parallax Theme Bower Bootstrap skrollr Grunt LiveReload Sass/Compass JSHint

    imageMin Uglify Gallery Plugin Bower FTScroller imagesLoaded Grunt Sass/Compass JSHint imageMin Uglify Plugin X Bower Hammer.js Grunt Sass/Compass JSHint imageMin Uglify
  10. Theme JS Folder Structure vendor bower package store bespoke your

    plugins / modules main.js main / bootstrap file main.min.js above contents optimised }
  11. In The Terminal: cd wp-content/themes/chosen_theme npm install grunt }Install Node

    pkgs Compile SASS LiveReload JSHint Uglify JS Could be made to support: LESS, Stylus, RequireJS, CSSLint, PHPLint
  12. functions.php and in plugin if(WP_ENV == 'local') { wp_register_script('livereload', 'http://highrise.dev:35729/livereload.js?snipver=1',

    null, false, true ); wp_register_script('myplugin', get_bloginfo('template_url') . '/js/bespoke/myplugin.js', null, array('jquery'), true ); wp_register_script( 'main', get_bloginfo('template_url') . '/js/main.js', null, array('jquery', 'myplugin'), true ); wp_enqueue_script('livereload'); } elseif (WP_ENV == 'staging' || WP_ENV == 'production') { wp_register_script('main', get_bloginfo('template_url') . '/js/main.min.js', null, array('jquery'), true ); } wp_enqueue_script('main'); original optimised { {
  13. wp-config.php local staging prod. if (file_exists(dirname(__FILE__) . '/wp-config-local.php')) { //

    Local Environment define('WP_ENV', 'local'); define('WP_DEBUG', true); define('WP_DEBUG_LOG', true); include(dirname(__FILE__) . '/wp-config-local.php'); } elseif (file_exists(dirname(__FILE__) . '/wp-config-staging.php')) { // Staging Environment define('WP_ENV', 'staging'); include(dirname(__FILE__) . '/wp-config-staging.php'); } elseif (file_exists(dirname(__FILE__) . '/wp-config-production.php' )) { // Production Environment define('WP_ENV', 'production'); include(dirname(__FILE__) . '/wp-config-production.php'); } { { {
  14. WPZest Had to create one to meet requirements 80% based

    on YeoPress —Yeoman lets you easily combine gens Environment constants in wp-config Plugin scaffolding based on WP Plugin Boilerplate Deployment option via WP-CLI-Deploy https://github.com/artificer/generator-wpzest
  15. What Just Happened? DL-ed WordPress Created wp-config.php with nice defaults

    DL-ed a starter theme Installed theme Grunt and Bower dependencies Initiated a git repo Made a first commit Staging & Prod Config http://yourchosenurl.dev
  16. There Is More Vagrant w/ puppet Custom dirs WP as

    git submodule This all Yeopress github.com/wesleytodd/YeoPress
  17. In The Terminal yo wpzest:pluginbp my-gallery cd wp-content/plugins/my-gallery grunt New

    Tab bower install imagesloaded --save bower install ftscroller --save
  18. What Just Happened? DL-ed WP Plugin Boilerplate Renamed files and

    classes Installed plugin Grunt dependencies Install Bower packages
  19. In The Terminal cd path/to/wp git clone https://github.com/c10b10/wp-cli-deploy touch wp-cli.local.yml

    wp-cli.local.yml require: - wp-cli-deploy/deploy.php Include wp-config-deploy.php from wp-config.php
  20. wp-config-deploy.php define('STAGING_URL', 'your.staging.url'); define('STAGING_WP_PATH', '/path/to/wp/root'); define('STAGING_HOST', 'your.staginghost.com'); define('STAGING_USER', 'staging_user'); define('STAGING_PORT',

    '22'); define('STAGING_PATH', '/path/to/site/root'); define('STAGING_UPLOADS_PATH', '/path/to/uploads/folder'); define('STAGING_THEMES_PATH', '/path/to/themes/folder'); define('STAGING_PLUGINS_PATH', 'path/to/pluglins/folder'); define('STAGING_DB_HOST', 'localhost'); define('STAGING_DB_NAME', 'stage_db_name'); define('STAGING_DB_USER', 'stage_db_user'); define('STAGING_DB_PASSWORD', 'stage_db_pass'); define('STAGING_EXCLUDES', 'node_modules/');
  21. In The Terminal wp deploy push staging --what=themes wp deploy

    push staging --what=plugins wp deploy push staging --what=uploads wp deploy pull staging --what=themes wp deploy pull staging --what=plugins wp deploy pull staging --what=uploads upload download { {
  22. wp deploy push staging --what=db Export local DB Search &

    replace Upload to server Substitute remote DB Export remote DB DL remote DB Search & replace Substitute local DB wp deploy pull staging --what=db } }
  23. Mega useful for Checking your design over a real network

    (without having to commit) Prototyping Testing on handhelds Working on site w/ content strategist —designing a CM-ed site in browser Deployment on shared hosting —Capistrano better for other types
  24. YES BUT Streamlined for task at hand i.e. WordPress specific

    Achieves more Singular interface, albeit CLI