Slide 1

Slide 1 text

Front End Workflow Automation for Theme and Plugin Development a.k.a. How to Make the Computer do the Boring Stuff

Slide 2

Slide 2 text

Milos Soskic Founder & Designer @ Citrus Mist citrus-mist.com @citrusmist

Slide 3

Slide 3 text

This is a DevOps talk

Slide 4

Slide 4 text

WTH !#?###?!????!

Slide 5

Slide 5 text

Designer talking DevOps! or why should you believe anything I say...

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

2014 12 total WP installs 8 new 6 on shared hosting

Slide 8

Slide 8 text

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.

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

Do Some Work › Optmise Imgs, JS & CSS › Deploy via Git › Export DB › Upload DB › Search & Replace CodeKit () Terminal phpMyAdmin Search Replace }

Slide 11

Slide 11 text

4 Different pieces of software excluding text editor & graphics

Slide 12

Slide 12 text

FACEPALM! Cognitively expensive Error prone Boring & cumbersome

Slide 13

Slide 13 text

There must be another way! Others have managed to streamline it.

Slide 14

Slide 14 text

Design a workflow which uses a streamlined singular interface for project scaffolding, asset processing and deployment. Needs to work on shared hosting. GOAL

Slide 15

Slide 15 text

REQUIREMENTS WP scaffolding Theme scaffolding LiveReload Code linting Theme asset processing Plugin scaffolding Plugin asset processing Deployment Conditional asset loading

Slide 16

Slide 16 text

Asset processing —Sass, JS Minification and Image Minification LiveReload Code linting 1 STEP

Slide 17

Slide 17 text

Grunt & Bower

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

Theme JS Folder Structure vendor bower package store bespoke your plugins / modules main.js main / bootstrap file main.min.js above contents optimised }

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

Watching for changes

Slide 23

Slide 23 text

When a file is updated

Slide 24

Slide 24 text

grunt build }Compile SASS JSHint Uglify JS ImageMin (JPG, GIF, PNG, SVG)

Slide 25

Slide 25 text

Conditional asset loading 2 STEP

Slide 26

Slide 26 text

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 { {

Slide 27

Slide 27 text

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'); } { { {

Slide 28

Slide 28 text

wp-config-{env}.php define('DB_NAME', 'db_user'); define('DB_USER', 'db_pass'); define('DB_PASSWORD', 'yourSafePass'); define('DB_HOST', 'localhost'); $table_prefix = 'wp_';

Slide 29

Slide 29 text

That is soooooooo much config BOOO!

Slide 30

Slide 30 text

WordPress Scaffolding Theme Scaffolding Plugin Scaffolding 3 STEP

Slide 31

Slide 31 text

Yeoman

Slide 32

Slide 32 text

Yeoman: base generator used for project scaffolding i.e. smart templates yeoman.io Requires: node.js with npm

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

In The Terminal npm install -g yo generator-wpzest mkdir my-wp-site cd my-wp-site yo wpzest

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

There Is More Vagrant w/ puppet Custom dirs WP as git submodule This all Yeopress github.com/wesleytodd/YeoPress

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

What Just Happened? DL-ed WP Plugin Boilerplate Renamed files and classes Installed plugin Grunt dependencies Install Bower packages

Slide 39

Slide 39 text

Deployment 4 STEP

Slide 40

Slide 40 text

WP-CLI-Deploy

Slide 41

Slide 41 text

WP-CLI-Deploy: rsync based deployement script made specifically for WordPress github.com/c10b10/wp-cli-deploy Requires: WP-CLI and passwordless SSH access to server

Slide 42

Slide 42 text

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

Slide 43

Slide 43 text

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/');

Slide 44

Slide 44 text

THE PAYOFF

Slide 45

Slide 45 text

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 { {

Slide 46

Slide 46 text

… and my favourites

Slide 47

Slide 47 text

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 } }

Slide 48

Slide 48 text

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

Slide 49

Slide 49 text

Is this just swapping one toolbox for another?

Slide 50

Slide 50 text

YES BUT Streamlined for task at hand i.e. WordPress specific Achieves more Singular interface, albeit CLI

Slide 51

Slide 51 text

THANK YOU!