Skip to content
This repository has been archived by the owner on Apr 7, 2024. It is now read-only.

Commit

Permalink
Use new project and change some composer logic (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
dafeder authored Mar 24, 2021
1 parent 6df56f5 commit cbec2a0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 50 deletions.
17 changes: 4 additions & 13 deletions src/Command/InitCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,11 @@ class InitCommands extends \Robo\Tasks
* If no version constraint is provided via the --dkan option, dktl will
* attempt to generate one based on the current git branch in "dkan".
*/
public function init($opts = ['drupal' => '9.0.0', 'dkan' => null, 'dkan-local' => false])
public function init($opts = ['dkan' => null, 'dkan-local' => false])
{
// Validate version is semantic and at least the minimum set
// in DrupalProjectTrait.
if (!$this->drupalProjectValidateVersion($opts['drupal'])) {
exit;
}
$this->initConfig();
$this->initSrc();
$this->initDrupal($opts['drupal']);
$this->initDrupal();
if ($opts['dkan-local']) {
$this->initLocalDkan();
$version = $this->localDkanVersion();
Expand Down Expand Up @@ -197,23 +192,19 @@ private function initCircleCI()
/**
* Create a new Drupal project in the current directory. If one exists, it
* will be overwritten.
*
* @param mixed $drupalVersion
* Drupal version to use, expressed as Composer constraint.
*/
public function initDrupal($drupalVersion)
public function initDrupal()
{
$this->io()->section('Creating new Drupal project.');
Util::prepareTmp();

// Composer's create-project requires an empty folder, so run it in
// Util::Tmp, then move the 2 composer files back into project root.
$this->drupalProjectCreate($drupalVersion);
$this->drupalProjectCreate();
$this->drupalProjectMoveComposerFiles();

// Modify project's scaffold and installation paths to `docroot`, then
// install Drupal in it.
$this->drupalProjectSetDocrootPath();
if (!is_dir('docroot')) {
$this->_mkdir('docroot');
}
Expand Down
6 changes: 3 additions & 3 deletions src/Command/MakeCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ class MakeCommands extends Tasks
*/
public function make($opts = [
'prefer-source' => false,
'prefer-dist' => false,
'no-dev' => false,
'prefer-dist' => true,
'optimize-autoloader' => false,
'dev' => true,
])
{
$this->io()->section("Running dktl make");

// Run composer install while passing the options.
$composerInstall = $this->taskComposerInstall();
$composerOptions = ['prefer-source', 'prefer-dist', 'no-dev', 'optimize-autoloader'];
$composerOptions = ['prefer-source', 'prefer-dist', 'optimize-autoloader', 'dev'];
foreach ($composerOptions as $opt) {
if ($opts[$opt]) {
$composerInstall->option($opt);
Expand Down
22 changes: 3 additions & 19 deletions src/DrupalProjectTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ trait DrupalProjectTrait
*/
private static $drupalDocroot = 'docroot';

private function drupalProjectCreate(string $version)
private function drupalProjectCreate()
{
$projectSource = "drupal/recommended-project:{$version}";
$projectSource = "getdkan/recommended-project:9.x-dev";
$createFiles = $this->taskComposerCreateProject()
->source($projectSource)
->target(Util::TMP_DIR)
->preferDist(true)
->noInstall()
->run();
if ($createFiles->getExitCode() != 0) {
Expand Down Expand Up @@ -66,23 +67,6 @@ private function drupalProjectMoveComposerFiles()
$this->io()->success('composer.json moved to project root.');
}

/**
* Rewrite composer.json with correct docroot.
*/
private function drupalProjectSetDocrootPath()
{
$docroot = self::$drupalDocroot;
$regexps = "s#web/#" . $docroot . "/#g";
$installationPaths = $this->taskExec("sed -i -E '{$regexps}'")
->arg('composer.json')
->run();
if ($installationPaths->getExitCode() != 0) {
$this->io()->error('Unable to modify composer.json paths.');
exit;
}
$this->io()->success("Composer installation paths modified to {$docroot}.");
}

/**
* Validate the Drupal version provided.
*
Expand Down
19 changes: 4 additions & 15 deletions tests/dktl_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,9 @@ testUninitialized() {
}

testDktlInitWithBadParameter() {
result=`dktl init --drupal=foobar`
assertContains "${result}" "[ERROR] version format not semantic.";
}

testDktlInitDrupalVersionLessThanMinimum()
{
result=`dktl init --drupal=8.7.1`;
assertContains "${result}" "[ERROR] drupal version below minimal required."
}

testDktlInitDrupalVersionMoreThanMaximum()
{
result=`dktl init --drupal=77.7.7`
assertContains "${result}" "Could not find package drupal/recommended-project with version 77.7.7."
result=`dktl init --dkan=foobar`
assertContains "${result}" "Could not parse version constraint foobar"
rm -rf composer.* dktl.yml docrot src
}

testDktlInit() {
Expand Down Expand Up @@ -82,7 +71,7 @@ testDktlInstall() {
result=`curl $url/user/login`
assertContains "${result}" "Enter your DKAN username"
result=`dktl install:sample`
assertContains "${result}" "Processed 30 items from the datastore_import"
assertContains "${result}" "Processed 10 items from the datastore_import"
}

testFrontEnd() {
Expand Down

0 comments on commit cbec2a0

Please sign in to comment.