The WordPress theme for the TODO website.
Here's how to get your local copy of the site up and running.
We create a local multi-site WordPress installation using Local by Flywheel, download this repository that contains the theme files, symlink the theme into the right place in the WordPress folder hierarchy, enable the theme in WordPress, install plugins, grab the latest staging/production database, and then get to work.
- Ask your development team leader to make you an administrator account on the staging server and save the login details in your 1Password account.
-
Download and install Local by Flywheel.
-
Open Local by Flywheel. Create a new site called 'TODO.' Keep the defaults, choose the 'Preferred' environment, and make it a WordPress Multisite (with subdomains).
Detailed settings:
- Page 1: What's your site's name?
- Name: TODO
- Advanced Options:
- Local site domain: TODO.local
- Local site path: ~/Local Sites/TODO/
- Create site from Blueprint: No
- Page 2: Choose your environment: Preferred
- Page 3: Setup WordPress:
- WordPress Username: admin
- WordPress Password: admin
- WordPress Email: [keep the default]
- Avanced Options:
- TODO: Is this a WordPress multisite? Yes — Subdomain
- TODO: Is this a WordPress multisite? No
- Page 1: What's your site's name?
-
Once the site is created in Local by Flywheel, click on the 'SSL' tab and click 'Trust' to enable SSL on the local installation.
-
Open the Local by Flywheel preferences. Click on the 'Advanced' tab and turn on 'IPv6 Loopback.' Close the preferences (‘×’ icon in the top right corner.)
-
Open your terminal app.
-
Install Homebrew if you haven't before.
Install mkcert to generate your own SSL certificate for
localhost
.brew install mkcert brew install nss mkcert -install mkcert localhost 127.0.0.1 ::1
Note: If you use Firefox, restart it now for the SSL certificate to work.
-
Change directory to the site installation:
cd ~/Local\ Sites/TODO
-
Clone this repository into it.
git clone [email protected]:owen-jones/TODO.git
-
Go back to Local by Flywheel. Click on the 'Add-ons' button in the sidebar (it looks like a puzzle piece). Click on the 'Volumes' add-on, install it, and then click the 'Enable & Relaunch' button.
-
Once Local by Flywheel relaunches, select the newly created site in the sidebar and click on the 'More' drop-down menu and click 'Volumes.'
-
Click 'Add Volume.' Settings are as follows:
- Click 'Browse,' browse to the
TODO
theme directory you just cloned, and click 'Open.' - In the 'Container Destination' column, enter this path:
/app/public/wp-content/themes/TODO
- Click 'Remap Volumes' and click OK in the confirmation popup.
- Click 'Browse,' browse to the
-
Make a copy of the
.env.example
file and call it.env
.Customize your
.env
file to match your installation. Below are the properties you should verify for your install. You may not need to change anything.ENVIRONMENT
: For all local dev environments, this should be set todev
.DEV_SITE_URL
: This should match your local URL (which will behttps://TODO.local
unless you changed it in Local by Flywheel during setup.)
-
Enable the theme. Go to the WordPress network admin theme settings and log in (username
admin
and passwordadmin
unless you changed that during setup). Under 'TODO' in the theme list, click 'Network Enable.' -
Now go to the main site WP Admin. In the admin sidebar, hover over the 'Appearance' menu and click 'Themes.' Click 'Activate' on the TODO theme. (You may delete the other default themes at this point, since we won't be using them.)
-
Once you activate the theme, you'll get a warning that some plugins are required. Click the 'Begin Installing Plugins' link in that warning. Select all of the plugins in the list, install them, then activate them.
[TODO: Once we deploy to the production for the first time, these instructions should be changed to point to the production endpoints.]
-
Add WP DB Migrate Pro license key on the settings page. The key is available in your Owen Jones 'Dev Team' vault in 1Password.
-
Still on the Migrate DB screen, click on the 'Migrate' tab. From the list of options, select 'Pull.'
-
In a new tab, copy the Connection Info key from the staging server WP DB Migrate Pro settings.
-
Go back to your local Migrate DB screen and paste the connection key.
-
Once connected, do an initial sync.
Detailed settings:
- Pull into a specific subsite: TODO.local
- Leave the 'Find & Replace' settings as is.
- Tables: Select All
- Exclude post types: leave unchecked
- Advanced Options: check all checkboxes
- Backup the local database before replacing it: leave unchecked
- Media Files: checked
- Compare, download then remove
- Save Migration Profile: name it Pull from staging
-
Click 'Pull & Save' to sync for the first time.
-
You will be logged off after this initial sync. From now on, you'll log in using credentials that were created for you at the beginning of this process.
-
Make sure you have Node and NPM installed.
-
Install dependencies:
npm install
- Source files are kept in the
/_src/
folder. - JavaScript is compiled by Webpack, which transpiles the code from ES6
syntax to browser-ready ES5 and bundles files from
/_src/js/
and into/assets/js/main.js
. - CSS is written in SASS, using SCSS syntax. It is located in
/_src/css/
and compiled to/assets/css/main.css
. - Images are optimized from
/_src/images/
and copied to/assets/images/
. ⚠️ NOTE: The/assets/images/
folder is the destination for optimized images. It will be deleted every time development scripts are run in order to clear out old files. Don't put files directly into the/assets/images/
folder!
Gulp is used to handle development tasks.
To start the asset compilation, run the script that builds and watches for changes in the CSS/JS/images folders:
npm run dev
OR
npm start
This script also "lints" (checks) your JS and CSS for code style and syntax errors. These errors will be reported in the terminal.
This script also starts a BrowserSync server at https://localhost:3000 to live-reload the browser when assets are updated. This is convenient for automatic reloading and for checking the website on other devices on the local network.
Gulp compiles CSS and images, but Webpack is used for compiling JS. (Gulp
launches Webpack when you run npm run dev
, but Webpack takes over after that.)
Webpack will generate a JS file for every file listed in the entry
array
defined at the top of the webpack.common.js
file. To generate a separate file
(e.g., a foo.js
file that will only be loaded on a certain page), add a
file to that list and then add the script to the template you want.
This site uses some features that are only found in newer browsers, and we
provide fallbacks using Modernizr. The modernizr.js
file is automatically generated by searching JS and CSS files for JS test names
and CSS class names that match the Modernizr ones
(see examples here).
Because generating the Modernizr file can be a little time-consuming and
generate a lot of console ouput, we only run it on the initial npm start
.
npm start
to regenerate the Modernizr
script.
TODO: How will deployment actually work?
-
Do a minified build.
npm run build git commit -a -m "Staging build." git push
-
SSH to OJP Projects server and update the site:
ssh ojp-projects cd /var/www/projects/TODO/ git pull
-
Run the
deploy
command:npm run deploy
TODO
I tested but ultimately decided against using the stylelint-no-unsupported-browser-features StyleLint plugin, because it has no way of seeing that you're using a fallback and clogs your terminal with warnings.
The settings would be, in
.stylelintrc
: