Skip to content

Latest commit

 

History

History
203 lines (160 loc) · 6.87 KB

INSTALLATION.md

File metadata and controls

203 lines (160 loc) · 6.87 KB

Dekode Project Base - Installation Guide

Requirements

Project Structure

  • Packages: Contains all project-specific code such as plugins, themes, mu-plugins, and custom libraries. These are built into the public directory using symlinks via Composer.
  • Public: Contains files used by WordPress, automatically generated from packages by Composer. This folder should not be modified manually.
  • Tools: Contains build and setup scripts used by Codeship and Local.
  • Config: Contains environment variable setup files.

Local Setup

Initial Setup

  1. Create a Git Repository:

    • If setting up a new project, create a git repository using Project Base as the template.
  2. Create a New Site in Local:

    • Enable multisite (subdirectory) if applicable to the project.

Setup Methods

Method 1: Replicating Server Structure

  1. Navigate to the app folder:

    cd app
  2. Remove the default public folder:

    rm -rf public
  3. Clone the project into the current folder:

    git clone [email protected]:DekodeInteraktiv/{YOUR_PROJECT} .
  4. Copy the environment example file:

    cp .env.example .env
  5. Update environment variables in the .env file:

    • DB_NAME, DB_USER, DB_PASSWORD, DB_HOST
    • WP_ENVIRONMENT_TYPE (local, development, staging, production)
    • WP_HOME (e.g., http://example.com)
    • WP_SITEURL (e.g., http://example.com/wp)
    • AUTH_KEY, SECURE_AUTH_KEY, LOGGED_IN_KEY, NONCE_KEY, AUTH_SALT, SECURE_AUTH_SALT, LOGGED_IN_SALT, NONCE_SALT
  6. Generate security keys (optional, requires wp-cli):

    wp package install aaemnnosttv/wp-cli-dotenv-command
    wp dotenv salts regenerate

    Or use the Roots WordPress Salt Generator.

  7. Install Composer dependencies:

    composer install
  8. Install npm dependencies:

    npm ci
  9. Run local setup scripts (ensure MYSQLI_DEFAULT_SOCKET is set if needed):

    cd app/tools/local
    ./setup-main-site.sh
    ./activate-plugins.sh
    bash multisite.sh  # Only for multisite setup
  10. Update URLs for multisite to use HTTPS:

    wp search-replace --url=http://{PROJECT}.site 'http://{PROJECT}.site' 'https://{PROJECT}.site' --recurse-objects --network --skip-columns=guid

Method 2: Using Local Structure (Symlink Method)

  1. Navigate to the site app folder and clone the project:

    cd path/to/app
    git clone [email protected]:DekodeInteraktiv/{YOUR_PROJECT} .
  2. Remove the default wp-content folder:

    rm -rf public/wp-content
  3. Create a symlink for wp-content:

    ln -s ../{project folder}/public/content public/wp-content
  4. Run local setup scripts:

    cd tools/local
    ./setup-main-site.sh
    ./activate-plugins.sh
    bash multisite.sh  # Only for multisite setup

Using wp-cli with Local

To use wp-cli with Local, you can use the built-in site shell. For default system console access, add a wp-cli.local.yml file to the root (app) directory:

path: public/wp
require:
  - wp-cli-local.php

Set the MYSQLI_DEFAULT_SOCKET in the .env file using the path from the Local Database tab.

Installation and Build

Run the following commands in the root directory to build the project:

composer install
npm ci && npm run build

(See packages/themes/block-theme for more details)

Extending Builds

Project Base uses wp-scripts out of the box for building front-end/view and editor assets. wp-script will scan all block.json files in the src/ folder to find available entries. This means that if you have a src folder with a view.js and a editor.js, you also need to add a block.json file at the same location. Have a look in the block-theme theme for example or read up on wp-script auto discovery for Webpack entry points. For a more advanced setup, you can always customize builds by adding your own webpack.config.js.

A quick overview of wp-scripts auto discovery:

  1. Supply entry points manully to the CLI, e.g. wp-scripts build src/view src/editor src/admin src/some-other-entry. This will bypass 2 and 3.
  2. Scan src folder for all block.json files. (Our default setup). This will support both theme/plugin assets (view/editor) and possible blocks inside the src/ folder.
  3. Fallback to src/index.* file. This will only look for a src/index.js file.

Adding a new package (plugin, mu-plugin or theme)

  1. Create a folder: Add a folder in ./packages (e.g., ./packages/plugins).

  2. Add a composer.json File (for themes, plugins, mu-plugins, and PHP dependencies):

    {
      "name": "project/package-name",
      "description": "Short description of the package.",
      "type": "wordpress-plugin/wordpress-muplugin/wordpress-theme/other",
      "version": "1.0.0"
    }

    Note: Use block-base for Gutenberg blocks.

    Note: A version should always be supplied. This ensures that package versions do not change between branches, leading to unneccesary merge conflicts.

  3. Add a package.json File (for frontend dependencies or custom React components):

    {
      "name": "package-name",
      "private": true,
      "version": "1.0.0",
      "description": "Package description",
      "author": "Dekode",
      "main": "index.js",
      "scripts": {
        "build": "echo \"Error: no build specified\" && exit 1",
        "start": "echo \"Error: no start specified\" && exit 1",
        "test": "echo \"Error: no test specified\" && exit 1",
        "clean": "rm -rf node_modules build dist"
      }
    }
  4. Update Root Configuration:

    • For Composer packages, add an entry under "require" in composer.json:
      "project/package-name": "@dev"
    • For npm packages, add an entry under "devDependencies" in package.json:
      "package-name": "file:packages/folder/package-name"
  5. Install the Package:

    • For Composer:
      composer update
    • For npm:
      npm install

    Re-run npm run build or npm run start if needed.

Additional Documentation