Skip to content

Instantly share code, notes, and snippets.

@mparker17
Last active May 11, 2019 20:27
Show Gist options
  • Save mparker17/67779d33d7eb6e496b6613e01416db92 to your computer and use it in GitHub Desktop.
Save mparker17/67779d33d7eb6e496b6613e01416db92 to your computer and use it in GitHub Desktop.
Trying out Mannequin with Lando and Drupal 8.6.
#!/bin/bash
# Variables.
export PROJECT_NAME="mannequin"
export DOCROOT_DIR="web"
export THEME_NAME="my_theme"
# Set up a directory for the project.
mkdir "$PROJECT_NAME"
cd "$PROJECT_NAME" || exit 1
# Set up a git repo for the project.
git init
git commit --allow-empty -m "Initial commit."
# Create a Drupal 8 environment for this project with Lando.
mkdir "$DOCROOT_DIR/"
touch "$DOCROOT_DIR/.gitkeep"
git add "$DOCROOT_DIR/.gitkeep"
tee -a .gitignore <<EOF
/.lando.local.yml
EOF
tee .lando.yml <<EOF
name: $PROJECT_NAME
recipe: drupal8
config:
webroot: $DOCROOT_DIR/
EOF
git add ".gitignore" ".lando.yml"
lando start
git commit -m "Create a Drupal 8 environment for this project with Lando."
# Set up composer stub.
tee -a .gitignore <<EOF
/vendor/
EOF
tee -a composer.json <<EOF
{
"extra": {
"installer-paths": {
"$DOCROOT_DIR/core": ["type:drupal-core"],
"$DOCROOT_DIR/libraries/{\$name}": [
"type:drupal-library",
"type:bower-asset",
"type:npm-asset"
],
"$DOCROOT_DIR/modules/contrib/{\$name}": ["type:drupal-module"],
"$DOCROOT_DIR/profiles/contrib/{\$name}": ["type:drupal-profile"],
"$DOCROOT_DIR/themes/contrib/{\$name}": ["type:drupal-theme"],
"drush/contrib/{\$name}": ["type:drupal-drush"]
}
}
}
EOF
git add ".gitignore" "composer.json"
git commit -m "Set up composer stub."
# Add drupal-composer/drupal-scaffold.
lando composer require "drupal-composer/drupal-scaffold:dev-master"
git add "composer.json" "composer.lock"
git commit -m "Add drupal-composer/drupal-scaffold."
# Add composer/installers.
lando composer require "composer/installers:^1.0.20"
git add "composer.json" "composer.lock"
git commit -m "Add composer/installers."
# Add drupal.org composer repositories.
lando composer config "repositories.0" "composer" "https://packages.drupal.org/8"
git add "composer.json" "composer.lock"
git commit -m "Add drupal.org composer repositories."
# Set up Drupal core.
tee -a .gitignore <<EOF
/$DOCROOT_DIR/sites/*/settings*.php
/$DOCROOT_DIR/sites/*/services*.yml
/$DOCROOT_DIR/sites/*/files
/$DOCROOT_DIR/sites/*/private
/$DOCROOT_DIR/sites/simpletest
EOF
lando composer require "drupal/core"
git add ".gitignore" "composer.json" "composer.lock"
git commit -m "Add drupal/core."
# Note we purposely didn't check in core's dotfiles, $DOCROOT_DIR/core,
# and the PHP files core puts at the docroot - that's left to the user's
# preference. Technically they're auto-generated and are almost never changed,
# so we likely don't need to check them into a repo containing only custom code.
# Set up drush.
lando composer require 'drush/drush:^9.6'
git add "composer.json" "composer.lock"
git commit -m "Add drush/drush."
# Install Drupal.
lando drush -y site-install minimal --db-url="mysql://drupal8:drupal8@database:3306/drupal8"
# Set up a theme to run mannequin in.
mkdir -p "$DOCROOT_DIR/themes/custom/$THEME_NAME/css" "$DOCROOT_DIR/themes/custom/$THEME_NAME/js" "$DOCROOT_DIR/themes/custom/$THEME_NAME/templates"
touch "$DOCROOT_DIR/themes/custom/$THEME_NAME/css/$THEME_NAME.css" "$DOCROOT_DIR/themes/custom/$THEME_NAME/js/$THEME_NAME.js" "$DOCROOT_DIR/themes/custom/$THEME_NAME/templates/.gitkeep"
git add "$DOCROOT_DIR/themes/custom/$THEME_NAME/css/$THEME_NAME.css" "$DOCROOT_DIR/themes/custom/$THEME_NAME/js/$THEME_NAME.js" "$DOCROOT_DIR/themes/custom/$THEME_NAME/templates/.gitkeep"
tee -a "$DOCROOT_DIR/themes/custom/$THEME_NAME/$THEME_NAME.libraries.yml" <<EOF
$THEME_NAME:
version: VERSION
css:
theme:
css/$THEME_NAME.css: {}
js:
js/$THEME_NAME.js: {}
EOF
git add "$DOCROOT_DIR/themes/custom/$THEME_NAME/$THEME_NAME.libraries.yml"
tee -a "$DOCROOT_DIR/themes/custom/$THEME_NAME/$THEME_NAME.info.yml" <<EOF
type: theme
core: 8.x
name: $THEME_NAME
base theme: stable
libraries:
- $THEME_NAME/$THEME_NAME
EOF
git add "$DOCROOT_DIR/themes/custom/$THEME_NAME/$THEME_NAME.info.yml"
git commit -m "Add a theme."
# Enable the theme.
lando drush theme-enable "$THEME_NAME"
lando drush -y config-set system.theme default "$THEME_NAME"
# We have to downgrade a few packages to satisfy both Drush and Mannequin's
# requirements.
lando composer require 'symfony/filesystem:^3'
lando composer require 'symfony/finder:^3'
git add "composer.json" "composer.lock"
git commit -m "Downgrade symfony/filesystem and symfony/finder to satisfy both drush/drush and lastcall/mannequin-drupal."
# Set up mannequin.
lando composer require lastcall/mannequin-drupal
git add "composer.json" "composer.lock"
tee -a ".mannequin.php" <<EOF
<?php
use LastCall\Mannequin\Core\MannequinConfig;
use LastCall\Mannequin\Drupal\DrupalExtension;
use Symfony\Component\Finder\Finder;
\$drupalFinder = Finder::create()
->in(__DIR__ . '/$DOCROOT_DIR/themes/custom/$THEME_NAME/templates')
->files()
->name('*.twig');
\$drupalExtension = new DrupalExtension([
'finder' => \$drupalFinder,
'drupal_root' => __DIR__ . '/$DOCROOT_DIR/',
]);
return MannequinConfig::create()
->addExtension(\$drupalExtension)
->setGlobalJs([
__DIR__ . '/$DOCROOT_DIR/themes/custom/$THEME_NAME/js/theme.js'
])
->setGlobalCss([
__DIR__ . '/$DOCROOT_DIR/themes/custom/$THEME_NAME/js/theme.js'
]);
EOF
git add ".mannequin.php"
git commit -m "Add lastcall/mannequin-drupal."
# Add Lando tooling for mannequin.
tee -a ".lando.yml" <<EOF
services:
mannequin:
type: compose
services:
image: mparker17/mannequin-drupal
command: '/app/vendor/bin/mannequin start *:80'
ports:
- '80'
EOF
git add ".lando.yml"
git commit -m "Add lando tooling for lastcall/mannequin-drupal."
lando -y rebuild
lando mannequin start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment