Skip to content

Commit

Permalink
[#97] Renamed code to use 'extension' instead of 'module'.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Jan 17, 2024
1 parent 455eab8 commit 5c20205
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @see https://github.com/AlexSkrypnyk/drupal_module_scaffold
# @see https://github.com/AlexSkrypnyk/drupal_extension_scaffold
version: 2

aliases:
Expand Down
30 changes: 18 additions & 12 deletions .devtools/build-codebase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# testing backward compatibility).
#
# - Retrieves the scaffold from drupal-composer/drupal-project or custom scaffold.
# - Builds Drupal site codebase with current module and it's dependencies.
# - Builds Drupal site codebase with current extension and it's dependencies.
# - Adds development dependencies.
# - Installs composer dependencies.
#
Expand Down Expand Up @@ -50,9 +50,12 @@ echo "> Validate tools."
! command -v composer >/dev/null && echo "ERROR: Composer (https://getcomposer.org/) is required for this script to run." && exit 1
! command -v jq >/dev/null && echo "ERROR: jq (https://stedolan.github.io/jq/) is required for this script to run." && exit 1

# Module name, taken from the .info file.
module="$(basename -s .info.yml -- ./*.info.yml)"
[ "${module}" == "*" ] && echo "ERROR: No .info.yml file found." && exit 1
# Extension name, taken from the .info file.
extension="$(basename -s .info.yml -- ./*.info.yml)"
[ "${extension}" == "*" ] && echo "ERROR: No .info.yml file found." && exit 1

# Extension type.
type=$(grep -q "type: theme" "${extension}.info.yml" && echo "themes" || echo "modules")

echo "> Validate Composer configuration."
composer validate --ansi --strict
Expand Down Expand Up @@ -83,18 +86,21 @@ fi
echo "> Merge configuration from composer.dev.json."
php -r "echo json_encode(array_replace_recursive(json_decode(file_get_contents('composer.dev.json'), true),json_decode(file_get_contents('build/composer.json'), true)),JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);" >"build/composer2.json" && mv -f "build/composer2.json" "build/composer.json"

echo "> Merge configuration from module's composer.json."
echo "> Merge configuration from extension's composer.json."
php -r "echo json_encode(array_replace_recursive(json_decode(file_get_contents('composer.json'), true),json_decode(file_get_contents('build/composer.json'), true)),JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);" >"build/composer2.json" && mv -f "build/composer2.json" "build/composer.json"

echo "> Create GitHub authentication token if provided."
[ -n "${GITHUB_TOKEN:-}" ] && composer config --global github-oauth.github.com "${GITHUB_TOKEN}" && echo "Token: " && composer config --global github-oauth.github.com

echo "> Create custom directories."
mkdir -p build/web/modules/custom build/web/themes/custom

echo "> Install dependencies."
composer --working-dir="build" install

# Suggested dependencies allow to install them for testing without requiring
# them in module's composer.json.
echo "> Install suggested dependencies from module's composer.json."
# them in extension's composer.json.
echo "> Install suggested dependencies from extension's composer.json."
composer_suggests=$(cat composer.json | jq -r 'select(.suggest != null) | .suggest | keys[]')
for composer_suggest in $composer_suggests; do
composer --working-dir="build" require "${composer_suggest}"
Expand All @@ -103,14 +109,14 @@ done
echo "> Copy tools configuration files."
cp phpcs.xml phpstan.neon phpmd.xml rector.php .twig_cs.php "build/"

echo "> Symlink module code."
rm -rf "build/web/modules/custom" >/dev/null && mkdir -p "build/web/modules/custom/${module}"
ln -s "$(pwd)"/* "build/web/modules/custom/${module}" && rm "build/web/modules/custom/${module}/build"
echo "> Symlink extension's code."
rm -rf "build/web/${type}/custom" >/dev/null && mkdir -p "build/web/${type}/custom/${extension}"
ln -s "$(pwd)"/* "build/web/${type}/custom/${extension}" && rm "build/web/${type}/custom/${extension}/build"

# If front-end dependencies are used in the project, package-lock.json is
# expected to be committed to the repository.
if [ -f "build/web/modules/custom/${module}/package-lock.json" ]; then
pushd "build/web/modules/custom/${module}" >/dev/null || exit 1
if [ -f "build/web/${type}/custom/${extension}/package-lock.json" ]; then
pushd "build/web/${type}/custom/${extension}" >/dev/null || exit 1
echo "> Install front-end dependencies."
[ -f ".nvmrc" ] && nvm use || true
[ ! -d "node_modules" ] && npm ci || true
Expand Down
18 changes: 9 additions & 9 deletions .devtools/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ DRUPAL_PROFILE="${DRUPAL_PROFILE:-standard}"

#-------------------------------------------------------------------------------

echo "-------------------------------"
echo " Install Drupal and modules "
echo "-------------------------------"
echo "----------------------------------"
echo " Install Drupal and extensions "
echo "----------------------------------"

drush() { "build/vendor/bin/drush" -r "$(pwd)/build/web" -y "$@"; }

# Module name, taken from .info file.
module="$(basename -s .info.yml -- ./*.info.yml)"
[ "${module}" == "*" ] && echo "ERROR: No .info.yml file found." && exit 1
# Extension name, taken from .info file.
extension="$(basename -s .info.yml -- ./*.info.yml)"
[ "${extension}" == "*" ] && echo "ERROR: No .info.yml file found." && exit 1

# Database file path.
db_file="/tmp/site_${module}.sqlite"
db_file="/tmp/site_${extension}.sqlite"

echo "> Install Drupal into SQLite database ${db_file}."
drush si "${DRUPAL_PROFILE}" -y --db-url "sqlite://${db_file}" --account-name=admin install_configure_form.enable_update_status_module=NULL install_configure_form.enable_update_status_emails=NULL
drush status

echo "> Enable module ${module}."
drush pm:enable "${module}" -y
echo "> Enable extension ${extension}."
drush pm:enable "${extension}" -y
drush cr

echo "> Enable suggested modules, if any."
Expand Down
10 changes: 5 additions & 5 deletions .devtools/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ echo "> Run tests."
# Do not fail if there are no tests.
[ ! -d "tests" ] && echo "> No tests were found. Skipping." && exit 0

# Module name, taken from .info file.
module="$(basename -s .info.yml -- ./*.info.yml)"
[ "${module}" == "*" ] && echo "ERROR: No .info.yml file found." && exit 1
# Extension name, taken from .info file.
extension="$(basename -s .info.yml -- ./*.info.yml)"
[ "${extension}" == "*" ] && echo "ERROR: No .info.yml file found." && exit 1

# Test database file path.
test_db_file="/tmp/test_${module}.sqlite"
test_db_file="/tmp/test_${extension}.sqlite"

# Re-create test results directory.
rm -rf "${TEST_RESULTS_DIR}" >/dev/null
Expand All @@ -50,4 +50,4 @@ php "./build/web/core/scripts/run-tests.sh" \
--color \
--verbose \
--suppress-deprecations \
--module "${module}"
--module "${extension}"
5 changes: 4 additions & 1 deletion .twig_cs.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@
->setSeverity('error')
->setReporter('console')
->setRuleSet(Twigcs\Ruleset\Official::class)
->addFinder(Twigcs\Finder\TemplateFinder::create()->in(__DIR__ . '/web/modules/custom'));
->addFinder(Twigcs\Finder\TemplateFinder::create()->in([
__DIR__ . '/web/modules/custom',
__DIR__ . '/web/themes/custom',
]));
52 changes: 27 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<p align="center">
<a href="" rel="noopener">
<img width=200px height=200px src="https://placehold.jp/000000/ffffff/200x200.png?text=Drupal+Module+Scaffold&css=%7B%22border-radius%22%3A%22%20100px%22%7D" alt="Yourproject logo"></a>
<img width=200px height=200px src="https://placehold.jp/000000/ffffff/200x200.png?text=Drupal+Extension+Scaffold&css=%7B%22border-radius%22%3A%22%20100px%22%7D" alt="Yourproject logo"></a>
</p>

<h1 align="center">Drupal module scaffold</h1>
<h1 align="center">Drupal extension scaffold</h1>

<div align="center">

[![GitHub Issues](https://img.shields.io/github/issues/AlexSkrypnyk/drupal_module_scaffold.svg)](https://github.com/AlexSkrypnyk/drupal_module_scaffold/issues)
[![GitHub Pull Requests](https://img.shields.io/github/issues-pr/AlexSkrypnyk/drupal_module_scaffold.svg)](https://github.com/AlexSkrypnyk/drupal_module_scaffold/pulls)
[![CircleCI](https://circleci.com/gh/AlexSkrypnyk/drupal_module_scaffold.svg?style=shield)](https://circleci.com/gh/AlexSkrypnyk/drupal_module_scaffold)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/AlexSkrypnyk/drupal_module_scaffold)
![LICENSE](https://img.shields.io/github/license/AlexSkrypnyk/drupal_module_scaffold)
[![GitHub Issues](https://img.shields.io/github/issues/AlexSkrypnyk/drupal_extension_scaffold.svg)](https://github.com/AlexSkrypnyk/drupal_extension_scaffold/issues)
[![GitHub Pull Requests](https://img.shields.io/github/issues-pr/AlexSkrypnyk/drupal_extension_scaffold.svg)](https://github.com/AlexSkrypnyk/drupal_extension_scaffold/pulls)
[![CircleCI](https://circleci.com/gh/AlexSkrypnyk/drupal_extension_scaffold.svg?style=shield)](https://circleci.com/gh/AlexSkrypnyk/drupal_extension_scaffold)
![GitHub release (latest by date)](https://img.shields.io/github/v/release/AlexSkrypnyk/drupal_extension_scaffold)
![LICENSE](https://img.shields.io/github/license/AlexSkrypnyk/drupal_extension_scaffold)
![Renovate](https://img.shields.io/badge/renovate-enabled-green?logo=renovatebot)

![Drupal 9](https://img.shields.io/badge/Drupal-9-blue.svg) ![Drupal 10](https://img.shields.io/badge/Drupal-10-blue.svg)
Expand All @@ -20,11 +20,11 @@

---

<p align="center">Drupal module template for development and testing in CI of your choice with mirroring to Drupal.org</p>
<p align="center">Drupal extension template for development and testing in CI of your choice with mirroring to Drupal.org</p>

## Use case

Perform module development in GitHub with testing in CI, and push code
Perform extension development in GitHub with testing in CI, and push code
committed only to main branches (`1.x`, `2.x` etc.)
to [drupal.org](https://drupal.org).

Expand All @@ -48,7 +48,7 @@ to [drupal.org](https://drupal.org).
[drupal.org](https://drupal.org)'s Drupal CI
bot (`core/scripts/run-tests.sh`).
- Support for including of additional dependencies for integration testing
between modules (add dependency into [`suggest`](composer.json#L25) section
between extensions (add dependency into [`suggest`](composer.json#L25) section
of `composer.json`).
- Uses [drupal-composer/drupal-project](https://github.com/drupal-composer/drupal-project)
to provision Drupal site. Providing a custom fork of `drupal-project` is also supported.
Expand All @@ -62,15 +62,17 @@ to [drupal.org](https://drupal.org).

<img src="https://user-images.githubusercontent.com/378794/253860380-7a702bf6-71f5-4c8c-a271-8dd3b25eaabf.png" alt="Screenshot of CI jobs" width="30%">

## Usage
## Setup

1. Create your module's repository on GitHub.
2. Download this module's code by pressing 'Clone or download' button in GitHub
1. Create your extension's repository on GitHub.
2. Download this extension's code by pressing 'Clone or download' button in GitHub
UI.
3. Copy the contents of the downloaded archive into your module's repository.
4. Replace `drupal_module_scaffold` with the machine name of your module.
5. Adjust several lines in `.gitattributes`.
6. Remove `.github/test-scaffold.yml` file.
3. Copy the contents of the downloaded archive into your extension's repository.
4. Adjust the codebase:
a. Replace `drupal_extension_scaffold` with the machine name of your extension:
b. Update `type: theme` in the `info.yml` file if your extension is a theme.
c. Adjust several lines in `.gitattributes`.
d. Remove `.github/test-scaffold.yml` file.
7. Commit and push to your new GitHub repo.
8. Login to your CI and add your new GitHub repository. Your project build will
start momentarily.
Expand All @@ -86,7 +88,7 @@ The deployment job runs when commits are pushed to main branches
(`1.x`, `2.x`, `10.x-1.x` etc.) or when release tags are created.

Example of deployment
repository: https://github.com/AlexSkrypnyk/drupal_module_scaffold_destination
repository: https://github.com/AlexSkrypnyk/drupal_extension_scaffold_destination

### Configure deployment

Expand Down Expand Up @@ -114,28 +116,28 @@ ssh-keygen -m PEM -t rsa -b 4096 -C "[email protected]"
remote repository (i.e., your name on drupal.org).
- `DEPLOY_USER_EMAIL` - the email address of the user who will be committing
to a remote repository (i.e., your email on drupal.org).
- `DEPLOY_REMOTE` - your modules remote drupal.org repository (
i.e. `[email protected]:project/mymodule.git`).
- `DEPLOY_REMOTE` - your extensions remote drupal.org repository (
i.e. `[email protected]:project/myextension.git`).
- `DEPLOY_PROCEED` - set to `1` once CI is working, and you are ready to
deploy.

## Maintenance / Local development

Provided that you have PHP installed locally, you can develop a module using
Provided that you have PHP installed locally, you can develop an extension using
the provided scripts.

### Build

Run `.devtools/build.sh` (or `ahoy build`
if [Ahoy](https://github.com/ahoy-cli/ahoy) is installed) to start inbuilt PHP
server locally and run the same commands as in CI, plus installing a site and
your module automatically.
your extension automatically.

![Build process](https://user-images.githubusercontent.com/378794/253732550-20bd3877-cabb-4a5a-b9a6-ffb5fe6c8e3e.gif)

### Code linting

Run `.devtools/lint.sh` (or `ahoy lint`
Run tools individually (or `ahoy lint` to run all tools
if [Ahoy](https://github.com/ahoy-cli/ahoy) is installed) to lint your code
according to
the [Drupal coding standards](https://www.drupal.org/docs/develop/standards).
Expand All @@ -152,14 +154,14 @@ the [Drupal coding standards](https://www.drupal.org/docs/develop/standards).

Run `.devtools/test.sh` (or `ahoy test`
if [Ahoy](https://github.com/ahoy-cli/ahoy) is installed) to run all test for
your module.
your extension.

![Test process](https://user-images.githubusercontent.com/378794/253732542-ea1b2f29-ce89-41bd-b92a-169b119731d3.gif)

### Browsing SQLite database

To browse the contents of created SQLite database
(located at `/tmp/site_[MODULE_NAME].sqlite`),
(located at `/tmp/site_[EXTENSION_NAME].sqlite`),
use [DB Browser for SQLite](https://sqlitebrowser.org/).

---
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drupal/drupal_module_scaffold",
"description": "Drupal module scaffold example used for template testing.",
"name": "drupal/drupal_extension_scaffold",
"description": "Drupal module scaffold example.",
"type": "drupal-module",
"license": "GPL-2.0-or-later",
"authors": [
Expand All @@ -11,10 +11,10 @@
"role": "Maintainer"
}
],
"homepage": "https://drupal.org/project/drupal_module_scaffold",
"homepage": "https://drupal.org/project/drupal_extension_scaffold",
"support": {
"issues": "https://drupal.org/project/issues/drupal_module_scaffold",
"source": "https://git.drupalcode.org/project/drupal_module_scaffold"
"issues": "https://drupal.org/project/issues/drupal_extension_scaffold",
"source": "https://git.drupalcode.org/project/drupal_extension_scaffold"
},
"require": {
"php": ">=8.1"
Expand Down
8 changes: 8 additions & 0 deletions drupal_extension_scaffold.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Drupal extension scaffold
type: module
description: Drupal extension scaffold example.
package: Testing
core_version_requirement: ^9 || ^10

dependencies:
- drupal:user
8 changes: 0 additions & 8 deletions drupal_module_scaffold.info.yml

This file was deleted.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@drupal/drupal_module_scaffold",
"name": "@drupal/drupal_extension_scaffold",
"version": "0.1.0",
"description": "Drupal module scaffold FE example used for template testing.",
"license": "GPL-2.0-or-later",
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<description>Custom PHPCS Standard, based on Drupal standards.</description>

<file>web/modules/custom</file>
<file>web/sites/default/settings.php</file>
<file>web/themes/custom</file>

<rule ref="Drupal"/>
<rule ref="DrupalPractice"/>
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ parameters:

paths:
- web/modules/custom
- web/themes/custom

excludePaths:
- vendor/*
Expand Down
6 changes: 3 additions & 3 deletions tests/src/Functional/DemoRoleFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types = 1);

namespace Drupal\Tests\drupal_module_scaffold\Functional;
namespace Drupal\Tests\drupal_extension_scaffold\Functional;

use Drupal\Tests\BrowserTestBase;

Expand All @@ -11,14 +11,14 @@
*
* Role testing for demo module.
*
* @group drupal_module_scaffold
* @group drupal_extension_scaffold
*/
class DemoRoleFunctionalTest extends BrowserTestBase {

/**
* {@inheritdoc}
*/
protected static $modules = ['pathauto', 'drupal_module_scaffold'];
protected static $modules = ['pathauto', 'drupal_extension_scaffold'];

/**
* {@inheritdoc}
Expand Down
4 changes: 2 additions & 2 deletions tests/src/Unit/ExampleUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types = 1);

namespace Drupal\Tests\drupal_module_scaffold\Unit;
namespace Drupal\Tests\drupal_extension_scaffold\Unit;

use Drupal\Tests\UnitTestCase;

Expand All @@ -11,7 +11,7 @@
*
* Demo test class to ensure that tests are discovered and can be ran.
*
* @group drupal_module_scaffold
* @group drupal_extension_scaffold
*/
class ExampleUnitTest extends UnitTestCase {

Expand Down

0 comments on commit 5c20205

Please sign in to comment.