Skip to content

Commit

Permalink
[#3] Automatic code formatting & linting (#12)
Browse files Browse the repository at this point in the history
* [#3] Add prettier and .editorconfig

* [#3] Run `prettier . --write`

* [#3] Install & configure eslint

* [#3] Install PHP ECS and run fix

* [#3] Install and configure PHPStan

* [#3] Install Husky

- npm install --save-dev husky
- npx husky init

Add DDEV configs to ensure Husky is connected to the user & DDEV's Git processes

* [#3] Install & configure lint-staged

This runs our linters & formatters on just the files that have changed.

* [#3] eslint disallow console.log

* [#3] Remove npm run prepare from ddev.

Apparently `prepare` runs after each npm install.

https://typicode.github.io/husky/how-to.html#manual-setup

* [#3] PR Feedback
  • Loading branch information
joshuapease authored May 22, 2024
1 parent 2e733b5 commit 06e90d3
Show file tree
Hide file tree
Showing 25 changed files with 1,948 additions and 648 deletions.
20 changes: 12 additions & 8 deletions .ddev/config.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
name: craft-starter
type: craftcms
docroot: web
php_version: "8.2"
php_version: '8.2'
webserver_type: nginx-fpm
xdebug_enabled: false
additional_hostnames: []
additional_fqdns: []
database:
type: mysql
version: "8.0"
type: mysql
version: '8.0'
use_dns_when_possible: true
composer_version: "2"
composer_version: '2'
web_environment: []
nodejs_version: "18"
nodejs_version: '18'
hooks:
post-start:
- composer: install
# Ensures that lint-staged runs properly in ddev container
- exec: git config --global --add safe.directory /var/www/html
web_extra_exposed_ports:
# Expose ports for vite
- name: vite
Expand All @@ -24,7 +29,6 @@ web_extra_daemons:
- name: 'vite'
command: 'npm install && npm run dev'
directory: /var/www/html

# Key features of ddev's config.yaml:

# name: <projectname> # Name of the project, automatically provides
Expand Down Expand Up @@ -61,7 +65,7 @@ web_extra_daemons:
# "ddev xhprof" to enable xhprof and "ddev xhprof off" to disable it work better,
# as leaving xhprof enabled all the time is a big performance hit.

# webserver_type: nginx-fpm, apache-fpm, or nginx-gunicorn
# webserver_type: nginx-fpm, apache-fpm, or nginx-gunicorn

# timezone: Europe/Berlin
# This is the timezone used in the containers and by PHP;
Expand Down Expand Up @@ -103,7 +107,7 @@ web_extra_daemons:
# Please take care with this because it can cause great confusion.

# upload_dirs: "custom/upload/dir"
#
#
# upload_dirs:
# - custom/upload/dir
# - ../private
Expand Down
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# http://EditorConfig.org

root = true

# Unix-style newlines with a newline ending every file
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.csv]
insert_final_newline = false

[*.{php,py}]
indent_size = 4

# https://www.markdownguide.org/basic-syntax/#line-breaks
[*.md]
trim_trailing_whitespace = false
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
.DS_Store
node_modules
/web/dist
/.vite
/.vite
php-cs-fixer.cache
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ddev exec npx lint-staged
9 changes: 9 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
.vscode
composer.lock
composer.json
vendor
config/project
storage
web
package-lock.json
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all"
}
12 changes: 7 additions & 5 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# Architecture

## Goals

- As simple as possible
- Easy to contribute
- Easy to contribute
- Use PHP/Composer as much as possible for setup scripts
- Easy to test changes
- Make it easy to `ddev start` this repo and test your plugin and build tool changes.
- It should feel like you're working on a typical Craft project
- Make it easy to `ddev start` this repo and test your plugin and build tool changes.
- It should feel like you're working on a typical Craft project
- Cross-platform (Mac, Windows, Linux)
- We can achieve this by using PHP/Composer and running scripts from within Docker containers.
- We can achieve this by using PHP/Composer and running scripts from within Docker containers.

## Overview

This starter is a Composer "project" that can be installed using `composer create-project`.

composer.json has a `post-create-project-cmd` [script](https://getcomposer.org/doc/articles/scripts.md) that will run after the project is created.

We use this hook to start the installation process (modify and delete files, edit config, etc).

Some aspects of the installation are single line bash scripts. However, more complex actions are handled by PHP files in the [install-scripts](/install-scripts) directory
Some aspects of the installation are single line bash scripts. However, more complex actions are handled by PHP files in the [install-scripts](/install-scripts) directory
45 changes: 25 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
# Getting Started

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.
Our starter uses DDEV for local development. Install it before doing any of the following steps.

## Create Project

1. [Install DDEV](https://ddev.readthedocs.io/en/stable/users/install/ddev-installation/)
2. Choose a folder for your project and move into it:
```shell
cd /path/to/web/projects
mkdir my-project
cd my-project
```
```shell
cd /path/to/web/projects
mkdir my-project
cd my-project
```
3. Create The Project
If you already have PHP and Composer running on your host machine (your computer, not Docker container or DDEV instance), you can run the following command
```shell
composer create-project viget/craft-site-starter=^5.0.0 ./ --ignore-platform-reqs
```

If you'd rather not set up PHP, you can create the project with a desposable Docker image ([Thanks nystudio107](https://nystudio107.com/blog/dock-life-using-docker-for-all-the-things)).
```shell
docker run --rm -it -v "$PWD":/app -v ${COMPOSER_HOME:-$HOME/.composer}:/tmp composer create-project viget/craft-site-starter=^5.0.0 ./ --ignore-platform-reqs
```
If you already have PHP and Composer running on your host machine (your computer, not Docker container or DDEV instance), you can run the following command

```shell
composer create-project viget/craft-site-starter=^5.0.0 ./ --ignore-platform-reqs
```

If you'd rather not set up PHP, you can create the project with a desposable Docker image ([Thanks nystudio107](https://nystudio107.com/blog/dock-life-using-docker-for-all-the-things)).

```shell
docker run --rm -it -v "$PWD":/app -v ${COMPOSER_HOME:-$HOME/.composer}:/tmp composer create-project viget/craft-site-starter=^5.0.0 ./ --ignore-platform-reqs
```

4. Start DDEV & Install Craft
```shell
ddev start
ddev craft install
```
```shell
ddev start
ddev craft install
```
5. Run `ddev launch` to open the project in your browser

# Contribute to this starter

## Local Dev

Ideally, you should be able to clone this repo and make modifications to plugin & build tool configs with minimal fuss.

Run `ddev start` and make edits in a feature branch.

See [ARCHITECTURE.md](ARCHITECTURE.md) for details on technical goals & decisions.
See [ARCHITECTURE.md](ARCHITECTURE.md) for details on technical goals & decisions.
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"vlucas/phpdotenv": "^5.4.0"
},
"require-dev": {
"craftcms/ecs": "dev-main",
"craftcms/generator": "^2.0.0",
"craftcms/phpstan": "dev-main",
"yiisoft/yii2-shell": "^2.0.3"
},
"autoload": {
Expand Down Expand Up @@ -44,6 +46,9 @@
],
"post-root-package-install": [
"@php -r \"file_exists('.env') || copy('.env.example.dev', '.env');\""
]
],
"ecs-check": "ecs check --ansi",
"ecs-fix": "ecs check --ansi --fix",
"phpstan": "phpstan --memory-limit=1G"
}
}
Loading

0 comments on commit 06e90d3

Please sign in to comment.