Skip to content

Commit

Permalink
Added composer based drupal installation files.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchauhan8726 committed Jun 18, 2018
1 parent 0760179 commit 8cb0086
Show file tree
Hide file tree
Showing 12 changed files with 365 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Copy and rename this file to .env at root of this project.
#

# A common use case is to supply database creds via the environment. Edit settings.php
# like so:
#
# $databases['default']['default'] = [
# 'database' => getenv('MYSQL_DATABASE'),
# 'driver' => 'mysql',
# 'host' => getenv('MYSQL_HOSTNAME'),
# 'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
# 'password' => getenv('MYSQL_PASSWORD'),
# 'port' => getenv('MYSQL_PORT'),
# 'prefix' => '',
# 'username' => getenv('MYSQL_USER'),
# ];
#
# Uncomment and populate as needed.
# MYSQL_DATABASE=
# MYSQL_HOSTNAME=
# MYSQL_PASSWORD=
# MYSQL_PORT=
# MYSQL_USER=

# Another common use case is to set Drush's --uri via environment.
# DRUSH_OPTIONS_URI=http://example.com
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Ignore directories generated by Composer
/drush/contrib/
/vendor/
/web/core/
/web/modules/contrib/
/web/themes/contrib/
/web/profiles/contrib/
/web/libraries/

# Ignore sensitive information
/web/sites/*/settings.php
/web/sites/*/settings.local.php

# Ignore Drupal's file directory
/web/sites/*/files/

# Ignore SimpleTest multi-site environment.
/web/sites/simpletest

# Ignore files generated by PhpStorm
/.idea/

# Ignore .env files as they are personal
/.env
49 changes: 49 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
language: php
dist: trusty
sudo: false

php:
- 5.6
- 7.0
- 7.1
- 7.2

env:
global:
- SIMPLETEST_DB=sqlite://tmp/site.sqlite
- SIMPLETEST_BASE_URL="http://127.0.0.1:8080"
matrix:
- RELEASE=stable COMPOSER_CHANNEL=stable
- RELEASE=dev COMPOSER_CHANNEL=stable
- RELEASE=stable COMPOSER_CHANNEL=snapshot

matrix:
exclude:
- php: 7.2
env: RELEASE=stable COMPOSER_CHANNEL=stable
- php: 7.2
env: RELEASE=stable COMPOSER_CHANNEL=snapshot

before_install:
- echo 'sendmail_path = /bin/true' >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- phpenv config-rm xdebug.ini
- composer --verbose self-update --$COMPOSER_CHANNEL
- composer --version

install:
- composer --verbose validate
- composer --verbose install

script:
- if [[ $RELEASE = dev ]]; then composer --verbose remove --no-update drupal/console; fi;
- if [[ $RELEASE = dev ]]; then composer --verbose require --no-update drupal/core:8.6.x-dev webflo/drupal-core-require-dev:8.6.x-dev; fi;
- if [[ $RELEASE = dev ]]; then composer --verbose update; fi;
- cd $TRAVIS_BUILD_DIR/web
- ./../vendor/bin/drush site-install --verbose --yes --db-url=sqlite://tmp/site.sqlite
- ./../vendor/bin/drush runserver $SIMPLETEST_BASE_URL &
- until curl -s $SIMPLETEST_BASE_URL; do true; done > /dev/null
# Skip core/tests/Drupal/Tests/ComposerIntegrationTest.php because web/ has no composer.json
# Ignore PageCache group temporarily, @see https://www.drupal.org/node/2770673
- ./../vendor/bin/phpunit -c core --testsuite unit --exclude-group Composer,DependencyInjection,PageCache
- ./../vendor/bin/drush
- if [[ $RELEASE = stable ]]; then ./../vendor/bin/drupal; fi;
Empty file modified README.md
100644 → 100755
Empty file.
70 changes: 70 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"name": "openhotel",
"description": "Project template for Drupal 8 projects with composer",
"type": "project",
"license": "GPL-2.0-or-later",
"authors": [
{
"name": "",
"role": ""
}
],
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
}
],
"require": {
"composer/installers": "^1.2",
"cweagans/composer-patches": "^1.6",
"drupal-composer/drupal-scaffold": "^2.5",
"drupal/console": "^1.0.2",
"drupal/core": "~8.5.3",
"drush/drush": "^9.0.0",
"vlucas/phpdotenv": "^2.4",
"webflo/drupal-finder": "^1.0.0",
"webmozart/path-util": "^2.3"
},
"require-dev": {
"webflo/drupal-core-require-dev": "~8.5.3"
},
"conflict": {
"drupal/drupal": "*"
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"sort-packages": true
},
"autoload": {
"classmap": [
"scripts/composer/ScriptHandler.php"
],
"files": ["load.environment.php"]
},
"scripts": {
"pre-install-cmd": [
"DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
],
"pre-update-cmd": [
"DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
],
"post-install-cmd": [
"DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
],
"post-update-cmd": [
"DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
]
},
"extra": {
"installer-paths": {
"web/core": ["type:drupal-core"],
"web/libraries/{$name}": ["type:drupal-library"],
"web/modules/contrib/{$name}": ["type:drupal-module"],
"web/profiles/contrib/{$name}": ["type:drupal-profile"],
"web/themes/contrib/{$name}": ["type:drupal-theme"],
"drush/Commands/{$name}": ["type:drupal-drush"]
}
}
}
39 changes: 39 additions & 0 deletions drush/Commands/PolicyCommands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Drush\Commands;

use Consolidation\AnnotatedCommand\CommandData;
use Drush\Commands\DrushCommands;

/**
* Edit this file to reflect your organization's needs.
*/
class PolicyCommands extends DrushCommands {

/**
* Prevent catastrophic braino. Note that this file has to be local to the
* machine that initiates the sql:sync command.
*
* @hook validate sql:sync
*
* @throws \Exception
*/
public function sqlSyncValidate(CommandData $commandData) {
if ($commandData->input()->getArgument('target') == '@prod') {
throw new \Exception(dt('Per !file, you may never overwrite the production database.', ['!file' => __FILE__]));
}
}

/**
* Limit rsync operations to production site.
*
* @hook validate core:rsync
*
* @throws \Exception
*/
public function rsyncValidate(CommandData $commandData) {
if (preg_match("/^@prod/", $commandData->input()->getArgument('target'))) {
throw new \Exception(dt('Per !file, you may never rsync to the production site.', ['!file' => __FILE__]));
}
}
}
1 change: 1 addition & 0 deletions drush/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This directory contains commands, configuration and site aliases for Drush. See https://packagist.org/search/?type=drupal-drush for a directory of Drush commands installable via Composer.
6 changes: 6 additions & 0 deletions drush/drush.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# A Drush configuration file
#
# Docs at https://github.com/drush-ops/drush/blob/master/examples/example.drush.yml
#
# Edit or remove this file as needed.
14 changes: 14 additions & 0 deletions drush/sites/self.site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Edit or remove this file as needed.
# Docs at https://github.com/drush-ops/drush/blob/master/examples/example.site.yml

#prod:
# host: prod.domain.com
# user: www-admin
# root: /path/to/drupal
# uri: http://www.example.com
#
#stage:
# host: stage.domain.com
# user: www-admin
# root: /path/to/drupal
# uri: http://stage.example.com
20 changes: 20 additions & 0 deletions load.environment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/**
* This file is included very early. See autoload.files in composer.json and
* https://getcomposer.org/doc/04-schema.md#files
*/

use Dotenv\Dotenv;
use Dotenv\Exception\InvalidPathException;

/**
* Load any .env file. See /.env.example.
*/
$dotenv = new Dotenv(__DIR__);
try {
$dotenv->load();
}
catch (InvalidPathException $e) {
// Do nothing. Production environments rarely use .env files.
}
15 changes: 15 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
verbose="true"
>
<testsuites>
<testsuite name="drupal-composer-project tests">
<directory>./test/</directory>
</testsuite>
</testsuites>
</phpunit>
100 changes: 100 additions & 0 deletions scripts/composer/ScriptHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php

/**
* @file
* Contains \DrupalProject\composer\ScriptHandler.
*/

namespace DrupalProject\composer;

use Composer\Script\Event;
use Composer\Semver\Comparator;
use DrupalFinder\DrupalFinder;
use Symfony\Component\Filesystem\Filesystem;
use Webmozart\PathUtil\Path;

class ScriptHandler {

public static function createRequiredFiles(Event $event) {
$fs = new Filesystem();
$drupalFinder = new DrupalFinder();
$drupalFinder->locateRoot(getcwd());
$drupalRoot = $drupalFinder->getDrupalRoot();

$dirs = [
'modules',
'profiles',
'themes',
];

// Required for unit testing
foreach ($dirs as $dir) {
if (!$fs->exists($drupalRoot . '/'. $dir)) {
$fs->mkdir($drupalRoot . '/'. $dir);
$fs->touch($drupalRoot . '/'. $dir . '/.gitkeep');
}
}

// Prepare the settings file for installation
if (!$fs->exists($drupalRoot . '/sites/default/settings.php') and $fs->exists($drupalRoot . '/sites/default/default.settings.php')) {
$fs->copy($drupalRoot . '/sites/default/default.settings.php', $drupalRoot . '/sites/default/settings.php');
require_once $drupalRoot . '/core/includes/bootstrap.inc';
require_once $drupalRoot . '/core/includes/install.inc';
$settings['config_directories'] = [
CONFIG_SYNC_DIRECTORY => (object) [
'value' => Path::makeRelative($drupalFinder->getComposerRoot() . '/config/sync', $drupalRoot),
'required' => TRUE,
],
];
drupal_rewrite_settings($settings, $drupalRoot . '/sites/default/settings.php');
$fs->chmod($drupalRoot . '/sites/default/settings.php', 0666);
$event->getIO()->write("Create a sites/default/settings.php file with chmod 0666");
}

// Create the files directory with chmod 0777
if (!$fs->exists($drupalRoot . '/sites/default/files')) {
$oldmask = umask(0);
$fs->mkdir($drupalRoot . '/sites/default/files', 0777);
umask($oldmask);
$event->getIO()->write("Create a sites/default/files directory with chmod 0777");
}
}

/**
* Checks if the installed version of Composer is compatible.
*
* Composer 1.0.0 and higher consider a `composer install` without having a
* lock file present as equal to `composer update`. We do not ship with a lock
* file to avoid merge conflicts downstream, meaning that if a project is
* installed with an older version of Composer the scaffolding of Drupal will
* not be triggered. We check this here instead of in drupal-scaffold to be
* able to give immediate feedback to the end user, rather than failing the
* installation after going through the lengthy process of compiling and
* downloading the Composer dependencies.
*
* @see https://github.com/composer/composer/pull/5035
*/
public static function checkComposerVersion(Event $event) {
$composer = $event->getComposer();
$io = $event->getIO();

$version = $composer::VERSION;

// The dev-channel of composer uses the git revision as version number,
// try to the branch alias instead.
if (preg_match('/^[0-9a-f]{40}$/i', $version)) {
$version = $composer::BRANCH_ALIAS_VERSION;
}

// If Composer is installed through git we have no easy way to determine if
// it is new enough, just display a warning.
if ($version === '@package_version@' || $version === '@package_branch_alias_version@') {
$io->writeError('<warning>You are running a development version of Composer. If you experience problems, please update Composer to the latest stable version.</warning>');
}
elseif (Comparator::lessThan($version, '1.0.0')) {
$io->writeError('<error>Drupal-project requires Composer version 1.0.0 or higher. Please update your Composer before continuing</error>.');
exit(1);
}
}

}

0 comments on commit 8cb0086

Please sign in to comment.