Skip to content

Commit

Permalink
[#14, #20, #21] include project config, Mailpit setup (#22)
Browse files Browse the repository at this point in the history
* [#14] Install Craft & Plugins. Commit project config

* [#21] Route all email through Mailpit

https://mailpit.axllent.org/

* [#20] Rename project config in post-create-project script

* [#20] Adjust ddev config renaming

* [#20] Rename package.json & package-lock.json

* [#20] Remove plugin license lines

* [#20] Clean up starter only .gitignore

* [#20] Clean out unused ScriptHelpers

* [#20] PC changes
  • Loading branch information
joshuapease authored May 31, 2024
1 parent cce8b08 commit a349449
Show file tree
Hide file tree
Showing 18 changed files with 260 additions and 111 deletions.
7 changes: 6 additions & 1 deletion .ddev/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ database:
version: '8.0'
use_dns_when_possible: true
composer_version: '2'
web_environment: []
web_environment:
# Use Mailpit
- SYSTEM_EMAIL_HOSTNAME=localhost
- SYSTEM_EMAIL_PORT=1025
- SYSTEM_EMAIL_USERNAME=abc
- SYSTEM_EMAIL_PASSWORD=123
nodejs_version: '18'
hooks:
post-start:
Expand Down
8 changes: 8 additions & 0 deletions .env.example.dev
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ CRAFT_APP_ID=
# The environment Craft is currently running in (dev, staging, production, etc.)
CRAFT_ENVIRONMENT=dev

# Email
[email protected]
SYSTEM_EMAIL_SENDER="Craft CMS"
SYSTEM_EMAIL_HOSTNAME=
SYSTEM_EMAIL_PORT=
SYSTEM_EMAIL_USERNAME=
SYSTEM_EMAIL_PASSWORD=

# Database connection settings
CRAFT_DB_DRIVER=mysql
CRAFT_DB_SERVER=127.0.0.1
Expand Down
7 changes: 7 additions & 0 deletions .env.example.production
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ CRAFT_APP_ID=
# The environment Craft is currently running in (dev, staging, production, etc.)
CRAFT_ENVIRONMENT=production

# Email
[email protected]
SYSTEM_EMAIL_HOSTNAME=
SYSTEM_EMAIL_PORT=
SYSTEM_EMAIL_USERNAME=
SYSTEM_EMAIL_PASSWORD=

# Database connection settings
CRAFT_DB_DRIVER=mysql
CRAFT_DB_SERVER=127.0.0.1
Expand Down
7 changes: 7 additions & 0 deletions .env.example.staging
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ CRAFT_APP_ID=
# The environment Craft is currently running in (dev, staging, production, etc.)
CRAFT_ENVIRONMENT=staging

# Email
[email protected]
SYSTEM_EMAIL_HOSTNAME=
SYSTEM_EMAIL_PORT=
SYSTEM_EMAIL_USERNAME=
SYSTEM_EMAIL_PASSWORD=

# Database connection settings
CRAFT_DB_DRIVER=mysql
CRAFT_DB_SERVER=127.0.0.1
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ node_modules
/web/dist
/.vite
php-cs-fixer.cache

# BEGIN-STARTER-ONLY
config/license.key
# END-STARTER-ONLY
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
# Getting Started
# Viget's Craft CMS Starter

This repo is a Composer "project" intended for use with the `composer create-project` command.

Our starter uses DDEV for local development. Install it before doing any of the following steps.

# Features

- Local development [powered by DDEV](https://ddev.com/)
- [Vite](https://vitejs.dev/) based front-end build tooling.
- Automatic linting, formatting and typechecking
- Runs on git pre-commit hook with [Husky](https://typicode.github.io/husky/)
- Only processes staged files using [lint-staged](https://github.com/lint-staged/lint-staged)
- [Prettier](https://prettier.io/), [eslint](https://eslint.org/), [PHPStan](https://github.com/craftcms/phpstan), [PHP
Easy Coding Standard](https://github.com/craftcms/ecs)
- Common plugins come pre-installed
- Local email is routed
through [Mailpit](https://ddev.readthedocs.io/en/stable/users/usage/developer-tools/#email-capture-and-review-mailpit) (
never worry about emailing a client or user)

# Getting Started

## Create Project

1. [Install DDEV](https://ddev.readthedocs.io/en/stable/users/install/ddev-installation/)
Expand Down
11 changes: 11 additions & 0 deletions composer-scripts/ScriptHelpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

class ScriptHelpers
{
public static function replaceFileText(string $filePath, string $pattern, string $replacement): void
{
$fileContent = file_get_contents($filePath);
$fileContent = preg_replace($pattern, $replacement, $fileContent);
file_put_contents($filePath, $fileContent);
}
}
94 changes: 94 additions & 0 deletions composer-scripts/post-create-project.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

use craft\helpers\Console;
use craft\helpers\StringHelper;

require_once 'ScriptHelpers.php';
require_once 'vendor/autoload.php';

$cwd = getcwd();

/**
* Prompt the user for input
*/
$projectName = Console::prompt('What is the name of your project (Example: My Client Name)? ', [
'required' => true,
]);

Console::output("Great! We'll use the name: $projectName");

$suggestedProjectSlug = StringHelper::toKebabCase($projectName);

$projectSlugPrompt = Console::prompt("Customize the project slug? This controls the DDEV URL, etc.", [
'default' => $suggestedProjectSlug,
]);

$projectSlug = !empty(trim($projectSlugPrompt)) ? StringHelper::toKebabCase($projectSlugPrompt) : $suggestedProjectSlug;

Console::output("Great! We'll use $projectSlug");

/**
* Update DDEV config
*/

ScriptHelpers::replaceFileText(
filePath: "$cwd/.ddev/config.yaml",
pattern: "/name:\s+viget-craft-starter/",
replacement: "name: $projectSlug",
);

/**
* Update package.json
*/

ScriptHelpers::replaceFileText(
filePath: "$cwd/package.json",
pattern: "/\"name\": \"viget-craft-starter\"/",
replacement: "\"name\": \"$projectSlug\"",
);

ScriptHelpers::replaceFileText(
filePath: "$cwd/package-lock.json",
pattern: "/\"name\": \"viget-craft-starter\"/",
replacement: "\"name\": \"$projectSlug\"",
);

/**
* Update project config
*/

ScriptHelpers::replaceFileText(
filePath: "$cwd/config/project/project.yaml",
pattern: "/Viget Craft Starter/",
replacement: "$projectName",
);

// Replace plugin license keys.
// These are regenerated when viewing the Control Panel
ScriptHelpers::replaceFileText(
filePath: "$cwd/config/project/project.yaml",
pattern: "/ licenseKey: REPLACE[\r\n|\r|\n]/", // Make sure to remove new line too
replacement: "",
);

ScriptHelpers::replaceFileText(
filePath: "$cwd/config/project/siteGroups/805d8826-faed-4186-9b88-f509eb9b07e6.yaml",
pattern: "/Viget Craft Starter/",
replacement: "$projectName",
);

ScriptHelpers::replaceFileText(
filePath: "$cwd/config/project/sites/default--35b563a0-4662-40b9-b885-a8450a2868d9.yaml",
pattern: "/Viget Craft Starter/",
replacement: "$projectName",
);

/**
* .gitignore
*/

ScriptHelpers::replaceFileText(
filePath: "$cwd/.gitignore",
pattern: "/# BEGIN-STARTER-ONLY\X*# END-STARTER-ONLY/m",
replacement: '',
);
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@
"scripts": {
"post-create-project-cmd": [
"@php -r \"file_exists('.env') || copy('.env.example.dev', '.env');\"",
"@php install-scripts/rename-ddev.php",
"@php composer-scripts/post-create-project.php",
"echo 'Cleaning composer.json'",
"@composer config --unset scripts.post-create-project-cmd",
"@composer config --unset name",
"@composer config --unset license",
"@composer config --unset type",
"@composer update --ignore-platform-reqs",
"@composer dump-autoload -o",
"rm -rf install-scripts "
"rm -rf composer-scripts"
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example.dev', '.env');\""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
headingLevels:
- 1
- 2
- 3
- 4
- 5
- 6
name: Simple
toolbar:
- heading
- '|'
- bold
- italic
- link
76 changes: 76 additions & 0 deletions config/project/project.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
dateModified: 1716932096
email:
fromEmail: $SYSTEM_EMAIL_FROM
fromName: 'Viget Craft Starter'
replyToEmail: null
template: null
transportSettings:
host: $SYSTEM_EMAIL_HOSTNAME
password: $SYSTEM_EMAIL_PASSWORD
port: $SYSTEM_EMAIL_PORT
useAuthentication: '1'
username: $SYSTEM_EMAIL_USERNAME
transportType: craft\mail\transportadapters\Smtp
meta:
__names__:
35b563a0-4662-40b9-b885-a8450a2868d9: 'Viget Craft Starter' # Viget Craft Starter
805d8826-faed-4186-9b88-f509eb9b07e6: 'Viget Craft Starter' # Viget Craft Starter
b7e66782-af96-4012-9e17-914134073ced: Simple # Simple
plugins:
aws-s3:
edition: standard
enabled: true
schemaVersion: '2.0'
ckeditor:
edition: standard
enabled: true
schemaVersion: 3.0.0.0
classnames:
edition: standard
enabled: true
schemaVersion: 3.0.0
cp-field-inspect:
edition: standard
enabled: true
schemaVersion: 1.0.0
empty-coalesce:
edition: standard
enabled: true
schemaVersion: 1.0.0
imager-x:
edition: lite
enabled: true
licenseKey: REPLACE
schemaVersion: 4.0.0
navigation:
edition: standard
enabled: true
licenseKey: REPLACE
schemaVersion: 2.1.0
retour:
edition: standard
enabled: true
licenseKey: REPLACE
schemaVersion: 3.0.12
seomatic:
edition: standard
enabled: true
licenseKey: REPLACE
schemaVersion: 3.0.12
vite:
edition: standard
enabled: true
schemaVersion: 1.0.0
system:
edition: solo
live: true
name: 'Viget Craft Starter'
schemaVersion: 5.0.0.20
timeZone: America/Los_Angeles
users:
allowPublicRegistration: false
defaultGroup: null
photoSubpath: null
photoVolumeUid: null
require2fa: false
requireEmailVerification: true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name: 'Viget Craft Starter'
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
baseUrl: $PRIMARY_SITE_URL
enabled: true
handle: default
hasUrls: true
language: en-US
name: 'Viget Craft Starter'
primary: true
siteGroup: 805d8826-faed-4186-9b88-f509eb9b07e6 # Viget Craft Starter
sortOrder: 1
Loading

0 comments on commit a349449

Please sign in to comment.